Fix serialization of messages in Control Loop and Participants 46/123246/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Mon, 9 Aug 2021 15:27:25 +0000 (16:27 +0100)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 11 Aug 2021 15:16:31 +0000 (16:16 +0100)
Issue-ID: POLICY-3536
Change-Id: I72207ba8b3894238412bf19c32b799b661a23c21
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
20 files changed:
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java
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/ParticipantAckMessageTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java
models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantMessagesTest.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.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/SupervisionHandler.java
runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java

index c3e6306..a8b268b 100644 (file)
@@ -32,7 +32,6 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
 import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
  * Class to represent the PARTICIPANT_STATUS message that all the participants send to the control loop runtime.
@@ -51,11 +50,11 @@ public class ParticipantStatus extends ParticipantMessage {
 
     // A map with Participant ID as its key, and a map of ControlLoopElements as value.
     // Returned in response to ParticipantStatusReq only
-    private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+    private Map<String, Map<UUID, ControlLoopElementDefinition>>
             participantDefinitionUpdateMap = new LinkedHashMap<>();
 
     // Map of ControlLoopInfo types indexed by ControlLoopId, one entry for each control loop
-    private Map<ToscaConceptIdentifier, ControlLoopInfo> controlLoopInfoMap;
+    private Map<String, ControlLoopInfo> controlLoopInfoMap;
 
     /**
      * Constructor for instantiating ParticipantStatus class with message name.
index 5fd00e2..2733de4 100644 (file)
@@ -23,14 +23,11 @@ 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.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
 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;
 
 /**
  * Class to represent the PARTICIPANT_UPDATE message that the control loop runtime sends to a participant.
@@ -42,7 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 public class ParticipantUpdate extends ParticipantMessage {
 
     // A map with Participant ID as its key, and a map of ControlLoopElements as value.
-    private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
+    private Map<String, Map<UUID, ControlLoopElementDefinition>>
             participantDefinitionUpdateMap = new LinkedHashMap<>();
 
     /**
index dd6a814..1bf155e 100644 (file)
@@ -22,6 +22,7 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.time.Instant;
@@ -29,6 +30,7 @@ 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.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
@@ -37,7 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 class ControlLoopStateChangeTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ControlLoopStateChange(null)).isInstanceOf(NullPointerException.class);
 
         ControlLoopStateChange orig = new ControlLoopStateChange();
@@ -57,5 +59,7 @@ class ControlLoopStateChangeTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ControlLoopStateChange(orig).toString()));
+
+        assertSerializable(orig, ControlLoopStateChange.class);
     }
 }
index 82ba5d1..b9c1053 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.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable;
 
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 
 class ParticipantAckMessageTest {
     private ParticipantAckMessage message;
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantAckMessage((ParticipantAckMessage) null))
                 .isInstanceOf(NullPointerException.class);
 
@@ -45,6 +47,8 @@ class ParticipantAckMessageTest {
         newmsg = new ParticipantAckMessage(message);
         newmsg.setResponseTo(message.getResponseTo());
         assertEquals(message.toString(), newmsg.toString());
+
+        assertSerializable(message, ParticipantAckMessage.class);
     }
 
     private ParticipantAckMessage makeMessage() {
index cfb891e..f1ae5f7 100644 (file)
@@ -22,16 +22,18 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantDeregisterAckTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantDeregisterAck(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantDeregisterAck orig = new ParticipantDeregisterAck();
@@ -51,5 +53,7 @@ class ParticipantDeregisterAckTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantDeregisterAck(orig).toString()));
+
+        assertSerializable(orig, ParticipantDeregisterAck.class);
     }
 }
index 2daefb6..8954689 100644 (file)
@@ -22,17 +22,19 @@ 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.assertSerializable;
 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.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantDeregisterTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantDeregister(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantDeregister orig = new ParticipantDeregister();
@@ -53,5 +55,7 @@ class ParticipantDeregisterTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantDeregister(orig).toString()));
+
+        assertSerializable(orig, ParticipantDeregister.class);
     }
 }
index 8d644f1..924ad8f 100644 (file)
@@ -24,17 +24,19 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable;
 
 import java.time.Instant;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantMessageTest {
     private ParticipantMessage message;
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantMessage((ParticipantMessage) null))
                 .isInstanceOf(NullPointerException.class);
 
@@ -51,6 +53,8 @@ class ParticipantMessageTest {
         newmsg.setMessageId(message.getMessageId());
         newmsg.setTimestamp(message.getTimestamp());
         assertEquals(message.toString(), newmsg.toString());
+
+        assertSerializable(message, ParticipantMessage.class);
     }
 
     @Test
index dfbc25d..78c278f 100644 (file)
 
 package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
 
+import static org.junit.Assert.assertEquals;
+
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
 /**
  * Utility class for tests of ParticipantMessage subclasses.
  */
@@ -32,4 +37,19 @@ public class ParticipantMessageUtils {
     public static String removeVariableFields(String text) {
         return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn");
     }
+
+    /**
+     * Check if object is Serializable.
+     *
+     * @param object the Object
+     * @param clazz the class of the Object
+     * @throws CoderException if object is not Serializable
+     */
+    public static <T> void assertSerializable(Object object, Class<T> clazz) throws CoderException {
+        var standardCoder = new StandardCoder();
+        var json = standardCoder.encode(object);
+        var other = standardCoder.decode(json, clazz);
+
+        assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString()));
+    }
 }
index f0c7211..886933a 100644 (file)
@@ -22,16 +22,18 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantRegisterAckTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantRegisterAck(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantRegisterAck orig = new ParticipantRegisterAck();
@@ -51,5 +53,7 @@ class ParticipantRegisterAckTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantRegisterAck(orig).toString()));
+
+        assertSerializable(orig, ParticipantRegisterAck.class);
     }
 }
index d7ce5bf..e86d9e8 100644 (file)
@@ -22,17 +22,19 @@ 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.assertSerializable;
 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.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantRegisterTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantRegister(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantRegister orig = new ParticipantRegister();
@@ -53,5 +55,7 @@ class ParticipantRegisterTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantRegister(orig).toString()));
+
+        assertSerializable(orig, ParticipantRegister.class);
     }
 }
index b391aa2..98c1271 100644 (file)
@@ -22,11 +22,13 @@ 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.assertSerializable;
 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.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 /**
@@ -34,7 +36,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
  */
 class ParticipantStatusReqTest {
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class);
 
         ParticipantStatusReq orig = new ParticipantStatusReq();
@@ -48,5 +50,7 @@ class ParticipantStatusReqTest {
 
         ParticipantStatusReq other = new ParticipantStatusReq(orig);
         assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+
+        assertSerializable(orig, ParticipantStatusReq.class);
     }
 }
index 05cfdd7..14252cd 100644 (file)
@@ -22,6 +22,7 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.time.Instant;
@@ -37,13 +38,14 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 class ParticipantStatusTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantStatus orig = new ParticipantStatus();
@@ -63,16 +65,18 @@ class ParticipantStatusTest {
         orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         ControlLoopInfo clInfo = getControlLoopInfo(id);
-        orig.setControlLoopInfoMap(Map.of(id, clInfo));
+        orig.setControlLoopInfoMap(Map.of(id.toString(), clInfo));
 
         ControlLoopElementDefinition clDefinition = getClElementDefinition();
         Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>>
+            participantDefinitionUpdateMap = Map.of(id.toString(), clElementDefinitionMap);
         orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantStatus(orig).toString()));
+
+        assertSerializable(orig, ParticipantStatus.class);
     }
 
     private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) {
index 8681476..d2a1910 100644 (file)
@@ -22,16 +22,18 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
 class ParticipantUpdateAckTest {
 
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class);
 
         final ParticipantUpdateAck orig = new ParticipantUpdateAck();
@@ -51,5 +53,7 @@ class ParticipantUpdateAckTest {
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantUpdateAck(orig).toString()));
+
+        assertSerializable(orig, ParticipantUpdateAck.class);
     }
 }
index 0944312..6ccdd20 100644 (file)
@@ -22,6 +22,7 @@ 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.assertSerializable;
 import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields;
 
 import java.time.Instant;
@@ -29,6 +30,7 @@ import java.util.Map;
 import java.util.UUID;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
+import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
@@ -37,7 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
  */
 class ParticipantUpdateTest {
     @Test
-    void testCopyConstructor() {
+    void testCopyConstructor() throws CoderException {
         assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class);
 
         ParticipantUpdate orig = new ParticipantUpdate();
@@ -65,12 +67,14 @@ class ParticipantUpdateTest {
 
         Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
 
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = Map.of(id, clElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap =
+                Map.of(id.toString(), clElementDefinitionMap);
         orig.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         ParticipantUpdate other = new ParticipantUpdate(orig);
 
         assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
+
+        assertSerializable(orig, ParticipantUpdate.class);
     }
 }
index aed0355..08e7154 100644 (file)
@@ -156,12 +156,12 @@ class ParticipantMessagesTest {
         final ParticipantStatus heartbeat = new ParticipantStatus();
         heartbeat.setParticipantId(getParticipantId());
         ControlLoopInfo clInfo = getControlLoopInfo(getControlLoopId());
-        heartbeat.setControlLoopInfoMap(Map.of(getControlLoopId(), clInfo));
+        heartbeat.setControlLoopInfoMap(Map.of(getControlLoopId().toString(), clInfo));
 
         ControlLoopElementDefinition clDefinition = getClElementDefinition();
         Map<UUID, ControlLoopElementDefinition> clElementDefinitionMap = Map.of(UUID.randomUUID(), clDefinition);
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = Map.of(getParticipantId(), clElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>>
+            participantDefinitionUpdateMap = Map.of(getParticipantId().toString(), clElementDefinitionMap);
         heartbeat.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         synchronized (lockit) {
index b91cff2..f87714e 100644 (file)
@@ -34,7 +34,6 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
 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.ParticipantState;
 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;
@@ -181,7 +180,7 @@ public class TestListenerUtils {
         final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
         ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
         ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(
-                        "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
+                "org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1");
 
         participantUpdateMsg.setParticipantId(participantId);
         participantUpdateMsg.setTimestamp(Instant.now());
@@ -200,10 +199,10 @@ public class TestListenerUtils {
         clDefinition.setCommonPropertiesMap(commonPropertiesMap);
 
         Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap =
-            Map.of(UUID.randomUUID(), clDefinition);
+                Map.of(UUID.randomUUID(), clDefinition);
 
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = Map.of(participantId, controlLoopElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap =
+                Map.of(participantId.toString(), controlLoopElementDefinitionMap);
         participantUpdateMsg.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         return participantUpdateMsg;
@@ -217,10 +216,8 @@ public class TestListenerUtils {
      * @return ControlLoopUpdate message
      * @throws CoderException exception while reading the file to object
      */
-    public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath)
-            throws CoderException {
-        ControlLoopUpdate controlLoopUpdateMsg =
-                CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
+    public static ControlLoopUpdate createParticipantClUpdateMsgFromJson(String jsonFilePath) throws CoderException {
+        ControlLoopUpdate controlLoopUpdateMsg = CODER.decode(new File(jsonFilePath), ControlLoopUpdate.class);
         return controlLoopUpdateMsg;
     }
 
@@ -254,7 +251,7 @@ public class TestListenerUtils {
             String policyTypeString = ResourceUtils.getResourceAsString(policyTypeFilePath);
 
             ToscaServiceTemplate foundPolicyTypeSt =
-                yamlTranslator.fromYaml(policyTypeString, ToscaServiceTemplate.class);
+                    yamlTranslator.fromYaml(policyTypeString, ToscaServiceTemplate.class);
 
             toscaServiceTemplate.setDerivedFrom(foundPolicyTypeSt.getDerivedFrom());
             toscaServiceTemplate.setDescription(foundPolicyTypeSt.getDescription());
@@ -291,7 +288,7 @@ public class TestListenerUtils {
             String policiesString = ResourceUtils.getResourceAsString(policiesFilePath);
 
             ToscaServiceTemplate foundPoliciesSt =
-                yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
+                    yamlTranslator.fromYaml(policiesString, ToscaServiceTemplate.class);
             toscaServiceTemplate.getToscaTopologyTemplate().setPolicies(
                     foundPoliciesSt.getToscaTopologyTemplate().getPolicies());
         }
@@ -305,7 +302,7 @@ public class TestListenerUtils {
             }
 
             ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
-                        controlLoopString, ToscaServiceTemplate.class);
+                    controlLoopString, ToscaServiceTemplate.class);
             return serviceTemplate;
         } catch (FileNotFoundException e) {
             LOGGER.error("cannot find YAML file", controlLoopFilePath);
index 6a0e758..7aa89be 100644 (file)
@@ -32,16 +32,13 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
 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.ParticipantDeregister;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatusReq;
 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
@@ -205,7 +202,7 @@ public class ParticipantHandler implements Closeable {
      */
     public void handleParticipantRegisterAck(ParticipantRegisterAck participantRegisterAckMsg) {
         LOGGER.debug("ParticipantRegisterAck message received as responseTo {}",
-            participantRegisterAckMsg.getResponseTo());
+                participantRegisterAckMsg.getResponseTo());
     }
 
     /**
@@ -226,7 +223,7 @@ public class ParticipantHandler implements Closeable {
      */
     public void handleParticipantDeregisterAck(ParticipantDeregisterAck participantDeregisterAckMsg) {
         LOGGER.debug("ParticipantDeregisterAck message received as responseTo {}",
-            participantDeregisterAckMsg.getResponseTo());
+                participantDeregisterAckMsg.getResponseTo());
     }
 
     /**
@@ -236,14 +233,14 @@ public class ParticipantHandler implements Closeable {
      */
     public void handleParticipantUpdate(ParticipantUpdate participantUpdateMsg) {
         LOGGER.debug("ParticipantUpdate message received for participantId {}",
-            participantUpdateMsg.getParticipantId());
+                participantUpdateMsg.getParticipantId());
 
         if (!participantUpdateMsg.appliesTo(participantType, participantId)) {
             return;
         }
 
-        Map<UUID, ControlLoopElementDefinition> clDefinitionMap =
-                participantUpdateMsg.getParticipantDefinitionUpdateMap().get(participantUpdateMsg.getParticipantId());
+        Map<UUID, ControlLoopElementDefinition> clDefinitionMap = participantUpdateMsg
+                .getParticipantDefinitionUpdateMap().get(participantUpdateMsg.getParticipantId().toString());
 
         for (ControlLoopElementDefinition element : clDefinitionMap.values()) {
             clElementDefsOnThisParticipant.put(element.getId(), element);
index 16dba0f..9180ced 100644 (file)
@@ -27,7 +27,6 @@ import lombok.AllArgsConstructor;
 import org.apache.commons.collections4.CollectionUtils;
 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
 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.ControlLoopInfo;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
@@ -312,17 +311,20 @@ public class SupervisionHandler {
 
     private void superviseControlLoops(ParticipantStatus participantStatusMessage)
             throws PfModelException, ControlLoopException {
-        for (Map.Entry<ToscaConceptIdentifier, ControlLoopInfo> clEntry :
-                participantStatusMessage.getControlLoopInfoMap().entrySet()) {
-            var dbControlLoop = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(
-                                clEntry.getKey().getName(), clEntry.getKey().getVersion()));
-            if (dbControlLoop == null) {
-                exceptionOccured(Response.Status.NOT_FOUND,
-                        "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey());
+        if (participantStatusMessage.getControlLoopInfoMap() != null) {
+            for (Map.Entry<String, ControlLoopInfo> clEntry : participantStatusMessage.getControlLoopInfoMap()
+                    .entrySet()) {
+                String[] key = clEntry.getKey().split(" ");
+                var dbControlLoop = controlLoopProvider.getControlLoop(
+                        new ToscaConceptIdentifier(key[0], key[1]));
+                if (dbControlLoop == null) {
+                    exceptionOccured(Response.Status.NOT_FOUND,
+                            "PARTICIPANT_STATUS control loop not found in database: " + clEntry.getKey());
+                }
+                dbControlLoop.setState(clEntry.getValue().getState());
+                monitoringProvider.createClElementStatistics(clEntry.getValue().getControlLoopStatistics()
+                        .getClElementStatisticsList().getClElementStatistics());
             }
-            dbControlLoop.setState(clEntry.getValue().getState());
-            monitoringProvider.createClElementStatistics(clEntry.getValue()
-                .getControlLoopStatistics().getClElementStatisticsList().getClElementStatistics());
         }
     }
 
index 88cf90d..cfc0e39 100644 (file)
@@ -71,9 +71,8 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
         Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap = new LinkedHashMap<>();
         controlLoopElementDefinitionMap.put(UUID.randomUUID(), clDefinition);
 
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap =
-                new LinkedHashMap<>();
-        participantDefinitionUpdateMap.put(participantId, controlLoopElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap = new LinkedHashMap<>();
+        participantDefinitionUpdateMap.put(participantId.toString(), controlLoopElementDefinitionMap);
         message.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         LOGGER.debug("Participant Update sent {}", message);
index 5f00706..e74af79 100644 (file)
@@ -79,8 +79,7 @@ class SupervisionMessagesTest extends CommonRestController {
     public static void setupDbProviderParameters() throws PfModelException {
         ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb");
 
-        modelsProvider =
-                CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
+        modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
         clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
         var participantStatisticsProvider =
                 new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
@@ -96,8 +95,8 @@ class SupervisionMessagesTest extends CommonRestController {
         var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
         var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
         supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider,
-                        controlLoopUpdatePublisher, controlLoopStateChangePublisher,
-                        participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
+                controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher,
+                participantDeregisterAckPublisher, participantUpdatePublisher);
     }
 
     @AfterAll
@@ -116,8 +115,8 @@ class SupervisionMessagesTest extends CommonRestController {
         synchronized (lockit) {
             ParticipantRegisterListener participantRegisterListener =
                     new ParticipantRegisterListener(supervisionHandler);
-            ToscaServiceTemplate serviceTemplate = yamlTranslator
-                .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+            ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
+                    ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
 
             List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null);
             commissioningProvider.createControlLoopDefinitions(serviceTemplate);
@@ -189,10 +188,10 @@ class SupervisionMessagesTest extends CommonRestController {
         clDefinition.setCommonPropertiesMap(commonPropertiesMap);
 
         Map<UUID, ControlLoopElementDefinition> controlLoopElementDefinitionMap =
-            Map.of(UUID.randomUUID(), clDefinition);
+                Map.of(UUID.randomUUID(), clDefinition);
 
-        Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElementDefinition>>
-            participantDefinitionUpdateMap = Map.of(getParticipantId(), controlLoopElementDefinitionMap);
+        Map<String, Map<UUID, ControlLoopElementDefinition>> participantDefinitionUpdateMap =
+                Map.of(getParticipantId().toString(), controlLoopElementDefinitionMap);
         participantUpdateMsg.setParticipantDefinitionUpdateMap(participantDefinitionUpdateMap);
 
         synchronized (lockit) {