Remove local HashMap in policy participant 97/138297/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Thu, 20 Jun 2024 12:51:35 +0000 (13:51 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Thu, 20 Jun 2024 15:38:56 +0000 (15:38 +0000)
Issue-ID: POLICY-5055
Change-Id: Id2495008a28ea3e50a5c17695af529813b1c0c35
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcLockHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java

index ae906e1..34c1955 100644 (file)
@@ -27,13 +27,13 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
 import org.apache.http.HttpStatus;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
+import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
 import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
 import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
 import org.onap.policy.clamp.models.acm.concepts.DeployState;
 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
 import org.onap.policy.models.base.PfModelException;
@@ -48,12 +48,10 @@ import org.springframework.stereotype.Component;
  * This class handles implementation of automationCompositionElement updates.
  */
 @Component
-public class AutomationCompositionElementHandler extends AcElementListenerV1 {
+public class AutomationCompositionElementHandler extends AcElementListenerV2 {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class);
 
-    private final Map<UUID, ToscaServiceTemplate> serviceTemplateMap = new ConcurrentHashMap<>();
-
     private final PolicyApiHttpClient apiHttpClient;
     private final PolicyPapHttpClient papHttpClient;
 
@@ -74,26 +72,28 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
     /**
      * Callback method to handle a automation composition element state change.
      *
-     * @param automationCompositionId the ID of the automation composition
-     * @param automationCompositionElementId the ID of the automation composition element
+     * @param compositionElement the information of the Automation Composition Definition Element
+     * @param instanceElement the information of the Automation Composition Instance Element
+     * @throws PfModelException in case of a model exception
      */
     @Override
-    public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException {
-        var automationCompositionDefinition = serviceTemplateMap.get(automationCompositionElementId);
-        if (automationCompositionDefinition == null) {
-            LOGGER.debug("No policies to undeploy to {}", automationCompositionElementId);
-            intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
-                    automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+    public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
+            throws PfModelException {
+        var automationCompositionDefinition = instanceElement.toscaServiceTemplateFragment();
+        if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
+            LOGGER.debug("No policies to undeploy to {}", instanceElement.elementId());
+            intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+                    instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
                     "Undeployed");
             return;
         }
         var policyList = getPolicyList(automationCompositionDefinition);
-        undeployPolicies(policyList, automationCompositionElementId);
+        undeployPolicies(policyList, instanceElement.elementId());
         var policyTypeList = getPolicyTypeList(automationCompositionDefinition);
         deletePolicyData(policyTypeList, policyList);
-        serviceTemplateMap.remove(automationCompositionElementId);
-        intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, automationCompositionElementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+        intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+                "Undeployed");
     }
 
     private void deletePolicyData(List<ToscaConceptIdentifier> policyTypeList,
@@ -151,24 +151,23 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
     /**
      * Callback method to handle an update on automation composition element.
      *
-     * @param automationCompositionId the automationComposition Id
-     * @param element the information on the automation composition element
-     * @param properties properties Map
-     * @throws PfModelException in case of an exception
+     * @param compositionElement the information of the Automation Composition Definition Element
+     * @param instanceElement the information of the Automation Composition Instance Element
+     * @throws PfModelException from Policy framework
      */
     @Override
-    public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
+    public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
             throws PfModelException {
         var createPolicyTypeResp = HttpStatus.SC_OK;
         var createPolicyResp = HttpStatus.SC_OK;
 
-        var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
+        var automationCompositionDefinition = instanceElement.toscaServiceTemplateFragment();
         if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
-            intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
-                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "ToscaTopologyTemplate not defined");
+            intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+                    instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+                    "ToscaTopologyTemplate not defined");
             return;
         }
-        serviceTemplateMap.put(element.getId(), automationCompositionDefinition);
         if (automationCompositionDefinition.getPolicyTypes() != null) {
             LOGGER.info("Found Policy Types in automation composition definition: {} , Creating Policy Types",
                     automationCompositionDefinition.getName());
@@ -186,12 +185,12 @@ public class AutomationCompositionElementHandler extends AcElementListenerV1 {
         if (createPolicyTypeResp == HttpStatus.SC_OK && createPolicyResp == HttpStatus.SC_OK) {
             LOGGER.info(
                     "PolicyTypes/Policies for the automation composition element : {} are created " + "successfully",
-                    element.getId());
+                    instanceElement.elementId());
             var policyList = getPolicyList(automationCompositionDefinition);
-            deployPolicies(policyList, automationCompositionId, element.getId());
+            deployPolicies(policyList, instanceElement.instanceId(), instanceElement.elementId());
         } else {
-            intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
-                    DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+            intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
+                    instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
                     "Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
         }
     }
