<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: JBPM5 - Process Versioning
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/KrisVerlaenen">Kris Verlaenen</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/577196#577196">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Yes, a section from documentation I still have to add:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><div class="section" lang="en-US"><div class="titlepage"><div><div><h2 class="title"><a class="jive-link-anchor-small">Updating processes</a></h2></div></div></div><p><a class="jive-link-anchor-small">Over time, processes may evolve, for example because the process itself&#160;&#160; needs to be improved, or due to changing requirements.&#160; Actually, you cannot really&#160;&#160; update a process, you can only deploy a new version of the process, the old process&#160;&#160; will still exist.&#160; That is because existing process instances might still need that&#160;&#160; process definition.&#160; So the new process should have a different id, though the name&#160;&#160; could be the same, and you can use the version parameter to show when a process is&#160;&#160; updated (the version parameter is just a String and is not validated by the process&#160;&#160; framework itself, so you can select your own format for specifying minor/major&#160;&#160; updates, etc.).</a></p><p><a class="jive-link-anchor-small">Whenever a process is updated, it is important to determine what should happen&#160;&#160; to the already running process instances.&#160; There are various strategies one could&#160;&#160; consider for each running instance:</a></p><div class="itemizedlist"><ul><li><p><a class="jive-link-anchor-small"><em>Proceed</em></a><a class="jive-link-anchor-small">: The running process instance proceeds as&#160;&#160;&#160;&#160;&#160;&#160; normal, following the process (definition) as it was defined when the process&#160;&#160;&#160;&#160;&#160;&#160; instance was started.&#160; As a result, the already running instance will proceed as&#160;&#160;&#160;&#160;&#160;&#160; if the process was never updated.&#160; New instances can be started using the updated&#160;&#160;&#160;&#160;&#160;&#160; process.</a></p></li><li><p><a class="jive-link-anchor-small"><em>Abort (and restart)</em></a><a class="jive-link-anchor-small">: The already running instance&#160;&#160;&#160;&#160;&#160;&#160; is aborted.&#160; If necessary, the process instance can be restarted using the new&#160;&#160;&#160;&#160;&#160;&#160; process definition.</a></p></li><li><p><a class="jive-link-anchor-small"><em>Transfer</em></a><a class="jive-link-anchor-small">: The process instance is migrated to the&#160;&#160;&#160;&#160;&#160;&#160; new process definition, meaning that - once it has been migrated successfully -&#160;&#160;&#160;&#160;&#160;&#160; it will continue executing based on the updated process logic.</a></p></li></ul></div><p><a class="jive-link-anchor-small">By default, jBPM5 uses the proceed approach, meaning that multiple&#160;&#160; versions of the same process can be deployed, but existing process instances will&#160;&#160; simply continue executing based on the process definition that was used when starting&#160;&#160; the process instance.&#160; Running process instances could always be aborted as well of&#160;&#160; course, using the process management API.&#160; Process instance migration is more difficult&#160;&#160; and is explained in the following paragraphs.</a></p><div class="section" lang="en-US"><div class="titlepage"><div><div><h3 class="title"><a class="jive-link-anchor-small">4.10.1. Process instance migration</a></h3></div></div></div><p><a class="jive-link-anchor-small">A process instance contains all the runtime information needed to continue&#160;&#160;&#160;&#160; execution at some later point in time.&#160; This includes all the data linked to this&#160;&#160;&#160;&#160; process instance (as variables), but also the current state in the process diagram.&#160;&#160;&#160;&#160; For each node that is currently active, a node instance is used to represent this.&#160;&#160;&#160;&#160; This node instance can also contain additional state linked to the execution of that&#160;&#160;&#160;&#160; specific node only.&#160; There are different types of node instances, one for each type&#160;&#160;&#160;&#160; of node.</a></p><p><a class="jive-link-anchor-small">A process instance only contains the runtime state and is linked to a particular&#160;&#160;&#160;&#160; process (indirectly, using id references) that represents the process logic that needs&#160;&#160;&#160;&#160; to be followed when executing this process instance (this clear separation of definition&#160;&#160;&#160;&#160; and runtime state allows reuse of the definition accross all process instances based&#160;&#160;&#160;&#160; on this process and minimizes runtime state).&#160; As a result, updating a running process&#160;&#160;&#160;&#160; instance to a newer version so it used the new process logic instead of the old one is&#160;&#160;&#160;&#160; simply a matter of changing the referenced process id from the old to the new id.</a></p><p><a class="jive-link-anchor-small">However, this does not take into account that the state of the process instance (the&#160;&#160;&#160;&#160; variable instances and the node instances) might need to be migrated as well.&#160; In cases&#160;&#160;&#160;&#160; where the process is only extended and all existing wait states are kept, this is pretty&#160;&#160;&#160;&#160; straightforward, the runtime state of the process instance does not need to change at all.&#160;&#160;&#160;&#160; However, it is also possible that a more sofisticated mapping is necessary.&#160; For example,&#160;&#160;&#160;&#160; when an existing wait state is removed, or split into multiple wait states, an existing&#160;&#160;&#160;&#160;&#160; process instance that is waiting in that state cannot simply be updated.&#160; Or when a new&#160;&#160;&#160;&#160; process variable is introduced, that variable might need to be initiazed correctly so it&#160;&#160;&#160;&#160; can be used in the remainder of the (updated) process.</a></p><p><a class="jive-link-anchor-small">The WorkflowProcessInstanceUpgrader can be used to upgrade a workflow process&#160;&#160;&#160;&#160; instance to a newer process instance.&#160; Of course, you need to provide the process instance&#160;&#160;&#160;&#160; and the new process id. By default, Drools Flow will automatically map old node instances&#160;&#160;&#160;&#160; to new node instances with the same id.&#160; But you can provide a mapping of the old (unique)&#160;&#160;&#160;&#160; node id to the new node id.&#160; The unique node id is the node id, preceded by the node ids&#160;&#160;&#160;&#160; of its parents (with a colon inbetween), to allow to uniquely identify a node when composite&#160;&#160;&#160;&#160; nodes are used (as a node id is only unique within its node container.&#160; The new node id&#160;&#160;&#160;&#160; is simply the new node id in the node container (so no unique node id here, simply the new&#160;&#160;&#160;&#160; node id).&#160; The following code snippet shows a simple example.</a></p><pre class="JAVA"><a class="jive-link-anchor-small"><br/>// create the session and start the process "com.sample.process"<br/><br/>KnowledgeBuilder kbuilder = ...<br/><br/>StatefulKnowledgeSession ksession = ...<br/><br/>ProcessInstance processInstance = ksession.startProcess("com.sample.process");<br/><br/><br/>// add a new version of the process "com.sample.process2"<br/><br/>kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br/><br/>kbuilder.add(..., ResourceType.BPMN2);<br/><br/>kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br/><br/><br/>// migrate process instance to new version<br/><br/>Map&lt;String, Long&gt; mapping = new HashMap&lt;String, Long&gt;();<br/><br/>// top level node 2 is mapped to a new node with id 3<br/><br/>mapping.put("2", 3L); <br/><br/>// node 2, which is part of composite node 5, is mapped to a new node with id 4<br/><br/>mapping.put("5.2", 4L); <br/><br/>WorkflowProcessInstanceUpgrader.upgradeProcessInstance(<br/><br/>&#160;&#160; ksession, processInstance.getId(),<br/><br/>&#160;&#160; "com.sample.process2", mapping);</a></pre><p><a class="jive-link-anchor-small">If this kind of mapping is still insufficient, you can still describe your own custom&#160;&#160;&#160;&#160; mappers for specific situations.&#160; Be sure to first disconnect the process instance, change&#160;&#160;&#160;&#160; the state accordingly and then reconnect the process instance, similar to how the&#160;&#160;&#160;&#160;&#160; WorkflowProcessinstanceUpgrader does it.</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I will add this to the online documentation shortly.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Kris</p></div></div></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/577196#577196">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>