Search in sources :

Example 1 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ProcessDefinitionCacheTest method testDeployRevisedProcessAfterDeleteOnOtherProcessEngine.

public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() {
    // Setup both process engines
    ProcessEngine processEngine1 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test-schema").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService1 = processEngine1.getRepositoryService();
    ProcessEngine processEngine2 = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000").setJobExecutorActivate(false).buildProcessEngine();
    RepositoryService repositoryService2 = processEngine2.getRepositoryService();
    RuntimeService runtimeService2 = processEngine2.getRuntimeService();
    TaskService taskService2 = processEngine2.getTaskService();
    // Deploy first version of process: start->originalTask->end on first process engine
    String deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second engine
    String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceById(processDefinitionId);
    Task task = taskService2.createTaskQuery().singleResult();
    assertEquals("original task", task.getName());
    // Delete the deployment on second process engine
    repositoryService2.deleteDeployment(deploymentId, true);
    assertEquals(0, repositoryService2.createDeploymentQuery().count());
    assertEquals(0, runtimeService2.createProcessInstanceQuery().count());
    // deploy a revised version of the process: start->revisedTask->end on first process engine
    //
    // Before the bugfix, this would set the cache on the first process engine,
    // but the second process engine still has the original process definition in his cache.
    // Since there is a deployment delete in between, the new generated process definition id is the same 
    // as in the original deployment, making the second process engine using the old cached process definition.
    deploymentId = repositoryService1.createDeployment().addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml").deploy().getId();
    // Start process instance on second process engine -> must use revised process definition
    repositoryService2.createProcessDefinitionQuery().singleResult().getId();
    runtimeService2.startProcessInstanceByKey("oneTaskProcess");
    task = taskService2.createTaskQuery().singleResult();
    assertEquals("revised task", task.getName());
    // cleanup
    repositoryService1.deleteDeployment(deploymentId, true);
    processEngine1.close();
    processEngine2.close();
}
Also used : Task(org.activiti.engine.task.Task) StandaloneProcessEngineConfiguration(org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration) RuntimeService(org.activiti.engine.RuntimeService) TaskService(org.activiti.engine.TaskService) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 2 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class DeploymentsJMXClientTest method testDeploymentsJmxClient.

