Search in sources :

Example 11 with ProcessApplicationRegistration

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;
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) NotValidException(org.camunda.bpm.engine.exception.NotValidException) Set(java.util.Set) HashSet(java.util.HashSet) DeploymentManager(org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager) NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) DeploymentEntity(org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity) ProcessApplicationDeploymentImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessApplicationDeploymentImpl) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ProcessApplicationRegistration

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);
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

Example 13 with ProcessApplicationRegistration

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);
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) Resource(org.camunda.bpm.engine.repository.Resource) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

Example 14 with ProcessApplicationRegistration

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);
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) Resource(org.camunda.bpm.engine.repository.Resource) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

Example 15 with ProcessApplicationRegistration

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);
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

Aggregations

ProcessApplicationRegistration (org.camunda.bpm.application.ProcessApplicationRegistration)17 ProcessApplicationDeployment (org.camunda.bpm.engine.repository.ProcessApplicationDeployment)15 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)9 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)8 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)4 Resource (org.camunda.bpm.engine.repository.Resource)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)1 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)1 NotValidException (org.camunda.bpm.engine.exception.NotValidException)1 DeploymentEntity (org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity)1 DeploymentManager (org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager)1 ProcessApplicationDeploymentImpl (org.camunda.bpm.engine.impl.persistence.entity.ProcessApplicationDeploymentImpl)1 ResourceEntity (org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)1