diff options
Diffstat (limited to 'src/main/java/org')
4 files changed, 53 insertions, 52 deletions
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 2ebab88bb..f062dfca6 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 @@ -19,7 +19,7 @@ * ============LICENSE_END============================================ * Modifications copyright (c) 2018 Nokia * =================================================================== - * + * */ package org.onap.clamp.clds.client.req.policy; @@ -77,7 +77,7 @@ public class OperationalPolicyReq { * @throws UnsupportedEncodingException */ public static Map<AttributeType, Map<String, String>> formatAttributes(ClampProperties refProp, - ModelProperties prop, String modelElementId, PolicyChain policyChain) + ModelProperties prop, String modelElementId, PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { Global global = prop.getGlobal(); prop.setCurrentModelElementId(modelElementId); @@ -130,7 +130,7 @@ public class OperationalPolicyReq { /** * Format Operational OpenLoop Policy yaml. - * + * * @param refProp * @param prop * @param modelElementId @@ -140,7 +140,7 @@ public class OperationalPolicyReq { * @throws UnsupportedEncodingException */ protected static String formatOpenLoopYaml(ClampProperties refProp, ModelProperties prop, String modelElementId, - PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { + PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects Global global = prop.getGlobal(); prop.setCurrentModelElementId(modelElementId); @@ -150,7 +150,7 @@ public class OperationalPolicyReq { Resource[] vfResources = convertToResource(global.getResourceVf(), ResourceType.VF); // create builder ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(), - policyChain.getTimeout(), service, vfResources); + policyChain.getTimeout(), service, vfResources); // builder.setTriggerPolicy(refProp.getStringValue("op.openloop.policy")); // Build the specification Results results = builder.buildSpecification(); @@ -170,7 +170,7 @@ public class OperationalPolicyReq { * @throws UnsupportedEncodingException */ protected static String formatYaml(ClampProperties refProp, ModelProperties prop, String modelElementId, - PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { + PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException { // get property objects Global global = prop.getGlobal(); prop.setCurrentModelElementId(modelElementId); @@ -181,7 +181,7 @@ public class OperationalPolicyReq { Resource[] vfcResources = convertToResource(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<>(); @@ -195,31 +195,21 @@ public class OperationalPolicyReq { target.setType(TargetType.valueOf(policyItem.getRecipeLevel())); } target.setResourceID(policyItem.getTargetResourceId()); - String actor = refProp.getStringValue("op.policy.appc"); - Map<String, String> payloadMap = null; - if ("health-diagnostic".equalsIgnoreCase(policyItem.getRecipe())) { - actor = refProp.getStringValue("op.policy.sdno"); - payloadMap = new HashMap<String, String>(); - payloadMap.put("ttl", policyItem.getRecipePayload()); - } - // For reboot recipe we have to send type as SOFT/HARD in pay load - if (policyItem.getRecipeInfo() != null && !policyItem.getRecipeInfo().isEmpty()) { - payloadMap = new HashMap<String, String>(); - payloadMap.put("type", policyItem.getRecipeInfo()); - } + String actor = policyItem.getActor(); + Map<String, String> payloadMap = policyItem.getRecipePayload(); 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(), convertToPolicyResult(policyItem.getParentPolicyConditions())); + policyItem.getRecipe(), payloadMap, policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(), + parentPolicyObj.getId(), convertToPolicyResult(policyItem.getParentPolicyConditions())); logger.info("policyObj.id=" + policyObj.getId() + "; parentPolicyObj.id=" + parentPolicyObj.getId()); } policyObjMap.put(policyItem.getId(), policyObj); @@ -274,7 +264,7 @@ public class OperationalPolicyReq { 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(); diff --git a/src/main/java/org/onap/clamp/clds/model/properties/Policy.java b/src/main/java/org/onap/clamp/clds/model/properties/Policy.java index 2ae0f07d8..501eb8077 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/Policy.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/Policy.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model.properties; @@ -27,6 +27,7 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -62,8 +63,9 @@ public class Policy extends AbstractModelElement { * @param modelProp * @param modelBpmn * @param modelJson + * @throws IOException */ - public Policy(ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) { + public Policy(ModelProperties modelProp, ModelBpmn modelBpmn, JsonNode modelJson) throws IOException { super(TYPE_POLICY, modelProp, modelBpmn, modelJson); // process policies diff --git a/src/main/java/org/onap/clamp/clds/model/properties/PolicyChain.java b/src/main/java/org/onap/clamp/clds/model/properties/PolicyChain.java index 96fc33c2a..cf24c7810 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/PolicyChain.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/PolicyChain.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model.properties; @@ -27,6 +27,7 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -65,23 +66,23 @@ public class PolicyChain { private List<PolicyItem> policyItems; private String policyType; - public PolicyChain(JsonNode node) { + public PolicyChain(JsonNode node) throws IOException { policyId = AbstractModelElement.getValueByName(node, "pid"); timeout = AbstractModelElement.getIntValueByName(node, "timeout"); policyType = AbstractModelElement.getValueByName(node, "policyType"); - - if(node != null && node.size() > 0) { - JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations"); - if(policyNode != null) { - Iterator<JsonNode> itr = policyNode.elements(); - policyItems = new ArrayList<>(); - while (itr.hasNext()) { - policyItems.add(new PolicyItem(itr.next())); - } - - } - } + + if(node != null && node.size() > 0) { + JsonNode policyNode = node.get(node.size() - 1).get("policyConfigurations"); + if(policyNode != null) { + Iterator<JsonNode> itr = policyNode.elements(); + policyItems = new ArrayList<>(); + while (itr.hasNext()) { + policyItems.add(new PolicyItem(itr.next())); + } + + } + } } /** * @return the policyId @@ -103,7 +104,7 @@ public class PolicyChain { public List<PolicyItem> getPolicyItems() { return policyItems; } - + /** * @return the 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 75bf6ae39..6e3e86593 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 @@ -18,16 +18,21 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.model.properties; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; import java.util.List; +import java.util.Map; + +import org.onap.clamp.clds.util.JacksonUtils; /** * Parse policyConfigurations from Policy json properties. @@ -61,7 +66,7 @@ public class PolicyItem implements Cloneable { private String targetResourceId; private String recipeInfo; private String recipeLevel; - private String recipePayload; + private Map<String, String> recipePayload; private String oapRop; private String oapLimit; @@ -69,8 +74,9 @@ public class PolicyItem implements Cloneable { * Parse Policy given json node. * * @param node + * @throws IOException */ - public PolicyItem(JsonNode node) { + public PolicyItem(JsonNode node) throws IOException { id = AbstractModelElement.getValueByName(node, "_id"); recipe = AbstractModelElement.getValueByName(node, "recipe"); maxRetries = AbstractModelElement.getIntValueByName(node, "maxRetries"); @@ -83,9 +89,16 @@ public class PolicyItem implements Cloneable { } recipeInfo = AbstractModelElement.getValueByName(node, "recipeInfo"); recipeLevel = AbstractModelElement.getValueByName(node, "recipeLevel"); - recipePayload = AbstractModelElement.getValueByName(node, "recipeInput"); + String payload = AbstractModelElement.getValueByName(node, "recipeInput"); + + + 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"); oapLimit = AbstractModelElement.getValueByName(node, "oapLimit"); + actor = AbstractModelElement.getValueByName(node, "actor"); } /** @@ -202,7 +215,7 @@ public class PolicyItem implements Cloneable { return recipeLevel; } - public String getRecipePayload() { + public Map<String, String> getRecipePayload() { return recipePayload; } @@ -219,9 +232,4 @@ public class PolicyItem implements Cloneable { } return oapLimit; } - - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } } |