Updates to participant messages 99/122899/5
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>
Tue, 27 Jul 2021 16:24:44 +0000 (17:24 +0100)
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>
Thu, 29 Jul 2021 07:59:27 +0000 (08:59 +0100)
Updated participant messages according to
https://wiki.onap.org/display/DW/The+CLAMP+Control+Loop+Participant+Protocol

Issue-ID: POLICY-3416
Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Change-Id: Idef19bee05116f11690c7aca0493e731dd128e06

19 files changed:
models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java [new file with mode: 0644]
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java [new file with mode: 0644]
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java [new file with mode: 0644]
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java
participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/main/rest/TestListenerUtils.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ControlLoopUpdatePublisher.java

index 83f062c..b99759e 100644 (file)
 
 package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
 import java.util.UUID;
+import java.util.function.UnaryOperator;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
 import lombok.ToString;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfUtils;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
@@ -57,6 +61,10 @@ public class ControlLoopElement {
 
     private ClElementStatistics clElementStatistics;
 
+    // A map indexed by the property name. Each map entry is the serialized value of the property,
+    // which can be deserialized into an instance of the type of the property.
+    private Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
+
     /**
      * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
      *
@@ -71,5 +79,6 @@ public class ControlLoopElement {
         this.orderedState = otherElement.orderedState;
         this.description = otherElement.description;
         this.clElementStatistics = otherElement.clElementStatistics;
+        this.commonPropertiesMap = PfUtils.mapMap(otherElement.commonPropertiesMap, UnaryOperator.identity());
     }
 }
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java
new file mode 100644 (file)
index 0000000..6a72ec1
--- /dev/null
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.controlloop.models.messages.dmaap.participant;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.function.UnaryOperator;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Class to represent the CONTROLLOOP_ACK message that a participant sends
+ * to control loop runtime as an acknowledgement to either ControlLoopUpdate
+ * or ControlLoopStateChange message.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class ControlLoopAck extends ParticipantAckMessage {
+
+    /**
+     * Participant ID, or {@code null} for messages from participants.
+     */
+    private ToscaConceptIdentifier participantId;
+
+    /**
+     * Participant Type, or {@code null} for messages from participants.
+     */
+    private ToscaConceptIdentifier participantType;
+
+    /**
+     * Control loop ID, or {@code null} for messages to participants.
+     */
+    private ToscaConceptIdentifier controlLoopId;
+
+    // A map with ControlLoopElementID as its key, and a pair of result and message as value per
+    // ControlLoopElement.
+    private Map<UUID, Map<UUID, Boolean>> controlLoopResultMap = new LinkedHashMap<>();
+
+    /**
+     * Constructor for instantiating ParticipantRegisterAck class with message name.
+     *
+     */
+    public ControlLoopAck(final ParticipantMessageType messageType) {
+        super(messageType);
+    }
+
+    /**
+     * Constructs the object, making a deep copy.
+     *
+     * @param source source from which to copy
+     */
+    public ControlLoopAck(final ControlLoopAck source) {
+        super(source);
+        this.participantId = source.participantId;
+        this.participantType = source.participantType;
+        this.controlLoopId = source.controlLoopId;
+        this.controlLoopResultMap = PfUtils.mapMap(source.controlLoopResultMap,
+                clElementResultMap -> PfUtils.mapMap(clElementResultMap, UnaryOperator.identity()));
+    }
+}
index 180d994..e6955b9 100644 (file)
@@ -24,6 +24,7 @@ import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 
 /**
  * Class to represent the CONTROL_LOOP_STATE_CHANGE message that the control loop runtime will send to
@@ -34,6 +35,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
 @ToString(callSuper = true)
 public class ControlLoopStateChange extends ParticipantMessage {
     private ControlLoopOrderedState orderedState;
+    private ControlLoopState currentState;
 
     /**
      * Constructor for instantiating ControlLoopStateChange class with message name.
@@ -52,5 +54,6 @@ public class ControlLoopStateChange extends ParticipantMessage {
         super(source);
 
         this.orderedState = source.orderedState;
+        this.currentState = source.currentState;
     }
 }
index 876c370..865264f 100644 (file)
 
 package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
  * Class to represent the CONTROL_LOOP_UPDATE message that the control loop runtime sends to a participant.
@@ -35,11 +40,13 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 @Setter
 @ToString(callSuper = true)
 public class ControlLoopUpdate extends ParticipantMessage {
+
     // The control loop
     private ControlLoop controlLoop;
 
-    // A service template containing a complete definition of the control loop
-    private ToscaServiceTemplate controlLoopDefinition;
+    // A map with Participant ID as its key, and a map of ControlLoopElements as value.
+    private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>>
+            participantUpdateMap = new LinkedHashMap<>();
 
     /**
      * Constructor for instantiating ControlLoopUpdate class with message name.
@@ -57,7 +64,8 @@ public class ControlLoopUpdate extends ParticipantMessage {
     public ControlLoopUpdate(ControlLoopUpdate source) {
         super(source);
 
-        this.controlLoop = new ControlLoop(source.controlLoop);
-        this.controlLoopDefinition = new ToscaServiceTemplate(source.controlLoopDefinition);
+        this.controlLoop = source.controlLoop;
+        this.participantUpdateMap = PfUtils.mapMap(source.participantUpdateMap,
+                clElementMap -> PfUtils.mapMap(clElementMap, ControlLoopElement::new));
     }
 }
index 0c39392..62b8d20 100644 (file)
@@ -83,5 +83,22 @@ public enum ParticipantMessageType {
      * Used by participant to acknowledge the receipt of Participant_Update message
      * from control loop runtime.
      */
