Skip to content

Commit

Permalink
Cam 6937 plugable deployment steps (camunda#254)
Browse files Browse the repository at this point in the history
* CAM-6937 enhance abstractProcessApplication with deployment steps

* CAM-6937 move steps to delegateImpl

* CAM-6937 define steps in extra methods to ease overwriting

* CAM-6937 make logger protected for subclasses

* CAM-6937 consolidate metaInf default value

* CAM-6937 inline imports
  • Loading branch information
jangalinski authored and aakhmerov committed Nov 7, 2016
1 parent 9fefe7e commit d00f435
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target
.classpath
.project
.settings
.editorconfig
build.properties
bin
.metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
*/
package org.camunda.bpm.application;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.Callable;

import javax.script.ScriptEngine;

import org.camunda.bpm.application.impl.DefaultElResolverLookup;
import org.camunda.bpm.application.impl.ProcessApplicationLogger;
import org.camunda.bpm.application.impl.ProcessApplicationScriptEnvironment;
Expand All @@ -34,10 +26,16 @@
import org.camunda.bpm.engine.impl.variable.serializer.VariableSerializers;
import org.camunda.bpm.engine.repository.DeploymentBuilder;

import javax.script.ScriptEngine;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.Callable;


/**
* @author Daniel Meyer
*
*/
public abstract class AbstractProcessApplication implements ProcessApplicationInterface {

Expand All @@ -54,18 +52,17 @@ public abstract class AbstractProcessApplication implements ProcessApplicationIn
// deployment /////////////////////////////////////////////////////

public void deploy() {
if(isDeployed) {
if (isDeployed) {
LOG.alreadyDeployed();
}
else {
} else {
// deploy the application
RuntimeContainerDelegate.INSTANCE.get().deployProcessApplication(this);
isDeployed = true;
}
}

public void undeploy() {
if(!isDeployed) {
if (!isDeployed) {
LOG.notDeployed();
} else {
// delegate stopping of the process application to the runtime container.
Expand All @@ -85,7 +82,7 @@ public String getName() {
String name = null;

ProcessApplication annotation = processApplicationClass.getAnnotation(ProcessApplication.class);
if(annotation != null) {
if (annotation != null) {
name = annotation.value();

if (name == null || name.length() == 0) {
Expand All @@ -94,7 +91,7 @@ public String getName() {
}


if(name == null || name.length()==0) {
if (name == null || name.length() == 0) {
name = autodetectProcessApplicationName();
}

Expand All @@ -116,11 +113,9 @@ public <T> T execute(Callable<T> callable) throws ProcessApplicationExecutionExc

return callable.call();

}
catch(Exception e) {
} catch (Exception e) {
throw LOG.processApplicationExecutionException(e);
}
finally {
} finally {
ClassLoaderUtil.setContextClassloader(originalClassloader);
}
}
Expand All @@ -146,9 +141,9 @@ public Map<String, String> getProperties() {
}

public ELResolver getElResolver() {
if(processApplicationElResolver == null) {
if (processApplicationElResolver == null) {
synchronized (this) {
if(processApplicationElResolver == null) {
if (processApplicationElResolver == null) {
processApplicationElResolver = initProcessApplicationElResolver();
}
}
Expand All @@ -158,9 +153,9 @@ public ELResolver getElResolver() {
}

public BeanELResolver getBeanElResolver() {
if(processApplicationBeanElResolver == null) {
if (processApplicationBeanElResolver == null) {
synchronized (this) {
if(processApplicationBeanElResolver == null) {
if (processApplicationBeanElResolver == null) {
processApplicationBeanElResolver = new BeanELResolver();
}
}
Expand All @@ -171,7 +166,7 @@ public BeanELResolver getBeanElResolver() {
/**
* <p>Initializes the process application provided ElResolver. This implementation uses the
* Java SE {@link ServiceLoader} facilities for resolving implementations of {@link ProcessApplicationElResolver}.</p>
*
* <p>
* <p>If you want to provide a custom implementation in your application, place a file named
* <code>META-INF/org.camunda.bpm.application.ProcessApplicationElResolver</code> inside your application
* which contains the fully qualified classname of your implementation. Or simply override this method.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
@Target(ElementType.TYPE)
public @interface ProcessApplication {

String META_INF_PROCESSES_XML = "META-INF/processes.xml";

/**
* Allows specifying the name of the process application.
* Overrides the {@code name} property.
Expand All @@ -49,6 +51,6 @@
*
* @return the location of the <code>processes.xml</code> file.
*/
String[] deploymentDescriptors() default { "META-INF/processes.xml" };
String[] deploymentDescriptors() default { META_INF_PROCESSES_XML };

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
*/
package org.camunda.bpm.container.impl;

import static org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.management.MBeanServer;

import org.camunda.bpm.ProcessApplicationService;
import org.camunda.bpm.ProcessEngineService;
import org.camunda.bpm.application.AbstractProcessApplication;
Expand All @@ -40,23 +33,31 @@
import org.camunda.bpm.container.impl.jmx.MBeanServiceContainer;
import org.camunda.bpm.container.impl.jmx.services.JmxManagedProcessApplication;
import org.camunda.bpm.container.impl.jmx.services.JmxManagedProcessEngine;
import org.camunda.bpm.container.impl.spi.DeploymentOperationStep;
import org.camunda.bpm.container.impl.spi.PlatformServiceContainer;
import org.camunda.bpm.container.impl.spi.ServiceTypes;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.impl.ProcessEngineLogger;

import javax.management.MBeanServer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull;

/**
* <p>This is the default {@link RuntimeContainerDelegate} implementation that delegates
* to the local {@link MBeanServer} infrastructure. The MBeanServer is available
* as per the Java Virtual Machine and allows the process engine to expose
* Management Resources.</p>
*
* @author Daniel Meyer
*
*/
public class RuntimeContainerDelegateImpl implements RuntimeContainerDelegate, ProcessEngineService, ProcessApplicationService {

private final static ContainerIntegrationLogger LOG = ProcessEngineLogger.CONTAINER_INTEGRATION_LOGGER;
protected final static ContainerIntegrationLogger LOG = ProcessEngineLogger.CONTAINER_INTEGRATION_LOGGER;

protected MBeanServiceContainer serviceContainer = new MBeanServiceContainer();

Expand Down Expand Up @@ -89,19 +90,14 @@ public void unregisterProcessEngine(ProcessEngine processEngine) {
public void deployProcessApplication(AbstractProcessApplication processApplication) {
ensureNotNull("Process application", processApplication);

final String operationName = "Deployment of Process Application "+processApplication.getName();
final String operationName = "Deployment of Process Application " + processApplication.getName();

serviceContainer.createDeploymentOperation(operationName)
.addAttachment(Attachments.PROCESS_APPLICATION, processApplication)
.addStep(new ParseProcessesXmlStep())
.addStep(new ProcessesXmlStartProcessEnginesStep())
.addStep(new DeployProcessArchivesStep())
.addStep(new StartProcessApplicationServiceStep())
.addStep(new PostDeployInvocationStep())
.addSteps(getDeploymentSteps())
.execute();

LOG.paDeployed(processApplication.getName());

}

@Override
Expand All @@ -111,25 +107,42 @@ public void undeployProcessApplication(AbstractProcessApplication processApplica
final String processAppName = processApplication.getName();

// if the process application is not deployed, ignore the request.
if(serviceContainer.getService(ServiceTypes.PROCESS_APPLICATION, processAppName) == null) {
if (serviceContainer.getService(ServiceTypes.PROCESS_APPLICATION, processAppName) == null) {
return;
}

final String operationName = "Undeployment of Process Application "+processAppName;
final String operationName = "Undeployment of Process Application " + processAppName;

// perform the undeployment
serviceContainer.createUndeploymentOperation(operationName)
.addAttachment(Attachments.PROCESS_APPLICATION, processApplication)
.addStep(new PreUndeployInvocationStep())
.addStep(new UndeployProcessArchivesStep())
.addStep(new ProcessesXmlStopProcessEnginesStep())
.addStep(new StopProcessApplicationServiceStep())
.addStep(new NotifyPostProcessApplicationUndeployedStep())
.addSteps(getUndeploymentSteps())
.execute();

LOG.paUndeployed(processApplication.getName());
}


protected List<DeploymentOperationStep> getDeploymentSteps() {
return Arrays.asList(
new ParseProcessesXmlStep(),
new ProcessesXmlStartProcessEnginesStep(),
new DeployProcessArchivesStep(),
new StartProcessApplicationServiceStep(),
new PostDeployInvocationStep());
}

protected List<DeploymentOperationStep> getUndeploymentSteps() {
return Arrays.asList(
new PreUndeployInvocationStep(),
new UndeployProcessArchivesStep(),
new ProcessesXmlStopProcessEnginesStep(),
new StopProcessApplicationServiceStep(),
new NotifyPostProcessApplicationUndeployedStep()
);
}


@Override
public ProcessEngineService getProcessEngineService() {
return this;
Expand Down Expand Up @@ -190,10 +203,9 @@ public ProcessApplicationInfo getProcessApplicationInfo(String processApplicatio

JmxManagedProcessApplication processApplicationService = serviceContainer.getServiceValue(ServiceTypes.PROCESS_APPLICATION, processApplicationName);

if(processApplicationService == null) {
if (processApplicationService == null) {
return null;
}
else {
} else {
return processApplicationService.getProcessApplicationInfo();
}
}
Expand All @@ -202,10 +214,9 @@ public ProcessApplicationInfo getProcessApplicationInfo(String processApplicatio
public ProcessApplicationReference getDeployedProcessApplication(String processApplicationName) {
JmxManagedProcessApplication processApplicationService = serviceContainer.getServiceValue(ServiceTypes.PROCESS_APPLICATION, processApplicationName);

if(processApplicationService == null) {
if (processApplicationService == null) {
return null;
}
else {
} else {
return processApplicationService.getProcessApplicationReference();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class ParseProcessesXmlStep extends DeploymentOperationStep {

private final static ContainerIntegrationLogger LOG = ProcessEngineLogger.CONTAINER_INTEGRATION_LOGGER;

private static final String META_INF_PROCESSES_XML = "META-INF/processes.xml";

public String getName() {
return "Parse processes.xml deployment descriptor files.";
}
Expand Down Expand Up @@ -118,7 +116,7 @@ protected List<URL> getProcessesXmlUrls(String[] deploymentDescriptors, Abstract
protected String[] getDeploymentDescriptorLocations(AbstractProcessApplication processApplication) {
ProcessApplication annotation = processApplication.getClass().getAnnotation(ProcessApplication.class);
if(annotation == null) {
return new String[] {META_INF_PROCESSES_XML};
return new String[] {ProcessApplication.META_INF_PROCESSES_XML};

} else {
return annotation.deploymentDescriptors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/
package org.camunda.bpm.container.impl.spi;

import org.camunda.bpm.container.impl.ContainerIntegrationLogger;
import org.camunda.bpm.engine.impl.ProcessEngineLogger;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.camunda.bpm.container.impl.ContainerIntegrationLogger;
import org.camunda.bpm.engine.impl.ProcessEngineLogger;

/**
* <p>A DeploymentOperation allows bundling multiple deployment steps into a
Expand Down Expand Up @@ -186,6 +188,13 @@ public DeploymentOperationBuilder addStep(DeploymentOperationStep step) {
return this;
}

public DeploymentOperationBuilder addSteps(Collection<DeploymentOperationStep> steps) {
for (DeploymentOperationStep step: steps) {
addStep(step);
}
return this;
}

public DeploymentOperationBuilder addAttachment(String name, Object value) {
initialAttachments.put(name, value);
return this;
Expand Down

0 comments on commit d00f435

Please sign in to comment.