Search in sources :

Example 26 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class DeploymentServiceWithSyncTest method testDeploymentOfProcessesBySync.

@Test
public void testDeploymentOfProcessesBySync() throws Exception {
    CoundDownDeploymentListener countDownListener = configureListener(1, true, false, false, false);
    Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits();
    assertNotNull(deployed);
    assertEquals(0, deployed.size());
    KModuleDeploymentUnit unit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    store.enableDeploymentUnit(unit);
    units.add(unit);
    countDownListener.waitTillCompleted(10000);
    deployed = deploymentService.getDeployedUnits();
    assertNotNull(deployed);
    assertEquals(1, deployed.size());
}
Also used : CoundDownDeploymentListener(org.jbpm.kie.services.test.objects.CoundDownDeploymentListener) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 27 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class DeploymentServiceWithSyncTest method testUndeploymentOfProcessesBySync.

@Test
public void testUndeploymentOfProcessesBySync() throws Exception {
    CoundDownDeploymentListener countDownListener = configureListener(1, false, true, false, false);
    Collection<DeployedUnit> deployed = deploymentService.getDeployedUnits();
    assertNotNull(deployed);
    assertEquals(0, deployed.size());
    KModuleDeploymentUnit unit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(unit);
    units.add(unit);
    deployed = deploymentService.getDeployedUnits();
    assertNotNull(deployed);
    assertEquals(1, deployed.size());
    countDownListener.waitTillCompleted(1000);
    store.disableDeploymentUnit(unit);
    countDownListener.waitTillCompleted(10000);
    deployed = deploymentService.getDeployedUnits();
    assertNotNull(deployed);
    assertEquals(0, deployed.size());
}
Also used : CoundDownDeploymentListener(org.jbpm.kie.services.test.objects.CoundDownDeploymentListener) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 28 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class DeploymentSynchronizer method synchronize.

public synchronized void synchronize() {
    try {
        Collection<DeploymentUnit> enabledSet = new HashSet<DeploymentUnit>();
        Collection<DeploymentUnit> disabledSet = new HashSet<DeploymentUnit>();
        Collection<DeploymentUnit> activatedSet = new HashSet<DeploymentUnit>();
        Collection<DeploymentUnit> deactivatedSet = new HashSet<DeploymentUnit>();
        Date timeOfSync = new Date();
        if (lastSync == null) {
            // initial load
            enabledSet = deploymentStore.getEnabledDeploymentUnits();
            deactivatedSet = deploymentStore.getDeactivatedDeploymentUnits();
        } else {
            deploymentStore.getDeploymentUnitsByDate(lastSync, enabledSet, disabledSet, activatedSet, deactivatedSet);
        }
        // update last sync date with time taken just before the query time
        this.lastSync = timeOfSync;
        logger.debug("About to synchronize deployment units, found new enabled {}, found new disabled {}", enabledSet, disabledSet);
        if (enabledSet != null) {
            for (DeploymentUnit unit : enabledSet) {
                if (!entries.containsKey(unit.getIdentifier()) && deploymentService.getDeployedUnit(unit.getIdentifier()) == null) {
                    try {
                        logger.debug("New deployment unit to be deployed {}", unit);
                        entries.put(unit.getIdentifier(), unit);
                        deploymentService.deploy(unit);
                    } catch (Exception e) {
                        entries.remove(unit.getIdentifier());
                        logger.warn("Deployment unit {} failed to deploy: {}", unit.getIdentifier(), e.getMessage());
                    }
                }
            }
        }
        if (disabledSet != null) {
            for (DeploymentUnit unit : disabledSet) {
                if (entries.containsKey(unit.getIdentifier()) && deploymentService.getDeployedUnit(unit.getIdentifier()) != null) {
                    try {
                        logger.debug("Existing deployment unit {} to be undeployed", unit.getIdentifier());
                        entries.remove(unit.getIdentifier());
                        deploymentService.undeploy(unit);
                    } catch (Exception e) {
                        logger.warn("Deployment unit {} failed to undeploy: {}", unit.getIdentifier(), e.getMessage(), e);
                        entries.put(unit.getIdentifier(), unit);
                        deploymentStore.markDeploymentUnitAsObsolete(unit);
                    }
                }
            }
        }
        logger.debug("About to synchronize deployment units, found new activated {}, found new deactivated {}", activatedSet, deactivatedSet);
        if (activatedSet != null) {
            for (DeploymentUnit unit : activatedSet) {
                DeployedUnit deployed = deploymentService.getDeployedUnit(unit.getIdentifier());
                if (deployed != null && !deployed.isActive()) {
                    deploymentService.activate(unit.getIdentifier());
                }
            }
        }
        if (deactivatedSet != null) {
            for (DeploymentUnit unit : deactivatedSet) {
                DeployedUnit deployed = deploymentService.getDeployedUnit(unit.getIdentifier());
                if (deployed != null && deployed.isActive()) {
                    deploymentService.deactivate(unit.getIdentifier());
                }
            }
        }
    } catch (Throwable e) {
        logger.error("Error while synchronizing deployments: {}", e.getMessage(), e);
    }
}
Also used : DeployedUnit(org.jbpm.services.api.model.DeployedUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) Date(java.util.Date) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) HashSet(java.util.HashSet)

