Search in sources :

Example 31 with DeploymentUnit

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

the class BPMN2DataServicesTest method testGetProcessDefinitionUndeployedDeploymentUnit.

@Test(expected = DeploymentNotFoundException.class)
public void testGetProcessDefinitionUndeployedDeploymentUnit() throws IOException {
    assertNotNull(deploymentService);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    deploymentService.undeploy(deploymentUnit);
    bpmn2Service.getProcessDefinition(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
}
Also used : KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 32 with DeploymentUnit

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

the class ClassloaderKModuleDeploymentServiceTest method cleanup.

@After
public void cleanup() {
    cleanupSingletonSessionId();
    if (units != null && !units.isEmpty()) {
        for (DeploymentUnit unit : units) {
            deploymentService.undeploy(unit);
        }
        units.clear();
    }
    close();
}
Also used : DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) After(org.junit.After)

Example 33 with DeploymentUnit

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

the class DeploymentStore method getEnabledDeploymentUnits.

public Collection<DeploymentUnit> getEnabledDeploymentUnits() {
    List<DeploymentUnit> activeDeployments = new ArrayList<DeploymentUnit>();
    Map<String, Object> params = new HashMap<String, Object>();
    List<Integer> states = new ArrayList<Integer>();
    states.add(STATE_ENABLED);
    states.add(STATE_ACTIVATED);
    states.add(STATE_DEACTIVATED);
    params.put("state", states);
    List<DeploymentStoreEntry> deployments = commandService.execute(new QueryNameCommand<List<DeploymentStoreEntry>>("getDeploymentUnitsByState", params));
    for (DeploymentStoreEntry entry : deployments) {
        String sync = getEntryAttributes(entry.getAttributes()).get("sync");
        // add to the deployable list only sync flag is set to true or does not exists (default)
        if (sync == null || sync.equalsIgnoreCase("true")) {
            DeploymentUnit unit = (DeploymentUnit) xstream.fromXML(entry.getDeploymentUnit());
            if (entry.getState() == STATE_DEACTIVATED) {
                ((KModuleDeploymentUnit) unit).setActive(false);
            }
            activeDeployments.add(unit);
        }
    }
    return activeDeployments;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) ArrayList(java.util.ArrayList) List(java.util.List) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit)

Example 34 with DeploymentUnit

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

the class DeploymentStore method getDeploymentUnitsByDate.

public void getDeploymentUnitsByDate(Date date, Collection<DeploymentUnit> enabled, Collection<DeploymentUnit> disabled, Collection<DeploymentUnit> activated, Collection<DeploymentUnit> deactivated) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("ludate", date);
    List<DeploymentStoreEntry> deployments = commandService.execute(new QueryNameCommand<List<DeploymentStoreEntry>>("getDeploymentUnitsByDate", params));
    for (DeploymentStoreEntry entry : deployments) {
        String sync = getEntryAttributes(entry.getAttributes()).get("sync");
        // add to the deployable list only sync flag is set to true or does not exists (default)
        if (sync == null || sync.equalsIgnoreCase("true")) {
            DeploymentUnit unit = (DeploymentUnit) xstream.fromXML(entry.getDeploymentUnit());
            if (entry.getState() == STATE_ENABLED) {
                enabled.add(unit);
            } else if (entry.getState() == STATE_DISABLED) {
                disabled.add(unit);
            } else if (entry.getState() == STATE_ACTIVATED) {
                activated.add(unit);
            } else if (entry.getState() == STATE_DEACTIVATED) {
                ((KModuleDeploymentUnit) unit).setActive(false);
                deactivated.add(unit);
            } else {
                logger.warn("Unknown state of deployment store entry {} for {} will be ignored", entry.getId(), entry);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit)

Example 35 with DeploymentUnit

use of org.jbpm.services.api.model.DeploymentUnit 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)

Aggregations

DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)104 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)88 Test (org.junit.Test)53 After (org.junit.After)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)34 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)28 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)25 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)19 HashMap (java.util.HashMap)16 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)15 ArrayList (java.util.ArrayList)14 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 QueryContext (org.kie.api.runtime.query.QueryContext)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 KieServices (org.kie.api.KieServices)10 ReleaseId (org.kie.api.builder.ReleaseId)10 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)9 AbstractEJBServicesTest (org.jbpm.test.container.AbstractEJBServicesTest)8 Collection (java.util.Collection)6 DeployedUnitImpl (org.jbpm.kie.services.impl.DeployedUnitImpl)6