diff options
author | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-04-29 09:33:24 +0100 |
---|---|---|
committer | Sirisha_Manchikanti <sirisha.manchikanti@est.tech> | 2021-05-07 16:14:40 +0100 |
commit | 65262f8dd9a6b9cbc284daa02ae332380e374483 (patch) | |
tree | 7e85493595c624c0e457bd0c8a7f85ffae71a864 /tosca-controlloop/models/src | |
parent | 15af7e7d708d3cbb5ae2bfbb75bdcd1810f214c5 (diff) |
Update TOSCA PoC with changes from demo integration
This commit includes demo version changes for establishing a PMSH controlloop.
Apologies for bringing a huge commit, this code is for the
ControlLoop Demo, and it can act as base for the actual release.
This framework is going to be completely changed including Spring
framework for the future release. Please consider this code as base for
any future work on controlloop.
Issue-ID: POLICY-3215
Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech>
Change-Id: I512626295d95ab32c29c6861375d31228d549ce9
Diffstat (limited to 'tosca-controlloop/models/src')
21 files changed, 225 insertions, 201 deletions
diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java index 014323090..4ef9bdcd9 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java @@ -26,10 +26,12 @@ import java.util.UUID; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; +import lombok.ToString; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @NoArgsConstructor @Data +@ToString public class ClElementStatistics implements Serializable { private static final long serialVersionUID = 3284285693112271055L; diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java index 417e02a5a..d0d79274c 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java @@ -20,14 +20,17 @@ package org.onap.policy.clamp.controlloop.models.controlloop.concepts; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.apache.commons.collections4.CollectionUtils; -import org.onap.policy.models.base.PfKey; +import org.apache.commons.collections4.MapUtils; +import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @@ -40,7 +43,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @EqualsAndHashCode(callSuper = true) public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> { @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull private ControlLoopState state = ControlLoopState.UNINITIALISED; @@ -48,7 +51,7 @@ public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> @NonNull private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; - private List<ControlLoopElement> elements; + private Map<UUID, ControlLoopElement> elements; @Override public String getType() { @@ -70,7 +73,7 @@ public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> this.definition = new ToscaConceptIdentifier(otherControlLoop.definition); this.state = otherControlLoop.state; this.orderedState = otherControlLoop.orderedState; - this.elements = PfUtils.mapList(otherControlLoop.elements, ControlLoopElement::new); + this.elements = PfUtils.mapMap(otherControlLoop.elements, ControlLoopElement::new); } @Override @@ -86,25 +89,25 @@ public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop> public void setCascadedOrderedState(final ControlLoopOrderedState orderedState) { this.orderedState = orderedState; - if (CollectionUtils.isEmpty(elements)) { + if (MapUtils.isEmpty(elements)) { return; } - elements.forEach(element -> element.setOrderedState(orderedState)); + elements.values().forEach(element -> element.setOrderedState(orderedState)); } /** - * Find the element with a given UUID for the control loop. + * Get a list of control loop element statistics. * - * @param id the UUID to search for - * @return the element or null if its not found + * @param controlLoop the control loop + * @return List of ClElementStatistics */ - - public ControlLoopElement getElement(final UUID id) { - if (CollectionUtils.isEmpty(elements)) { + public List<ClElementStatistics> getControlLoopElementStatisticsList(final ControlLoop controlLoop) { + if (MapUtils.isEmpty(controlLoop.elements)) { return null; } - return elements.stream().filter(element -> id.equals(element.getId())).findAny().orElse(null); + return controlLoop.elements.values().stream().map(ControlLoopElement::getClElementStatistics) + .collect(Collectors.toList()); } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java index a8d317c2b..83f062c74 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java @@ -25,7 +25,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.ToString; -import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** @@ -39,10 +39,13 @@ public class ControlLoopElement { private UUID id = UUID.randomUUID(); @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull - private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull private ControlLoopState state = ControlLoopState.UNINITIALISED; @@ -52,6 +55,8 @@ public class ControlLoopElement { private String description; + private ClElementStatistics clElementStatistics; + /** * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. * @@ -60,9 +65,11 @@ public class ControlLoopElement { public ControlLoopElement(final ControlLoopElement otherElement) { this.id = otherElement.id; this.definition = new ToscaConceptIdentifier(otherElement.definition); + this.participantType = new ToscaConceptIdentifier(otherElement.participantType); this.participantId = new ToscaConceptIdentifier(otherElement.participantId); this.state = otherElement.state; this.orderedState = otherElement.orderedState; this.description = otherElement.description; + this.clElementStatistics = otherElement.clElementStatistics; } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java index 43ad49b7c..3130b6c2f 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java @@ -24,7 +24,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.NonNull; -import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @@ -36,7 +36,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; @EqualsAndHashCode(callSuper = true) public class Participant extends ToscaEntity implements Comparable<Participant> { @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_NAME); + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); @NonNull private ParticipantState participantState = ParticipantState.UNKNOWN; diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java index ec5dbb32c..c5ce99677 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java @@ -24,7 +24,6 @@ import java.io.Serializable; import java.util.List; import java.util.UUID; import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; @@ -190,6 +189,6 @@ public class JpaClElementStatistics extends PfConcept implements PfAuthorative<C final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept; return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state) - .append(this.clElementUptime, other.clElementUptime).toComparison(); + .append(this.clElementUptime, other.clElementUptime).toComparison(); } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java index 3f54ac2bb..cac405abd 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java @@ -20,21 +20,21 @@ package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts; -import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; -import java.util.stream.Collectors; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.CascadeType; -import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; +import javax.persistence.ManyToMany; import javax.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; @@ -96,16 +96,9 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo private String description; // @formatter:off - @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) - @CollectionTable(joinColumns = { - @JoinColumn(name = "controlLoopParentKeyName", referencedColumnName = "parentKeyName"), - @JoinColumn(name = "controlLoopParentKeyVersion", referencedColumnName = "parentKeyVersion"), - @JoinColumn(name = "controlLoopParentLocalName", referencedColumnName = "parentLocalName"), - @JoinColumn(name = "controlLoopLocalUUID", referencedColumnName = "localUUID") - }) - // @formatter:on + @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @NotNull - private List<@NotNull @Valid JpaControlLoopElement> elements; + private Map<@NotNull UUID, @NotNull @Valid JpaControlLoopElement> elements; /** * The Default Constructor creates a {@link JpaControlLoop} object with a null key. @@ -120,7 +113,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo * @param key the key */ public JpaControlLoop(@NonNull final PfConceptKey key) { - this(key, new PfConceptKey(), ControlLoopState.UNINITIALISED, new ArrayList<>()); + this(key, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); } /** @@ -132,7 +125,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo * @param elements the elements of the control looop in participants */ public JpaControlLoop(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, - @NonNull final ControlLoopState state, @NonNull final List<JpaControlLoopElement> elements) { + @NonNull final ControlLoopState state, @NonNull final Map<UUID, JpaControlLoopElement> elements) { this.key = key; this.definition = definition; this.state = state; @@ -151,7 +144,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo this.state = copyConcept.state; this.orderedState = copyConcept.orderedState; this.description = copyConcept.description; - this.elements = PfUtils.mapList(copyConcept.elements, JpaControlLoopElement::new, new ArrayList<>(0)); + this.elements = PfUtils.mapMap(copyConcept.elements, JpaControlLoopElement::new, new LinkedHashMap<>(0)); } /** @@ -173,9 +166,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo controlLoop.setState(state); controlLoop.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); controlLoop.setDescription(description); - - controlLoop - .setElements(elements.stream().map(JpaControlLoopElement::toAuthorative).collect(Collectors.toList())); + controlLoop.setElements(PfUtils.mapMap(elements, JpaControlLoopElement::toAuthorative, new LinkedHashMap<>(0))); return controlLoop; } @@ -191,12 +182,12 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo this.orderedState = controlLoop.getOrderedState(); this.description = controlLoop.getDescription(); - this.elements = new ArrayList<>(controlLoop.getElements().size()); - for (ControlLoopElement element : controlLoop.getElements()) { + this.elements = new LinkedHashMap<>(controlLoop.getElements().size()); + for (Entry<UUID, ControlLoopElement> elementEntry : controlLoop.getElements().entrySet()) { JpaControlLoopElement jpaControlLoopElement = new JpaControlLoopElement(); - jpaControlLoopElement.setKey(new PfReferenceKey(getKey(), element.getId().toString())); - jpaControlLoopElement.fromAuthorative(element); - this.elements.add(jpaControlLoopElement); + jpaControlLoopElement.setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString())); + jpaControlLoopElement.fromAuthorative(elementEntry.getValue()); + this.elements.put(elementEntry.getKey(), jpaControlLoopElement); } } @@ -206,7 +197,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo keyList.add(definition); - for (JpaControlLoopElement element : elements) { + for (JpaControlLoopElement element : elements.values()) { keyList.addAll(element.getKeys()); } @@ -219,7 +210,7 @@ public class JpaControlLoop extends PfConcept implements PfAuthorative<ControlLo definition.clean(); description = (description == null ? null : description.trim()); - for (JpaControlLoopElement element : elements) { + for (JpaControlLoopElement element : elements.values()) { element.clean(); } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java index 042cb16e1..911a52089 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java @@ -23,7 +23,6 @@ package org.onap.policy.clamp.controlloop.models.controlloop.persistence.concept import java.util.List; import java.util.UUID; import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; @@ -67,20 +66,19 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co // @formatter:off @VerifyKey @NotNull - @AttributeOverrides({ - @AttributeOverride(name = "name", column = @Column(name = "definition_name")), - @AttributeOverride(name = "version", column = @Column(name = "definition_version")) - } - ) + @AttributeOverride(name = "name", column = @Column(name = "definition_name")) + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) private PfConceptKey definition; @VerifyKey @NotNull - @AttributeOverrides({ - @AttributeOverride(name = "name", column = @Column(name = "participant_name")), - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - } - ) + @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) + private PfConceptKey participantType; + + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "participant_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) private PfConceptKey participantId; // @formatter:on @@ -116,14 +114,14 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co * * @param key the key * @param definition the TOSCA definition of the control loop element - * @param participantId the TOSCA definition of the participant running the control loop element + * @param participantType the TOSCA definition of the participant running the control loop element * @param state the state of the control loop */ public JpaControlLoopElement(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey definition, - @NonNull final PfConceptKey participantId, @NonNull final ControlLoopState state) { + @NonNull final PfConceptKey participantType, @NonNull final ControlLoopState state) { this.key = key; this.definition = definition; - this.participantId = participantId; + this.participantType = participantType; this.state = state; } @@ -136,6 +134,7 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co super(copyConcept); this.key = new PfReferenceKey(copyConcept.key); this.definition = new PfConceptKey(copyConcept.definition); + this.participantType = new PfConceptKey(copyConcept.participantType); this.participantId = new PfConceptKey(copyConcept.participantId); this.state = copyConcept.state; this.orderedState = copyConcept.orderedState; @@ -157,6 +156,7 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co element.setId(UUID.fromString(getKey().getLocalName())); element.setDefinition(new ToscaConceptIdentifier(definition)); + element.setParticipantType(new ToscaConceptIdentifier(participantType)); element.setParticipantId(new ToscaConceptIdentifier(participantId)); element.setState(state); element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); @@ -173,6 +173,7 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co } this.definition = element.getDefinition().asConceptKey(); + this.participantType = element.getParticipantType().asConceptKey(); this.participantId = element.getParticipantId().asConceptKey(); this.state = element.getState(); this.orderedState = element.getOrderedState(); @@ -184,6 +185,7 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co List<PfKey> keyList = getKey().getKeys(); keyList.add(definition); + keyList.add(participantType); keyList.add(participantId); return keyList; @@ -193,6 +195,7 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co public void clean() { key.clean(); definition.clean(); + participantType.clean(); participantId.clean(); if (description != null) { @@ -223,6 +226,11 @@ public class JpaControlLoopElement extends PfConcept implements PfAuthorative<Co return result; } + result = participantType.compareTo(other.participantType); + if (result != 0) { + return result; + } + result = participantId.compareTo(other.participantId); if (result != 0) { return result; diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java index c09658f80..8a06cbf1e 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java @@ -62,10 +62,10 @@ public class ClElementStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors creating clElement statistics */ public List<ClElementStatistics> createClElementStatistics( - @NonNull final List<ClElementStatistics> clElementStatisticsList) throws PfModelException { + @NonNull final List<ClElementStatistics> clElementStatisticsList) throws PfModelException { BeanValidationResult validationResult = - new BeanValidationResult("control loop element statistics list", clElementStatisticsList); + new BeanValidationResult("control loop element statistics list", clElementStatisticsList); for (ClElementStatistics clElementStatistics : clElementStatisticsList) { JpaClElementStatistics jpaClElementStatistics = new JpaClElementStatistics(); jpaClElementStatistics.fromAuthorative(clElementStatistics); @@ -118,7 +118,7 @@ public class ClElementStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors getting clElement statistics */ public List<ClElementStatistics> getClElementStatistics(final String name, final String version, final String id, - final Instant timestamp) throws PfModelException { + final Instant timestamp) throws PfModelException { List<ClElementStatistics> clElementStatistics = new ArrayList<>(1); if (name != null && version != null && timestamp != null && id != null) { clElementStatistics.add(getPfDao() @@ -146,11 +146,9 @@ public class ClElementStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors getting policies */ public List<ClElementStatistics> getFilteredClElementStatistics(final String name, final String version, - final Instant startTimeStamp, - final Instant endTimeStamp, - Map<String, Object> filterMap, - final String sortOrder, final int getRecordNum) { + final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap, + final String sortOrder, final int getRecordNum) { return asClElementStatisticsList(getPfDao().getFiltered(JpaClElementStatistics.class, name, version, - startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); + startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java index ebb81942b..6b075278c 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java @@ -62,12 +62,12 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors getting participant statistics */ public List<ParticipantStatistics> getParticipantStatistics(final String name, final String version, - final Instant timestamp) throws PfModelException { + final Instant timestamp) throws PfModelException { if (name != null && version != null && timestamp != null) { List<ParticipantStatistics> participantStatistics = new ArrayList<>(1); participantStatistics.add(getPfDao() - .get(JpaParticipantStatistics.class, new PfTimestampKey(name, version, timestamp)).toAuthorative()); + .get(JpaParticipantStatistics.class, new PfTimestampKey(name, version, timestamp)).toAuthorative()); return participantStatistics; } else if (name != null) { return getFilteredParticipantStatistics(name, version, timestamp, null, null, @@ -90,14 +90,11 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors getting policies */ public List<ParticipantStatistics> getFilteredParticipantStatistics(final String name, final String version, - final Instant startTimeStamp, - final Instant endTimeStamp, - Map<String, Object> filterMap, - final String sortOrder, - final int getRecordNum) { + final Instant startTimeStamp, final Instant endTimeStamp, Map<String, Object> filterMap, + final String sortOrder, final int getRecordNum) { return asParticipantStatisticsList(getPfDao().getFiltered(JpaParticipantStatistics.class, name, version, - startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); + startTimeStamp, endTimeStamp, filterMap, sortOrder, getRecordNum)); } @@ -109,10 +106,10 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider { * @throws PfModelException on errors creating participant statistics */ public List<ParticipantStatistics> createParticipantStatistics( - @NonNull final List<ParticipantStatistics> participantStatisticsList) throws PfModelException { + @NonNull final List<ParticipantStatistics> participantStatisticsList) throws PfModelException { BeanValidationResult validationResult = - new BeanValidationResult("participant statistics List", participantStatisticsList); + new BeanValidationResult("participant statistics List", participantStatisticsList); for (ParticipantStatistics participantStatistics : participantStatisticsList) { JpaParticipantStatistics jpaParticipantStatistics = new JpaParticipantStatistics(); @@ -137,9 +134,9 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider { for (ParticipantStatistics participantStatisticsItem : participantStatisticsList) { JpaParticipantStatistics jpaParticipantStatistics = getPfDao().get(JpaParticipantStatistics.class, - new PfTimestampKey(participantStatisticsItem.getParticipantId().getName(), - participantStatisticsItem.getParticipantId().getVersion(), - participantStatisticsItem.getTimeStamp())); + new PfTimestampKey(participantStatisticsItem.getParticipantId().getName(), + participantStatisticsItem.getParticipantId().getVersion(), + participantStatisticsItem.getTimeStamp())); participantStatistics.add(jpaParticipantStatistics.toAuthorative()); } @@ -154,9 +151,9 @@ public class ParticipantStatisticsProvider extends AbstractModelsProvider { * @return the participant statistics list */ private List<ParticipantStatistics> asParticipantStatisticsList( - List<JpaParticipantStatistics> jpaParticipantStatisticsList) { + List<JpaParticipantStatistics> jpaParticipantStatisticsList) { return jpaParticipantStatisticsList.stream().map(JpaParticipantStatistics::toAuthorative) - .collect(Collectors.toList()); + .collect(Collectors.toList()); } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java index 4b27e0df3..3ca4d3d34 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java @@ -30,8 +30,8 @@ import lombok.ToString; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** - * Class to represent the base class for various messages that will be exchanged between - * the control loop runtime and participants. + * Class to represent the base class for various messages that will be exchanged between the control loop runtime and + * participants. */ @Getter @Setter @@ -43,18 +43,22 @@ public class ParticipantMessage { private UUID messageId = UUID.randomUUID(); /** - * Time-stamp, in milliseconds, when the message was created. Defaults to the current - * time. + * Time-stamp, in milliseconds, when the message was created. Defaults to the current time. */ private Instant timestamp = Instant.now(); /** - * Participant ID, or {@code null} for state-change broadcast messages. + * Participant Type, or {@code null} for messages from participants. + */ + private ToscaConceptIdentifier participantType; + + /** + * Participant ID, or {@code null} for messages from participants. */ private ToscaConceptIdentifier participantId; /** - * Control loop ID. For state-change messages, this may be {@code null}. + * Control loop ID, or {@code null} for messages to participants. */ private ToscaConceptIdentifier controlLoopId; @@ -68,30 +72,42 @@ public class ParticipantMessage { } /** - * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or - * the time stamp. + * Constructs the object, making a deep copy. Does <i>not</i> copy the request id or the time stamp. * * @param source source from which to copy */ public ParticipantMessage(final ParticipantMessage source) { this.messageType = source.messageType; + this.participantType = source.participantType; this.participantId = source.participantId; this.controlLoopId = source.controlLoopId; } /** - * Determines if this message applies to this participant. + * Determines if this message applies to this participant type. * + * @param participantType type of the participant to match against * @param participantId id of the participant to match against * @return {@code true} if this message applies to this participant, {@code false} otherwise */ - public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantId) { - if (participantId.equals(this.participantId)) { + public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, + @NonNull final ToscaConceptIdentifier participantId) { + // Broadcast message to all participants + if (this.participantType == null) { + return true; + } + + // Broadcast message to all control loop elements on this participant + if (participantType.equals(this.participantType) && this.participantId == null) { + return true; + } + + // Targeted message at this specific participant + if (participantType.equals(this.participantType) && participantId.equals(this.participantId)) { return true; } - // false: message included a participant ID, but it does not match - // true: its a broadcast message - return this.participantId == null; + // Message is not for this participant + return false; } } diff --git a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java index b7140d4b8..5b9284243 100644 --- a/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java +++ b/tosca-controlloop/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java @@ -26,6 +26,7 @@ import lombok.ToString; 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.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; /** * Class to represent the PARTICIPANT_STATUS message that all the participants send to the control loop runtime. @@ -44,6 +45,9 @@ public class ParticipantStatus extends ParticipantMessage { // Control Loops on the participant private ControlLoops controlLoops; + // Participant statistics + private ParticipantStatistics participantStatistics; + // Description. May be left {@code null}. private String message; diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java index 2c0a45541..c865b76ab 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.UUID; import org.junit.Test; import org.onap.policy.models.base.PfKey; @@ -51,6 +51,7 @@ public class ControlLoopTest { public void testControlLoopLombok() { assertNotNull(new ControlLoop()); ControlLoop cl0 = new ControlLoop(); + cl0.setElements(new LinkedHashMap<>()); assertThat(cl0.toString()).contains("ControlLoop("); assertThat(cl0.hashCode()).isNotZero(); @@ -61,7 +62,7 @@ public class ControlLoopTest { cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); cl1.setDescription("Description"); - cl1.setElements(new ArrayList<>()); + cl1.setElements(new LinkedHashMap<>()); cl1.setName("Name"); cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); cl1.setState(ControlLoopState.UNINITIALISED); @@ -75,6 +76,7 @@ public class ControlLoopTest { assertNotEquals(cl1, cl0); ControlLoop cl2 = new ControlLoop(); + cl2.setElements(new LinkedHashMap<>()); // @formatter:off assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class); @@ -87,14 +89,13 @@ public class ControlLoopTest { cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE); assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState()); - cl1.getElements().add(new ControlLoopElement()); + cl1.getElements().put(UUID.randomUUID(), new ControlLoopElement()); cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING); assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState()); - assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().get(0).getOrderedState()); + assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().values().iterator().next().getOrderedState()); - assertNull(cl0.getElement(UUID.randomUUID())); - assertNull(cl1.getElement(UUID.randomUUID())); - assertEquals(cl1.getElements().get(0), cl1.getElement(cl1.getElements().get(0).getId())); + assertNull(cl0.getElements().get(UUID.randomUUID())); + assertNull(cl1.getElements().get(UUID.randomUUID())); assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName()); } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java index c82dcf060..16c302f94 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java @@ -83,7 +83,7 @@ public class JpaClElementStatisticsTest { }).hasMessageMatching("clElementStatistics is marked .*ull but is null"); assertThatThrownBy(() -> new JpaClElementStatistics((JpaClElementStatistics) null)) - .isInstanceOf(NullPointerException.class); + .isInstanceOf(NullPointerException.class); JpaClElementStatistics testJpaClElementStatisticsFa = new JpaClElementStatistics(); testJpaClElementStatisticsFa.setKey(null); diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java index cd105a671..032d655e3 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java @@ -112,11 +112,11 @@ public class JpaControlLoopElementTest { assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, null); - }).hasMessageMatching("participantId is marked .*ull but is null"); + }).hasMessageMatching("participantType is marked .*ull but is null"); assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching("participantId is marked .*ull but is null"); + }).hasMessageMatching("participantType is marked .*ull but is null"); assertThatThrownBy(() -> { new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), @@ -240,9 +240,9 @@ public class JpaControlLoopElementTest { testJpaControlLoopElement.setState(ControlLoopState.UNINITIALISED); assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setParticipantId(new PfConceptKey("dummy", "0.0.1")); + testJpaControlLoopElement.setParticipantType(new PfConceptKey("dummy", "0.0.1")); assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setParticipantId(new PfConceptKey("participant", "0.0.1")); + testJpaControlLoopElement.setParticipantType(new PfConceptKey("participantType", "0.0.1")); assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); assertEquals(testJpaControlLoopElement, new JpaControlLoopElement(testJpaControlLoopElement)); @@ -293,7 +293,7 @@ public class JpaControlLoopElementTest { ControlLoopElement controlLoopElement = new ControlLoopElement(); controlLoopElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); controlLoopElement.setDefinition(new ToscaConceptIdentifier("cleDef", "0.0.1")); - controlLoopElement.setParticipantId(new ToscaConceptIdentifier("participant", "0.0.1")); + controlLoopElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1")); return controlLoopElement; } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java index 7ef7e3276..01062b046 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java @@ -30,7 +30,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.ArrayList; +import java.util.LinkedHashMap; import org.junit.Test; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; @@ -63,7 +63,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, null, null, new ArrayList<>()); + new JpaControlLoop(null, null, null, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -71,7 +71,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -79,7 +79,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), null, new ArrayList<>()); + new JpaControlLoop(null, new PfConceptKey(), null, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -87,7 +87,7 @@ public class JpaControlLoopTest { }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching(NULL_KEY_ERROR); assertThatThrownBy(() -> { @@ -95,7 +95,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, null, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), null, null, new LinkedHashMap<>()); }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -103,7 +103,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); }).hasMessageMatching("definition is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -111,7 +111,7 @@ public class JpaControlLoopTest { }).hasMessageMatching("state is marked .*ull but is null"); assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new ArrayList<>()); + new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>()); }).hasMessageMatching("state is marked .*ull but is null"); assertThatThrownBy(() -> { @@ -121,7 +121,7 @@ public class JpaControlLoopTest { assertNotNull(new JpaControlLoop()); assertNotNull(new JpaControlLoop((new PfConceptKey()))); assertNotNull(new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, - new ArrayList<>())); + new LinkedHashMap<>())); } @Test @@ -188,7 +188,7 @@ public class JpaControlLoopTest { JpaControlLoop jpaControlLoopWithElements = new JpaControlLoop(controlLoopsWithElements.getControlLoopList().get(0)); assertEquals(4, jpaControlLoopWithElements.getElements().size()); - assertEquals(14, jpaControlLoopWithElements.getKeys().size()); + assertEquals(18, jpaControlLoopWithElements.getKeys().size()); assertThatCode(() -> jpaControlLoopWithElements.clean()).doesNotThrowAnyException(); assertEquals(controlLoopsWithElements.getControlLoopList().get(0), jpaControlLoopWithElements.toAuthorative()); @@ -258,7 +258,7 @@ public class JpaControlLoopTest { cl1.setDefinition(new PfConceptKey("defName", "0.0.1")); cl1.setDescription("Description"); - cl1.setElements(new ArrayList<>()); + cl1.setElements(new LinkedHashMap<>()); cl1.setKey(new PfConceptKey("participant", "0.0.1")); cl1.setState(ControlLoopState.UNINITIALISED); @@ -289,7 +289,7 @@ public class JpaControlLoopTest { testControlLoop.setName("control-loop"); testControlLoop.setVersion("0.0.1"); testControlLoop.setDefinition(new ToscaConceptIdentifier("controlLoopDefinitionName", "0.0.1")); - testControlLoop.setElements(new ArrayList<>()); + testControlLoop.setElements(new LinkedHashMap<>()); return testControlLoop; } diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java index fb443c82e..96b63a23d 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java @@ -91,11 +91,8 @@ public class ControlLoopProviderTest { ControlLoops createdControlLoops = new ControlLoops(); createdControlLoops .setControlLoopList(controlLoopProvider.createControlLoops(inputControlLoops.getControlLoopList())); - String createdJson = CODER.encode(createdControlLoops, true); - System.err.println(originalJson); - System.out.println(createdJson); - assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + assertEquals(inputControlLoops, createdControlLoops); } @Test diff --git a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java index f66c99262..d27d3a22c 100644 --- a/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java +++ b/tosca-controlloop/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java @@ -57,9 +57,11 @@ public class ParticipantMessageTest { public void testAppliesTo_NullParticipantId() { message = makeMessage(); - assertThatThrownBy(() -> message.appliesTo(null)) - .isInstanceOf(NullPointerException.class); - + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), null)) + .isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, new ToscaConceptIdentifier("id", "1.2.3"))) + .isInstanceOf(NullPointerException.class); } @Test @@ -67,33 +69,32 @@ public class ParticipantMessageTest { message = makeMessage(); // ParticipantId matches - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - assertTrue(message.appliesTo(id)); + assertTrue(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), + new ToscaConceptIdentifier("id", "1.2.3"))); + assertFalse(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.6"), + new ToscaConceptIdentifier("id", "1.2.4"))); + assertFalse(message.appliesTo(new ToscaConceptIdentifier("PType", "4.5.7"), + new ToscaConceptIdentifier("id", "1.2.3"))); } @Test public void testAppliesTo_ParticipantIdNoMatch() { message = makeMessage(); - // ParticipantId doesnot match + // ParticipantId does not match ToscaConceptIdentifier id = new ToscaConceptIdentifier(); id.setName("id1111"); id.setVersion("3.2.1"); - assertFalse(message.appliesTo(id)); - message.setParticipantId(null); - assertTrue(message.appliesTo(id)); + assertFalse(message.appliesTo(id, id)); + message.setParticipantType(null); + assertTrue(message.appliesTo(id, id)); } private ParticipantMessage makeMessage() { ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - msg.setControlLoopId(id); - msg.setParticipantId(id); + msg.setParticipantType(new ToscaConceptIdentifier("PType", "4.5.6")); + msg.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); msg.setMessageId(UUID.randomUUID()); msg.setTimestamp(Instant.ofEpochMilli(3000)); diff --git a/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml b/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml index 8f0e0648b..078d534be 100644 --- a/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml +++ b/tosca-controlloop/models/src/test/resources/META-INF/persistence.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2019-2020 Nordix Foundation. + 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. diff --git a/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json b/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json index e9da16aad..33a63e604 100644 --- a/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json +++ b/tosca-controlloop/models/src/test/resources/json/ControlLoopElementNoOrderedState.json @@ -4,8 +4,8 @@ "name": "cleDef", "version": "0.0.1" }, - "participantId": { - "name": "participant", + "participantType": { + "name": "participantType", "version": "0.0.1" }, "state": "UNINITIALISED", diff --git a/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json b/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json index 25e36458c..fedda9600 100644 --- a/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json +++ b/tosca-controlloop/models/src/test/resources/providers/TestControlLoops.json @@ -7,64 +7,64 @@ }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", - "elements": [ - { + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c20": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", "definition": { "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, - "participantId": { - "name": "DCAEParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c21": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", "definition": { "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "PolicyParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c22": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", "definition": { "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "PolicyParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c23": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", "definition": { "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "CDSParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", + "version": "2.2.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "CDS Control Loop Element for the PMSH instance 0 control loop" } - ], + }, "name": "PMSHInstance0", "version": "1.0.1", "description": "PMSH control loop instance 0" @@ -76,64 +76,64 @@ }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", - "elements": [ - { + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c24": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c24", "definition": { "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, - "participantId": { - "name": "DCAEParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "DCAE Control Loop Element for the PMSH instance 1 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c25": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c25", "definition": { "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "PolicyParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c26": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c26", "definition": { "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "PolicyParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop" }, - { + "709c62b3-8918-41b9-a747-e21eb79c6c27": { "id": "709c62b3-8918-41b9-a747-e21eb79c6c27", "definition": { "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "CDSParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", + "version": "2.2.1" }, "state": "UNINITIALISED", "orderedState": "UNINITIALISED", "description": "CDS Control Loop Element for the PMSH instance 1 control loop" } - ], + }, "name": "PMSHInstance1", "version": "1.0.1", "description": "PMSH control loop instance 1" diff --git a/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json b/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json index 0ae402629..2d6bd0753 100644 --- a/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json +++ b/tosca-controlloop/models/src/test/resources/providers/UpdateControlLoops.json @@ -10,64 +10,64 @@ "state": "RUNNING", "orderedState": "RUNNING", "description": "PMSH control loop instance 0", - "elements": [ - { + "elements": { + "709c62b3-8918-41b9-a747-d21eb79c6c20": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", "definition": { "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", "version": "1.2.3" }, - "participantId": { - "name": "DCAEParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "version": "2.3.4" }, "state": "RUNNING", "orderedState": "RUNNING", "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-d21eb79c6c21": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", "definition": { "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "PolicyParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", + "version": "2.3.1" }, "state": "RUNNING", "orderedState": "RUNNING", "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-d21eb79c6c22": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", "definition": { "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", - "version": "1.2.3" + "version": "2.3.1" }, - "participantId": { - "name": "PolicyParticipant0", + "participantType": { + "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", "version": "1.0.0" }, "state": "RUNNING", "orderedState": "RUNNING", "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" }, - { + "709c62b3-8918-41b9-a747-d21eb79c6c23": { "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", "definition": { "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", "version": "1.2.3" }, - "participantId": { - "name": "CDSParticipant0", - "version": "1.0.0" + "participantType": { + "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", + "version": "2.2.1" }, "state": "RUNNING", "orderedState": "RUNNING", "description": "CDS Control Loop Element for the PMSH instance 0 control loop" } - ] + } } ] } |