Add UseState and OperationalState support in ACM 63/134063/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 5 Apr 2023 15:32:38 +0000 (16:32 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Tue, 11 Apr 2023 09:06:21 +0000 (10:06 +0100)
Issue-ID: POLICY-4639
Change-Id: Iac5249c054bf41d830463826a8f61f477c48235b
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
21 files changed:
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionDeployAckTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java
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/api/AutomationCompositionElementListener.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/ParticipantHandler.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java

index 8f8a54f..6113360 100644 (file)
@@ -37,6 +37,10 @@ public class AcElementDeployAck {
     // State of the AutomationCompositionElement
     private LockState lockState;
 
+    private String operationalState;
+
+    private String useState;
+
     // Result: Success/Fail.
     private Boolean result;
 
index 0180316..edc9e1c 100644 (file)
@@ -54,6 +54,10 @@ public class AutomationCompositionElement {
     @NonNull
     private LockState lockState = LockState.LOCKED;
 
+    private String operationalState;
+
+    private String useState;
+
     private String description;
 
     // A map indexed by the property name. Each map entry is the serialized value of the property,
@@ -73,5 +77,7 @@ public class AutomationCompositionElement {
         this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
         this.deployState = otherElement.deployState;
         this.lockState = otherElement.lockState;
+        this.operationalState = otherElement.operationalState;
+        this.useState = otherElement.useState;
     }
 }
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
new file mode 100644 (file)
index 0000000..1eb4bf8
--- /dev/null
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.concepts;
+
+import java.util.UUID;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * Class to represent a automation composition element info instance.
+ */
+@NoArgsConstructor
+@Data
+@ToString
+public class AutomationCompositionElementInfo {
+
+    private UUID automationCompositionElementId;
+
+    private DeployState deployState = DeployState.UNDEPLOYED;
+
+    private LockState lockState = LockState.LOCKED;
+
+    private String operationalState;
+
+    private String useState;
+
+    /**
+     * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
+     *
+     * @param otherElement the other element to copy from
+     */
+    public AutomationCompositionElementInfo(AutomationCompositionElementInfo otherElement) {
+        this.automationCompositionElementId = otherElement.automationCompositionElementId;
+        this.deployState = otherElement.deployState;
+        this.lockState = otherElement.lockState;
+        this.operationalState = otherElement.operationalState;
+        this.useState = otherElement.useState;
+    }
+}
index 17875c4..64cfa80 100644 (file)
 
 package org.onap.policy.clamp.models.acm.concepts;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
 
 /**
  * Class to represent a automation composition info instance.
@@ -39,6 +42,8 @@ public class AutomationCompositionInfo {
 
     private LockState lockState = LockState.LOCKED;
 
+    private List<AutomationCompositionElementInfo> elements = new ArrayList<>();
+
     /**
      * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
      *
@@ -48,5 +53,6 @@ public class AutomationCompositionInfo {
         this.automationCompositionId = otherElement.automationCompositionId;
         this.deployState = otherElement.deployState;
         this.lockState = otherElement.lockState;
+        this.elements = PfUtils.mapList(otherElement.elements, AutomationCompositionElementInfo::new);
     }
 }
index 4c3a6a3..4ba336e 100644 (file)
@@ -92,6 +92,12 @@ public class JpaAutomationCompositionElement extends Validated
     @NotNull
     private LockState lockState;
 
+    @Column
+    private String operationalState;
+
+    @Column
+    private String useState;
+
     @Column
     private String description;
 
@@ -152,6 +158,8 @@ public class JpaAutomationCompositionElement extends Validated
         this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
         this.deployState = copyConcept.deployState;
         this.lockState = copyConcept.lockState;
+        this.operationalState = copyConcept.operationalState;
+        this.useState = copyConcept.useState;
     }
 
     /**
@@ -174,6 +182,8 @@ public class JpaAutomationCompositionElement extends Validated
         element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
         element.setDeployState(deployState);
         element.setLockState(lockState);
+        element.setOperationalState(operationalState);
+        element.setUseState(useState);
 
         return element;
     }
@@ -186,6 +196,8 @@ public class JpaAutomationCompositionElement extends Validated
         this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
         this.deployState = element.getDeployState();
         this.lockState = element.getLockState();
+        this.operationalState = element.getOperationalState();
+        this.useState = element.getUseState();
     }
 
     @Override
@@ -227,6 +239,16 @@ public class JpaAutomationCompositionElement extends Validated
             return result;
         }
 
+        result = ObjectUtils.compare(useState, other.useState);
+        if (result != 0) {
+            return result;
+        }
+
+        result = ObjectUtils.compare(operationalState, other.operationalState);
+        if (result != 0) {
+            return result;
+        }
+
         return ObjectUtils.compare(description, other.description);
     }
 }
index 058feae..959fd76 100644 (file)
@@ -22,6 +22,7 @@
 
 package org.onap.policy.clamp.models.acm.persistence.provider;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.UUID;
@@ -30,9 +31,12 @@ import javax.ws.rs.core.Response.Status;
 import lombok.AllArgsConstructor;
 import lombok.NonNull;
 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
 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.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
 import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
 import org.onap.policy.clamp.models.acm.utils.AcmUtils;
 import org.onap.policy.models.base.PfModelRuntimeException;
@@ -50,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional;
 public class AutomationCompositionProvider {
 
     private final AutomationCompositionRepository automationCompositionRepository;
+    private final AutomationCompositionElementRepository acElementRepository;
 
     /**
      * Get automation composition.
@@ -182,4 +187,25 @@ public class AutomationCompositionProvider {
 
         return jpaDeleteAutomationComposition.get().toAuthorative();
     }
+
+    /**
+     * Upgrade States.
+     *
+     * @param automationCompositionInfoList list of AutomationCompositionInfo
+     */
+    public void upgradeStates(@NonNull final List<AutomationCompositionInfo> automationCompositionInfoList) {
+        if (automationCompositionInfoList.isEmpty()) {
+            return;
+        }
+        List<JpaAutomationCompositionElement> jpaList = new ArrayList<>();
+        for (var acInstance : automationCompositionInfoList) {
+            for (var element : acInstance.getElements()) {
+                var jpa = acElementRepository.getReferenceById(element.getAutomationCompositionElementId().toString());
+                jpa.setUseState(element.getUseState());
+                jpa.setOperationalState(element.getOperationalState());
+                jpaList.add(jpa);
+            }
+        }
+        acElementRepository.saveAll(jpaList);
+    }
 }
index 8c50b01..95a1699 100644 (file)
@@ -50,7 +50,7 @@ class AutomationCompositionDeployAckTest {
         // verify with all values
         orig.setAutomationCompositionId(UUID.randomUUID());
         orig.setParticipantId(CommonTestData.getParticipantId());
-        var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED,
+        var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "",
             true, "AutomationCompositionElement result");
         final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult);
         orig.setAutomationCompositionResultMap(automationCompositionResultMap);
