Add delete in reverting migration 65/142065/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Fri, 12 Sep 2025 09:34:29 +0000 (10:34 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Thu, 18 Sep 2025 09:35:46 +0000 (09:35 +0000)
handle delete in reverting migration,
add migrationState and compositionTargetId in sync message.

Issue-ID: POLICY-5454
Change-Id: I862268b20168b40305aa7598b3caa0214e9f11e8
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementRestart.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantRestartAc.java
models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandler.java
participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorService.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerTest.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/SimulatorServiceTest.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionOutHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/cache/CacheProvider.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantSyncPublisher.java

index 4acb42a..e80fa5e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2025 Nordix Foundation.
+ *  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@ public class AcElementRestart {
     // State of the AutomationCompositionElement
     private LockState lockState;
 
+    private MigrationState migrationState;
     private String operationalState;
     private String useState;
 
@@ -73,6 +74,7 @@ public class AcElementRestart {
         this.participantId = otherElement.participantId;
         this.deployState = otherElement.deployState;
         this.lockState = otherElement.lockState;
+        this.migrationState = otherElement.migrationState;
         this.operationalState = otherElement.operationalState;
         this.useState = otherElement.useState;
         this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
@@ -89,6 +91,7 @@ public class AcElementRestart {
                 + ", participantId=" + participantId
                 + ", deployState=" + deployState
                 + ", lockState=" + lockState
+                + ", migrationState=" + migrationState
                 + ", operationalState='" + operationalState + '\''
                 + ", useState='" + useState + '\''
                 + ", toscaServiceTemplateFragment=" + toscaServiceTemplateFragment
index 4ccd240..18aa473 100644 (file)
@@ -41,6 +41,7 @@ public class ParticipantRestartAc {
     private LockState lockState;
     private StateChangeResult stateChangeResult;
     private UUID revisionId;
+    private UUID compositionTargetId;
 
     private List<AcElementRestart> acElementList = new ArrayList<>();
 
@@ -56,5 +57,6 @@ public class ParticipantRestartAc {
         this.stateChangeResult = copyConstructor.stateChangeResult;
         this.revisionId = copyConstructor.revisionId;
         this.acElementList = PfUtils.mapList(copyConstructor.acElementList, AcElementRestart::new);
+        this.compositionTargetId = copyConstructor.compositionTargetId;
     }
 }
index c424bed..987e6c7 100644 (file)
@@ -476,6 +476,7 @@ public final class AcmUtils {
         syncAc.setDeployState(automationComposition.getDeployState());
         syncAc.setLockState(automationComposition.getLockState());
         syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
+        syncAc.setCompositionTargetId(automationComposition.getCompositionTargetId());
         for (var element : automationComposition.getElements().values()) {
             if (participantId.equals(element.getParticipantId())) {
                 var acElementSync = createAcElementRestart(element);
@@ -498,6 +499,7 @@ public final class AcmUtils {
         acElementRestart.setParticipantId(element.getParticipantId());
         acElementRestart.setDeployState(element.getDeployState());
         acElementRestart.setLockState(element.getLockState());
+        acElementRestart.setMigrationState(element.getMigrationState());
         acElementRestart.setOperationalState(element.getOperationalState());
         acElementRestart.setUseState(element.getUseState());
         acElementRestart.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()));
index 26b53f1..4bcedc1 100644 (file)
@@ -167,9 +167,7 @@ public class AutomationCompositionElementHandler extends AcElementListenerV4 {
             LOGGER.debug("new element scenario");
         }
         if (ElementState.REMOVED.equals(instanceElementRollback.state())) {
-            simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId(),
-                    instanceElement.outProperties());
-            simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
+            simulatorService.deleteInRollback(instanceElement.instanceId(), instanceElement.elementId());
         } else {
             simulatorService.rollback(instanceElementRollback.instanceId(), instanceElementRollback.elementId(), stage,
                     compositionElementRollback.inProperties(), instanceElementRollback.outProperties());
index c1228e9..d4743cf 100644 (file)
@@ -293,10 +293,26 @@ public class SimulatorService {
     public void deleteInMigration(UUID instanceId, UUID elementId) {
         if (getConfig().isMigrateSuccess()) {
             intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
-                    DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+                    DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
         } else {
             intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
-                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Delete failed!");
+                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Migration - Delete failed!");
+        }
+    }
+
+    /**
+     * Handle deleting an automation composition element in rollback.
+     *
+     * @param instanceId the instanceId
+     * @param elementId  the elementId
+     */
+    public void deleteInRollback(UUID instanceId, UUID elementId) {
+        if (getConfig().isRollback()) {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
+        } else {
+            intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId,
+                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Rollback - Delete failed!");
         }
     }
 
index 309cf32..314d05e 100644 (file)
@@ -286,7 +286,7 @@ class AutomationCompositionElementHandlerTest {
             .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
         verify(intermediaryApi).updateAutomationCompositionElementState(
             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
-            DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+            DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
     }
 
     @Test
@@ -441,9 +441,6 @@ class AutomationCompositionElementHandlerTest {
                 .rollbackMigration(COMPOSITION_ELEMENT, compoElRollbackRemove, INSTANCE_ELEMENT, inElRollbackRemove, 0);
         verify(intermediaryApi).updateAutomationCompositionElementState(
                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
-                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
-        verify(intermediaryApi).updateAutomationCompositionElementState(
-                INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
-                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
     }
 }
index 4562f22..29d0f76 100644 (file)
@@ -179,11 +179,28 @@ class SimulatorServiceTest {
         var elementId = UUID.randomUUID();
         simulatorService.deleteInMigration(instanceId, elementId);
         verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
-                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
 
         simulatorService.getConfig().setMigrateSuccess(false);
         simulatorService.deleteInMigration(instanceId, elementId);
         verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Delete failed!");
+                DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Migration - Delete failed!");
+    }
+
+
+    @Test
+    void testDeleteInRollback() {
+        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+        var simulatorService = new SimulatorService(intermediaryApi);
+        var instanceId = UUID.randomUUID();
+        var elementId = UUID.randomUUID();
+        simulatorService.deleteInRollback(instanceId, elementId);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
+                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
+
+        simulatorService.getConfig().setRollback(false);
+        simulatorService.deleteInRollback(instanceId, elementId);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceId, elementId,
+                DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Rollback - Delete failed!");
     }
 }
index 37e0e22..32b8c8a 100644 (file)
@@ -191,7 +191,7 @@ public class AutomationCompositionOutHandler {
             acStateChangeAck.setStateChangeResult(stateChangeResult);
             acStateChangeAck.setAutomationCompositionId(instance);
             acStateChangeAck.getAutomationCompositionResultMap().put(elementId,
-                    new AcElementDeployAck(deployState, null, null,
+                    new AcElementDeployAck(deployState, LockState.NONE, null,
                             null, Map.of(), true, message));
             LOGGER.debug(MSG_STATE_CHANGE, elementId, deployState);
             publisher.sendAutomationCompositionAck(acStateChangeAck);
index 3b982e0..19f66ab 100644 (file)
@@ -247,6 +247,7 @@ public class CacheProvider {
 
         var automationComposition = new AutomationComposition();
         automationComposition.setCompositionId(compositionId);
+        automationComposition.setCompositionTargetId(participantRestartAc.getCompositionTargetId());
         automationComposition.setDeployState(participantRestartAc.getDeployState());
         automationComposition.setLockState(participantRestartAc.getLockState());
         automationComposition.setInstanceId(participantRestartAc.getAutomationCompositionId());
index b5fe222..ddbc06e 100644 (file)
@@ -128,6 +128,7 @@ public class ParticipantSyncPublisher extends AbstractParticipantPublisher<Parti
         message.setMessageId(UUID.randomUUID());
         message.setTimestamp(Instant.now());
         var syncAc = new ParticipantRestartAc();
+        syncAc.setCompositionTargetId(automationComposition.getCompositionTargetId());
         syncAc.setAutomationCompositionId(automationComposition.getInstanceId());
         syncAc.setRevisionId(automationComposition.getRevisionId());
         syncAc.setDeployState(automationComposition.getDeployState());