-    PARTICIPANT_UPDATE_ACK
+    PARTICIPANT_UPDATE_ACK,
+
+    /**
+     * Used by participant to acknowledge the receipt of ControlLoop_Update message
+     * from control loop runtime.
+     */
+    CONTROLLOOP_UPDATE_ACK,
+
+    /**
+     * Used by participant to acknowledge the receipt of ControlLoop_StateChange message
+     * from control loop runtime.
+     */
+    CONTROLLOOP_STATECHANGE_ACK,
+
+    /**
+     * Used by control loop runtime to request for ParticipantStatus message immediately.
+     */
+    PARTICIPANT_STATUS_REQ
 }
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java
new file mode 100644 (file)
index 0000000..9242cea
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.controlloop.models.messages.dmaap.participant;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+/**
+ * Class to represent the PARTICIPANT_STATUS_REQ message that controlloop runtime
+ * sends to participants for an immediate ParticipantStatus from participants.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class ParticipantStatusReq extends ParticipantMessage {
+
+    /**
+     * Constructor for instantiating a participant status request class.
+     */
+    public ParticipantStatusReq() {
+        super(ParticipantMessageType.PARTICIPANT_STATUS_REQ);
+    }
+
+    /**
+     * Constructs the object, making a deep copy.
+     *
+     * @param source source from which to copy
+     */
+    public ParticipantStatusReq(final ParticipantStatusReq source) {
+        super(source);
+    }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java
new file mode 100644 (file)
index 0000000..8734a43
--- /dev/null
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.controlloop.models.messages.dmaap.participant;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.util.Map;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class ControlLoopAckTest {
+
+    @Test
+    void testCopyConstructor() {
+        assertThatThrownBy(() -> new ControlLoopAck((ControlLoopAck) null))
+            .isInstanceOf(NullPointerException.class);
+
+        final ControlLoopAck orig = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_UPDATE);
+
+        // verify with null values
+        assertEquals(removeVariableFields(orig.toString()),
+                removeVariableFields(new ControlLoopAck(orig).toString()));
+
+        // verify with all values
+        ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
+        orig.setControlLoopId(id);
+        orig.setParticipantId(id);
+        orig.setParticipantType(id);
+
+        Map<UUID, Boolean> clElementResult = Map.of(UUID.randomUUID(), true);
+        final Map<UUID, Map<UUID, Boolean>> controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult);
+        orig.setControlLoopResultMap(controlLoopResultMap);
+
+        orig.setResponseTo(UUID.randomUUID());
+        orig.setResult(true);
+        orig.setMessage("Successfully processed ControlLoopUpdate message");
+
+        assertEquals(removeVariableFields(orig.toString()),
+                removeVariableFields(new ControlLoopAck(orig).toString()));
+    }
+}
index 5b7fda0..dd6a814 100644 (file)
@@ -28,6 +28,7 @@ import java.time.Instant;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
@@ -46,13 +47,12 @@ class ControlLoopStateChangeTest {
                 removeVariableFields(new ControlLoopStateChange(orig).toString()));
 
         // verify with all values
-        ToscaConceptIdentifier id = new ToscaConceptIdentifier();
-        id.setName("id");
-        id.setVersion("1.2.3");
+        ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
         orig.setMessageId(UUID.randomUUID());
         orig.setOrderedState(ControlLoopOrderedState.RUNNING);
