aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormuszkiet <lukasz.muszkieta@nokia.com>2017-12-11 16:15:07 +0100
committermuszkiet <lukasz.muszkieta@nokia.com>2017-12-12 09:22:23 +0100
commitcb766efc03a625bf95ece11b5f840deea31df236 (patch)
treee66d029120dc6958bd6b7cf217ce96205f936651 /src
parent53f4973f159c8649a6d8a102fd82d82f5b01d2ba (diff)
Code refactoring
remove duplication, methods improvements Change-Id: Ifadb3ed931892f93ef6fb9ad128232c851828314 Issue-ID: CLAMP-93 Signed-off-by: muszkiet <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java10
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java39
2 files changed, 15 insertions, 34 deletions
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 e6af4336..58f5e008 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<AttributeType, Map<String, String>> 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 fcf6cda5..db84a124 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<String, String> 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");
}
/**