Search in sources :

Example 1 with ProcessApplicationDeploymentBuilder

use of org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder in project camunda-bpm-platform by camunda.

the class ProcessApplicationDeploymentService method performDeployment.

protected void performDeployment() throws StartException {
    ManagedReference reference = null;
    try {
        // get process engine
        ProcessEngine processEngine = processEngineInjector.getValue();
        // get the process application component
        ProcessApplicationInterface processApplication = null;
        ComponentView componentView = paComponentViewInjector.getOptionalValue();
        if (componentView != null) {
            reference = componentView.createInstance();
            processApplication = (ProcessApplicationInterface) reference.getInstance();
        } else {
            processApplication = noViewProcessApplication.getValue();
        }
        // get the application name
        String processApplicationName = processApplication.getName();
        // build the deployment
        final RepositoryService repositoryService = processEngine.getRepositoryService();
        final ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());
        // enable duplicate filtering
        deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));
        // enable resuming of previous versions:
        if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
            enableResumingOfPreviousVersions(deploymentBuilder);
        }
        // set the name for the deployment
        String deploymentName = processArchive.getName();
        if (deploymentName == null || deploymentName.isEmpty()) {
            deploymentName = processApplicationName;
        }
        deploymentBuilder.name(deploymentName);
        // set the tenant id for the deployment
        String tenantId = processArchive.getTenantId();
        if (tenantId != null && !tenantId.isEmpty()) {
            deploymentBuilder.tenantId(tenantId);
        }
        // add deployment resources
        for (Entry<String, byte[]> resource : deploymentMap.entrySet()) {
            deploymentBuilder.addInputStream(resource.getKey(), new ByteArrayInputStream(resource.getValue()));
        }
        // let the process application component add resources to the deployment.
        processApplication.createDeployment(processArchive.getName(), deploymentBuilder);
        Collection<String> resourceNames = deploymentBuilder.getResourceNames();
        if (!resourceNames.isEmpty()) {
            logDeploymentSummary(resourceNames, deploymentName, processApplicationName);
            // perform the actual deployment
            deployment = Tccl.runUnderClassloader(new Tccl.Operation<ProcessApplicationDeployment>() {

                public ProcessApplicationDeployment run() {
                    return deploymentBuilder.deploy();
                }
            }, module.getClassLoader());
        } else {
            LOGGER.info("Not creating a deployment for process archive '" + processArchive.getName() + "': no resources provided.");
        }
    } catch (Exception e) {
        throw new StartException("Could not register process application with shared process engine ", e);
    } finally {
        if (reference != null) {
            reference.release();
        }
    }
}
Also used : ManagedReference(org.jboss.as.naming.ManagedReference) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) StartException(org.jboss.msc.service.StartException) ProcessApplicationDeploymentBuilder(org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder) ComponentView(org.jboss.as.ee.component.ComponentView) ByteArrayInputStream(java.io.ByteArrayInputStream) StartException(org.jboss.msc.service.StartException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 2 with ProcessApplicationDeploymentBuilder

use of org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder in project camunda-bpm-platform by camunda.

the class DeployProcessArchiveStep method performOperationStep.

@Override
public void performOperationStep(DeploymentOperation operationContext) {
    final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
    final AbstractProcessApplication processApplication = operationContext.getAttachment(Attachments.PROCESS_APPLICATION);
    final ClassLoader processApplicationClassloader = processApplication.getProcessApplicationClassloader();
    ProcessEngine processEngine = getProcessEngine(serviceContainer);
    // start building deployment map
    Map<String, byte[]> deploymentMap = new HashMap<String, byte[]>();
    // add all processes listed in the processes.xml
    List<String> listedProcessResources = processArchive.getProcessResourceNames();
    for (String processResource : listedProcessResources) {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = processApplicationClassloader.getResourceAsStream(processResource);
            byte[] bytes = IoUtil.readInputStream(resourceAsStream, processResource);
            deploymentMap.put(processResource, bytes);
        } finally {
            IoUtil.closeSilently(resourceAsStream);
        }
    }
    // scan for additional process definitions if not turned off
    if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, true)) {
        String paResourceRoot = processArchive.getProperties().get(ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH);
        String[] additionalResourceSuffixes = StringUtil.split(processArchive.getProperties().get(ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES), ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES_SEPARATOR);
        deploymentMap.putAll(findResources(processApplicationClassloader, paResourceRoot, additionalResourceSuffixes));
    }
    // perform process engine deployment
    RepositoryService repositoryService = processEngine.getRepositoryService();
    ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());
    // set the name for the deployment
    String deploymentName = processArchive.getName();
    if (deploymentName == null || deploymentName.isEmpty()) {
        deploymentName = processApplication.getName();
    }
    deploymentBuilder.name(deploymentName);
    // set the tenant id for the deployment
    String tenantId = processArchive.getTenantId();
    if (tenantId != null && !tenantId.isEmpty()) {
        deploymentBuilder.tenantId(tenantId);
    }
    // enable duplicate filtering
    deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));
    if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
        enableResumingOfPreviousVersions(deploymentBuilder);
    }
    // add all resources obtained through the processes.xml and through scanning
    for (Entry<String, byte[]> deploymentResource : deploymentMap.entrySet()) {
        deploymentBuilder.addInputStream(deploymentResource.getKey(), new ByteArrayInputStream(deploymentResource.getValue()));
    }
    // allow the process application to add additional resources to the deployment
    processApplication.createDeployment(processArchive.getName(), deploymentBuilder);
    Collection<String> deploymentResourceNames = deploymentBuilder.getResourceNames();
    if (!deploymentResourceNames.isEmpty()) {
        LOG.deploymentSummary(deploymentResourceNames, deploymentName);
        // perform the process engine deployment
        deployment = deploymentBuilder.deploy();
        // add attachment
        Map<String, DeployedProcessArchive> processArchiveDeploymentMap = operationContext.getAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP);
        if (processArchiveDeploymentMap == null) {
            processArchiveDeploymentMap = new HashMap<String, DeployedProcessArchive>();
            operationContext.addAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP, processArchiveDeploymentMap);
        }
        processArchiveDeploymentMap.put(processArchive.getName(), new DeployedProcessArchive(deployment));
    } else {
        LOG.notCreatingPaDeployment(processApplication.getName());
    }
}
Also used : DeployedProcessArchive(org.camunda.bpm.container.impl.deployment.util.DeployedProcessArchive) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProcessApplicationDeploymentBuilder(org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder) AbstractProcessApplication(org.camunda.bpm.application.AbstractProcessApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) PlatformServiceContainer(org.camunda.bpm.container.impl.spi.PlatformServiceContainer) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 RepositoryService (org.camunda.bpm.engine.RepositoryService)2 ProcessApplicationDeploymentBuilder (org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 AbstractProcessApplication (org.camunda.bpm.application.AbstractProcessApplication)1 ProcessApplicationInterface (org.camunda.bpm.application.ProcessApplicationInterface)1 DeployedProcessArchive (org.camunda.bpm.container.impl.deployment.util.DeployedProcessArchive)1 PlatformServiceContainer (org.camunda.bpm.container.impl.spi.PlatformServiceContainer)1 ComponentView (org.jboss.as.ee.component.ComponentView)1 ManagedReference (org.jboss.as.naming.ManagedReference)1 StartException (org.jboss.msc.service.StartException)1