index 711af2f..894d67d 100644 (file)
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
 import org.onap.policy.clamp.models.acm.concepts.DeployState;
 import org.onap.policy.clamp.models.acm.concepts.LockState;
@@ -54,6 +55,7 @@ class ParticipantStatusTest {
 
         // verify with all values
         var automationCompositionId = UUID.randomUUID();
+        var acElementId = UUID.randomUUID();
         orig.setAutomationCompositionId(automationCompositionId);
         var participantId = CommonTestData.getParticipantId();
         orig.setParticipantId(participantId);
@@ -61,7 +63,7 @@ class ParticipantStatusTest {
         orig.setState(ParticipantState.ON_LINE);
         orig.setTimestamp(Instant.ofEpochMilli(3000));
 
-        var acInfo = getAutomationCompositionInfo(automationCompositionId);
+        var acInfo = getAutomationCompositionInfo(automationCompositionId, acElementId);
         orig.setAutomationCompositionInfoList(List.of(acInfo));
 
         var participantDefinitionUpdate = new ParticipantDefinition();
@@ -76,12 +78,19 @@ class ParticipantStatusTest {
         assertSerializable(orig, ParticipantStatus.class);
     }
 
-    private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) {
+    private AutomationCompositionInfo getAutomationCompositionInfo(UUID id, UUID acElementId) {
         var acInfo = new AutomationCompositionInfo();
         acInfo.setDeployState(DeployState.DEPLOYED);
         acInfo.setLockState(LockState.LOCKED);
         acInfo.setAutomationCompositionId(id);
 
+        var acInfoElement = new AutomationCompositionElementInfo();
+        acInfoElement.setAutomationCompositionElementId(acElementId);
+        acInfoElement.setDeployState(DeployState.DEPLOYED);
+        acInfoElement.setLockState(LockState.LOCKED);
+        acInfoElement.setOperationalState("DEFAULT");
+        acInfoElement.setUseState("IDLE");
+        acInfo.getElements().add(acInfoElement);
         return acInfo;
     }
 
index e9df9b7..2a79aee 100644 (file)
@@ -122,8 +122,13 @@ class JpaAutomationCompositionElementTest {
 
         assertEquals(ELEMENT_ID, testJpaAcElement.getElementId());
 
-        var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
-        assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
+        var testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
+        assertEquals(testJpaAcElement, testJpaAcElement2);
+
+        testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement.toAuthorative());
+        testJpaAcElement2.setElementId(ELEMENT_ID);
+        testJpaAcElement2.setInstanceId(INSTANCE_ID);
+        assertEquals(testJpaAcElement, testJpaAcElement2);
     }
 
     @Test
@@ -138,52 +143,60 @@ class JpaAutomationCompositionElementTest {
 
     @Test
     void testJpaAutomationCompositionElementCompareTo() {
-        var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
+        var testJpaAcElement = createJpaAutomationCompositionElementInstance();
 
-        var otherJpaAutomationCompositionElement =
-                new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement));
+        var otherJpaAcElement =
+                new JpaAutomationCompositionElement(testJpaAcElement);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        assertEquals(-1, testJpaAcElement.compareTo(null));
+        assertEquals(0, testJpaAcElement.compareTo(testJpaAcElement));
         assertNotEquals(0,
-                testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
-
-        testJpaAutomationCompositionElement.setElementId("BadValue");
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setElementId(ELEMENT_ID);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        testJpaAutomationCompositionElement.setInstanceId("BadValue");
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        testJpaAutomationCompositionElement.setDescription("Description");
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setDescription(null);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED);
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        testJpaAutomationCompositionElement.setLockState(LockState.UNLOCKED);
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setLockState(LockState.LOCKED);
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-        testJpaAutomationCompositionElement.setParticipantId(UUID.randomUUID().toString());
-        assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
-        assertEquals(testJpaAutomationCompositionElement,
-                new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
+                testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
+
+        testJpaAcElement.setElementId("BadValue");
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setElementId(ELEMENT_ID);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setInstanceId("BadValue");
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setInstanceId(INSTANCE_ID);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setDescription("Description");
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setDescription(null);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setDeployState(DeployState.DEPLOYED);
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setDeployState(DeployState.UNDEPLOYED);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setLockState(LockState.UNLOCKED);
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setLockState(LockState.LOCKED);
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setUseState("BadValue");
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setUseState("IDLE");
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setOperationalState("BadValue");
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+        testJpaAcElement.setOperationalState("DEFAULT");
+        assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
+        assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+        assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement));
     }
 
     @Test
