diff options
Diffstat (limited to 'src/main/java/org')
3 files changed, 58 insertions, 37 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java index ad466ee7d..a64bd7177 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java @@ -66,6 +66,10 @@ public class OperationalPolicyReq { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyReq.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); + private OperationalPolicyReq() { + + } + /** * Format Operational Policy attributes. * @@ -127,12 +131,16 @@ public class OperationalPolicyReq { String recipe = policyItem.getRecipe(); String maxRetries = String.valueOf(policyItem.getMaxRetries()); String retryTimeLimit = String.valueOf(policyItem.getRetryTimeLimit()); + String targetResourceId = String.valueOf(policyItem.getTargetResourceId()); logger.info("recipe=" + recipe); logger.info("maxRetries=" + maxRetries); logger.info("retryTimeLimit=" + retryTimeLimit); + logger.info("targetResourceId=" + targetResourceId); ruleAttributes.put("Recipe", recipe); ruleAttributes.put("MaxRetries", maxRetries); ruleAttributes.put("RetryTimeLimit", retryTimeLimit); + ruleAttributes.put("ResourceId", targetResourceId); + } else { logger.info("templateName=" + templateName); logger.info("operationTopic=" + operationTopic); @@ -189,24 +197,22 @@ public class OperationalPolicyReq { builder.addResource(vfcResources); // process each policy - HashMap<String, org.onap.policy.controlloop.policy.Policy> policyObjMap = new HashMap<>(); + HashMap<String, Policy> policyObjMap = new HashMap<>(); List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems()); - Target target = new Target(); - target.setType(TargetType.VM); - for (int i = 0; i < policyItemList.size(); i++) { - - org.onap.policy.controlloop.policy.Policy policyObj; - PolicyItem policyItem = policyItemList.get(i); + for (PolicyItem policyItem : policyItemList) { String policyName = policyItem.getRecipe() + " Policy"; - if (i == 0) { + Target target = new Target(); + target.setType(TargetType.VM); + target.setResourceID(policyItem.getTargetResourceId()); + Policy policyObj; + if (policyItemList.indexOf(policyItem) == 0) { String policyDescription = policyItem.getRecipe() + " Policy - the trigger (no parent) policy - created by CLDS"; policyObj = builder.setTriggerPolicy(policyName, policyDescription, refProp.getStringValue("op.policy.appc"), target, policyItem.getRecipe(), null, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit()); } else { - org.onap.policy.controlloop.policy.Policy parentPolicyObj = policyObjMap - .get(policyItem.getParentPolicy()); + Policy parentPolicyObj = policyObjMap.get(policyItem.getParentPolicy()); String policyDescription = policyItem.getRecipe() + " Policy - triggered conditionally by " + parentPolicyObj.getName() + " - created by CLDS"; policyObj = builder.setPolicyForPolicyResult(policyName, policyDescription, @@ -269,14 +275,15 @@ public class OperationalPolicyReq { HashMap<String, Policy> policyObjMap = new HashMap<>(); List<PolicyItem> policyItemList = addAOTSActorRecipe(refProp, global.getService(), policyChain.getPolicyItems()); - Target target = new Target(); - target.setType(TargetType.VM); + Policy lastPolicyObj = new Policy(); - for (int i = 0; i < policyItemList.size(); i++) { - org.onap.policy.controlloop.policy.Policy policyObj; - PolicyItem policyItem = policyItemList.get(i); + for (PolicyItem policyItem : policyItemList) { + Target target = new Target(); + target.setType(TargetType.VM); + target.setResourceID(policyItem.getTargetResourceId()); String policyName = policyItem.getRecipe() + " Policy"; - if (i == 0) { + Policy policyObj; + if (policyItemList.indexOf(policyItem) == 0) { // To set up time window payload for trigger policy Map<String, String> payloadMap = new HashMap<>(); payloadMap.put("timeWindow", refProp.getStringValue("op.eNodeB.timeWindow")); diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java index c8c2ef461..5264629f2 100644 --- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java +++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyChain.java @@ -23,14 +23,14 @@ package org.onap.clamp.clds.model.prop; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + /** * Parse Policy json properties. * @@ -42,24 +42,27 @@ import com.fasterxml.jackson.databind.JsonNode; * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name": * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name": * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name": - * "parentPolicy","value":[""]}]]}],"PolicyTest2":[{"name":"pname","value": + * "parentPolicy","value":[""]},{"name": + * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}], + * "PolicyTest2":[{"name":"pname","value": * "PolicyTest2"},{"name":"pid","value":"2"},{"name":"timeout","value":"345"},{ * "policyConfigurations":[[{"name":"recipe","value":["restart"]},{"name": * "maxRetries","value":["3"]},{"name":"retryTimeLimit","value":["180"]},{"name" * :"_id","value":["q2JmHD5"]},{"name":"parentPolicy","value":[""]}],[{"name": * "recipe","value":["rebuild"]},{"name":"maxRetries","value":["3"]},{"name": * "retryTimeLimit","value":["180"]},{"name":"_id","value":["0ZqHdrR"]},{"name": - * "parentPolicy","value":[""]}]]}]}} f + * "parentPolicy","value":[""]},{"name": + * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}]}} f * */ public class PolicyChain { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyChain.class); protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - private String policyId; - private Integer timeout; - private List<PolicyItem> policyItems; + private String policyId; + private Integer timeout; + private List<PolicyItem> policyItems; public PolicyChain(JsonNode node) { diff --git a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java index c84affefe..5fc829835 100644 --- a/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java +++ b/src/main/java/org/onap/clamp/clds/model/prop/PolicyItem.java @@ -23,12 +23,12 @@ package org.onap.clamp.clds.model.prop; -import java.util.List; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; +import java.util.List; + /** * Parse policyConfigurations from Policy json properties. * <p> @@ -44,19 +44,21 @@ import com.fasterxml.jackson.databind.JsonNode; * ,{"name":"location","value":["san_diego"]},{"name":"resource","value":["vCTS" * ]},{"name":"onMaxRetriesLimit","value":[""]},{"name":"onTimeLimit","value":[ * ""]},{"name":"onOtherFailure","value":[""]},{"name":"policy_parent","value":[ - * "vf3RtPi"]}]]}] + * "vf3RtPi"]},{"name": + * "targetResourceId","value":["Eace933104d443b496b8.nodes.heat.vpg"]}]]}] */ public class PolicyItem implements Cloneable { - protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class); + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyItem.class); protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); - private String id; - private String recipe; - private int maxRetries; - private int retryTimeLimit; - private String parentPolicy; - private List<String> parentPolicyConditions; - private String actor; + private String id; + private String recipe; + private int maxRetries; + private int retryTimeLimit; + private String parentPolicy; + private List<String> parentPolicyConditions; + private String actor; + private String targetResourceId; /** * Parse Policy given json node. @@ -70,6 +72,7 @@ public class PolicyItem implements Cloneable { retryTimeLimit = AbstractModelElement.getIntValueByName(node, "retryTimeLimit"); parentPolicy = AbstractModelElement.getValueByName(node, "parentPolicy"); parentPolicyConditions = AbstractModelElement.getValuesByName(node, "parentPolicyConditions"); + targetResourceId = AbstractModelElement.getValueByName(node, "targetResourceId"); } @@ -171,6 +174,14 @@ public class PolicyItem implements Cloneable { this.actor = actor; } + public String getTargetResourceId() { + return targetResourceId; + } + + public void setTargetResourceId(String targetResourceId) { + this.targetResourceId = targetResourceId; + } + @Override public Object clone() throws CloneNotSupportedException { return super.clone(); |