Fix validation in ACM-runtime 44/139644/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 28 Nov 2024 14:54:21 +0000 (14:54 +0000)
committerFrancesco Fiora <francesco.fiora@est.tech>
Wed, 4 Dec 2024 10:28:02 +0000 (10:28 +0000)
Fix validation after migration fail
and undeploy fail in ACM-runtime.
Add more information in fail validation.

Issue-ID: POLICY-5195
Change-Id: I870fd31b59bb65db8cb6e8e1b9ee502fc3d63743
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java

index 9239b3a..09f1b09 100644 (file)
@@ -100,19 +100,12 @@ public class AcInstanceStateResolver {
             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);
+        setAllowed(DEPLOY);
+        setAllowed(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);
@@ -131,23 +124,12 @@ public class AcInstanceStateResolver {
             DEPLOYED, LOCKED, MIGRATION_PRECHECKING, FAILED}, MIGRATE_PRECHECK);
 
         // timeout
-        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,
-            UNDEPLOYING, LOCKED, 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);
@@ -168,6 +150,28 @@ public class AcInstanceStateResolver {
             DEPLOYED, LOCKED, MIGRATION_PRECHECKING, TIMEOUT}, MIGRATE_PRECHECK);
     }
 
+    private void setAllowed(String deployOrder) {
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, deployOrder);
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            UNDEPLOYING, LOCKED, SUB_STATE_NONE, FAILED}, deployOrder);
+
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            UNDEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, deployOrder);
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            UNDEPLOYING, LOCKED, SUB_STATE_NONE, TIMEOUT}, deployOrder);
+
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, FAILED}, deployOrder);
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            DEPLOYING, LOCKED, SUB_STATE_NONE, FAILED}, deployOrder);
+
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            DEPLOYING, STATE_LOCKED_NONE, SUB_STATE_NONE, TIMEOUT}, deployOrder);
+        this.graph.put(new String[] {deployOrder, LOCK_NONE, SUB_NONE,
+            DEPLOYING, LOCKED, SUB_STATE_NONE, TIMEOUT}, deployOrder);
+    }
+
     /**
      * Check if Deploy Order and Lock Order are consistent with current DeployState and LockState.
      *
index 42af705..0979a81 100644 (file)
@@ -68,6 +68,8 @@ import org.springframework.transaction.annotation.Transactional;
 public class AutomationCompositionInstantiationProvider {
     private static final String DO_NOT_MATCH = " do not match with ";
     private static final String ELEMENT_ID_NOT_PRESENT = "Element id not present ";
+    private static final String NOT_VALID_ORDER =
+            "Not valid order %s; DeployState: %s; LockState: %s; SubState: %s; StateChangeResult: %s";
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionInstantiationProvider.class);
 
@@ -472,7 +474,10 @@ public class AutomationCompositionInstantiationProvider {
                 break;
 
             default:
-                throw new PfModelRuntimeException(Status.BAD_REQUEST, "Not valid " + acInstanceStateUpdate);
+                var msg = String.format(NOT_VALID_ORDER, acInstanceStateUpdate,
+                        automationComposition.getDeployState(), automationComposition.getLockState(),
+                        automationComposition.getSubState(), automationComposition.getStateChangeResult());
+                throw new PfModelRuntimeException(Status.BAD_REQUEST, msg);
         }
     }
 }