diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-07-23 10:22:27 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-07-23 09:27:30 +0000 |
commit | 1c144c87fbe077eb471650064c64888c4501f581 (patch) | |
tree | d4fcc2018f0cf78e6495fd1f020edd324bd0480e /models/src/main/java | |
parent | af4d49da0f35da5d1086f0181b594dcc772e383d (diff) |
Add support for Prepare, Review and Migrate pre-check in ACM runtime
Issue-ID: POLICY-5079
Change-Id: I6e54d2bce31f906efcc4d5bf3b930d34e7913fd2
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java')
2 files changed, 131 insertions, 50 deletions
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 ace246c5d..fd8b63582 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,10 @@ 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.concepts.SubState; 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.messages.rest.instantiation.SubOrder; import org.onap.policy.clamp.models.acm.utils.StateDefinition; import org.springframework.stereotype.Component; @@ -39,6 +41,10 @@ public class AcInstanceStateResolver { private static final String UPDATING = DeployState.UPDATING.name(); private static final String DELETING = DeployState.DELETING.name(); private static final String MIGRATING = DeployState.MIGRATING.name(); + private static final String MIGRATION_PRECHECKING = SubState.MIGRATION_PRECHECKING.name(); + private static final String PREPARING = SubState.PREPARING.name(); + private static final String REVIEWING = SubState.REVIEWING.name(); + private static final String SUB_STATE_NONE = SubState.NONE.name(); private static final String LOCKED = LockState.LOCKED.name(); private static final String LOCKING = LockState.LOCKING.name(); @@ -48,6 +54,7 @@ public class AcInstanceStateResolver { private static final String DEPLOY_NONE = DeployOrder.NONE.name(); private static final String LOCK_NONE = LockOrder.NONE.name(); + private static final String SUB_NONE = SubOrder.NONE.name(); private static final String NO_ERROR = StateChangeResult.NO_ERROR.name(); private static final String FAILED = StateChangeResult.FAILED.name(); @@ -60,55 +67,105 @@ public class AcInstanceStateResolver { public static final String LOCK = LockOrder.LOCK.name(); public static final String UNLOCK = LockOrder.UNLOCK.name(); public static final String MIGRATE = DeployOrder.MIGRATE.name(); + public static final String MIGRATE_PRECHECK = SubOrder.MIGRATE_PRECHECK.name(); + public static final String PREPARE = SubOrder.PREPARE.name(); + public static final String REVIEW = SubOrder.REVIEW.name(); + public static final String UPDATE = DeployOrder.UPDATE.name(); public static final String NONE = "NONE"; /** * Construct. */ public AcInstanceStateResolver() { - 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); - this.graph.put(new String[] {MIGRATE, LOCK_NONE, DEPLOYED, LOCKED, NO_ERROR}, MIGRATE); - - // failed - this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, FAILED}, DEPLOY); - this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, 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, LOCKED, FAILED}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, MIGRATING, LOCKED, FAILED}, UNDEPLOY); - 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, UNLOCK, DEPLOYED, UNLOCKING, FAILED}, UNLOCK); - - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, FAILED}, LOCK); - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, FAILED}, LOCK); + this.graph = new StateDefinition<>(7, NONE); + + // make an order when there are no fails + this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE, + UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, DEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNDEPLOY); + this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE, + UNDEPLOYED, LOCK_NONE, SUB_STATE_NONE, NO_ERROR}, DELETE); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, + DEPLOYED, UNLOCKED, SUB_STATE_NONE, NO_ERROR}, LOCK); + this.graph.put(new String[] {MIGRATE, LOCK_NONE, SUB_NONE, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE); + this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, UPDATE); + this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, REVIEW, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, REVIEW); + this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, PREPARE, + UNDEPLOYED, STATE_LOCKED_NONE, SUB_STATE_NONE, NO_ERROR}, PREPARE); + this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK, + DEPLOYED, LOCKED, SUB_STATE_NONE, NO_ERROR}, MIGRATE_PRECHECK); + + // make an order in a failed scenario + this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE, + UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, DEPLOY); + this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE, + DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, DEPLOY); + + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + MIGRATING, LOCKED, SUB_STATE_NONE, FAILED}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, UNDEPLOY); + + this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE, + DELETING, LOCK_NONE, SUB_STATE_NONE, FAILED}, DELETE); + + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE, + DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE, + DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, UNLOCK); + + this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, LOCKING, SUB_STATE_NONE, FAILED}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, DEPLOYED, UNLOCKING, SUB_STATE_NONE, FAILED}, LOCK); + + this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, FAILED}, UPDATE); + + this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK, + DEPLOYED, LOCKED, MIGRATION_PRECHECKING, FAILED}, MIGRATE_PRECHECK); // timeout - this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY); - this.graph.put(new String[] {DEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, DEPLOY); - - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UNDEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, UPDATING, LOCKED, TIMEOUT}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, MIGRATING, LOCKED, TIMEOUT}, UNDEPLOY); - this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYING, STATE_LOCKED_NONE, TIMEOUT}, UNDEPLOY); - - this.graph.put(new String[] {DELETE, LOCK_NONE, DELETING, LOCK_NONE, TIMEOUT}, DELETE); - - this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKING, TIMEOUT}, UNLOCK); - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, LOCKING, TIMEOUT}, LOCK); - - this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKING, TIMEOUT}, LOCK); - this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, UNLOCKING, TIMEOUT}, UNLOCK); + this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE, + UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, DEPLOY); + this.graph.put(new String[] {DEPLOY, LOCK_NONE, SUB_NONE, + DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, DEPLOY); + + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + MIGRATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + MIGRATION_PRECHECKING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, SUB_NONE, + DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, UNDEPLOY); + + this.graph.put(new String[] {DELETE, LOCK_NONE, SUB_NONE, + DELETING, LOCK_NONE, SUB_STATE_NONE, TIMEOUT}, DELETE); + + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE, + DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, + DEPLOYED, LOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK); + + this.graph.put(new String[] {DEPLOY_NONE, LOCK, SUB_NONE, + DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, LOCK); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, SUB_NONE, + DEPLOYED, UNLOCKING, SUB_STATE_NONE, TIMEOUT}, UNLOCK); + + this.graph.put(new String[] {UPDATE, LOCK_NONE, SUB_NONE, UPDATING, LOCKED, SUB_STATE_NONE, TIMEOUT}, UPDATE); + + this.graph.put(new String[] {DEPLOY_NONE, LOCK_NONE, MIGRATE_PRECHECK, + DEPLOYED, LOCKED, MIGRATION_PRECHECKING, TIMEOUT}, MIGRATE_PRECHECK); } /** @@ -116,20 +173,24 @@ public class AcInstanceStateResolver { * * @param acDeployOrder the Deploy Ordered * @param acLockOrder the Lock Ordered + * @param acSubOrder the Sub Ordered * @param acDeployState then current Deploy State * @param acLockState the current Lock State + * @param acSubState the current Sub 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, StateChangeResult acStateChangeResult) { + public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, SubOrder acSubOrder, + DeployState acDeployState, LockState acLockState, SubState acSubState, StateChangeResult acStateChangeResult) { var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE; var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.NONE; + var subOrder = acSubOrder != null ? acSubOrder : SubOrder.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(), - stateChangeResult.name()}); + var subState = acSubState != null ? acSubState : SubState.NONE; + return this.graph.get(new String[] {deployOrder.name(), lockOrder.name(), subOrder.name(), + deployState.name(), lockState.name(), subState.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 f90e5a807..50b8d14ad 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 @@ -51,6 +51,7 @@ import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy; import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; +import org.onap.policy.clamp.models.acm.concepts.SubState; 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.persistence.concepts.StringToMapConverter; @@ -288,16 +289,20 @@ public final class AcmUtils { // @formatter:on } + /** - * Return true if DeployState and LockState are in a Transitional State. + * Return true if DeployState, LockState and SubState are in a Transitional State. * - * @return true if DeployState and LockState are in a Transitional State + * @param deployState the DeployState + * @param lockState the LockState + * @param subState the SubState + * @return true if there is a state in a Transitional State */ - public static boolean isInTransitionalState(DeployState deployState, LockState lockState) { + public static boolean isInTransitionalState(DeployState deployState, LockState lockState, SubState subState) { return DeployState.DEPLOYING.equals(deployState) || DeployState.UNDEPLOYING.equals(deployState) || LockState.LOCKING.equals(lockState) || LockState.UNLOCKING.equals(lockState) || DeployState.DELETING.equals(deployState) || DeployState.UPDATING.equals(deployState) - || DeployState.MIGRATING.equals(deployState); + || DeployState.MIGRATING.equals(deployState) || !SubState.NONE.equals(subState); } /** @@ -381,9 +386,23 @@ public final class AcmUtils { */ public static void setCascadedState(final AutomationComposition automationComposition, final DeployState deployState, final LockState lockState) { + setCascadedState(automationComposition, deployState, lockState, SubState.NONE); + } + + /** + /** + * Set the states on the automation composition and on all its automation composition elements. + * + * @param deployState the DeployState we want the automation composition to transition to + * @param lockState the LockState we want the automation composition to transition to + * @param subState the SubState we want the automation composition to transition to + */ + public static void setCascadedState(final AutomationComposition automationComposition, + final DeployState deployState, final LockState lockState, final SubState subState) { automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); automationComposition.setLastMsg(TimestampHelper.now()); + automationComposition.setSubState(subState); if (MapUtils.isEmpty(automationComposition.getElements())) { return; @@ -392,6 +411,7 @@ public final class AcmUtils { for (var element : automationComposition.getElements().values()) { element.setDeployState(deployState); element.setLockState(lockState); + element.setSubState(subState); element.setMessage(null); } } |