13 Replies Latest reply on Nov 16, 2009 3:08 PM by sebastian.s

    Jbpm 4.2 how to enable variable history

      Hello.

      We are integrating jbpm 4.2 in our webapp and we are building our own console inside our application.

      Is there a way to keep history for all variables? (including the ones that are created on th fly from the FormPlugin when ftl forms are loaded)

      I read in Jira, that history issues are to be adressed in jbpm 4.3 but I was wondering if there is a way to enable variable-history (perhaps through configuration files ?)

      thanks
      Athina

        • 1. Re: Jbpm 4.2 how to enable variable history
          kukeltje

          no sorry if it was possible this way it would have been mentioned

          • 2. Re: Jbpm 4.2 how to enable variable history
            xalperte

            Hi,

            We are using the 4.2 version, and when our processes arrives to an end state the system deletes the instance and all of its variables from database.

            It's the normal behaviour? If so, we are loosing all our process data and does not sounds very well. There are any way to avoid that? or maybe use the History feature (if available for variables)?

            Thanks in advance

            • 3. Re: Jbpm 4.2 how to enable variable history
              sebastian.s

              What do you mean by "deletes the instance"? When the process reaches the end state the instance should be terminated. AFAIK variable history is not yet functional.

              In the jbpm-console and thus in jBPM there is a clear distinction between terminating and deleting process instances. Terminating just ends the execution while deleting ends the execution and deletes all process relevant data so that no trace of the process instance remains in the database.

              • 4. Re: Jbpm 4.2 how to enable variable history

                 

                "kukeltje" wrote:
                no sorry if it was possible this way it would have been mentioned


                Do you plan to implement this feature in next releases?
                Or we will have to indicate the historyEnabled for each variable in our process definitions?

                thanks
                athina

                • 5. Re: Jbpm 4.2 how to enable variable history
                  kukeltje

                  The jira tells you what will be implemented when. I think historyenbled will default to true

                  • 6. Re: Jbpm 4.2 how to enable variable history
                    xalperte

                    Well, this is the problem, by default the setVariable implementation (ScopeInstanceImpl.java) is always calling the createVariable method with false for the "isHistoryEnabled" argument, then never creates an HistoryVariable.

                    The "deletes instances" means exactly that, the jbpm is deleting the execution information from database when the process reaches the end state (all the instance data in the jbpm4_execution, jbpm4_jobs, jbpm4_variable, jbpm4_task tables) . In fact, the "assertProcessInstanceEnded" of the JbpmTestCase class checks if the instance is ended looking if the instance exists or not in the database.

                    When the executions are deleted the variables associated to them are also deleted losing all the data associated with the process.

                    I think this must be the correct behaviour for the execution information, but there is a bug is in the Variable History side.

                    What we can do in order to maintain the process data? It's really a very important issue, without that the jbpm 4.2 can not be used in production environments.

                    Thanks

                    • 7. Re: Jbpm 4.2 how to enable variable history
                      xalperte

                      I made a test in order to force the HistoryVariable activation but didn't work.

                      The test code is that:

                      if( execution.getVariable("message") != null ) {
                       ((ExecutionImpl) execution).removeVariable("message");
                      }
                      ((ExecutionImpl) execution).createVariable("message", message, null, true);
                      


                      The problem is inside the createVariable implementation logic where the VariableUpdate event is being fired before the CreateVariable event.

                      The VariableUpdate event is fired by the Variable object, when you do "setValue" the implementation is firing the VariableUpdate event:

                       variable.setKey(key);
                       variable.setExecution(getExecution());
                       variable.setTask(getTask());
                       variable.setHistoryEnabled(isHistoryEnabled);
                      
                       variable.setValue(value);
                      
                       long dbid = DbidGenerator.getDbidGenerator().getNextId();
                       variable.setDbid(dbid);
                      
                       if (isHistoryEnabled) {
                       HistoryEvent.fire(new VariableCreate(variable));
                       }
                      


                      Maybe a solution could be do something similar to that:

                       variable.setKey(key);
                       variable.setExecution(getExecution());
                       variable.setTask(getTask());
                       variable.setHistoryEnabled(false);
                      
                       variable.setValue(value);
                      
                       long dbid = DbidGenerator.getDbidGenerator().getNextId();
                       variable.setDbid(dbid);
                      
                       if (isHistoryEnabled) {
                       HistoryEvent.fire(new VariableCreate(variable));
                       }
                      
                       variable.setHistoryEnabled(isHistoryEnabled);
                      



                      • 8. Re: Jbpm 4.2 how to enable variable history
                        xalperte

                        Sorry, I use format inside the Code block and it doesn't works....

                        This is the actual code: (ScopeInstanceImpl.createVariableObject), using isHistoryEnabled=true

                         variable.setKey(key);
                         variable.setExecution(getExecution());
                         variable.setTask(getTask());
                         variable.setHistoryEnabled(isHistoryEnabled); <------- true
                         variable.setValue(value); <------- Fires the VariableUpdate event
                        
                         long dbid = DbidGenerator.getDbidGenerator().getNextId();
                         variable.setDbid(dbid);
                        
                         if (isHistoryEnabled) { <------- true
                         HistoryEvent.fire(new VariableCreate(variable)); <------- fires VariableCreate event
                         }
                        


                        and that the code I thing could work:


                         variable.setKey(key);
                         variable.setExecution(getExecution());
                         variable.setTask(getTask());
                         variable.setHistoryEnabled(false); <------- force false
                         variable.setValue(value); <------- Now no VariableUpdate event will be fired
                        
                         long dbid = DbidGenerator.getDbidGenerator().getNextId();
                         variable.setDbid(dbid);
                        
                         if (isHistoryEnabled) { <------- true
                         HistoryEvent.fire(new VariableCreate(variable)); <------- fires VariableCreate event
                         }
                        
                         variable.setHistoryEnabled(isHistoryEnabled); <------- true
                        


                        I hope that helps.

                        • 9. Re: Jbpm 4.2 how to enable variable history
                          xalperte

                          Buff, I'm looking inside the HistoryVariableImpl class and it only maintains a String representation of the original variable value, its not enough, to be functional the HistoryVariableImpl should maintain the exact value and type of the original variable.

                          I think the better approach is not delete the process instances when they are ended, and extends the ProcessInstanceQuery with the ended flag. This could be a short term solution. Why do you deletes the instances when it were ended? because the performance? the number of records in the tables?

                          • 10. Re: Jbpm 4.2 how to enable variable history
                            kukeltje

                            don't draw conclusions... the jira issue is about fixing history stuff. We *know* there are issues. And they (mostly) will be fixed in the 4.3 release.

                            • 11. Re: Jbpm 4.2 how to enable variable history
                              xalperte

                              Hi Ronald,

                              The historic functionality is important but not basic to run the system in production.

                              The real problem, and I consider very serious, is that we're losing all the data associated with the instance when it reaches the end state.

                              Thanks.

                              • 12. Re: Jbpm 4.2 how to enable variable history
                                kukeltje

                                 

                                "xalperte" wrote:
                                Hi Ronald,

                                The historic functionality is important but not basic to run the system in production.

                                The real problem, and I consider very serious, is that we're losing all the data associated with the instance when it reaches the end state.

                                Thanks.


                                That is what the histyory tables are for. Having all (relevant) data available after a process instance ends.

                                • 13. Re: Jbpm 4.2 how to enable variable history
                                  sebastian.s

                                   

                                  "xalperte" wrote:

                                  Buff, I'm looking inside the HistoryVariableImpl class and it only maintains a String representation of the original variable value, its not enough, to be functional the HistoryVariableImpl should maintain the exact value and type of the original variable.

                                  I think the better approach is not delete the process instances when they are ended, and extends the ProcessInstanceQuery with the ended flag. This could be a short term solution. Why do you deletes the instances when it were ended? because the performance? the number of records in the tables?


                                  To answer one of your questions:

                                  I think ended process instances are stored inside a seperate table because the tables used during runtime tend to get really big. If I recall it correctly this was the reason.