use of org.camunda.bpm.application.ProcessApplicationRegistration in project camunda-bpm-platform by camunda.
the class DeployCmd method doExecute.
protected DeploymentWithDefinitions doExecute(final CommandContext commandContext) {
DeploymentManager deploymentManager = commandContext.getDeploymentManager();
Set<String> deploymentIds = getAllDeploymentIds(deploymentBuilder);
if (!deploymentIds.isEmpty()) {
String[] deploymentIdArray = deploymentIds.toArray(new String[deploymentIds.size()]);
List<DeploymentEntity> deployments = deploymentManager.findDeploymentsByIds(deploymentIdArray);
ensureDeploymentsWithIdsExists(deploymentIds, deployments);
}
checkCreateAndReadDeployments(commandContext, deploymentIds);
// set deployment name if it should retrieved from an existing deployment
String nameFromDeployment = deploymentBuilder.getNameFromDeployment();
setDeploymentName(nameFromDeployment, deploymentBuilder, commandContext);
// get resources to re-deploy
List<ResourceEntity> resources = getResources(deploymentBuilder, commandContext);
// .. and add them the builder
addResources(resources, deploymentBuilder);
Collection<String> resourceNames = deploymentBuilder.getResourceNames();
if (resourceNames == null || resourceNames.isEmpty()) {
throw new NotValidException("No deployment resources contained to deploy.");
}
// perform deployment
DeploymentWithDefinitions deployment = commandContext.runWithoutAuthorization(new Callable<DeploymentWithDefinitions>() {
@Override
public DeploymentWithDefinitions call() throws Exception {
acquireExclusiveLock(commandContext);
DeploymentEntity deployment = initDeployment();
Map<String, ResourceEntity> resourcesToDeploy = resolveResourcesToDeploy(commandContext, deployment);
Map<String, ResourceEntity> resourcesToIgnore = new HashMap<String, ResourceEntity>(deployment.getResources());
resourcesToIgnore.keySet().removeAll(resourcesToDeploy.keySet());
if (!resourcesToDeploy.isEmpty()) {
LOG.debugCreatingNewDeployment();
deployment.setResources(resourcesToDeploy);
deploy(deployment);
} else {
LOG.usingExistingDeployment();
deployment = getExistingDeployment(commandContext, deployment.getName());
}
scheduleProcessDefinitionActivation(commandContext, deployment);
if (deploymentBuilder instanceof ProcessApplicationDeploymentBuilder) {
// for process application deployments, job executor registration is managed by
// process application manager
Set<String> processesToRegisterFor = retrieveProcessKeysFromResources(resourcesToIgnore);
ProcessApplicationRegistration registration = registerProcessApplication(commandContext, deployment, processesToRegisterFor);
return new ProcessApplicationDeploymentImpl(deployment, registration);
} else {
registerWithJobExecutor(commandContext, deployment);
}
return deployment;
}
});
createUserOperationLog(deploymentBuilder, deployment, commandContext);
return deployment;
}
use of org.camunda.bpm.application.ProcessApplicationRegistration in project camunda-bpm-platform by camunda.
the class ProcessApplicationDeploymentTest method testPartialChangesResumePreviousVersionByDeploymentName.
public void testPartialChangesResumePreviousVersionByDeploymentName() {
BpmnModelInstance model1 = Bpmn.createExecutableProcess("process1").done();
BpmnModelInstance model2 = Bpmn.createExecutableProcess("process2").done();
// create initial deployment
ProcessApplicationDeployment deployment1 = repositoryService.createDeployment(processApplication.getReference()).name("deployment").addModelInstance("process1.bpmn20.xml", model1).deploy();
ProcessApplicationDeployment deployment2 = repositoryService.createDeployment(processApplication.getReference()).name("deployment").enableDuplicateFiltering(true).resumePreviousVersions().resumePreviousVersionsBy(ResumePreviousBy.RESUME_BY_DEPLOYMENT_NAME).addModelInstance("process1.bpmn20.xml", model1).addModelInstance("process2.bpmn20.xml", model2).deploy();
ProcessApplicationRegistration registration = deployment2.getProcessApplicationRegistration();
assertEquals(2, registration.getDeploymentIds().size());
deleteDeployments(deployment1, deployment2);
}
use of org.camunda.bpm.application.ProcessApplicationRegistration in project camunda-bpm-platform by camunda.
the class RedeploymentTest method testProcessApplicationDeploymentResumePreviousVersionsByDeploymentName.
public void testProcessApplicationDeploymentResumePreviousVersionsByDeploymentName() {
// given
EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication();
// first deployment
BpmnModelInstance model = createProcessWithServiceTask(PROCESS_KEY);
ProcessApplicationDeployment deployment1 = repositoryService.createDeployment(processApplication.getReference()).name(DEPLOYMENT_NAME).addModelInstance(RESOURCE_NAME, model).enableDuplicateFiltering(true).deploy();
Resource resource1 = getResourceByName(deployment1.getId(), RESOURCE_NAME);
// second deployment
model = createProcessWithUserTask(PROCESS_KEY);
ProcessApplicationDeployment deployment2 = repositoryService.createDeployment(processApplication.getReference()).name(DEPLOYMENT_NAME).addModelInstance(RESOURCE_NAME, model).enableDuplicateFiltering(true).deploy();
// when
ProcessApplicationDeployment deployment3 = repositoryService.createDeployment(processApplication.getReference()).name(DEPLOYMENT_NAME).resumePreviousVersions().resumePreviousVersionsBy(ResumePreviousBy.RESUME_BY_DEPLOYMENT_NAME).addDeploymentResourceById(deployment1.getId(), resource1.getId()).deploy();
// then
// old deployment was resumed
ProcessApplicationRegistration registration = deployment3.getProcessApplicationRegistration();
Set<String> deploymentIds = registration.getDeploymentIds();
assertEquals(3, deploymentIds.size());
deleteDeployments(deployment1, deployment2, deployment3);
}
use of org.camunda.bpm.application.ProcessApplicationRegistration in project camunda-bpm-platform by camunda.
the class RedeploymentTest method testSimpleProcessApplicationDeployment.
public void testSimpleProcessApplicationDeployment() {
// given
EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication();
BpmnModelInstance model = createProcessWithServiceTask(PROCESS_KEY);
ProcessApplicationDeployment deployment1 = repositoryService.createDeployment(processApplication.getReference()).name(DEPLOYMENT_NAME).addModelInstance(RESOURCE_NAME, model).enableDuplicateFiltering(true).deploy();
Resource resource1 = getResourceByName(deployment1.getId(), RESOURCE_NAME);
// when
ProcessApplicationDeployment deployment2 = repositoryService.createDeployment(processApplication.getReference()).name(DEPLOYMENT_NAME).addDeploymentResourceById(deployment1.getId(), resource1.getId()).deploy();
// then
// registration was performed:
ProcessApplicationRegistration registration = deployment2.getProcessApplicationRegistration();
Set<String> deploymentIds = registration.getDeploymentIds();
assertEquals(1, deploymentIds.size());
assertTrue(deploymentIds.contains(deployment2.getId()));
deleteDeployments(deployment1, deployment2);
}
use of org.camunda.bpm.application.ProcessApplicationRegistration in project camunda-bpm-platform by camunda.
the class ProcessApplicationDeploymentTest method testPartialChangesDeployChangedOnly.
/**
* Test re-deployment of only those resources that have actually changed
*/
public void testPartialChangesDeployChangedOnly() {
BpmnModelInstance model1 = Bpmn.createExecutableProcess("process1").done();
BpmnModelInstance model2 = Bpmn.createExecutableProcess("process2").done();
// create initial deployment
ProcessApplicationDeployment deployment1 = repositoryService.createDeployment(processApplication.getReference()).name("deployment").addModelInstance("process1.bpmn20.xml", model1).addModelInstance("process2.bpmn20.xml", model2).deploy();
BpmnModelInstance changedModel2 = Bpmn.createExecutableProcess("process2").startEvent().done();
// second deployment with partial changes:
ProcessApplicationDeployment deployment2 = repositoryService.createDeployment(processApplication.getReference()).name("deployment").enableDuplicateFiltering(true).resumePreviousVersions().addModelInstance("process1.bpmn20.xml", model1).addModelInstance("process2.bpmn20.xml", changedModel2).deploy();
assertEquals(3, repositoryService.createProcessDefinitionQuery().count());
// there is one version of process1 deployed
ProcessDefinition processDefinitionModel1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
assertNotNull(processDefinitionModel1);
assertEquals(1, processDefinitionModel1.getVersion());
assertEquals(deployment1.getId(), processDefinitionModel1.getDeploymentId());
// there are two versions of process2 deployed
List<ProcessDefinition> processDefinitionsModel2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").orderByProcessDefinitionVersion().asc().list();
assertEquals(2, processDefinitionsModel2.size());
assertEquals(1, processDefinitionsModel2.get(0).getVersion());
assertEquals(2, processDefinitionsModel2.get(1).getVersion());
// old deployment was resumed
ProcessApplicationRegistration registration = deployment2.getProcessApplicationRegistration();
Set<String> deploymentIds = registration.getDeploymentIds();
assertEquals(2, deploymentIds.size());
BpmnModelInstance anotherChangedModel2 = Bpmn.createExecutableProcess("process2").startEvent().endEvent().done();
// testing with a third deployment to ensure the change check is not only performed against
// the last version of the deployment
ProcessApplicationDeployment deployment3 = repositoryService.createDeployment(processApplication.getReference()).enableDuplicateFiltering(true).resumePreviousVersions().addModelInstance("process1.bpmn20.xml", model1).addModelInstance("process2.bpmn20.xml", anotherChangedModel2).name("deployment").deploy();
// there should still be one version of process 1
assertEquals(1, repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").count());
// there should be three versions of process 2
assertEquals(3, repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").count());
// old deployments are resumed
registration = deployment3.getProcessApplicationRegistration();
deploymentIds = registration.getDeploymentIds();
assertEquals(3, deploymentIds.size());
deleteDeployments(deployment1, deployment2, deployment3);
}
Aggregations