Brief introduction
Example of scenario with a deployed instance with two element:
- user call undeploy command
- first instance element success with UNDEPLOYED state
- second instance element fail with DEPLOYED state
- user call undeploy command again
- first instance element does not know that the element is already UNDEPLOYED
Add support for the participant to understand what was the last state.
Additional comments
It is important to make distinction between the state of the instance/element in the flow, and the state of the application involved. A deployed element means that a participant has completed a deploy action, and should not be confused with a deployed application.
There are scenarios where it make sense when a process is failed, all elements should be repeat fully, by in other scenarios could be different, it depend of the context. Anyway a participant could implement idempotent operations.
The responsibility to know what it needs to be done is delegated to the participant.
When a participant cannot implement idempotent operations, in order to cover the scenario with failed process with more than one element involved, it has to know what was the previous state.
Solutions
A simple solution from participant side is that it can use "outProperties" to save information related to the deployment process.
"outProperties" is controlled by the participant side, and saved into ACM-r Db by status message (by sendAcElementInfo method).
The examples below are suggestions.
- Below a simple example:
@Override public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException { if ("DEPLOYED".equals(instanceElement.outProperties().get("state"))) { // deploy process already done intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Already Deployed"); return; } // deployment process ....................................... ....................................... // end of the deployment process if (isDeploySuccess()) { instanceElement.outProperties().put("state", "DEPLOYED"); intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), null, null, instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); } else { instanceElement.outProperties().put("state", "UNDEPLOYED"); intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), null, null, instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!"); } } @Override public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException { if ("DEPLOYED".equals(instanceElement.outProperties().get("state"))) { // undeploy process already done intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Already Undeployed"); return; } // undeployment process ....................................... ....................................... // end of the undeployment process if (isUndeploySuccess()) { instanceElement.outProperties().put("state", "UNDEPLOYED"); intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), null, null, instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); } else { instanceElement.outProperties().put("state", "DEPLOYED"); intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), null, null, instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Undeploy failed!"); } }
- Below other suggestion with operationalState and useState:
@Override public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException { if ("DEPLOYED".equals(instanceElement.operationalState())) { // clean up deployment } else if ("DEPLOYING".equals(instanceElement.operationalState()) || "UNDEPLOYING".equals(instanceElement.operationalState()) { // check and clean up } // deployment process ....................................... ....................................... intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "Step1", "DEPLOYING", instanceElement.outProperties()); ....................................... ....................................... intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "Step2", "DEPLOYING", instanceElement.outProperties()); ....................................... ....................................... // end of the deployment process intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "", "DEPLOYED", instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed"); } @Override public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException { if ("UNDEPLOYED".equals(instanceElement.operationalState())) { // undeploy process already done intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Already Undeployed"); return; } if ("DEPLOYING".equals(instanceElement.operationalState()) || "UNDEPLOYING".equals(instanceElement.operationalState()) { // check and clean up } // undeployment process ....................................... ....................................... intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "Step1", "UNDEPLOYING", instanceElement.outProperties()); ....................................... ....................................... intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "Step2", "UNDEPLOYING", instanceElement.outProperties()); ....................................... ....................................... // end of the undeployment process intermediaryApi.sendAcElementInfo(instanceElement.instanceId(), instanceElement.elementId(), "", "UNDEPLOYED", instanceElement.outProperties()); intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed"); }