index 013cb34..39f35e6 100644 (file)
@@ -31,15 +31,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
+import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
 import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
 import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
-import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
 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.models.base.PfModelException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -49,11 +47,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
 
 class AutomationCompositionElementHandlerTest {
 
-    private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
-    private static final String ID_VERSION = "1.0.1";
-    private static final UUID automationCompositionElementId = UUID.randomUUID();
-    public static final UUID AC_ID = UUID.randomUUID();
-    private static final ToscaConceptIdentifier DEFINITION = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+    private static final ToscaConceptIdentifier DEFINITION =
+            new ToscaConceptIdentifier("1.0.1", "org.onap.PM_CDS_Blueprint");
 
     @Test
     void testHandlerUndeployNoPolicy() throws PfModelException {
@@ -61,22 +56,25 @@ class AutomationCompositionElementHandlerTest {
         var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
                 mock(PolicyPapHttpClient.class), intermediaryApi);
 
-        handler.undeploy(AC_ID, automationCompositionElementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElementWithNullTopology();
+
+        handler.undeploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+                "Undeployed");
+    }
+
+    private CompositionElementDto getCompositionElement() {
+        return new CompositionElementDto(UUID.randomUUID(), DEFINITION, Map.of(), Map.of());
     }
 
-    private AcElementDeploy getTestingAcElement() {
-        var element = new AcElementDeploy();
-        element.setDefinition(DEFINITION);
-        element.setId(automationCompositionElementId);
-        element.setOrderedState(DeployOrder.DEPLOY);
+    private InstanceElementDto getInstanceElement() {
         var template = new ToscaServiceTemplate();
         template.setToscaTopologyTemplate(new ToscaTopologyTemplate());
         template.getToscaTopologyTemplate().setPolicies(List.of(Map.of("DummyPolicy", new ToscaPolicy())));
         template.setPolicyTypes(Map.of("dummy policy type", new ToscaPolicyType()));
-        element.setToscaServiceTemplateFragment(template);
-        return element;
+        return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), template, Map.of(), Map.of());
     }
 
     @Test
@@ -92,13 +90,18 @@ class AutomationCompositionElementHandlerTest {
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
 
-        handler.deploy(AC_ID, getTestingAcElement(), Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElement();
+
+        handler.deploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR,
+                "Deployed");
 
-        handler.undeploy(AC_ID, automationCompositionElementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
+        handler.undeploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+                "Undeployed");
     }
 
     @Test
@@ -107,11 +110,18 @@ class AutomationCompositionElementHandlerTest {
         var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
                 mock(PolicyPapHttpClient.class), intermediaryApi);
 
-        var acElement = getTestingAcElement();
-        acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
-        handler.deploy(AC_ID, acElement, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "ToscaTopologyTemplate not defined");
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElementWithNullTopology();
+        handler.deploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+                "ToscaTopologyTemplate not defined");
+    }
+
+    private InstanceElementDto getInstanceElementWithNullTopology() {
+        var template = new ToscaServiceTemplate();
+        template.setToscaTopologyTemplate(null);
+        return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), template, Map.of(), Map.of());
     }
 
     @Test
@@ -126,12 +136,13 @@ class AutomationCompositionElementHandlerTest {
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
 
-        var element = getTestingAcElement();
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElement();
 
         // Mock failure in policy type creation
-        handler.deploy(AC_ID, element, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+        handler.deploy(compositionElement, instanceElement);
+        verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+                instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
                 "Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
     }
 
@@ -147,88 +158,9 @@ class AutomationCompositionElementHandlerTest {
         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
         var handler = new AutomationCompositionElementHandler(api, pap, intermediaryApi);
 
-        var element = getTestingAcElement();
-        assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
+        var compositionElement = getCompositionElement();
+        var instanceElement = getInstanceElement();
+        assertThatThrownBy(() -> handler.deploy(compositionElement, instanceElement))
                 .hasMessageMatching("Deploy of Policy failed.");
     }
-
-    @Test
-    void testUpdate() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        var acElement = getTestingAcElement();
-        acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
-        handler.update(AC_ID, acElement, Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
-    }
-
-    @Test
-    void testLock() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        handler.lock(AC_ID, automationCompositionElementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
-                LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
-    }
-
-    @Test
-    void testUnlock() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        handler.unlock(AC_ID, automationCompositionElementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
-                LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
-    }
-
-    @Test
-    void testDelete() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        handler.delete(AC_ID, automationCompositionElementId);
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
-    }
-
-    @Test
-    void testPrime() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        handler.prime(AC_ID, List.of());
-        verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
-    }
-
-    @Test
-    void testDeprime() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        handler.deprime(AC_ID);
-        verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
-                "Deprimed");
-    }
-
-    @Test
-    void testMigrate() throws Exception {
-        var intermediaryApi = mock(ParticipantIntermediaryApi.class);
-        var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
-                mock(PolicyPapHttpClient.class), intermediaryApi);
-
-        var acElement = getTestingAcElement();
-        acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
-        handler.migrate(AC_ID, acElement, UUID.randomUUID(), Map.of());
-        verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
-                DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
-    }
 }