@@ -229,6 +242,8 @@ class JpaAutomationCompositionElementTest {
         automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
         automationCompositionElement.setParticipantId(CommonTestData.getParticipantId());
         automationCompositionElement.setProperties(Map.of("key", "{}"));
+        automationCompositionElement.setUseState("IDLE");
+        automationCompositionElement.setOperationalState("DEFAULT");
 
         return automationCompositionElement;
     }
index ba1e33c..0991c1b 100644 (file)
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
 import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
 import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -64,7 +65,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testAutomationCompositionCreate() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         when(automationCompositionRepository.save(any(JpaAutomationComposition.class)))
                 .thenReturn(inputAutomationCompositionsJpa.get(0));
@@ -78,7 +80,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testAutomationCompositionUpdate() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         assertThatThrownBy(() -> automationCompositionProvider.updateAutomationComposition(null))
                 .hasMessageMatching(OBJECT_IS_NULL);
@@ -95,7 +98,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testGetAutomationCompositions() throws Exception {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
         var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
@@ -112,7 +116,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testGetAutomationComposition() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
         assertThatThrownBy(
@@ -128,7 +133,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testFindAutomationComposition() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
         var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
@@ -151,7 +157,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testGetAcInstancesByCompositionId() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
         when(automationCompositionRepository.findByCompositionId(automationComposition.getCompositionId().toString()))
@@ -164,7 +171,8 @@ class AutomationCompositionProviderTest {
     @Test
     void testDeleteAutomationComposition() {
         var automationCompositionRepository = mock(AutomationCompositionRepository.class);
-        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+        var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+                mock(AutomationCompositionElementRepository.class));
 
         assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationComposition(UUID.randomUUID()))
                 .hasMessageMatching(".*.failed, automation composition does not exist");
index 3e74019..d40ac32 100644 (file)
@@ -201,4 +201,16 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
 
         return policyList;
     }
+
+    @Override
+    public String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        return "IDLE";
+    }
+
+    @Override
+    public String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        return "ENABLED";
+    }
 }
index 47c2799..ecc0b88 100644 (file)
@@ -21,6 +21,7 @@
 package org.onap.policy.clamp.acm.participant.policy.main.handler;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -133,4 +134,22 @@ class AutomationCompositionElementHandlerTest {
         assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
                 .hasMessageMatching("Deploy of Policy failed.");
     }
+
+    @Test
+    void testGetOperationalState() throws PfModelException {
+        var api = mock(PolicyApiHttpClient.class);
+        var pap = mock(PolicyPapHttpClient.class);
+        var handler = new AutomationCompositionElementHandler(api, pap);
+
+        assertEquals("ENABLED", handler.getOperationalState(UUID.randomUUID(), UUID.randomUUID()));
+    }
+
+    @Test
+    void testGetUseState() throws PfModelException {
+        var api = mock(PolicyApiHttpClient.class);
+        var pap = mock(PolicyPapHttpClient.class);
+        var handler = new AutomationCompositionElementHandler(api, pap);
+
+        assertEquals("IDLE", handler.getUseState(UUID.randomUUID(), UUID.randomUUID()));
+    }
 }
index da6bccb..c99241f 100644 (file)
@@ -47,4 +47,26 @@ public interface AutomationCompositionElementListener {
      */
     public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
             throws PfModelException;
+
+    public default void lock(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        // default Lock Operation
+    }
+
+    public default void unlock(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        // default Unlock Operation
+    }
+
+    public default String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        // default Use State
+        return "";
+    }
+
+    public default String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+            throws PfModelException {
+        // default Operational State
+        return "";
+    }
 }
index d767001..1eaf63d 100644 (file)
@@ -111,6 +111,8 @@ public class AutomationCompositionHandler {
             if (element != null) {
                 element.setDeployState(deployState);
                 element.setLockState(lockState);
+                element.setUseState(getUseState(automationCompositionId, id));
+                element.setOperationalState(getOperationalState(automationCompositionId, id));
             }
             var checkOpt = automationComposition.getElements().values().stream()
                     .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
@@ -133,8 +135,11 @@ public class AutomationCompositionHandler {
             automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId);
             acElement.setDeployState(deployState);
             acElement.setLockState(lockState);
+            acElement.setUseState(getUseState(automationCompositionId, id));
+            acElement.setOperationalState(getOperationalState(automationCompositionId, id));
             automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(),
-                    new AcElementDeployAck(deployState, lockState, true,
+                    new AcElementDeployAck(deployState, lockState,
+                            acElement.getOperationalState(), acElement.getUseState(), true,
                             "Automation composition element {} state changed to {}\", id, newState)"));
             LOGGER.debug("Automation composition element {} state changed to {}", id, deployState);
             automationCompositionStateChangeAck
@@ -408,8 +413,15 @@ public class AutomationCompositionHandler {
         if (acElementNodeTemplate != null) {
             int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
             if (startPhaseMsg.equals(startPhase)) {
-                updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
-                        LockState.LOCKED);
+                for (var acElementListener : listeners) {
+                    try {
+                        acElementListener.lock(instanceId, acElement.getId());
+                        updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+                                LockState.LOCKED);
+                    } catch (PfModelException e) {
+                        LOGGER.error("Automation composition element lock failed {}", instanceId);
+                    }
+                }
             }
         }
     }
