cancel
Showing results for 
Search instead for 
Did you mean: 

deployment didn't put process definition in the cache

gguimezanes
Champ in-the-making
Champ in-the-making
Hello
I am trying to deploy a process definition, not from a BPML file, but from a ProcessDefinitionEntity that I created programmatically.
When I test deploying my process, creating an instance of it, listing and completing tasks, all in the same standalone process engine execution, it works like a charm.
However, if I run another test that constructs a new standalone process engine (with the same configuration file) and I try to list tasks for the process I created previously, I get the following Exception:
org.activiti.engine.ActivitiException: deployment '1' didn't put process definition '2' in the cache
If I run the activity explorer, I can see my deployment and my process definition, however when I click on "start process" I get the same exception.

Here is the execute method of my deploy command (toDeploy is a ProcessdefinitionEntity that is given as parameter of the command)… as you see I put the ProcessdefinitionEntity in the cache, which explains why I don't get the exception when I manipulate the process in the same engine execution as the deployment.


@Override
    public Void execute(CommandContext commandContext) {

        DbSqlSession dbSqlSession = commandContext.getSession(DbSqlSession.class);

        DeploymentEntity deploymentEntity = new DeploymentEntity();
        deploymentEntity.setName(toDeploy.getName());
        deploymentEntity.setNew(true);
        dbSqlSession.insert(deploymentEntity);

        int versionNumber = computeVersion(commandContext);
        toDeploy.setVersion(versionNumber);
        toDeploy.setDeploymentId(deploymentEntity.getId());

        dbSqlSession.insert(toDeploy);

        Context.getProcessEngineConfiguration().getDeploymentCache().addProcessDefinition(toDeploy);
        return null;
    }

Do you know what I should do so that the deployment cache is correctly loaded when I start a new process engine? Is it something I should add in my deployment command, or something I should do when starting my new process engine?

I start the engine this way (using the default activiti.cfg.xml using a standalone h2 database):

ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
I use my command this way:

((ProcessEngineConfigurationImpl) processEngineConfiguration).getCommandExecutorTxRequired().execute(
                myDeployCommand);

Thanks.
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
A ProcessDefinitionEntity, when you retrieve it to the query API for example, only contains the database data.
This means, it doesn't contain any bpmn 2 information, which is required to be loaded in the deployment cache.

In your code, the 'deploy' method is never called, hence the process definition is never parsed. Check the DeployCmd on how to do this, but note that this is more complex than you might anticipate 😉

gguimezanes
Champ in-the-making
Champ in-the-making
Thanks for your answer, however I do not want to do any parsing, it's the exact reason why I needed to create my own deploy command that skips parsing a BPMN file. I might not have been precise enough in my intro.

I do not create a BPMN file. I do not want to manipulate BPMN, I want to create my process directly in Java.

The ProcessDefinitionEntity that I deploy has been entirely created programmatically, not the result of any query, and it does contain "bpmn 2 information", that I do not parse but that I create in plain Java (I used BpmnParse as an example on how to create the ActivityImpl and TransitionImpl for representing  start event, tasks, end event and sequence flows).

The process engine does know of the process description, otherwise I would not be able to start a process instance and list the tasks and I would not be able to see the second task in the list when I complete the first one programmatically.
My own deploy command is already inspired by the DeployCmd – in fact, by the deploy method in BpmnDeployer. Otherwise I would never have thought of adding the caching code :

Context
        .getProcessEngineConfiguration()
        .getDeploymentCache()
        .addProcessDefinition(processDefinition);

My question is, why does it work when I use my process in the same process engine execution as my deployment, but does not work when I deploy my process, then start a new process engine, then try to use the previously deployed process (which does appear in the database)?
Maybe you could give me more info as to when/how the DeploymentCache is initialized with the already deployed process definitions when the process engine is started?

Thanks.

jbarrez
Star Contributor
Star Contributor
My question is, why does it work when I use my process in the same process engine execution as my deployment, but does not work when I deploy my process, then start a new process engine, then try to use the previously deployed process (which does appear in the database)?
Maybe you could give me more info as to when/how the DeploymentCache is initialized with the already deployed process definitions when the process engine is started?

Well, exactly because of the reasons I described above … :

The second time, the process definition comes from the database. It only has the values stored in ACT_RE_PROC_DEF_, these do not contain any information to actually run the process definition. These are obtained when the process definition XML is parsed by the BpmnParse class.

The first time, all the activityImpl and transitions are there when you pass them. That's the reason it works. However, these are *nowhere* stored in the database, that's my point. In the normal Activiti way, it would fetch the XML from the database, and parse the process definition again, thus creating all the activityImpl and transitions. That's not happening in your case.

gguimezanes
Champ in-the-making
Champ in-the-making
Ah ok sorry I hadn't really looked into the underlying database model and I assumed the actual TaskImpl and TransitionImpl were stored, not the bpmn…
So basically if I want my process definition to be persisted I need a bpmn file… Is there already a functionality to write the bpmn file from the process definition entity, or is it only the other way around and I should write my own xml writer?

jbarrez
Star Contributor
Star Contributor
Is there already a functionality to write the bpmn file from the process definition entity, or is it only the other way around and I should write my own xml writer?

No, there is logic to go from process definition -> xml, only the other way around.

You could take a look at the BpmnConverter which was introduced in Activiti 5.11 (but not yet exposed, but you can already add the dependency to your pom.xml). That allows you to write the xml using pojo's.