From ebb4d0cf867d752ae148880dd0109fc3cf6d6025 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Wed, 31 May 2023 16:38:22 +0100 Subject: Add Failure handling support in the ACM-R Issue-ID: POLICY-4705 Change-Id: I919b7981cdbe69ac7ce703fceb2e980a6d9a056e Signed-off-by: FrancescoFioraEst --- .../models/acm/concepts/AutomationComposition.java | 3 ++ .../acm/concepts/AutomationCompositionElement.java | 4 +- .../models/acm/concepts/StateChangeResult.java | 26 ++++++++++++ .../dmaap/participant/ParticipantAckMessage.java | 6 ++- .../concepts/JpaAutomationComposition.java | 15 ++++++- .../concepts/JpaAutomationCompositionElement.java | 10 +++++ .../provider/AcInstanceStateResolver.java | 49 +++++++++++++++++----- .../policy/clamp/models/acm/utils/AcmUtils.java | 3 +- 8 files changed, 100 insertions(+), 16 deletions(-) create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/StateChangeResult.java (limited to 'models/src/main/java/org') diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java index dc8a39b34..54c9b6190 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -50,6 +50,8 @@ public class AutomationComposition extends ToscaEntity implements Comparable elements; + private StateChangeResult stateChangeResult; + /** * Copy contructor, does a deep copy. * @@ -62,6 +64,7 @@ public class AutomationComposition extends ToscaEntity implements Comparable(), DeployState.UNDEPLOYED, LockState.LOCKED); + new ArrayList<>(), DeployState.UNDEPLOYED, LockState.NONE); } /** @@ -139,6 +143,7 @@ public class JpaAutomationComposition extends Validated this.deployState = copyConcept.deployState; this.lockState = copyConcept.lockState; this.description = copyConcept.description; + this.stateChangeResult = copyConcept.stateChangeResult; this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new); } @@ -162,6 +167,7 @@ public class JpaAutomationComposition extends Validated automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); automationComposition.setDescription(description); + automationComposition.setStateChangeResult(stateChangeResult); automationComposition.setElements(new LinkedHashMap<>(this.elements.size())); for (var element : this.elements) { automationComposition.getElements().put(UUID.fromString(element.getElementId()), element.toAuthorative()); @@ -179,7 +185,7 @@ public class JpaAutomationComposition extends Validated this.deployState = automationComposition.getDeployState(); this.lockState = automationComposition.getLockState(); this.description = automationComposition.getDescription(); - + this.stateChangeResult = automationComposition.getStateChangeResult(); this.elements = new ArrayList<>(automationComposition.getElements().size()); for (var elementEntry : automationComposition.getElements().entrySet()) { var jpaAutomationCompositionElement = @@ -232,6 +238,11 @@ public class JpaAutomationComposition extends Validated if (result != 0) { return result; } + + result = ObjectUtils.compare(stateChangeResult, other.stateChangeResult); + if (result != 0) { + return result; + } return PfUtils.compareObjects(elements, other.elements); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index 27da0399c..60a911b21 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -101,6 +101,9 @@ public class JpaAutomationCompositionElement extends Validated @Column private String description; + @Column + private String message; + @Lob @NotNull @Valid @@ -169,6 +172,7 @@ public class JpaAutomationCompositionElement extends Validated this.lockState = copyConcept.lockState; this.operationalState = copyConcept.operationalState; this.useState = copyConcept.useState; + this.message = copyConcept.message; } /** @@ -194,6 +198,7 @@ public class JpaAutomationCompositionElement extends Validated element.setLockState(lockState); element.setOperationalState(operationalState); element.setUseState(useState); + element.setMessage(message); return element; } @@ -209,6 +214,7 @@ public class JpaAutomationCompositionElement extends Validated this.lockState = element.getLockState(); this.operationalState = element.getOperationalState(); this.useState = element.getUseState(); + this.message = element.getMessage(); } @Override @@ -260,6 +266,10 @@ public class JpaAutomationCompositionElement extends Validated return result; } + result = ObjectUtils.compare(message, other.message); + if (result != 0) { + return result; + } return ObjectUtils.compare(description, other.description); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java index 8676b3397..659169b9f 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.models.acm.persistence.provider; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.clamp.models.acm.utils.StateDefinition; @@ -32,15 +33,24 @@ public class AcInstanceStateResolver { private final StateDefinition graph; private static final String DEPLOYED = DeployState.DEPLOYED.name(); + private static final String DEPLOYING = DeployState.DEPLOYING.name(); private static final String UNDEPLOYED = DeployState.UNDEPLOYED.name(); + private static final String UNDEPLOYING = DeployState.UNDEPLOYING.name(); + private static final String UPDATING = DeployState.UPDATING.name(); + private static final String DELETING = DeployState.DELETING.name(); private static final String LOCKED = LockState.LOCKED.name(); + private static final String LOCKING = LockState.LOCKING.name(); private static final String UNLOCKED = LockState.UNLOCKED.name(); + private static final String UNLOCKING = LockState.UNLOCKING.name(); private static final String STATE_LOCKED_NONE = LockState.NONE.name(); private static final String DEPLOY_NONE = DeployOrder.NONE.name(); private static final String LOCK_NONE = LockOrder.NONE.name(); + private static final String NO_ERROR = StateChangeResult.NO_ERROR.name(); + private static final String FAILED = StateChangeResult.FAILED.name(); + // list of results public static final String DEPLOY = DeployOrder.DEPLOY.name(); public static final String UNDEPLOY = DeployOrder.UNDEPLOY.name(); @@ -53,13 +63,30 @@ public class AcInstanceStateResolver { * Construct. */ public AcInstanceStateResolver() { - this.graph = new StateDefinition<>(4, NONE); + this.graph = new StateDefinition<>(5, NONE); + + // no error + this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE, NO_ERROR}, DEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED, NO_ERROR}, UNDEPLOY); + this.graph.put(new String[] {DELETE, LOCK_NONE, UNDEPLOYED, LOCK_NONE, NO_ERROR}, DELETE); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED, NO_ERROR}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED, NO_ERROR}, LOCK); + + // failed + this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); + + this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, FAILED}, UNDEPLOY); + + this.graph.put(new String[] {DELETE, LOCK_NONE, DELETING, LOCK_NONE, FAILED}, DELETE); + + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKING, FAILED}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); - this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE}, DEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED}, UNDEPLOY); - this.graph.put(new String[] {DELETE, LOCK_NONE, UNDEPLOYED, LOCK_NONE}, DELETE); - this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED}, UNLOCK); - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, FAILED}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); } /** @@ -68,17 +95,19 @@ public class AcInstanceStateResolver { * @param acDeployOrder the Deploy Ordered * @param acLockOrder the Lock Ordered * @param acDeployState then current Deploy State - * @param acLockState the current Lock State + * @param acLockState the current Lock State + * @param acStateChangeResult the current Result of the State Change * @return the order (DEPLOY/UNDEPLOY/LOCK/UNLOCK) to send to participant or NONE if order is not consistent */ public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, DeployState acDeployState, - LockState acLockState) { + LockState acLockState, StateChangeResult acStateChangeResult) { var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE; var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.NONE; + var stateChangeResult = acStateChangeResult != null ? acStateChangeResult : StateChangeResult.NO_ERROR; var deployState = acDeployState != null ? acDeployState : DeployState.UNDEPLOYED; var lockState = acLockState != null ? acLockState : LockState.NONE; - return this.graph - .get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name()}); + return this.graph.get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name(), + stateChangeResult.name()}); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java index 7de4720ad..671aca60f 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -285,7 +285,7 @@ public final class AcmUtils { public static boolean isInTransitionalState(DeployState deployState, LockState lockState) { return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState) || LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState) - || DeployState.DELETING.equals(deployState); + || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState); } /** @@ -339,6 +339,7 @@ public final class AcmUtils { public static DeployState deployCompleted(DeployState deployState) { DeployState result = null; switch (deployState) { + case UPDATING: case DEPLOYING: result = DeployState.DEPLOYED; break; -- cgit 1.2.3-korg