@@ -420,8 +432,15 @@ public class AutomationCompositionHandler {
         if (acElementNodeTemplate != null) {
             int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
             if (startPhaseMsg.equals(startPhase)) {
-                updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
-                        LockState.UNLOCKED);
+                for (var acElementListener : listeners) {
+                    try {
+                        acElementListener.unlock(instanceId, acElement.getId());
+                        updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+                                LockState.UNLOCKED);
+                    } catch (PfModelException e) {
+                        LOGGER.error("Automation composition element unlock failed {}", instanceId);
+                    }
+                }
             }
         }
     }
@@ -436,10 +455,46 @@ public class AutomationCompositionHandler {
                     try {
                         acElementListener.undeploy(instanceId, acElement.getId());
                     } catch (PfModelException e) {
-                        LOGGER.debug("Automation composition element update failed {}", instanceId);
+                        LOGGER.error("Automation composition element update failed {}", instanceId);
                     }
                 }
             }
         }
     }
+
+    /**
+     * Get UseState.
+     *
+     * @param instanceId the instance Id
+     * @param acElementId the Automation Composition Element Id
+     * @return the UseState of the Automation Composition Element
+     */
+    public String getUseState(UUID instanceId, UUID acElementId) {
+        for (var acElementListener : listeners) {
+            try {
+                return acElementListener.getUseState(instanceId, acElementId);
+            } catch (PfModelException e) {
+                LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Get OperationalState.
+     *
+     * @param instanceId the instance Id
+     * @param acElementId the Automation Composition Element Id
+     * @return the OperationalState of the Automation Composition Element
+     */
+    public String getOperationalState(UUID instanceId, UUID acElementId) {
+        for (var acElementListener : listeners) {
+            try {
+                return acElementListener.getOperationalState(instanceId, acElementId);
+            } catch (PfModelException e) {
+                LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+            }
+        }
+        return null;
+    }
 }
index 5565e0b..9e2484c 100644 (file)
@@ -33,6 +33,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag
 import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
@@ -290,6 +291,16 @@ public class ParticipantHandler {
             acInfo.setAutomationCompositionId(entry.getKey());
             acInfo.setDeployState(entry.getValue().getDeployState());
             acInfo.setLockState(entry.getValue().getLockState());
+            for (var element : entry.getValue().getElements().values()) {
+                var elementInfo = new AutomationCompositionElementInfo();
+                elementInfo.setAutomationCompositionElementId(element.getId());
+                elementInfo.setDeployState(element.getDeployState());
+                elementInfo.setLockState(element.getLockState());
+                elementInfo.setOperationalState(
+                        automationCompositionHandler.getOperationalState(entry.getKey(), element.getId()));
+                elementInfo.setUseState(automationCompositionHandler.getUseState(entry.getKey(), element.getId()));
+                acInfo.getElements().add(elementInfo);
+            }
             automationCompositionInfoList.add(acInfo);
         }
         return automationCompositionInfoList;
index 35da039..25b1fac 100644 (file)
@@ -24,7 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.util.List;
 import java.util.UUID;
@@ -41,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCom
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
 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.models.base.PfModelException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
@@ -49,6 +55,8 @@ class AutomationCompositionHandlerTest {
 
     private final CommonTestData commonTestData = new CommonTestData();
 
+    private static final String STATE_VALUE = "STATE_VALUE";
+
     @Test
     void automationCompositionHandlerTest() {
         var ach = commonTestData.getMockAutomationCompositionHandler();
@@ -116,10 +124,11 @@ class AutomationCompositionHandlerTest {
     }
 
     @Test
-    void handleAutomationCompositionDeployTest() {
+    void handleAutomationCompositionDeployTest() throws PfModelException {
         var acd = new AutomationCompositionElementDefinition();
         var definition = CommonTestData.getDefinition();
         acd.setAcElementDefinitionId(definition);
+        acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
         var updateMsg = new AutomationCompositionDeploy();
         updateMsg.setAutomationCompositionId(UUID.randomUUID());
         var uuid = UUID.randomUUID();
@@ -130,19 +139,25 @@ class AutomationCompositionHandlerTest {
         updateMsg.setStartPhase(0);
         var acElementDefinitions = List.of(acd);
         var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+        var listener = mock(AutomationCompositionElementListener.class);
+        ach.registerAutomationCompositionElementListener(listener);
+        ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+        verify(listener, times(0)).deploy(any(), any(), anyMap());
         updateMsg.setFirstStartPhase(false);
         updateMsg.setStartPhase(1);
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+        ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+        verify(listener, times(0)).deploy(any(), any(), anyMap());
 
         ach.getAutomationCompositionMap().clear();
         updateMsg.setFirstStartPhase(true);
         updateMsg.setStartPhase(0);
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+        ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+        verify(listener, times(0)).deploy(any(), any(), anyMap());
 
         updateMsg.setAutomationCompositionId(UUID.randomUUID());
         updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class)));
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+        ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+        verify(listener, times(0)).deploy(any(), any(), anyMap());
 
         updateMsg.setStartPhase(1);
         var participantDeploy = new ParticipantDeploy();
@@ -152,15 +167,13 @@ class AutomationCompositionHandlerTest {
         participantDeploy.setAcElementList(List.of(element));
         updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
 
-        var acd2 = new AutomationCompositionElementDefinition();
-        acd2.setAcElementDefinitionId(definition);
-        acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, List.of(acd2)));
-
+        updateMsg.setStartPhase(0);
+        ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+        verify(listener, times(1)).deploy(any(), any(), anyMap());
     }
 
     @Test
-    void acUndeployTest() {
+    void acUndeployTest() throws PfModelException {
         var uuid = UUID.randomUUID();
         var partecipantId = CommonTestData.getParticipantId();
         var definition = CommonTestData.getDefinition();
@@ -171,14 +184,46 @@ class AutomationCompositionHandlerTest {
         var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
         stateChangeUndeploy
                 .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
-        ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of());
+        var listener = mock(AutomationCompositionElementListener.class);
+        ach.registerAutomationCompositionElementListener(listener);
+
+        var acd = new AutomationCompositionElementDefinition();
+        acd.setAcElementDefinitionId(definition);
+        acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+        ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd));
+        verify(listener, times(1)).undeploy(any(), any());
+
         stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID());
         stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId());
         assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()));
     }
 
     @Test
