diff options
author | sebdet <sebastien.determe@intl.att.com> | 2018-12-01 15:06:42 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2018-12-01 15:06:42 +0100 |
commit | d1779040e9f6aeaff20a8c0f4da64f4ac7774ae0 (patch) | |
tree | b27584b8dca3b1c0834dd5b50034cf9e5c514984 /src | |
parent | 13cd99b20365b23d1db641eb367456a961d89c33 (diff) |
Some minor improvements
Minor improvements of condition, sonar reporting
Issue-ID: CLAMP-252
Change-Id: I216a0896f15e92a0b72e85d0c1ebc114a7302036
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src')
6 files changed, 142 insertions, 20 deletions
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 87299935..5a983b78 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java @@ -60,15 +60,19 @@ public class OperationalPolicyDeleteDelegate { Policy policy = prop.getType(Policy.class); prop.setCurrentModelElementId(policy.getId()); String eventAction = (String) camelExchange.getProperty("eventAction"); - String responseMessage = ""; - if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) { - for (PolicyChain policyChain : policy.getPolicyChains()) { - prop.setPolicyUniqueId(policyChain.getPolicyId()); - responseMessage = policyClient.deleteBrms(prop); - } - if (responseMessage != null) { - camelExchange.setProperty("operationalPolicyDeleteResponseMessage", responseMessage.getBytes()); + if(policy.getPolicyChains() != null && policy.getPolicyChains().size() > 0) { + String responseMessage = ""; + + if (!eventAction.equalsIgnoreCase(CldsEvent.ACTION_CREATE) && policy.isFound()) { + for (PolicyChain policyChain : policy.getPolicyChains()) { + prop.setPolicyUniqueId(policyChain.getPolicyId()); + responseMessage = policyClient.deleteBrms(prop); + } + if (responseMessage != null) { + camelExchange.setProperty("operationalPolicyDeleteResponseMessage", responseMessage.getBytes()); + } } } + } } diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java index de86faa2..0b4cbeab 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/GuardPolicyAttributesConstructor.java @@ -44,7 +44,8 @@ public class GuardPolicyAttributesConstructor { private GuardPolicyAttributesConstructor() { } - public static Map<AttributeType, Map<String, String>> formatAttributes(ModelProperties modelProperties, PolicyItem policyItem) { + public static Map<AttributeType, Map<String, String>> formatAttributes(ModelProperties modelProperties, + PolicyItem policyItem) { Map<String, String> matchingAttributes = prepareMatchingAttributes(policyItem, modelProperties); return createAttributesMap(matchingAttributes); } @@ -62,20 +63,20 @@ public class GuardPolicyAttributesConstructor { private static Map<String, String> prepareMatchingAttributes(PolicyItem policyItem, ModelProperties modelProp) { logger.info("Preparing matching attributes for guard..."); Map<String, String> matchingAttributes = new HashMap<>(); - matchingAttributes.put("actor",policyItem.getActor()); - matchingAttributes.put("recipe",policyItem.getRecipe()); - matchingAttributes.put("targets",policyItem.getGuardTargets()); - matchingAttributes.put("clname",modelProp.getControlNameAndPolicyUniqueId()); + matchingAttributes.put("actor", policyItem.getActor()); + matchingAttributes.put("recipe", policyItem.getRecipe()); + matchingAttributes.put("targets", policyItem.getGuardTargets()); + matchingAttributes.put("clname", modelProp.getControlNameAndPolicyUniqueId()); if (RuleProvider.GUARD_MIN_MAX.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) { - matchingAttributes.put("min",policyItem.getMinGuard()); - matchingAttributes.put("max",policyItem.getMaxGuard()); + matchingAttributes.put("min", policyItem.getMinGuard()); + matchingAttributes.put("max", policyItem.getMaxGuard()); } else if (RuleProvider.GUARD_YAML.equals(RuleProvider.valueOf(policyItem.getGuardPolicyType()))) { - matchingAttributes.put("limit",policyItem.getLimitGuard()); - matchingAttributes.put("timeWindow",policyItem.getTimeWindowGuard()); - matchingAttributes.put("timeUnits",policyItem.getTimeUnitsGuard()); + matchingAttributes.put("limit", policyItem.getLimitGuard()); + matchingAttributes.put("timeWindow", policyItem.getTimeWindowGuard()); + matchingAttributes.put("timeUnits", policyItem.getTimeUnitsGuard()); } - matchingAttributes.put("guardActiveStart",policyItem.getGuardActiveStart()); - matchingAttributes.put("guardActiveEnd",policyItem.getGuardActiveEnd()); + matchingAttributes.put("guardActiveStart", policyItem.getGuardActiveStart()); + matchingAttributes.put("guardActiveEnd", policyItem.getGuardActiveEnd()); logger.info("Prepared: " + matchingAttributes); return matchingAttributes; diff --git a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java index bdb4dda5..7c6c6ff6 100644 --- a/src/main/java/org/onap/clamp/clds/config/ClampProperties.java +++ b/src/main/java/org/onap/clamp/clds/config/ClampProperties.java @@ -24,10 +24,12 @@ package org.onap.clamp.clds.config; import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.base.Splitter; import java.io.IOException; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.List; import org.apache.commons.io.IOUtils; import org.onap.clamp.clds.util.JacksonUtils; @@ -47,6 +49,8 @@ public class ClampProperties { @Autowired private Environment env; public static final String CONFIG_PREFIX = "clamp.config."; + public static final String TOSCA_POLICY_TYPES_CONFIG= "tosca.policyTypes"; + public static final String IMPORT_TOSCA_POLICY= "import.tosca.model"; /** * get property value. @@ -153,4 +157,19 @@ public class ClampProperties { URL url = appContext.getResource(filepath).getURL(); return IOUtils.toString(url, StandardCharsets.UTF_8); } + + /** + * + * + * @param key + * property key + * @param separator + * property value separator + * @return + * List of Strings split with a separator + */ + public List<String> getStringList(String key, String separator) { + return Splitter.on(separator).trimResults().omitEmptyStrings() + .splitToList(env.getProperty(CONFIG_PREFIX + key)); + } } diff --git a/src/main/java/org/onap/clamp/clds/model/properties/Global.java b/src/main/java/org/onap/clamp/clds/model/properties/Global.java index 6fabc7a5..e8674072 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/Global.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/Global.java @@ -47,6 +47,7 @@ public class Global { private List<String> resourceVfc; private JsonNode deployParameters; private List<String> location; + private String vnfScope; /** * Parse global given json node. @@ -61,6 +62,7 @@ public class Global { resourceVfc = AbstractModelElement.getValuesByName(globalNode, "vfc"); deployParameters = AbstractModelElement.getJsonNodeByName(globalNode, "deployParameters"); location = AbstractModelElement.getValuesByName(globalNode, "location"); + vnfScope = AbstractModelElement.getValueByName(globalNode, "vnf"); } /** @@ -141,4 +143,9 @@ public class Global { public void setDeployParameters(JsonNode deployParameters) { this.deployParameters = deployParameters; } + + public String getVnfScope() { + return vnfScope; + } + } diff --git a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java index f38e8c1c..b5679400 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java @@ -264,6 +264,23 @@ public class ModelProperties { } /** + * @return the PolicyNameWithScopeContext + */ + public String getPolicyNameWithScopeContext(String policyScope, String policyType, String vnfScope, String context, String userDefinedName) { + return normalizePolicyScopeName( + policyScope + createScopeSeparator(policyScope) + policyType + "_" + vnfScope + "_" + context + "_" + modelName + "_" + userDefinedName); + } + + /** + * @return the PolicyNameWithPrefixScopeContext + */ + public String getPolicyNameWithPrefixScopeContext(String policyScope, String policyType, String vnfScope, String context, + String userDefinedName, String policyPrefix) { + return normalizePolicyScopeName(policyScope + createScopeSeparator(policyScope) + policyPrefix + policyType + "_" + vnfScope + "_" + + context + "_" + modelName + "_" + userDefinedName); + } + + /** * Replace all '-' with '_' within policy scope and name. * * @param inName diff --git a/src/test/resources/example/dao/bpmn-prop.json b/src/test/resources/example/dao/bpmn-prop.json index f1b87a00..a38d58c3 100644 --- a/src/test/resources/example/dao/bpmn-prop.json +++ b/src/test/resources/example/dao/bpmn-prop.json @@ -5,6 +5,80 @@ "value": "uktukk" } ], + "TCA_11n5nl9": { + "group1": [ + { + "name": "tname", + "value": "group1" + }, + { + "name": "tuuid", + "value": "f734f031-10aa-t8fb-330f-04dde2886325" + }, + { + "name": "tcaPolId", + "value": "policy1" + }, + { + "name": "eventName", + "value": "vFirewallBroadcastPackets" + }, + { + "name": "controlLoopSchemaType", + "value": "VNF" + }, + { + "serviceConfigurations": [ + [ + "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "LESS_OR_EQUAL", + "123", + "ABATED" + ], + [ + "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value", + "GREATER_OR_EQUAL", + "123", + "ONSET" + ] + ] + } + ] + }, + "global": + [ + { + "name": "service", + "value": + [ + "0f983e18-4603-4bb4-a98c-e29691fb16a1" + ] + }, + + { + "name": "vf", + "value": + [ + "6c7aaec2-59eb-41d9-8681-b7f976ab668d" + ] + }, + + { + "name": "actionSet", + "value": + [ + "vnfRecipe" + ] + }, + + { + "name": "location", + "value": + [ + "SNDGCA64" + ] + } + ], "Policy_19c1hms": { "policy1": [ { |