import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
@Getter
@Setter
@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);
+ }
}
package org.onap.policy.clamp.controlloop.models.messages.dmaap.participant;
+import java.time.Instant;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Getter;
@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.
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.
*
/**
* participant operation failed.
*/
- FAIL
+ FAIL,
+
+ /**
+ * periodic response.
+ */
+ PERIODIC
}
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.
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;
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));
}
}
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));
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;
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()));
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;
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");
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;
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()));
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;
// 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());
}
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;
}
}
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");
}
}
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;
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()));
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;
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");