@SuppressWarnings("unchecked")
@Test
public void testDeploymentsJmxClient() throws IOException, InterruptedException, MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException, IntrospectionException {
    String hostName = Utils.getHostName();
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostName + ":10111/jndi/rmi://" + hostName + ":1099/jmxrmi/activiti");
    ProcessEngineConfiguration processEngineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    ProcessEngine processEngine = processEngineConfig.buildProcessEngine();
    // wait for jmx server to come up
    Thread.sleep(500);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName deploymentsBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=Deployments");
    Thread.sleep(500);
    // no process deployed yet
    List<List<String>> deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertEquals(0, deployments.size());
    // deploy process remotely
    URL fileName = Thread.currentThread().getContextClassLoader().getResource("org/activiti/management/jmx/trivialProcess.bpmn");
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // one process is there now, test remote deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    String firstDeploymentId = deployments.get(0).get(0);
    // test remote process definition
    List<List<String>> pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(1, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertNotNull(pdList.get(0).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    // version
    assertEquals("1", pdList.get(0).get(2));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    // redeploy the same process
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // now there should be two deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(2, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertEquals(3, deployments.get(1).size());
    // there should be two process definitions, one with version equals to two
    pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(2, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertEquals(5, pdList.get(1).size());
    // check there is one with version= = 1 and another one with version == 2, other attributed are the same
    String pidV2 = null;
    String pidV1 = null;
    if (pdList.get(0).get(2).equals("1") && pdList.get(1).get(2).equals("2")) {
        pidV2 = pdList.get(1).get(0);
        pidV1 = pdList.get(0).get(0);
    } else if (pdList.get(1).get(2).equals("1") && pdList.get(0).get(2).equals("2")) {
        pidV2 = pdList.get(0).get(0);
        pidV1 = pdList.get(1).get(0);
    } else
        fail("there should one process definition with version == 1 and another one with version == 2. It is not the case");
    assertNotNull(pdList.get(0).get(0));
    assertNotNull(pdList.get(1).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    assertEquals("My process", pdList.get(1).get(1));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    // not suspended
    assertEquals("false", pdList.get(1).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    assertEquals("This process to test JMX", pdList.get(1).get(4));
    //suspend the one with version == 2    
    mbsc.invoke(deploymentsBeanName, "suspendProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // test if it is realy suspended and not the other one
    assertTrue(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if it is reported as suspended and not the other one
    List<String> pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("true", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now reactivate the same suspended process 
    mbsc.invoke(deploymentsBeanName, "activatedProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    // test if both processes are active again
    assertFalse(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if they are properly reported as activated
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now undeploy the one with version == 1
    mbsc.invoke(deploymentsBeanName, "deleteDeployment", new String[] { firstDeploymentId }, new String[] { String.class.getName() });
    // now there should be only one deployment and only one process definition with version 2, first check it with API
    assertEquals(1, repositoryService.createDeploymentQuery().count());
    assertTrue(!repositoryService.createDeploymentQuery().singleResult().getId().equals(firstDeploymentId));
    // check if it is also affected in returned results.
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertTrue(!deployments.get(0).get(0).equals(firstDeploymentId));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) JMXConnector(javax.management.remote.JMXConnector) List(java.util.List) MBeanServerConnection(javax.management.MBeanServerConnection) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngine(org.activiti.engine.ProcessEngine) ObjectName(javax.management.ObjectName) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 3 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class ReportingUtil method generateTaskDurationReport.

// WARNING!!! DemoWare!!!
public static void generateTaskDurationReport(String processDefinitionId) {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // Fetch process definition
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
    // Report descriptin
    String reportDescription = "Average task duration report for process definition " + processDefinition.getName() + " ( version " + processDefinition.getVersion() + ")";
    // Script (just plain String for the moment)
    String script = "importPackage(java.sql);" + "importPackage(java.lang);" + "importPackage(org.activiti.explorer.reporting);" + "" + "var processDefinitionId = '" + processDefinitionId + "';" + "" + "var result = ReportingUtil.executeSelectSqlQuery(\"select NAME_, avg(DURATION_) from ACT_HI_TASKINST where PROC_DEF_ID_ = '" + processDefinitionId + "' and END_TIME_ is not null group by NAME_\");" + "" + "var reportData = new ReportData();" + "var dataset = reportData.newDataset();" + "dataset.type = 'pieChart';" + "dataset.description = '" + reportDescription + "';" + "" + "while (result.next()) { " + "  var name = result.getString(1);" + "  var val = result.getLong(2) / 1000;" + "  dataset.add(name, val);" + "}" + "" + "execution.setVariable('reportData', reportData.toBytes());";
    // Generate bpmn model
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name(processDefinition.getName() + " task duration report").description(reportDescription).addScriptStep(script);
    // Convert to BPMN 2.0 XML
    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    conversion.getBpmnModel().setTargetNamespace("activiti-report");
    // Generate DI
    BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(conversion.getBpmnModel());
    bpmnAutoLayout.execute();
    // Deploy
    repositoryService.createDeployment().name(processDefinition.getName() + " - task duration report").addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml()).deploy();
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 4 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class IntegrationAutoConfigurationTest method testLaunchingGatewayProcessDefinition.

@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
    AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);
    RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
    RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
    Assert.assertNotNull("the process engine should not be null", processEngine);
    Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
    String integrationGatewayProcess = "integrationGatewayProcess";
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionKey(integrationGatewayProcess).list();
    ProcessDefinition processDefinition = processDefinitionList.iterator().next();
    Assert.assertEquals(processDefinition.getKey(), integrationGatewayProcess);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("customerId", 232);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
    Assert.assertNotNull("the processInstance should not be null", processInstance);
    org.junit.Assert.assertTrue(applicationContext.getBean(InboundGatewayConfiguration.AnalysingService.class).getStringAtomicReference().get().equals(projectId));
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RuntimeService(org.activiti.engine.RuntimeService) HashMap(java.util.HashMap) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) RepositoryService(org.activiti.engine.RepositoryService) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 5 with ProcessEngine

use of org.activiti.engine.ProcessEngine in project Activiti by Activiti.

the class SpringProcessEngineConfiguration method buildProcessEngine.

@Override
public ProcessEngine buildProcessEngine() {
    ProcessEngine processEngine = super.buildProcessEngine();
    ProcessEngines.setInitialized(true);
    autoDeployResources(processEngine);
    return processEngine;
}
Also used : ProcessEngine(org.activiti.engine.ProcessEngine)

Aggregations

ProcessEngine (org.activiti.engine.ProcessEngine)31 Test (org.junit.Test)13 RepositoryService (org.activiti.engine.RepositoryService)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 ActivitiException (org.activiti.engine.ActivitiException)6 RuntimeService (org.activiti.engine.RuntimeService)6 TaskService (org.activiti.engine.TaskService)4 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)4 StandaloneProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration)4 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 Task (org.activiti.engine.task.Task)4 StandaloneInMemProcessEngineConfiguration (org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)3 Deployment (org.activiti.engine.repository.Deployment)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1