+        orig.setCurrentState(ControlLoopState.PASSIVE);
         orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         assertEquals(removeVariableFields(orig.toString()),
index ac164e3..0ac4f53 100644 (file)
@@ -22,15 +22,17 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.time.Instant;
+import java.util.Map;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
  * Test the copy constructor.
@@ -42,30 +44,37 @@ class ControlLoopUpdateTest {
 
         ControlLoopUpdate orig = new ControlLoopUpdate();
         // verify with all values
-        ToscaConceptIdentifier id = new ToscaConceptIdentifier();
-        id.setName("id");
-        id.setVersion("1.2.3");
+        ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
         orig.setControlLoopId(id);
-        orig.setParticipantId(id);
+        orig.setParticipantId(null);
         orig.setMessageId(UUID.randomUUID());
         orig.setTimestamp(Instant.ofEpochMilli(3000));
 
+        ControlLoopElement clElement = new ControlLoopElement();
+        clElement.setId(UUID.randomUUID());
+        clElement.setDefinition(id);
+        clElement.setDescription("Description");
+        clElement.setOrderedState(ControlLoopOrderedState.PASSIVE);
+        clElement.setState(ControlLoopState.PASSIVE);
+        clElement.setParticipantId(id);
+        clElement.setParticipantType(id);
+
         ControlLoop controlLoop = new ControlLoop();
         controlLoop.setName("controlLoop");
-        ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
-        toscaServiceTemplate.setName("serviceTemplate");
-        toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
-        toscaServiceTemplate.setDescription("Description of serviceTemplate");
-        toscaServiceTemplate.setVersion("1.2.3");
-        orig.setControlLoopDefinition(toscaServiceTemplate);
+        Map<UUID, ControlLoopElement> elements = Map.of(clElement.getId(), clElement);
+        controlLoop.setElements(elements);
         orig.setControlLoop(controlLoop);
 
+        Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
+        clElement.setCommonPropertiesMap(commonPropertiesMap);
+
+        Map<UUID, ControlLoopElement> controlLoopElementMap = Map.of(UUID.randomUUID(), clElement);
+        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>>
+            participantUpdateMap = Map.of(id, controlLoopElementMap);
+        orig.setParticipantUpdateMap(participantUpdateMap);
+
         ControlLoopUpdate other = new ControlLoopUpdate(orig);
 
         assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
-
-        // ensure list and items are not the same object
-        assertNotSame(other.getControlLoop(), controlLoop);
-        assertNotSame(other.getControlLoopDefinition(), toscaServiceTemplate);
     }
 }
index 1a56a39..e67fbc1 100644 (file)
@@ -46,6 +46,8 @@ class ParticipantPojosTest {
         pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class));
         pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class));
         pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class));
+        pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAck.class));
+        pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAckTest.class));
 
         // @formatter:off
         final Validator validator = ValidatorBuilder
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java
new file mode 100644 (file)
index 0000000..b391aa2
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.controlloop.models.messages.dmaap.participant;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Test the copy constructor.
+ */
+class ParticipantStatusReqTest {
+    @Test
+    void testCopyConstructor() {
+        assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class);
+
+        ParticipantStatusReq orig = new ParticipantStatusReq();
+        // verify with all values
+        ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
+        orig.setParticipantId(id);
+        orig.setControlLoopId(null);
+        orig.setParticipantType(null);
+        orig.setMessageId(UUID.randomUUID());
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
+
+        ParticipantStatusReq other = new ParticipantStatusReq(orig);
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+    }
+}
index 4f8b42b..0944312 100644 (file)
@@ -22,11 +22,9 @@ package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.time.Instant;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
@@ -62,16 +60,13 @@ class ParticipantUpdateTest {
         ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
         clDefinition.setId(UUID.randomUUID());
         clDefinition.setControlLoopElementToscaServiceTemplate(toscaServiceTemplate);
-        Map<String, String> commonPropertiesMap = new LinkedHashMap<>();
-        commonPropertiesMap.put("Prop1", "PropValue");
+        Map<String, String> commonPropertiesMap = Map.of("Prop1", "PropValue");
         clDefinition.setCommonPropertiesMap(commonPropertiesMap);
 
-        Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
-        controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
+        Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
 
         Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = new LinkedHashMap<>();
-        participantDefinitionUpdateMap.put(id, controlLoopElementDefinitionMap);
+            participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap);
         orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         ParticipantUpdate other = new ParticipantUpdate(orig);
