Select configuration

Hi

I am running Camunda as an embedded service on Jboss EAP 6.4.21. Camunda is bootstraped by extending EjbProcessApplication and annotating it with @ProcessApplication. The configuration is placed in META-INF/processes.xml.

My situation is the following. When I build my application I deploy it to two different environments. In production I need to run it backed by an Oracle database. In the other environment where I deploy the application it should run with an inmem configuration. It is not an option just to build a new version, since I need it to be the same version. I have an environment variable, which I can use to determine which environment I am in.

So to the question, is there af way to switch the configuration (ei processes.xml to processesInmem.xml)? I have tried to make two subclasses of EjbProcessApplication and make a conditional call to the deploy method as shown below and vice versa in the other bean

@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@ProcessApplication(deploymentDescriptors = {"META-INF/processes_inmem.xml"})
@Local(ProcessApplicationInterface.class)
public class BootableProcessApplicationInMem extends EjbProcessApplication {

    @PostConstruct
    public void start() {
    	if (ProcessEnvironment.isInMem()) {
    		deploy();
    	}
    }

I was almost there until I ran into the ServletProcessApplicationDeployer.class where I am stopped by

 String contextPath = ctx.getContextPath();
    if(c.size() > 1) {
      // a deployment must only contain a single PA
      throw LOG.multiplePasException(c, contextPath);

because I have two beans annotated with ProcessApplication.class

Is there a solution to my issue that you could suggest?

Best regards,
Allan

I found a solution which I will share in case other should have the same need.

I solved it with help form the link
RuntimeAnnotations

This lets you change the annotation of a class programmatically. So now I just have one BootableProcessApplication and it looks like this:

@PostConstruct
public void start() {
	if (ProcessEnvironment.isInMem()) {
		// A bit nasty but a way to run with a different processes-xml file.
		// We change the  @ProcessApplication annotation programmatically 
		// Note: we need to declare all the properties also the empty ones
		// the server will fail on startup if they are missing
		Map<String, Object> valuesMap = new HashMap<>();
		String[] deploymentDescriptors = new String[] {"META-INF/processes_inmem.xml"};
  	valuesMap.put("deploymentDescriptors",  deploymentDescriptors);
		valuesMap.put("value", "");
		valuesMap.put("name", "");
		
		RuntimeAnnotations.putAnnotation(BootableProcessApplication.class, ProcessApplication.class, valuesMap);
		
		logger.info("NOTE: @ProcessApplication changed programmatically to use deploymentDescriptors: {} ", String.join(",", deploymentDescriptors));
	}
	deploy();
}

Note the RuntimeAnnotations works form java version 8.

Might not be the best or safest solution. But we only do this when running in a specific test environment.

Best regards,
Allan