summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-04-07 09:49:41 -0400
committerJim Hahn <jrh3@att.com>2019-04-07 10:07:33 -0400
commit53bba4720a910d29a99b20f75529a5457485aed2 (patch)
tree849c0afa089d0c8156f301d73375a0fe142135fa /models-pdp/src/main
parent82699a970d5f06c6dc1391d8beb0efe76bf84089 (diff)
Add PdpMessage.appliesTo()
Added a method to determine if a message is applicable to a particular PDP. This is a common function that should have been added previously, as each PDP type has had to create an implementation of it. Nevertheless, this provides a "reference" implementation. Change-Id: I54073c77a9d2b4c1f902c5ac0bce9fa5fa485503 Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java40
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpUpdate.java11
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;
/**