Example 29 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class DeploymentServiceEJBIntegrationTest method testDeploymentOfProcessesVerifyTransientObjectOmitted.

@Test
public void testDeploymentOfProcessesVerifyTransientObjectOmitted() {
    assertNotNull(deploymentService);
    assertNotNull(commandService);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertNotNull(runtimeDataService);
    Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
    assertNotNull(processes);
    assertEquals(5, processes.size());
    DeploymentStore store = new DeploymentStore();
    store.setCommandService(commandService);
    Collection<DeploymentUnit> units = store.getEnabledDeploymentUnits();
    assertNotNull(units);
    assertEquals(1, units.size());
    DeploymentUnit enabled = units.iterator().next();
    assertNotNull(enabled);
    assertTrue(enabled instanceof KModuleDeploymentUnit);
    KModuleDeploymentUnit kmoduleEnabled = (KModuleDeploymentUnit) enabled;
    DeploymentDescriptor dd = kmoduleEnabled.getDeploymentDescriptor();
    assertNotNull(dd);
    // ejb deployment service add transitively Async WorkItem handler that should not be stored as part of deployment store
    assertEquals(0, dd.getWorkItemHandlers().size());
}
Also used : DeploymentStore(org.jbpm.kie.services.impl.store.DeploymentStore) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Test(org.junit.Test)

Example 30 with DeployedUnit

use of org.jbpm.services.api.model.DeployedUnit in project jbpm by kiegroup.

the class DeploymentServiceEJBIntegrationTest method testDeploymentOfAllProcesses.

@Test
public void testDeploymentOfAllProcesses() {
    assertNotNull(deploymentService);
    // deploy first unit
    DeploymentUnit deploymentUnitGeneral = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnitGeneral);
    units.add(deploymentUnitGeneral);
    RuntimeManager managerGeneral = deploymentService.getRuntimeManager(deploymentUnitGeneral.getIdentifier());
    assertNotNull(managerGeneral);
    // deploy second unit
    DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, "support", VERSION);
    deploymentService.deploy(deploymentUnitSupport);
    units.add(deploymentUnitSupport);
    DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnitGeneral.getIdentifier());
    assertNotNull(deployedGeneral);
    assertNotNull(deployedGeneral.getDeploymentUnit());
    assertNotNull(deployedGeneral.getRuntimeManager());
    RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier());
    assertNotNull(managerSupport);
    DeployedUnit deployedSupport = deploymentService.getDeployedUnit(deploymentUnitSupport.getIdentifier());
    assertNotNull(deployedSupport);
    assertNotNull(deployedSupport.getDeploymentUnit());
    assertNotNull(deployedSupport.getRuntimeManager());
    // execute process that is bundled in first deployment unit
    RuntimeEngine engine = managerGeneral.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", "test");
    ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    // execute process that is in second deployment unit
    RuntimeEngine engineSupport = managerSupport.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engineSupport);
    ProcessInstance supportPI = engineSupport.getKieSession().startProcess("support.process");
    assertEquals(ProcessInstance.STATE_ACTIVE, supportPI.getState());
    List<TaskSummary> tasks = engineSupport.getTaskService().getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    engineSupport.getKieSession().abortProcessInstance(supportPI.getId());
    assertNull(engineSupport.getKieSession().getProcessInstance(supportPI.getState()));
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Test(org.junit.Test)

Aggregations

DeployedUnit (org.jbpm.services.api.model.DeployedUnit)69 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)42 Test (org.junit.Test)41 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)38 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)37 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)32 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)30 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)28 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)20 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)19 QueryContext (org.kie.api.runtime.query.QueryContext)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 KieSession (org.kie.api.runtime.KieSession)17 HashMap (java.util.HashMap)16 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)13 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)10 ArrayList (java.util.ArrayList)8 CoundDownDeploymentListener (org.jbpm.kie.services.test.objects.CoundDownDeploymentListener)8 File (java.io.File)7