-    void automationCompositionStateUnlock() {
+    void automationCompositionStateLock() throws PfModelException {
+        var uuid = UUID.randomUUID();
+        var partecipantId = CommonTestData.getParticipantId();
+        var definition = CommonTestData.getDefinition();
+
+        var stateChangeLock =
+                commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK);
+
+        var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+        var listener = mock(AutomationCompositionElementListener.class);
+        ach.registerAutomationCompositionElementListener(listener);
+        stateChangeLock
+                .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+        var acd = new AutomationCompositionElementDefinition();
+        acd.setAcElementDefinitionId(definition);
+        acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+        ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd));
+        stateChangeLock.setAutomationCompositionId(UUID.randomUUID());
+        stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId());
+        ach.handleAutomationCompositionStateChange(stateChangeLock, List.of());
+        verify(listener, times(1)).lock(any(), any());
+    }
+
+    @Test
+    void automationCompositionStateUnlock() throws PfModelException {
         var uuid = UUID.randomUUID();
         var partecipantId = CommonTestData.getParticipantId();
         var definition = CommonTestData.getDefinition();
@@ -187,11 +232,41 @@ class AutomationCompositionHandlerTest {
                 commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
 
         var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+        var listener = mock(AutomationCompositionElementListener.class);
+        ach.registerAutomationCompositionElementListener(listener);
         stateChangeUnlock
                 .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
-        ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+        var acd = new AutomationCompositionElementDefinition();
+        acd.setAcElementDefinitionId(definition);
+        acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+        ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd));
         stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID());
         stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId());
-        assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()));
+        ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+        verify(listener, times(1)).unlock(any(), any());
+    }
+
+    @Test
+    void testGetUseState() throws PfModelException {
+        var uuid = UUID.randomUUID();
+        var partecipantId = CommonTestData.getParticipantId();
+        var definition = CommonTestData.getDefinition();
+        var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+        var listener = mock(AutomationCompositionElementListener.class);
+        when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE);
+        ach.registerAutomationCompositionElementListener(listener);
+        assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid));
+    }
+
+    @Test
+    void testGetOperationalState() throws PfModelException {
+        var uuid = UUID.randomUUID();
+        var partecipantId = CommonTestData.getParticipantId();
+        var definition = CommonTestData.getDefinition();
+        var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+        var listener = mock(AutomationCompositionElementListener.class);
+        when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE);
+        ach.registerAutomationCompositionElementListener(listener);
+        assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid));
     }
 }
