aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorsebdet <sd378r@intl.att.com>2018-09-03 15:12:31 +0200
committersebdet <sd378r@intl.att.com>2018-09-03 16:30:11 +0200
commitd1ff5b9dcfce8c3a69b80832ad2cbe4dbaf1d9cc (patch)
tree8b24c46669da289ea6d20b8541fda523fa766321 /src/main
parent6651e17eab83a2231e1502f8083689f0ddc4751b (diff)
Update policy libraries
Update policy libraries + small reworking of the op policy code Issue-ID: CLAMP-215 Change-Id: I5dad2b9eaf4f6855d2c69f4533b3aae95d155d25 Signed-off-by: sebdet <sd378r@intl.att.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java11
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java103
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java82
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java46
-rw-r--r--src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java12
6 files changed, 135 insertions, 123 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 ddadb55c..39377d4a 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
@@ -19,7 +19,7 @@
* ============LICENSE_END============================================
* Modifications copyright (c) 2018 Nokia
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client;
@@ -55,14 +55,11 @@ public class OperationalPolicyDelegate {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private final PolicyClient policyClient;
private final ClampProperties refProp;
- private final OperationalPolicyAttributesConstructor attributesConstructor;
@Autowired
- public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp,
- OperationalPolicyAttributesConstructor attributesConstructor) {
+ public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) {
this.policyClient = policyClient;
this.refProp = refProp;
- this.attributesConstructor = attributesConstructor;
}
/**
@@ -82,8 +79,8 @@ public class OperationalPolicyDelegate {
Policy policy = prop.getType(Policy.class);
if (policy.isFound()) {
for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
- Map<AttributeType, Map<String, String>> attributes = attributesConstructor.formatAttributes(refProp,
- prop, prop.getType(Policy.class).getId(), policyChain);
+ Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(refProp,
+ prop, prop.getType(Policy.class).getId(), policyChain);
responseMessage = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId());
}
if (responseMessage != null) {
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
index 08cfba14..87299935 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
@@ -18,7 +18,7 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client;
@@ -43,7 +43,7 @@ import org.springframework.stereotype.Component;
public class OperationalPolicyDeleteDelegate {
protected static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(OperationalPolicyDeleteDelegate.class);
+ .getLogger(OperationalPolicyDeleteDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
@Autowired
private PolicyClient policyClient;
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
index 09f98f19..c28f700b 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyAttributesConstructor.java
@@ -28,45 +28,40 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
+
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.PolicyChain;
import org.onap.clamp.clds.model.properties.PolicyItem;
import org.onap.policy.api.AttributeType;
import org.onap.policy.controlloop.policy.builder.BuilderException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.UnsupportedEncodingException;
-import java.util.HashMap;
-import java.util.Map;
-@Component
public class OperationalPolicyAttributesConstructor {
private static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(OperationalPolicyAttributesConstructor.class);
- static final String TEMPLATE_NAME = "templateName";
- static final String CLOSED_LOOP_CONTROL_NAME = "closedLoopControlName";
- static final String NOTIFICATION_TOPIC = "notificationTopic";
- static final String OPERATION_TOPIC = "operationTopic";
- static final String CONTROL_LOOP_YAML = "controlLoopYaml";
- static final String CONTROLLER = "controller";
- static final String RECIPE = "Recipe";
- static final String MAX_RETRIES = "MaxRetries";
- static final String RETRY_TIME_LIMIT = "RetryTimeLimit";
- static final String RESOURCE_ID = "ResourceId";
- static final String RECIPE_TOPIC = "RecipeTopic";
- private OperationalPolicyYamlFormatter policyYamlFormatter;
-
- @Autowired
- protected OperationalPolicyAttributesConstructor(OperationalPolicyYamlFormatter policyYamlFormatter) {
- this.policyYamlFormatter = policyYamlFormatter;
+ .getLogger(OperationalPolicyAttributesConstructor.class);
+ public static final String TEMPLATE_NAME = "templateName";
+ public static final String CLOSED_LOOP_CONTROL_NAME = "closedLoopControlName";
+ public static final String NOTIFICATION_TOPIC = "notificationTopic";
+ public static final String OPERATION_TOPIC = "operationTopic";
+ public static final String CONTROL_LOOP_YAML = "controlLoopYaml";
+ public static final String CONTROLLER = "controller";
+ public static final String RECIPE = "Recipe";
+ public static final String MAX_RETRIES = "MaxRetries";
+ public static final String RETRY_TIME_LIMIT = "RetryTimeLimit";
+ public static final String RESOURCE_ID = "ResourceId";
+ public static final String RECIPE_TOPIC = "RecipeTopic";
+
+ private OperationalPolicyAttributesConstructor() {
}
- public Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
- ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain)
+ public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp,
+ ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain)
throws BuilderException, UnsupportedEncodingException {
modelProperties.setCurrentModelElementId(modelElementId);
modelProperties.setPolicyUniqueId(policyChain.getPolicyId());
@@ -74,14 +69,14 @@ public class OperationalPolicyAttributesConstructor {
String globalService = modelProperties.getGlobal().getService();
Map<String, String> ruleAttributes = prepareRuleAttributes(refProp, modelProperties, modelElementId,
- policyChain, globalService);
+ policyChain, globalService);
Map<String, String> matchingAttributes = prepareMatchingAttributes(refProp, globalService);
return createAttributesMap(matchingAttributes, ruleAttributes);
}
- private Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain, String globalService)
+ private static Map<String, String> prepareRuleAttributes(ClampProperties clampProperties, ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain, String globalService)
throws BuilderException, UnsupportedEncodingException {
logger.info("Preparing rule attributes...");
String templateName = clampProperties.getStringValue("op.templateName", globalService);
@@ -94,13 +89,13 @@ public class OperationalPolicyAttributesConstructor {
ruleAttributes.put(NOTIFICATION_TOPIC, notificationTopic);
ImmutableMap<String, String> attributes = createRuleAttributesFromPolicy(clampProperties, modelProperties,
- modelElementId, policyChain, globalService, operationTopic);
+ modelElementId, policyChain, globalService, operationTopic);
ruleAttributes.putAll(attributes);
logger.info("Prepared: " + ruleAttributes);
return ruleAttributes;
}
- private Map<String, String> prepareMatchingAttributes(ClampProperties refProp, String globalService) {
+ private static Map<String, String> prepareMatchingAttributes(ClampProperties refProp, String globalService) {
logger.info("Preparing matching attributes...");
String controller = refProp.getStringValue("op.controller", globalService);
Map<String, String> matchingAttributes = new HashMap<>();
@@ -109,50 +104,50 @@ public class OperationalPolicyAttributesConstructor {
return matchingAttributes;
}
- private Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes,
- Map<String, String> ruleAttributes) {
+ private static Map<AttributeType, Map<String, String>> createAttributesMap(Map<String, String> matchingAttributes,
+ Map<String, String> ruleAttributes) {
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, ruleAttributes);
attributes.put(AttributeType.MATCHING, matchingAttributes);
return attributes;
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, ModelProperties modelProperties,
- String modelElementId, PolicyChain policyChain,
- String globalService, String operationTopic)
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicy(ClampProperties refProp, ModelProperties modelProperties,
+ String modelElementId, PolicyChain policyChain,
+ String globalService, String operationTopic)
throws BuilderException, UnsupportedEncodingException {
if (Strings.isNullOrEmpty(operationTopic)) {
// if no operationTopic, then don't format yaml - use first policy
String recipeTopic = refProp.getStringValue("op.recipeTopic", globalService);
return createRuleAttributesFromPolicyItem(
- policyChain.getPolicyItems().get(0), recipeTopic);
+ policyChain.getPolicyItems().get(0), recipeTopic);
} else {
return createRuleAttributesFromPolicyChain(policyChain, modelProperties,
- modelElementId, operationTopic);
+ modelElementId, operationTopic);
}
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, String recipeTopic) {
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicyItem(PolicyItem policyItem, String recipeTopic) {
logger.info("recipeTopic=" + recipeTopic);
return ImmutableMap.<String, String>builder()
- .put(RECIPE_TOPIC, recipeTopic)
- .put(RECIPE, policyItem.getRecipe())
- .put(MAX_RETRIES, String.valueOf(policyItem.getMaxRetries()))
- .put(RETRY_TIME_LIMIT, String.valueOf(policyItem.getRetryTimeLimit()))
- .put(RESOURCE_ID, String.valueOf(policyItem.getTargetResourceId()))
- .build();
+ .put(RECIPE_TOPIC, recipeTopic)
+ .put(RECIPE, policyItem.getRecipe())
+ .put(MAX_RETRIES, String.valueOf(policyItem.getMaxRetries()))
+ .put(RETRY_TIME_LIMIT, String.valueOf(policyItem.getRetryTimeLimit()))
+ .put(RESOURCE_ID, String.valueOf(policyItem.getTargetResourceId()))
+ .build();
}
- private ImmutableMap<String, String> createRuleAttributesFromPolicyChain(PolicyChain policyChain,
- ModelProperties modelProperties,
- String modelElementId,
- String operationTopic)
+ private static ImmutableMap<String, String> createRuleAttributesFromPolicyChain(PolicyChain policyChain,
+ ModelProperties modelProperties,
+ String modelElementId,
+ String operationTopic)
throws BuilderException, UnsupportedEncodingException {
logger.info("operationTopic=" + operationTopic);
- String yaml = policyYamlFormatter.formatYaml(modelProperties, modelElementId, policyChain);
+ String yaml = OperationalPolicyYamlFormatter.formatYaml(modelProperties, modelElementId, policyChain);
return ImmutableMap.<String, String>builder()
- .put(OPERATION_TOPIC, operationTopic)
- .put(CONTROL_LOOP_YAML, yaml)
- .build();
+ .put(OPERATION_TOPIC, operationTopic)
+ .put(CONTROL_LOOP_YAML, yaml)
+ .build();
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
index 550c4dcc..1fc36082 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyYamlFormatter.java
@@ -25,6 +25,17 @@ package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.ws.rs.BadRequestException;
+
import org.onap.clamp.clds.model.properties.Global;
import org.onap.clamp.clds.model.properties.ModelProperties;
import org.onap.clamp.clds.model.properties.PolicyChain;
@@ -40,24 +51,43 @@ import org.onap.policy.controlloop.policy.builder.Results;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.ResourceType;
import org.onap.policy.sdc.Service;
-import org.springframework.stereotype.Component;
-import javax.ws.rs.BadRequestException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-@Component
-class OperationalPolicyYamlFormatter {
+public class OperationalPolicyYamlFormatter {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyYamlFormatter.class);
+ protected OperationalPolicyYamlFormatter() {
+ }
+ /**
+ * Format Operational OpenLoop Policy yaml.
+ *
+ * @param prop
+ * @param modelElementId
+ * @param policyChain
+ * @return
+ * @throws BuilderException
+ * @throws UnsupportedEncodingException
+ */
+ public static String formatOpenLoopYaml(ModelProperties prop, String modelElementId,
+ PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
+ // get property objects
+ Global global = prop.getGlobal();
+ prop.setCurrentModelElementId(modelElementId);
+ prop.setPolicyUniqueId(policyChain.getPolicyId());
+ // convert values to SDC objects
+ Service service = new Service(global.getService());
+ Resource[] vfResources = convertToResources(global.getResourceVf(), ResourceType.VF);
+ // create builder
+ ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
+ policyChain.getTimeout(), service, vfResources);
+ // builder.setTriggerPolicy(refProp.getStringValue("op.openloop.policy"));
+ // Build the specification
+ Results results = builder.buildSpecification();
+ validate(results);
+ return URLEncoder.encode(results.getSpecification(), "UTF-8");
+ }
- String formatYaml(ModelProperties prop, String modelElementId,
- PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
+ public static String formatYaml(ModelProperties prop, String modelElementId,
+ PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
// get property objects
Global global = prop.getGlobal();
prop.setCurrentModelElementId(modelElementId);
@@ -68,10 +98,10 @@ class OperationalPolicyYamlFormatter {
Resource[] vfcResources = convertToResources(global.getResourceVfc(), ResourceType.VFC);
// create builder
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
- policyChain.getTimeout(), service, vfResources);
+ policyChain.getTimeout(), service, vfResources);
builder.addResource(vfcResources);
// process each policy
- Map<String, Policy> policyObjMap = new HashMap<String, Policy>();
+ Map<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems());
for (PolicyItem policyItem : policyItemList) {
String policyName = policyItem.getRecipe() + " Policy";
@@ -87,16 +117,16 @@ class OperationalPolicyYamlFormatter {
Policy policyObj;
if (policyItemList.indexOf(policyItem) == 0) {
String policyDescription = policyItem.getRecipe()
- + " Policy - the trigger (no parent) policy - created by CLDS";
+ + " Policy - the trigger (no parent) policy - created by CLDS";
policyObj = builder.setTriggerPolicy(policyName, policyDescription, actor, target,
- policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit());
+ policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit());
} else {
Policy parentPolicyObj = policyObjMap.get(policyItem.getParentPolicy());
String policyDescription = policyItem.getRecipe() + " Policy - triggered conditionally by "
- + parentPolicyObj.getName() + " - created by CLDS";
+ + parentPolicyObj.getName() + " - created by CLDS";
policyObj = builder.setPolicyForPolicyResult(policyName, policyDescription, actor, target,
- policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(),
- parentPolicyObj.getId(), convertToPolicyResults(policyItem.getParentPolicyConditions()));
+ policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(),
+ parentPolicyObj.getId(), convertToPolicyResults(policyItem.getParentPolicyConditions()));
logger.info("policyObj.id=" + policyObj.getId() + "; parentPolicyObj.id=" + parentPolicyObj.getId());
}
policyObjMap.put(policyItem.getId(), policyObj);
@@ -107,7 +137,7 @@ class OperationalPolicyYamlFormatter {
return URLEncoder.encode(results.getSpecification(), "UTF-8");
}
- private List<PolicyItem> orderParentFirst(List<PolicyItem> inOrigList) {
+ protected static List<PolicyItem> orderParentFirst(List<PolicyItem> inOrigList) {
List<PolicyItem> inList = new ArrayList<>();
inList.addAll(inOrigList);
List<PolicyItem> outList = new ArrayList<>();
@@ -129,7 +159,7 @@ class OperationalPolicyYamlFormatter {
if (parent == null || parent.length() == 0) {
if (!outList.isEmpty()) {
throw new BadRequestException(
- "Operation Policy validation problem: more than one trigger policy");
+ "Operation Policy validation problem: more than one trigger policy");
} else {
outList.add(inItem);
inListItr.remove();
@@ -151,7 +181,7 @@ class OperationalPolicyYamlFormatter {
return outList;
}
- private void validate(Results results) {
+ protected static void validate(Results results) {
if (results.isValid()) {
logger.info("results.getSpecification()=" + results.getSpecification());
} else {
@@ -167,14 +197,14 @@ class OperationalPolicyYamlFormatter {
}
- Resource[] convertToResources(List<String> stringList, ResourceType resourceType) {
+ protected static Resource[] convertToResources(List<String> stringList, ResourceType resourceType) {
if (stringList == null || stringList.isEmpty()) {
return new Resource[0];
}
return stringList.stream().map(stringElem -> new Resource(stringElem, resourceType)).toArray(Resource[]::new);
}
- PolicyResult[] convertToPolicyResults(List<String> prList) {
+ protected static PolicyResult[] convertToPolicyResults(List<String> prList) {
if (prList == null || prList.isEmpty()) {
return new PolicyResult[0];
}
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
index cc97a7ce..cd387b3c 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
@@ -18,7 +18,7 @@
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- *
+ *
*/
package org.onap.clamp.clds.client.req.policy;
@@ -26,11 +26,8 @@ package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -46,7 +43,6 @@ import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.DeletePolicyCondition;
import org.onap.policy.api.DeletePolicyParameters;
import org.onap.policy.api.PolicyChangeResponse;
-import org.onap.policy.api.PolicyConfig;
import org.onap.policy.api.PolicyConfigException;
import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
@@ -95,7 +91,7 @@ public class PolicyClient {
* @return The response message of policy
*/
public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
- String policyRequestUuid) {
+ String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type(Mandatory)
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
@@ -160,7 +156,7 @@ public class PolicyClient {
* @return The answer from policy call
*/
public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
- String policyRequestUuid) {
+ String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.Base);
@@ -181,7 +177,7 @@ public class PolicyClient {
/**
* Perform send of Microservice policy in OTHER type.
- *
+ *
* @param configBody
* The config policy string body
* @param prop
@@ -224,8 +220,7 @@ public class PolicyClient {
String responseMessage = "";
Date startTime = new Date();
try {
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (versions.isEmpty()) {
+ if (!checkPolicyExists(policyNamePrefix, prop)) {
LoggingUtils.setTargetContext("Policy", "createPolicy");
logger.info("Attempting to create policy for action=" + prop.getActionCd());
response = getPolicyEngine().createPolicy(policyParameters);
@@ -313,8 +308,8 @@ public class PolicyClient {
}
/**
- * Use Get Config Policy API to retrieve the versions for a policy. Return
- * versions in sorted order. Return empty list if none found.
+ * Use list Policy API to retrieve the policy. Return true if policy exists
+ * otherwise return false.
*
* @param policyNamePrefix
* The Policy Name Prefix
@@ -324,8 +319,8 @@ public class PolicyClient {
* @throws PolicyConfigException
* In case of issues with policy engine
*/
- protected List<Integer> getVersions(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
- ArrayList<Integer> versions = new ArrayList<>();
+ protected boolean checkPolicyExists(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
+ boolean policyexists = false;
ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
String policyName = "";
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
@@ -336,27 +331,20 @@ public class PolicyClient {
logger.info("Search in Policy Engine for policyName=" + policyName);
configRequestParameters.setPolicyName(policyName);
try {
- Collection<PolicyConfig> response = getPolicyEngine().getConfig(configRequestParameters);
- for (PolicyConfig policyConfig : response) {
- if (policyConfig.getPolicyVersion() != null) {
- Integer version = Integer.valueOf(policyConfig.getPolicyVersion());
- versions.add(version);
- } else {
- logger.warn("Policy version was null, unable to convert it to Integer");
- }
+ Collection<String> response = getPolicyEngine().listConfig(configRequestParameters);
+ if (response != null && !response.isEmpty()) {
+ policyexists = true;
}
- Collections.sort(versions);
- logger.info("Policy versions.size()=" + versions.size());
} catch (PolicyConfigException e) {
// just print warning - if no policy version found
logger.warn("policy not found...policy name - " + policyName, e);
}
- return versions;
+ return policyexists;
}
/**
* This method create a new policy engine.
- *
+ *
* @return A new policy engine
*/
private synchronized PolicyEngine getPolicyEngine() {
@@ -381,8 +369,7 @@ public class PolicyClient {
String deletePolicyResponse = "";
try {
String policyNamePrefix = refProp.getStringValue(POLICY_MS_NAME_PREFIX_PROPERTY_NAME);
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (!versions.isEmpty()) {
+ if (checkPolicyExists(policyNamePrefix, prop)) {
String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
deletePolicyResponse = deletePolicy(prop, policyType);
}
@@ -415,8 +402,7 @@ public class PolicyClient {
String deletePolicyResponse = "";
try {
String policyNamePrefix = refProp.getStringValue(POLICY_OP_NAME_PREFIX_PROPERTY_NAME);
- List<Integer> versions = getVersions(policyNamePrefix, prop);
- if (!versions.isEmpty()) {
+ if (checkPolicyExists(policyNamePrefix, prop)) {
String policyType = refProp.getStringValue(POLICY_OP_TYPE_PROPERTY_NAME);
deletePolicyResponse = deletePolicy(prop, policyType);
}
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
index 6e3e8659..7caba41f 100644
--- a/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/properties/PolicyItem.java
@@ -66,6 +66,7 @@ public class PolicyItem implements Cloneable {
private String targetResourceId;
private String recipeInfo;
private String recipeLevel;
+ private String recipeInput;
private Map<String, String> recipePayload;
private String oapRop;
private String oapLimit;
@@ -76,7 +77,7 @@ public class PolicyItem implements Cloneable {
* @param node
* @throws IOException
*/
- public PolicyItem(JsonNode node) throws IOException {
+ public PolicyItem(JsonNode node) throws IOException {
id = AbstractModelElement.getValueByName(node, "_id");
recipe = AbstractModelElement.getValueByName(node, "recipe");
maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries");
@@ -89,11 +90,10 @@ public class PolicyItem implements Cloneable {
}
recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo");
recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel");
- String payload = AbstractModelElement.getValueByName(node, "recipeInput");
-
+ recipeInput = AbstractModelElement.getValueByName(node, "recipeInput");
+ String payload = AbstractModelElement.getValueByName(node, "recipePayload");
if (payload != null && !payload.isEmpty()) {
- //recipePayload = JacksonUtils.getObjectMapperInstance().convertValue(payload, Map.class);
recipePayload = JacksonUtils.getObjectMapperInstance().readValue(payload, new TypeReference<Map<String, String>>(){});
}
oapRop = AbstractModelElement.getValueByName(node, "oapRop");
@@ -215,6 +215,10 @@ public class PolicyItem implements Cloneable {
return recipeLevel;
}
+ public String getRecipeInput() {
+ return recipeInput;
+ }
+
public Map<String, String> getRecipePayload() {
return recipePayload;
}