X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2Freq%2FOperationalPolicyReq.java;h=1d345e9caa803c4169edf7f420377a423d5bb1ad;hb=c06db6e74139422b874ce0365842624ecde81f8d;hp=e7f956d3330c30c3267fe8747a8beb44d7f6058d;hpb=f13efdabda4ff77eedccf5595616c9423710f405;p=clamp.git 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 e7f956d3..1d345e9c 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 @@ -46,9 +46,9 @@ import org.onap.clamp.clds.model.prop.PolicyItem; import org.onap.clamp.clds.model.prop.Tca; import org.onap.clamp.clds.model.refprop.RefProp; import org.onap.policy.api.AttributeType; -import org.onap.policy.asdc.Resource; -import org.onap.policy.asdc.ResourceType; -import org.onap.policy.asdc.Service; +import org.onap.policy.sdc.Resource; +import org.onap.policy.sdc.ResourceType; +import org.onap.policy.sdc.Service; import org.onap.policy.controlloop.policy.OperationsAccumulateParams; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; @@ -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. * @@ -85,8 +89,8 @@ public class OperationalPolicyReq { String operationTopic = ""; String notificationTopic = ""; String controller = ""; - Tca tca = prop.getTca(); - if (tca.isFound()) { + Tca tca = prop.getType(Tca.class); + if (tca != null && tca.isFound()) { if (!global.getActionSet().equalsIgnoreCase("enbRecipe")) { throw new BadRequestException( "Operation Policy validation problem: action set is not selected properly."); @@ -108,9 +112,9 @@ public class OperationalPolicyReq { String recipeTopic = refProp.getStringValue("op.recipeTopic", global.getService()); // ruleAttributes - Map ruleAttributes = new HashMap(); + Map ruleAttributes = new HashMap<>(); - if (operationTopic == null || operationTopic.length() == 0) { + if (operationTopic == null || operationTopic.isEmpty()) { logger.info("templateName=" + templateName); logger.info("recipeTopic=" + recipeTopic); logger.info("notificationTopic=" + notificationTopic); @@ -127,19 +131,23 @@ 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); logger.info("notificationTopic=" + notificationTopic); // format yaml - String yaml = tca.isFound() ? formateNodeBYaml(refProp, prop, modelElementId, policyChain) + String yaml = (tca != null && tca.isFound()) ? formateNodeBYaml(refProp, prop, modelElementId, policyChain) : formatYaml(refProp, prop, modelElementId, policyChain); ruleAttributes.put("templateName", templateName); @@ -151,10 +159,10 @@ public class OperationalPolicyReq { } // matchingAttributes - Map matchingAttributes = new HashMap(); + Map matchingAttributes = new HashMap<>(); matchingAttributes.put("controller", controller); - Map> attributes = new HashMap>(); + Map> attributes = new HashMap<>(); attributes.put(AttributeType.RULE, ruleAttributes); attributes.put(AttributeType.MATCHING, matchingAttributes); @@ -189,24 +197,22 @@ public class OperationalPolicyReq { builder.addResource(vfcResources); // process each policy - HashMap policyObjMap = new HashMap(); + Map policyObjMap = new HashMap<>(); List 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, @@ -227,7 +233,7 @@ public class OperationalPolicyReq { logger.info("results.getSpecification()=" + results.getSpecification()); } else { // throw exception with error info - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("Operation Policy validation problem: ControlLoopPolicyBuilder failed with following messages: "); for (Message message : results.getMessages()) { sb.append(message.getMessage()); @@ -235,10 +241,7 @@ public class OperationalPolicyReq { } throw new BadRequestException(sb.toString()); } - - String encodedYaml = URLEncoder.encode(results.getSpecification(), "UTF-8"); - - return encodedYaml; + return URLEncoder.encode(results.getSpecification(), "UTF-8"); } /** @@ -269,19 +272,20 @@ public class OperationalPolicyReq { builder.addResource(vfcResources); // process each policy - HashMap policyObjMap = new HashMap(); + Map policyObjMap = new HashMap<>(); List 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 payloadMap = new HashMap(); + Map payloadMap = new HashMap<>(); payloadMap.put("timeWindow", refProp.getStringValue("op.eNodeB.timeWindow")); String policyDescription = policyItem.getRecipe() + " Policy - the trigger (no parent) policy - created by CLDS"; @@ -314,7 +318,7 @@ public class OperationalPolicyReq { logger.info("results.getSpecification()=" + results.getSpecification()); } else { // throw exception with error info - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("Operation Policy validation problem: ControlLoopPolicyBuilder failed with following messages: "); for (Message message : results.getMessages()) { sb.append(message.getMessage()); @@ -322,10 +326,7 @@ public class OperationalPolicyReq { } throw new BadRequestException(sb.toString()); } - - String encodedYaml = URLEncoder.encode(results.getSpecification(), "UTF-8"); - - return encodedYaml; + return URLEncoder.encode(results.getSpecification(), "UTF-8"); } /** @@ -335,7 +336,7 @@ public class OperationalPolicyReq { * @return */ private static List addAOTSActorRecipe(RefProp refProp, String service, List inOrigList) { - List outList = new ArrayList(); + List outList = new ArrayList<>(); try { PolicyItem policyItem = inOrigList.get(0); ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("op.eNodeB.recipe", service); @@ -354,7 +355,7 @@ public class OperationalPolicyReq { policyItemObj.setRetryTimeLimit(Integer.parseInt(recipeNode.path("TimeLimit").asText())); } if (!recipeNode.path("PPConditions").asText().isEmpty()) { - List parentPolicyConditions = new ArrayList(); + List parentPolicyConditions = new ArrayList<>(); for (String ppCondition : recipeNode.path("PPConditions").asText().split(",")) { parentPolicyConditions.add(ppCondition); } @@ -395,7 +396,7 @@ public class OperationalPolicyReq { // check for trigger policy (no parent) String parent = inItem.getParentPolicy(); if (parent == null || parent.length() == 0) { - if (outList.size() > 0) { + if (!outList.isEmpty()) { throw new BadRequestException( "Operation Policy validation problem: more than one trigger policy"); } else {