diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-04-08 15:26:21 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-08 15:26:21 +0000 |
commit | 7117afaf8019cd8cff19b8cb0a4d6ee6b6bd7ca4 (patch) | |
tree | 9d73b044d0125aaed1358908521d27c85f405740 /models-pdp/src/main | |
parent | eb7127ac85b3df30a09277721a5f9271033843e7 (diff) | |
parent | 53bba4720a910d29a99b20f75529a5457485aed2 (diff) |
Merge "Add PdpMessage.appliesTo()"
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r-- | models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java | 40 | ||||
-rw-r--r-- | models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java | 11 |
2 files changed, 50 insertions, 1 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java index a48724e34..5d0359c74 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java @@ -24,6 +24,7 @@ package org.onap.policy.models.pdp.concepts; import java.util.UUID; import lombok.AccessLevel; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import lombok.ToString; import org.onap.policy.models.pdp.enums.PdpMessageType; @@ -89,4 +90,43 @@ public class PdpMessage { this.pdpGroup = source.pdpGroup; this.pdpSubgroup = source.pdpSubgroup; } + + /** + * Determines if this message applies to this PDP. + * + * @param pdpName name of this PDP + * @param group group to which this PDP has been assigned, or {@code null} if the PDP + * has not been assigned to a group yet + * @param subgroup group to which this PDP has been assigned, or {@code null} if the + * PDP has not been assigned to a subgroup yet + * @return {@code true} if this message applies to this PDP, {@code false} otherwise + */ + public boolean appliesTo(@NonNull String pdpName, String group, String subgroup) { + if (pdpName.equals(name)) { + return true; + } + + if (name != null) { + // message included a PDP name, but it does not match + return false; + } + + // message does not provide a PDP name - must be a broadcast + + if (group == null || subgroup == null) { + // this PDP has no assignment yet, thus should ignore broadcast messages + return false; + } + + if (!group.equals(pdpGroup)) { + return false; + } + + if (pdpSubgroup == null) { + // message was broadcast to entire group + return true; + } + + return subgroup.equals(pdpSubgroup); + } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java index a28bd7640..5d0e225c3 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java @@ -30,7 +30,9 @@ import org.onap.policy.models.pdp.enums.PdpMessageType; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** - * Class to represent the PDP_UPDATE message that PAP will send to a PDP. + * Class to represent the PDP_UPDATE message that PAP will send to a PDP. When a PDP + * receives this message, it should save the group and subgroup and pass them to + * {@link #appliesTo(String, String, String)} of subsequent messages that it receives. * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @@ -45,6 +47,13 @@ public class PdpUpdate extends PdpMessage { private String description; private Long pdpHeartbeatIntervalMs; + + /** + * Policies that the PDP should deploy. This is a complete list, so PDPs should be + * prepared to deploy new policies listed and undeploy policies that are no longer + * listed. Note: this list may be empty, as a PDP may remain attached to a subgroup + * even if all of the policies are removed from the subgroup. + */ private List<ToscaPolicy> policies; /** |