index ddf465a..89daa5f 100644 (file)
@@ -70,6 +70,9 @@ public class AcLockHandler {
 
     private void handleLockState(UUID messageId, final AutomationComposition automationComposition,
                                  Integer startPhaseMsg) {
+        automationComposition.setLockState(LockState.LOCKING);
+        var serviceTemplateFragment = cacheProvider
+                .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId());
         for (var element : automationComposition.getElements().values()) {
             var compositionInProperties = cacheProvider
                     .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition());
@@ -79,7 +82,7 @@ public class AcLockHandler {
                 var compositionElement = cacheProvider.createCompositionElementDto(
                         automationComposition.getCompositionId(), element, compositionInProperties);
                 var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(),
-                        null, element.getProperties(), element.getOutProperties());
+                        serviceTemplateFragment, element.getProperties(), element.getOutProperties());
                 listener.lock(messageId, compositionElement, instanceElement);
             }
         }
@@ -87,6 +90,9 @@ public class AcLockHandler {
 
     private void handleUnlockState(UUID messageId, final AutomationComposition automationComposition,
                                    Integer startPhaseMsg) {
+        automationComposition.setLockState(LockState.UNLOCKING);
+        var serviceTemplateFragment = cacheProvider
+                .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId());
         for (var element : automationComposition.getElements().values()) {
             var compositionInProperties = cacheProvider
                     .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition());
@@ -96,7 +102,7 @@ public class AcLockHandler {
                 var compositionElement = cacheProvider.createCompositionElementDto(
                         automationComposition.getCompositionId(), element, compositionInProperties);
                 var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(),
-                        null, element.getProperties(), element.getOutProperties());
+                        serviceTemplateFragment, element.getProperties(), element.getOutProperties());
                 listener.unlock(messageId, compositionElement, instanceElement);
             }
         }
