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");
}
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();
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations