Update tosca-poc models for changed messages 66/118466/1
authorliamfallon <liam.fallon@est.tech>
Wed, 24 Feb 2021 16:15:40 +0000 (16:15 +0000)
committerliamfallon <liam.fallon@est.tech>
Wed, 24 Feb 2021 16:19:58 +0000 (16:19 +0000)
The models of REST and DMaaP messages are updated as are the moels for
the database as we evolve the functionality of the TOSCA PoC.

POLICY-2995
Change-Id: I490f7033bf41080d1b0b1123541ea884afc5f29e
Signed-off-by: liamfallon <liam.fallon@est.tech>
13 files changed:
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseDetails.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java
tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopStateChangeTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantControlLoopUpdateTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantHealthCheckTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStateChangeTest.java
tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java

index 7fb6a1a..0c7ed07 100644 (file)
@@ -24,6 +24,7 @@ import lombok.Getter;
 import lombok.NoArgsConstructor;
 import lombok.Setter;
 import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
 
 @Getter
 @Setter
@@ -32,4 +33,13 @@ import lombok.ToString;
 @AllArgsConstructor
 public class ControlLoops {
     private List<ControlLoop> controlLoopList;
+
+    /**
+     * Copy contructor, does a deep copy.
+     *
+     * @param otherControlLoops the other element to copy from
+     */
+    public ControlLoops(final ControlLoops otherControlLoops) {
+        this.controlLoopList = PfUtils.mapList(controlLoopList, ControlLoop::new);
+    }
 }
index 2146f7d..4b27e0d 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
 
+import java.time.Instant;
 import java.util.UUID;
 import lombok.AccessLevel;
 import lombok.Getter;