index c0bd896..10563cd 100644 (file)
 package org.onap.policy.clamp.controlloop.participant.policy.endtoend;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
 import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
 import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantUpdateListener;
 import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
 import org.onap.policy.clamp.controlloop.participant.policy.main.utils.TestListenerUtils;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -58,9 +55,6 @@ class ParticipantPolicyTest {
         ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
         controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
 
-        // Verify that the ToscaServicetemplate has policy_types
-        assertNotNull(controlLoopUpdateMsg.getControlLoopDefinition().getPolicyTypes());
-
         synchronized (lockit) {
             ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
 
@@ -75,13 +69,6 @@ class ParticipantPolicyTest {
         ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
         controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
 
-        // Add policies to the toscaServiceTemplate
-        TestListenerUtils.addPoliciesToToscaServiceTemplate(controlLoopUpdateMsg.getControlLoopDefinition());
-
-        // Verify that the ToscaServicetemplate has policies
-        assertNotNull(
-                controlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
-
         synchronized (lockit) {
             ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
 
@@ -96,13 +83,6 @@ class ParticipantPolicyTest {
         ControlLoopUpdate controlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
         controlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
 
-        // Add policies to the toscaServiceTemplate
-        TestListenerUtils.addPoliciesToToscaServiceTemplate(controlLoopUpdateMsg.getControlLoopDefinition());
-
-        // Verify that the ToscaServicetemplate has policies
-        assertNotNull(
-                controlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
-
         synchronized (lockit) {
             ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
 
index 6f1e001..fe7e17f 100644 (file)
@@ -168,7 +168,6 @@ public class TestListenerUtils {
         controlLoop.setVersion("1.0.0");
         controlLoop.setDefinition(controlLoopId);
         clUpdateMsg.setControlLoop(controlLoop);
-        clUpdateMsg.setControlLoopDefinition(toscaServiceTemplate);
 
         return clUpdateMsg;
     }
@@ -190,11 +189,9 @@ public class TestListenerUtils {
         participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
         participantUpdateMsg.setMessageId(UUID.randomUUID());
 
-        ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
-        toscaServiceTemplate.setName("serviceTemplate");
-        toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
-        toscaServiceTemplate.setDescription("Description of serviceTemplate");
-        toscaServiceTemplate.setVersion("1.2.3");
+        ToscaServiceTemplate toscaServiceTemplate = testControlLoopRead();
+        // Add policies to the toscaServiceTemplate
+        TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate);
 
         ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition();
         clDefinition.setId(UUID.randomUUID());
index e1a7e7f..c9da127 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
@@ -177,7 +178,8 @@ public class ControlLoopHandler {
      *
      * @param updateMsg the update message
      */
-    public void handleControlLoopUpdate(ControlLoopUpdate updateMsg) {
+    public void handleControlLoopUpdate(ControlLoopUpdate updateMsg,
+                Map<UUID, ControlLoopElementDefinition> clElementDefinitions) {
 
         if (!updateMsg.appliesTo(participantType, participantId)) {
             return;
@@ -211,7 +213,8 @@ public class ControlLoopHandler {
         for (ControlLoopElementListener clElementListener : listeners) {
             try {
                 for (ControlLoopElement element : updateMsg.getControlLoop().getElements().values()) {
-                    clElementListener.controlLoopElementUpdate(element, updateMsg.getControlLoopDefinition());
+                    clElementListener.controlLoopElementUpdate(element,
+                        clElementDefinitions.get(element.getId()).getControlLoopElementToscaServiceTemplate());
                 }
             } catch (PfModelException e) {
                 LOGGER.debug("Control loop element update failed {}", updateMsg.getControlLoopId());
index ed1da58..9daff72 100644 (file)
@@ -115,7 +115,7 @@ public class ParticipantHandler implements Closeable {
      * @param updateMsg the update message
      */
     public void handleControlLoopUpdate(ControlLoopUpdate updateMsg) {
-        controlLoopHandler.handleControlLoopUpdate(updateMsg);
+        controlLoopHandler.handleControlLoopUpdate(updateMsg, clElementDefsOnThisParticipant);
     }
 
     /**
index e366ba4..448662c 100644 (file)
@@ -23,8 +23,6 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
 import lombok.AllArgsConstructor;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
-import org.onap.policy.models.base.PfModelException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -38,8 +36,6 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdatePublisher.class);
 
-    private final CommissioningProvider commissioningProvider;
-
     /**
      * Send ControlLoopUpdate to Participant.
      *
@@ -49,14 +45,7 @@ public class ControlLoopUpdatePublisher extends AbstractParticipantPublisher<Con
         var controlLoopUpdateMsg = new ControlLoopUpdate();
         controlLoopUpdateMsg.setControlLoopId(controlLoop.getKey().asIdentifier());
         controlLoopUpdateMsg.setControlLoop(controlLoop);
-        // TODO: We should look up the correct TOSCA node template here for the control loop
-        // Tiny hack implemented to return the tosca service template entry from the database and be passed onto dmaap
-        try {
-            controlLoopUpdateMsg.setControlLoopDefinition(commissioningProvider.getToscaServiceTemplate(null, null));
-        } catch (PfModelException pfme) {
-            LOGGER.warn("Get of tosca service template failed, cannot send ParticipantControlLoopUpdate", pfme);
-            return;
-        }
+        LOGGER.debug("ControlLoopUpdate message sent", controlLoopUpdateMsg);
         super.send(controlLoopUpdateMsg);
     }
 }