index a3eafd8..b60d637 100644 (file)
@@ -59,7 +59,6 @@ public class AutomationCompositionHandler {
     private final ParticipantMessagePublisher publisher;
     private final ThreadHandler listener;
 
-
     /**
      * Handle a automation composition state change message.
      *
@@ -116,9 +115,10 @@ public class AutomationCompositionHandler {
 
         for (var participantDeploy : updateMsg.getParticipantUpdatesList()) {
             if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) {
-
-                var acCopy = new AutomationComposition(cacheProvider.getAutomationComposition(
-                    updateMsg.getAutomationCompositionId()));
+                var automationComposition = cacheProvider.getAutomationComposition(
+                        updateMsg.getAutomationCompositionId());
+                automationComposition.setDeployState(DeployState.UPDATING);
+                var acCopy = new AutomationComposition(automationComposition);
                 updateExistingElementsOnThisParticipant(updateMsg.getAutomationCompositionId(), participantDeploy,
                         DeployState.UPDATING);
 
@@ -154,6 +154,7 @@ public class AutomationCompositionHandler {
     private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElementDeployList,
             Integer startPhaseMsg, UUID instanceId) {
         var automationComposition = cacheProvider.getAutomationComposition(instanceId);
+        automationComposition.setDeployState(DeployState.DEPLOYING);
         for (var elementDeploy : acElementDeployList) {
             var element = automationComposition.getElements().get(elementDeploy.getId());
             var compositionInProperties = cacheProvider
@@ -188,9 +189,11 @@ public class AutomationCompositionHandler {
 
     private Map<UUID, InstanceElementDto> getInstanceElementDtoMap(AutomationComposition automationComposition) {
         Map<UUID, InstanceElementDto> map = new HashMap<>();
+        var serviceTemplateFragment = cacheProvider
+                .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId());
         for (var element : automationComposition.getElements().values()) {
             var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(),
-                null, element.getProperties(), element.getOutProperties());
+                    serviceTemplateFragment, element.getProperties(), element.getOutProperties());
             map.put(element.getId(), instanceElement);
         }
         return map;
@@ -229,6 +232,9 @@ public class AutomationCompositionHandler {
     private void handleUndeployState(UUID messageId, final AutomationComposition automationComposition,
             Integer startPhaseMsg) {
         automationComposition.setCompositionTargetId(null);
+        automationComposition.setDeployState(DeployState.UNDEPLOYING);
+        var serviceTemplateFragment = cacheProvider
+                .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId());
         for (var element : automationComposition.getElements().values()) {
             var compositionInProperties = cacheProvider
                 .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition());
@@ -238,7 +244,7 @@ public class AutomationCompositionHandler {
                 var compositionElement = cacheProvider.createCompositionElementDto(
                         automationComposition.getCompositionId(), element, compositionInProperties);
                 var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(),
-                    null, element.getProperties(), element.getOutProperties());
+                        serviceTemplateFragment, element.getProperties(), element.getOutProperties());
                 listener.undeploy(messageId, compositionElement, instanceElement);
             }
         }
@@ -246,6 +252,9 @@ public class AutomationCompositionHandler {
 
     private void handleDeleteState(UUID messageId, final AutomationComposition automationComposition,
             Integer startPhaseMsg) {
+        automationComposition.setDeployState(DeployState.DELETING);
+        var serviceTemplateFragment = cacheProvider
+                .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId());
         for (var element : automationComposition.getElements().values()) {
             var compositionInProperties = cacheProvider
                 .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition());
@@ -255,7 +264,7 @@ public class AutomationCompositionHandler {
                 var compositionElement = cacheProvider.createCompositionElementDto(
                         automationComposition.getCompositionId(), element, compositionInProperties);
                 var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(),
-                    null, element.getProperties(), element.getOutProperties());
+                        serviceTemplateFragment, element.getProperties(), element.getOutProperties());
                 listener.delete(messageId, compositionElement, instanceElement);
             }
         }
@@ -279,6 +288,7 @@ public class AutomationCompositionHandler {
         }
         var acCopy = new AutomationComposition(automationComposition);
         automationComposition.setCompositionTargetId(migrationMsg.getCompositionTargetId());
+        automationComposition.setDeployState(DeployState.MIGRATING);
         for (var participantDeploy : migrationMsg.getParticipantUpdatesList()) {
             if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) {
 
index 7a00e08..29b77fc 100644 (file)
@@ -41,6 +41,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
 import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -68,6 +69,9 @@ public class CacheProvider {
     @Getter
     private final Map<UUID, UUID> msgIdentification = new ConcurrentHashMap<>();
 
+    @Getter
+    private final Map<UUID, ToscaServiceTemplate> serviceTemplateFragmentMap = new ConcurrentHashMap<>();
+
     /**
      * Constructor.
      *
@@ -118,6 +122,7 @@ public class CacheProvider {
 
     public void removeElementDefinition(@NonNull UUID compositionId) {
         acElementsDefinitions.remove(compositionId);
+        serviceTemplateFragmentMap.remove(compositionId);
     }
 
     /**
@@ -171,6 +176,9 @@ public class CacheProvider {
                 acElement.setOutProperties(acElementLast.getOutProperties());
                 acElement.setOperationalState(acElementLast.getOperationalState());
                 acElement.setUseState(acElementLast.getUseState());
+                if (element.getToscaServiceTemplateFragment() != null) {
+                    serviceTemplateFragmentMap.put(compositionId, element.getToscaServiceTemplateFragment());
+                }
             }
             acElementMap.put(element.getId(), acElement);
         }
@@ -205,6 +213,9 @@ public class CacheProvider {
             acElement.setProperties(element.getProperties());
             acElement.setOutProperties(element.getOutProperties());
             acElementMap.put(element.getId(), acElement);
+            if (element.getToscaServiceTemplateFragment() != null) {
+                serviceTemplateFragmentMap.put(compositionId, element.getToscaServiceTemplateFragment());
+            }
         }
 
         var automationComposition = new AutomationComposition();
index b6b95ba..a116f12 100644 (file)
@@ -50,6 +50,7 @@ import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
  * Class to hold/create all parameters for test cases.
@@ -260,6 +261,7 @@ public class CommonTestData {
         acElementRestart.setUseState("UseState");
         acElementRestart.setProperties(Map.of("key", "value"));
         acElementRestart.setOutProperties(Map.of("keyOut", "valueOut"));
+        acElementRestart.setToscaServiceTemplateFragment(new ToscaServiceTemplate());
         acElementRestart.setId(UUID.randomUUID());
         participantRestartAc.getAcElementList().add(acElementRestart);
         return participantRestartAc;
@@ -281,6 +283,7 @@ public class CommonTestData {
             acElement.setId(element.getId());
             acElement.setDefinition(element.getDefinition());
             acElement.setProperties(element.getProperties());
+            acElement.setToscaServiceTemplateFragment(new ToscaServiceTemplate());
             participantDeploy.getAcElementList().add(acElement);
         }
         return participantDeploy;