@@ -39,13 +40,13 @@ public class ParticipantMessage {
     @Setter(AccessLevel.NONE)
     private ParticipantMessageType messageType;
 
-    private UUID requestId = UUID.randomUUID();
+    private UUID messageId = UUID.randomUUID();
 
     /**
      * Time-stamp, in milliseconds, when the message was created. Defaults to the current
      * time.
      */
-    private long timestampMs = System.currentTimeMillis();
+    private Instant timestamp = Instant.now();
 
     /**
      * Participant ID, or {@code null} for state-change broadcast messages.
index 2c9bcd9..4c771b4 100644 (file)
@@ -40,6 +40,17 @@ public class ParticipantResponseDetails {
     private ParticipantResponseStatus responseStatus;
     private String responseMessage;
 
+    /**
+     * Constructs the object as a response to.
+     *
+     * @param triggerMessage the message to which this is a response
+     */
+    public ParticipantResponseDetails(ParticipantMessage triggerMessage) {
+        this.responseMessage = null;
+        this.responseStatus = ParticipantResponseStatus.FAIL;
+        this.responseTo = triggerMessage.getMessageId();
+    }
+
     /**
      * Constructs the object, making a deep copy.
      *
index 4bc865c..b7140d4 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.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
-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.
@@ -46,11 +41,8 @@ public class ParticipantStatus extends ParticipantMessage {
     private ParticipantState state;
     private ParticipantHealthStatus healthStatus;
 
-    // This map is a map of the state of all control loop elements the participant has. The ToscaConceptIdentifier key
-    // of the outer map is a key that identifies the control loop. There is an inner map for each control loop the
-    // participant has. Each inner map has the UUID that identifies the ControlLoopElement instance, and the value is
-    // the ControlLoopInstance itself.
-    private Map<ToscaConceptIdentifier, Map<UUID, ControlLoopElement>> elements;
+    // Control Loops on the participant
+    private ControlLoops controlLoops;
 
     // Description. May be left {@code null}.
     private String message;
@@ -74,7 +66,7 @@ public class ParticipantStatus extends ParticipantMessage {
         this.state = source.state;
         this.healthStatus = source.healthStatus;
         this.message = source.message;
-        this.elements = PfUtils.mapMap(elements, LinkedHashMap::new);
+        this.controlLoops = (source.controlLoops == null ? null : new ControlLoops(source.controlLoops));
         this.response = (source.response == null ? null : new ParticipantResponseDetails(source.response));
     }
 }
index 05721b6..2c0a455 100644 (file)
@@ -53,7 +53,7 @@ public class ControlLoopTest {
         ControlLoop cl0 = new ControlLoop();
 
         assertThat(cl0.toString()).contains("ControlLoop(");
-        assertEquals(false, cl0.hashCode() == 0);
+        assertThat(cl0.hashCode()).isNotZero();
         assertEquals(true, cl0.equals(cl0));
         assertEquals(false, cl0.equals(null));
 
index 3250ce7..06d6ecf 100644 (file)
@@ -24,6 +24,7 @@ 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.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
@@ -50,9 +51,9 @@ public class ParticipantControlLoopStateChangeTest {
         id.setVersion("1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
-        orig.setRequestId(UUID.randomUUID());
+        orig.setMessageId(UUID.randomUUID());
         orig.setOrderedState(ControlLoopOrderedState.RUNNING);
-        orig.setTimestampMs(Long.valueOf(3000));
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantControlLoopStateChange(orig).toString()));
index 6be84ca..4397bf1 100644 (file)
@@ -25,6 +25,7 @@ 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.UUID;
 import org.junit.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
@@ -46,8 +47,8 @@ public class ParticipantControlLoopUpdateTest {
         id.setVersion("1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
-        orig.setRequestId(UUID.randomUUID());
-        orig.setTimestampMs(Long.valueOf(3000));
+        orig.setMessageId(UUID.randomUUID());
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         ControlLoop controlLoop = new ControlLoop();
         controlLoop.setName("controlLoop");
index f78365c..1cc3566 100644 (file)
@@ -24,6 +24,7 @@ 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.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
@@ -50,9 +51,9 @@ public class ParticipantHealthCheckTest {
         id.setVersion("1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
-        orig.setRequestId(UUID.randomUUID());
+        orig.setMessageId(UUID.randomUUID());
         orig.setState(ParticipantState.ACTIVE);
-        orig.setTimestampMs(Long.valueOf(3000));
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         assertEquals(removeVariableFields(orig.toString()),
                         removeVariableFields(new ParticipantHealthCheck(orig).toString()));
index a17b0f8..f66c992 100644 (file)
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.time.Instant;
 import java.util.UUID;
 import org.junit.Test;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -40,15 +41,15 @@ public class ParticipantMessageTest {
         // verify with null values
         message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
         ParticipantMessage newmsg = new ParticipantMessage(message);
-        newmsg.setRequestId(message.getRequestId());
-        newmsg.setTimestampMs(message.getTimestampMs());
+        newmsg.setMessageId(message.getMessageId());
+        newmsg.setTimestamp(message.getTimestamp());
         assertEquals(message.toString(), newmsg.toString());
 
         // verify with all values
         message = makeMessage();
         newmsg = new ParticipantMessage(message);
-        newmsg.setRequestId(message.getRequestId());
-        newmsg.setTimestampMs(message.getTimestampMs());
+        newmsg.setMessageId(message.getMessageId());
+        newmsg.setTimestamp(message.getTimestamp());
         assertEquals(message.toString(), newmsg.toString());
     }
 
@@ -93,8 +94,8 @@ public class ParticipantMessageTest {
         id.setVersion("1.2.3");
         msg.setControlLoopId(id);
         msg.setParticipantId(id);
-        msg.setRequestId(UUID.randomUUID());
-        msg.setTimestampMs(Long.valueOf(3000));
+        msg.setMessageId(UUID.randomUUID());
+        msg.setTimestamp(Instant.ofEpochMilli(3000));
 
         return msg;
     }
index a7a76c0..dfbc25d 100644 (file)
@@ -30,6 +30,6 @@ public class ParticipantMessageUtils {
     }
 
     public static String removeVariableFields(String text) {
-        return text.replaceAll("requestId=[^,]*", "requestId=xxx").replaceAll("timestampMs=[^,]*", "timestampMs=nnn");
+        return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn");
     }
 }
index 192f363..2355326 100644 (file)
@@ -24,6 +24,7 @@ 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.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
@@ -50,9 +51,9 @@ public class ParticipantStateChangeTest {
         id.setVersion("1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
-        orig.setRequestId(UUID.randomUUID());
+        orig.setMessageId(UUID.randomUUID());
         orig.setState(ParticipantState.ACTIVE);
-        orig.setTimestampMs(Long.valueOf(3000));
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         assertEquals(removeVariableFields(orig.toString()),
                 removeVariableFields(new ParticipantStateChange(orig).toString()));
index 62b3d9d..9b5722b 100644 (file)
@@ -24,6 +24,7 @@ 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.Test;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
@@ -47,9 +48,9 @@ public class ParticipantStatusTest {
         id.setVersion("1.2.3");
         orig.setControlLoopId(id);
         orig.setParticipantId(id);
-        orig.setRequestId(UUID.randomUUID());
+        orig.setMessageId(UUID.randomUUID());
         orig.setState(ParticipantState.ACTIVE);
-        orig.setTimestampMs(Long.valueOf(3000));
+        orig.setTimestamp(Instant.ofEpochMilli(3000));
 
         final ParticipantResponseDetails resp = new ParticipantResponseDetails();
         resp.setResponseMessage("my-response");