index 4dcfd14..140fd94 100644 (file)
@@ -163,7 +163,7 @@ public class CommonTestData {
     }
 
     public static ToscaConceptIdentifier getDefinition() {
-        return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
+        return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3");
     }
 
     /**
@@ -308,6 +308,7 @@ public class CommonTestData {
     public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
             DeployOrder deployOrder, LockOrder lockOrder) {
         var stateChange = new AutomationCompositionStateChange();
+        stateChange.setStartPhase(0);
         stateChange.setAutomationCompositionId(UUID.randomUUID());
         stateChange.setParticipantId(participantId);
         stateChange.setMessageId(uuid);
index 5fcb383..85beb76 100644 (file)
@@ -163,6 +163,13 @@ public class SupervisionAcHandler {
             if (element != null) {
                 element.setDeployState(acElementAck.getValue().getDeployState());
                 element.setLockState(acElementAck.getValue().getLockState());
+                if (DeployState.DEPLOYED.equals(element.getDeployState())) {
+                    element.setOperationalState(acElementAck.getValue().getOperationalState());
+                    element.setUseState(acElementAck.getValue().getUseState());
+                } else {
+                    element.setOperationalState(null);
+                    element.setUseState(null);
+                }
                 updated = true;
             }
         }
index c1bfcf0..564fa8d 100644 (file)
@@ -36,6 +36,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage;
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,6 +53,7 @@ public class SupervisionParticipantHandler {
     private final ParticipantProvider participantProvider;
     private final ParticipantRegisterAckPublisher participantRegisterAckPublisher;
     private final ParticipantDeregisterAckPublisher participantDeregisterAckPublisher;
+    private final AutomationCompositionProvider automationCompositionProvider;
 
     /**
      * Handle a ParticipantRegister message from a participant.
@@ -101,6 +103,9 @@ public class SupervisionParticipantHandler {
         LOGGER.debug("Participant Status received {}", participantStatusMsg);
         saveParticipantStatus(participantStatusMsg,
             listToMap(participantStatusMsg.getParticipantSupportedElementType()));
+        if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) {
+            automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList());
+        }
     }
 
     private void saveParticipantStatus(ParticipantMessage participantMessage,
index 153f7a0..c44fa1d 100644 (file)
@@ -64,7 +64,7 @@ class SupervisionAcHandlerTest {
         var automationCompositionAckMessage =
                 new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
         for (var elementEntry : automationComposition.getElements().entrySet()) {
-            var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+            var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, "", "", true, "");
             automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
                     acElementDeployAck);
         }
@@ -86,7 +86,7 @@ class SupervisionAcHandlerTest {
         var automationCompositionAckMessage =
                 new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
         for (var elementEntry : automationComposition.getElements().entrySet()) {
-            var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, true, "");
+            var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", true, "");
             automationCompositionAckMessage
                     .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
         }
index fb12e04..f00747c 100644 (file)
@@ -38,6 +38,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
 
 class SupervisionParticipantHandlerTest {
@@ -54,7 +55,8 @@ class SupervisionParticipantHandlerTest {
         participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
         var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
         var handler = new SupervisionParticipantHandler(participantProvider,
-            mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
+            mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
+            mock(AutomationCompositionProvider.class));
 
         handler.handleParticipantMessage(participantDeregisterMessage);
 
@@ -76,7 +78,8 @@ class SupervisionParticipantHandlerTest {
         var participantProvider = mock(ParticipantProvider.class);
         var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
         var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
-                mock(ParticipantDeregisterAckPublisher.class));
+                mock(ParticipantDeregisterAckPublisher.class),
+                mock(AutomationCompositionProvider.class));
         handler.handleParticipantMessage(participantRegisterMessage);
 
         verify(participantProvider).saveParticipant(any());
@@ -97,7 +100,8 @@ class SupervisionParticipantHandlerTest {
 
         var participantProvider = mock(ParticipantProvider.class);
         var handler = new SupervisionParticipantHandler(participantProvider,
-            mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
+            mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+            mock(AutomationCompositionProvider.class));
         var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
         when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
                 .thenReturn(Optional.of(participant));