cancel
Showing results for 
Search instead for 
Did you mean: 

Two places for process definition identifier on deployment?

klemens
Champ in-the-making
Champ in-the-making
Hi,

I am wondering why it is necessary to provide the process definition two times during deployment. The first time I need to give it to the the method call:

repositoryService.createDeployment().addInputStream(identifier, inputStream).deploy();
and the second time I need to specify it inside the id element of the process definition.

Now I have the scenario where a user uploads workflow definitions to a server. The server executes the workflows based on these definitions. The problem is, that the user can not know which identifiers where used by other users to upload worklfows, so I need to assign identifiers on the server side. This is only possible by exchanging the identifier in the process definition, which requires me to parse the XML on the server side. That is quite ugly, since I had hoped that the identifier provided to the "addInputStream" method would be sufficient to call access the workflow definition later on.
13 REPLIES 13

trademak
Star Contributor
Star Contributor
Hi,

I don't understand your question, why is it necessary to provide the process definition two times?

Best regards,

klemens
Champ in-the-making
Champ in-the-making
It is necessary if the process is changed while the system is running.

So lets say the process is deployed initially and runs for several days on some server. After that time someone changes the process definition on a client and loads the changed definition (new XML File) file to the server. From that time on all processes should be started with the new definition instead of the old and the old one should be removed from the server.

To be more concrete: We have a server that carries out complex information extraction algorithms on some business documents. From time to time we try different algorithms. The task of the workflow steering those algorithms always stays the same. We need to exchange the old workflow definition with a new one every time we reconfigure which algorithms are used to achieve our task. This needs to be done using some REST API on our server. So what I need to achieve is the ability to upload a bpmn process definition to the server via the REST interface. As soon as the server recieves the new process definition it should start new calls to the information extraction algorithms with the new process definition.

I already solved the problem with the process identifier which is defined in two places by parsing the XML description and changing the identifier within the XML description to the one the server uses internally. However when I try to exchange the process defintions I always get the message: "org.activiti.engine.ActivitiException: no processes deployed with key 'extraction'".

Some minimalistic code:

String processIdentifier = "extraction";
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

// Load the original process definition from hard disk.
String processDefinition1 = FileUtils.readFileToString("processDefinition1.bpmn20.xml");

// deploy original process definition. The first problem occurs here since I can not be sure that the id attribute of the process element in "processDefinition1.bpmn20.xml" is equal to "processIdentifier".
repositoryService.createDeployment().addString(processIdentifier, processDefinition1).deploy();

// maybe run the process once.
RuntimeService runtimeService = processEngine.getRuntimeService();
runtimeService.startProcessInstanceByKey(processIdentifier);

// Load the changed process definition from hard disk.
String processDefinition2 = FileUtils.readFileToString("processDefinition2.bpmn20.xml");

// exchange the old process definition with the new one.
String deploymentIdentifier = repositoryService.createProcessDefinitionQuery().processDefinitionId(processIdentifier).list().get(0).getId();
repositoryService.deleteDeployment(deploymentIdentifier);
repositoryService.createDeployment().addString(processIdentifier,processDefinition2).deploy();

// now the changed process definition should run but I get: org.activiti.engine.ActivitiException: no processes deployed with key 'extraction'
runtimeService.startProcessInstanceByKey(processIdentifier);

chen4613
Champ in-the-making
Champ in-the-making
It would be very convenient the DeploymentBuilder can specify the process id insteadof get it from the process definition in some conditions.

frederikherema1
Star Contributor
Star Contributor
Don't really see the use case for specifying the key twice… Now we base it on the key that is present in the process-definition XML, so there is only a single source of truth.

One use case is:
- deploy process for testing(test_process_id)
- create test process instance and test it, test instances must not shown in product processes list.
- if process is pass
  - deploy the same process in product mode(product_process_id)

Can avtiviti achieve this case without change the process id of process-definintion?

jbarrez
Star Contributor
Star Contributor
Process definitions have a category, that can be used in queries.
You can set the category to 'development' for the test ones and 'production' for the 'real ones'. However, the id (key) must indeed be unique accross the system.

chen4613
Champ in-the-making
Champ in-the-making
Thanks, but how to start a process instance with the specified category? BTW, I am using activiti-camel.

frederikherema1
Star Contributor
Star Contributor
Query process-definitions by category and name-combination (perhaps even use processDefinitionKeyLike) and get the ID (actual entity ID, not key Smiley Wink) of the one you need to start the process (using repositoryService.createProcessDefinitionQuery().processDefinitionCategory()).

As joram says, you'll have different keys for the processes, but have another mechanism to indicate they belong together.

chen4613
Champ in-the-making
Champ in-the-making
Thanks, I got it,  ProcessDefinition.getKey() is the id attribute of bpmn xml file definition, ProcessDefinition.getId() is the deployed definition id in repositoy(which is combined with key and revision info?). If we deploy a bpmn with different categories, we will get different definitions in repository with different id, so we can start process instances by the definition id(not the bpmn file id), and query them by key(bpmn id) and category, am I right?

But.. when I deploy a process with category, the category is always refer to targetNamespace of the bpmn definition, not the category I specified, what's wrong with me?

Here is th e code snippet:

ProcessEngine processEngine = ProcessEngineConfiguration
                .createStandaloneInMemProcessEngineConfiguration()
                .buildProcessEngine();
        RepositoryService repositoryService = processEngine
                .getRepositoryService();
        repositoryService.createDeployment().category("category")
                .addClasspathResource("bookorder.bpmn20.xml").deploy();

        assertEquals(0, repositoryService.createProcessDefinitionQuery()
                .processDefinitionCategory("category").list().size());

        assertEquals(1, repositoryService.createProcessDefinitionQuery()
                .processDefinitionCategory("http://www.bpmnwithactiviti.org").list().size());