From cb766efc03a625bf95ece11b5f840deea31df236 Mon Sep 17 00:00:00 2001 From: muszkiet Date: Mon, 11 Dec 2017 16:15:07 +0100 Subject: Code refactoring remove duplication, methods improvements Change-Id: Ifadb3ed931892f93ef6fb9ad128232c851828314 Issue-ID: CLAMP-93 Signed-off-by: muszkiet --- .../clds/client/OperationalPolicyDelegate.java | 10 ++---- .../client/req/policy/OperationalPolicyReq.java | 39 +++++++--------------- 2 files changed, 15 insertions(+), 34 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java index e6af43363..58f5e0086 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java @@ -39,14 +39,13 @@ import org.onap.clamp.clds.model.prop.PolicyChain; import org.onap.clamp.clds.model.refprop.RefProp; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.policy.api.AttributeType; -import org.onap.policy.api.PolicyEngineException; import org.onap.policy.controlloop.policy.builder.BuilderException; import org.springframework.beans.factory.annotation.Autowired; /** * Send Operational Policy info to policy api. It uses the policy code to define * the model and communicate with it. See also the PolicyClient class. - * + * */ public class OperationalPolicyDelegate implements JavaDelegate { protected static final EELFLogger logger = EELFManager.getInstance() @@ -70,20 +69,17 @@ public class OperationalPolicyDelegate implements JavaDelegate { * The DelegateExecution * @throws BuilderException * In case of issues with OperationalPolicyReq - * @throws PolicyEngineException - * In case of issues with the PolicyEngine creation * @throws UnsupportedEncodingException */ @Override public void execute(DelegateExecution execution) - throws BuilderException, PolicyEngineException, UnsupportedEncodingException { + throws BuilderException, UnsupportedEncodingException { String responseMessage = null; - String operationalPolicyRequestUuid = null; ModelProperties prop = ModelProperties.create(execution); Policy policy = prop.getType(Policy.class); if (policy.isFound()) { for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - operationalPolicyRequestUuid = LoggingUtils.getRequestId(); + String operationalPolicyRequestUuid = LoggingUtils.getRequestId(); Map> attributes = OperationalPolicyReq.formatAttributes(refProp, prop, prop.getType(Policy.class).getId(), policyChain); responseMessage = policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid); diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java index fcf6cda57..db84a1240 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java @@ -107,20 +107,21 @@ public class OperationalPolicyReq { notificationTopic = refProp.getStringValue("op.notificationTopic", global.getService()); controller = refProp.getStringValue("op.controller", global.getService()); } + String recipeTopic = refProp.getStringValue("op.recipeTopic", global.getService()); // ruleAttributes + logger.info("templateName=" + templateName); + logger.info("notificationTopic=" + notificationTopic); Map ruleAttributes = new HashMap<>(); + ruleAttributes.put("templateName", templateName); + ruleAttributes.put("ClosedLoopControlName", prop.getControlNameAndPolicyUniqueId()); + ruleAttributes.put("NotificationTopic", notificationTopic); if (operationTopic == null || operationTopic.isEmpty()) { - logger.info("templateName=" + templateName); logger.info("recipeTopic=" + recipeTopic); - logger.info("notificationTopic=" + notificationTopic); // if no operationTopic, then don't format yaml - use first policy // from list PolicyItem policyItem = policyChain.getPolicyItems().get(0); - ruleAttributes.put("templateName", templateName); - ruleAttributes.put("ClosedLoopControlName", prop.getControlNameAndPolicyUniqueId()); ruleAttributes.put("RecipeTopic", recipeTopic); - ruleAttributes.put("NotificationTopic", notificationTopic); String recipe = policyItem.getRecipe(); String maxRetries = String.valueOf(policyItem.getMaxRetries()); String retryTimeLimit = String.valueOf(policyItem.getRetryTimeLimit()); @@ -134,16 +135,11 @@ public class OperationalPolicyReq { 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 != null && tca.isFound()) ? formateNodeBYaml(refProp, prop, modelElementId, policyChain) : formatYaml(refProp, prop, modelElementId, policyChain); - ruleAttributes.put("templateName", templateName); - ruleAttributes.put("ClosedLoopControlName", prop.getControlNameAndPolicyUniqueId()); ruleAttributes.put("OperationTopic", operationTopic); - ruleAttributes.put("NotificationTopic", notificationTopic); ruleAttributes.put("ControlLoopYaml", yaml); } // matchingAttributes @@ -205,22 +201,9 @@ public class OperationalPolicyReq { } policyObjMap.put(policyItem.getId(), policyObj); } - // // Build the specification - // Results results = builder.buildSpecification(); - if (results.isValid()) { - logger.info("results.getSpecification()=" + results.getSpecification()); - } else { - // throw exception with error info - StringBuilder sb = new StringBuilder(); - sb.append("Operation Policy validation problem: ControlLoopPolicyBuilder failed with following messages: "); - for (Message message : results.getMessages()) { - sb.append(message.getMessage()); - sb.append("; "); - } - throw new BadRequestException(sb.toString()); - } + validate(results); return URLEncoder.encode(results.getSpecification(), "UTF-8"); } @@ -284,10 +267,13 @@ public class OperationalPolicyReq { operationsAccumulateParams.setLimit(Integer.valueOf(refProp.getStringValue("op.eNodeB.limit"))); operationsAccumulateParams.setPeriod(refProp.getStringValue("op.eNodeB.period")); builder.addOperationsAccumulateParams(lastPolicyObj.getId(), operationsAccumulateParams); - // // Build the specification - // Results results = builder.buildSpecification(); + validate(results); + return URLEncoder.encode(results.getSpecification(), "UTF-8"); + } + + private static void validate (Results results) { if (results.isValid()) { logger.info("results.getSpecification()=" + results.getSpecification()); } else { @@ -300,7 +286,6 @@ public class OperationalPolicyReq { } throw new BadRequestException(sb.toString()); } - return URLEncoder.encode(results.getSpecification(), "UTF-8"); } /** -- cgit 1.2.3-korg