[jbpm-commits] JBoss JBPM SVN: r4182 - in jbpm4/branches/hbraun/modules: integration/jboss5/src/main/java/org/jbpm/integration/jboss5 and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Mar 6 15:29:02 EST 2009
Author: heiko.braun at jboss.com
Date: 2009-03-06 15:29:01 -0500 (Fri, 06 Mar 2009)
New Revision: 4182
Modified:
jbpm4/branches/hbraun/modules/integration/jboss5/scripts/assembly-config.xml
jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java
jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java
Log:
Implement undeployment
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/scripts/assembly-config.xml
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/scripts/assembly-config.xml 2009-03-06 19:33:49 UTC (rev 4181)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/scripts/assembly-config.xml 2009-03-06 20:29:01 UTC (rev 4182)
@@ -11,7 +11,7 @@
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*beans.xml</include>
- <exclude>**/jbpm.deployer.cfg.xml</exclude>
+ <include>**/jbpm.deployer.cfg.xml</include>
</includes>
</fileSet>
</fileSets>
Modified: jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java
===================================================================
--- jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java 2009-03-06 19:33:49 UTC (rev 4181)
+++ jbpm4/branches/hbraun/modules/integration/jboss5/src/main/java/org/jbpm/integration/jboss5/JBPMDeployer.java 2009-03-06 20:29:01 UTC (rev 4182)
@@ -26,21 +26,27 @@
import org.jboss.deployers.vfs.spi.deployer.AbstractSimpleVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jbpm.Deployment;
+import org.jbpm.ProcessDefinition;
import org.jbpm.ProcessService;
-import org.jbpm.env.Environment;
-import org.jbpm.env.EnvironmentFactory;
import org.jbpm.integration.spi.JBPMService;
import org.jbpm.integration.spi.JBPMServiceLocator;
import org.jbpm.internal.log.Log;
import javax.naming.InitialContext;
+import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
-import javax.transaction.SystemException;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
/**
* Deploys JBPM processes and associates a classloader.
+ * <p>
+ * Upon undeployment the existance of the deployment artifact will be checked,
+ * and if deleted, the process will be removed.
*
+ * @see org.jbpm.integration.spi.JBPMServiceLocator
+ *
* @author Heiko.Braun <heiko.braun at jboss.com>
*/
public class JBPMDeployer extends AbstractSimpleVFSRealDeployer<JBPMDeploymentMetaData>
@@ -72,7 +78,6 @@
tx = (UserTransaction)ctx.lookup("UserTransaction");
tx.begin();
-
// deploy to process engine
ProcessService processService = jbpmService.getProcessEngine().getProcessService();
@@ -82,10 +87,27 @@
Deployment dpl = processService.createDeployment()
.addUrl(deployment.getProcessDescriptor())
.addObject("jbpmdeployer.deploymentArtifact.timestamp", Long.valueOf(deploymentFile.lastModified()))
- .addObject("jbpmdeployer.deploymentArtifact.location", deployment.getDeploymentUnit());
+ .addObject("jbpmdeployer.deploymentArtifact.location", unit.getTopLevel().getRoot().toURL().getPath());
- dpl.deploy();
+ List<ProcessDefinition> processesInScope =
+ dpl
+ .deploy()
+ .getProcessDefinitions();
+ // pass reference to the deployment unit for undeployment
+ List<ProcessDeploymentRef> processRefs = new ArrayList<ProcessDeploymentRef>();
+ for(ProcessDefinition pd : processesInScope)
+ {
+ ProcessDeploymentRef ref = new ProcessDeploymentRef(
+ pd.getId(),
+ pd.getVersion(),
+ unit.getTopLevel().getRoot().toURL().getPath()
+ );
+ processRefs.add(ref);
+ }
+
+ unit.addAttachment("jbpmdeployer.reference", processRefs);
+
tx.commit();
}
@@ -99,7 +121,7 @@
}
catch (SystemException e1) {}
}
-
+
throw new DeploymentException("Failed to deploy process", e);
}
@@ -109,6 +131,75 @@
{
log.info("Undeploy "+deployment);
- super.undeploy(unit, deployment);
+ UserTransaction tx = null;
+
+ try
+ {
+
+ List<ProcessDeploymentRef> processRefs =
+ (List<ProcessDeploymentRef>)unit.getAttachment("jbpmdeployer.reference");
+
+ if(null==processRefs)
+ {
+ log.info("Failed to retrieve process reference information. Ignore undepoyment call: "+ deployment);
+ return;
+ }
+
+ JBPMService jbpmService = JBPMServiceLocator.locateService();
+ ProcessService processService = jbpmService.getProcessEngine().getProcessService();
+
+ InitialContext ctx = new InitialContext();
+ tx = (UserTransaction)ctx.lookup("UserTransaction");
+
+ tx.begin();
+
+ for(ProcessDeploymentRef ref : processRefs)
+ {
+ // if the physical artifact has been removed the process can be deleted
+ File deploymentArtifact = new File(ref.location);
+ if(!deploymentArtifact.exists())
+ {
+ log.info("The deployment artifact for process '"+ref+" has been removed."+
+ " The process will be deleted");
+
+ processService.deleteProcessDefinition(ref.processId);
+ }
+ }
+
+ tx.commit();
+
+ }
+ catch(Exception e)
+ {
+ if(tx!=null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ catch (SystemException e1) {}
+ }
+
+ }
}
+
+ final class ProcessDeploymentRef
+ {
+ String processId;
+ int version;
+ String location;
+
+ public ProcessDeploymentRef(String processId, int version, String location)
+ {
+ this.processId = processId;
+ this.version = version;
+ this.location = location;
+ }
+
+
+ public String toString()
+ {
+ return "ProcessDeploymentRef {id="+processId+", version="+version+", location="+location+"}";
+ }
+ }
}
Modified: jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java
===================================================================
--- jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java 2009-03-06 19:33:49 UTC (rev 4181)
+++ jbpm4/branches/hbraun/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/VersionTimestampPolicy.java 2009-03-06 20:29:01 UTC (rev 4182)
@@ -65,11 +65,11 @@
// @see JBPMDeployer, it provides the timestamp
long currentTimestamp = (Long)deployment.getObject(DEPLOYER_TIMESTAMP);
- URL deloymentLocation = (URL)deployment.getObject(DEPLOYER_LOCATION);
+ String deloymentLocation = (String)deployment.getObject(DEPLOYER_LOCATION);
// provide evaluation properties
evaluation.getResults().put(DEPLOYER_TIMESTAMP, String.valueOf(currentTimestamp));
- evaluation.getResults().put(DEPLOYER_LOCATION, String.valueOf(deloymentLocation.getPath()));
+ evaluation.getResults().put(DEPLOYER_LOCATION, String.valueOf(deloymentLocation));
// can either be key or name given
String identifier = nameAttribute!=null ? nameAttribute : keyAttribute;
More information about the jbpm-commits
mailing list