diff options
Diffstat (limited to 'src/main')
5 files changed, 39 insertions, 25 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java index aecc8f4f5..260bd1e48 100644 --- a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java +++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java @@ -30,6 +30,7 @@ import com.google.gson.JsonObject; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.builder.ExchangeBuilder; @@ -153,13 +154,14 @@ public class PolicyEngineServices { logger.info("Downloading the policy model " + policyType + "/" + policyVersion); DumperOptions options = new DumperOptions(); options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); - options.setIndent(2); + options.setIndent(4); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - return (new Yaml(options)).dump(callCamelRoute( + Yaml yamlParser = new Yaml(options); + return yamlParser.dump((Map<String, Object>) yamlParser.load(callCamelRoute( ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType) .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model", - "Get one policy")); + "Get one policy"))); } /** diff --git a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java index 89332bbd0..8fce5cafd 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java @@ -47,6 +47,7 @@ public class DcaeComponent extends ExternalComponent { private static final String DEPLOYMENT_PARAMETER = "dcaeDeployParameters"; private static final String DCAE_SERVICETYPE_ID = "serviceTypeId"; private static final String DCAE_INPUTS = "inputs"; + private static final String SINGLE_BLUEPRINT_POLICYID = "loop template blueprint"; private String name; @@ -131,7 +132,7 @@ public class DcaeComponent extends ExternalComponent { */ public static String getDeployPayload(Loop loop) { JsonObject globalProp = loop.getGlobalPropertiesJson(); - JsonObject deploymentProp = globalProp.getAsJsonObject(DEPLOYMENT_PARAMETER); + JsonObject deploymentProp = globalProp.getAsJsonObject(DEPLOYMENT_PARAMETER).getAsJsonObject(SINGLE_BLUEPRINT_POLICYID); String serviceTypeId = loop.getLoopTemplate().getDcaeBlueprintId(); diff --git a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java index 99b021947..2d7b807c0 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java @@ -28,15 +28,12 @@ import com.att.eelf.configuration.EELFManager; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; - import javax.persistence.Transient; - import org.apache.camel.Exchange; import org.onap.clamp.loop.Loop; import org.onap.clamp.policy.microservice.MicroServicePolicy; @@ -82,11 +79,11 @@ public class PolicyComponent extends ExternalComponent { * @return The json, payload to send */ public static String createPoliciesPayloadPdpGroup(Loop loop) { - HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap = new HashMap <String,HashMap<String, List<JsonObject>>>(); + HashMap<String, HashMap<String, List<JsonObject>>> pdpGroupMap = new HashMap<>(); for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { pdpGroupMap = updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), - opPolicy.getName(), - opPolicy.getPolicyModel().getVersion(), pdpGroupMap); + opPolicy.getName(), + opPolicy.getPolicyModel().getVersion(), pdpGroupMap); } for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) { @@ -96,13 +93,17 @@ public class PolicyComponent extends ExternalComponent { } String payload = new GsonBuilder().setPrettyPrinting().create() - .toJson(generateActivatePdpGroupPayload(pdpGroupMap)); + .toJson(generateActivatePdpGroupPayload(pdpGroupMap)); logger.info("PdpGroup policy payload: " + payload); return payload; } - private static HashMap<String,HashMap<String, List<JsonObject>>> updatePdpGroupMap (String pdpGroup, String pdpSubGroup, String policyName, - String policyModelVersion, HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap){ + private static HashMap<String, HashMap<String, List<JsonObject>>> updatePdpGroupMap(String pdpGroup, + String pdpSubGroup, + String policyName, + String policyModelVersion, + HashMap<String, HashMap<String, + List<JsonObject>>> pdpGroupMap) { JsonObject policyJson = new JsonObject(); policyJson.addProperty("name", policyName); @@ -110,14 +111,16 @@ public class PolicyComponent extends ExternalComponent { HashMap<String, List<JsonObject>> pdpSubGroupMap; List<JsonObject> policyList; if (pdpGroupMap.get(pdpGroup) == null) { - pdpSubGroupMap = new HashMap <String, List<JsonObject>>(); + pdpSubGroupMap = new HashMap<String, List<JsonObject>>(); policyList = new LinkedList<JsonObject>(); - } else { + } + else { pdpSubGroupMap = pdpGroupMap.get(pdpGroup); if (pdpSubGroupMap.get(pdpSubGroup) == null) { policyList = new LinkedList<JsonObject>(); - } else { - policyList = (List<JsonObject>)pdpSubGroupMap.get(pdpSubGroup); + } + else { + policyList = (List<JsonObject>) pdpSubGroupMap.get(pdpSubGroup); } } policyList.add(policyJson); @@ -127,7 +130,8 @@ public class PolicyComponent extends ExternalComponent { return pdpGroupMap; } - private static JsonObject generateActivatePdpGroupPayload(HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap) { + private static JsonObject generateActivatePdpGroupPayload( + HashMap<String, HashMap<String, List<JsonObject>>> pdpGroupMap) { JsonArray payloadArray = new JsonArray(); for (Entry<String, HashMap<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) { JsonObject pdpGroupNode = new JsonObject(); @@ -181,16 +185,18 @@ public class PolicyComponent extends ExternalComponent { ExternalComponentState newState = NOT_SENT; if (found && deployed) { newState = SENT_AND_DEPLOYED; - } else if (found) { + } + else if (found) { newState = SENT; - } else if (deployed) { + } + else if (deployed) { newState = IN_ERROR; } return newState; } private static ExternalComponentState mergeStates(ExternalComponentState oldState, - ExternalComponentState newState) { + ExternalComponentState newState) { return (oldState.compareTo(newState) < 0) ? newState : oldState; } @@ -201,7 +207,6 @@ public class PolicyComponent extends ExternalComponent { * this method is called multiple times from the camel route and must be reset * for a new global policy state retrieval. The state to compute the global * policy state is stored in this class. - * */ @Override public ExternalComponentState computeState(Exchange camelExchange) { diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index e997b4309..77627a31a 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -128,7 +128,9 @@ public class MicroServicePolicy extends Policy implements Serializable { public MicroServicePolicy(Loop loop, Service service, LoopElementModel loopElementModel, ToscaConverterWithDictionarySupport toscaConverter) { this(Policy.generatePolicyName("MICROSERVICE", service.getName(), service.getVersion(), - RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), + loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_' + + loopElementModel.getPolicyModels().first().getVersion(), + RandomStringUtils.randomAlphanumeric(3)), loopElementModel.getPolicyModels().first(), false, new JsonObject(), loopElementModel, null, null); this.updateJsonRepresentation(toscaConverter, service); } diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java index b5a88b39d..18ee84f77 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java @@ -123,7 +123,9 @@ public class OperationalPolicy extends Policy implements Serializable { public OperationalPolicy(Loop loop, Service service, LoopElementModel loopElementModel, ToscaConverterWithDictionarySupport toscaConverter) { this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(), - RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(), + loopElementModel.getPolicyModels().first().getPolicyAcronym() + '_' + + loopElementModel.getPolicyModels().first().getVersion(), + RandomStringUtils.randomAlphanumeric(3)), new JsonObject(), new JsonObject(), loopElementModel.getPolicyModels().first(), loopElementModel, null, null); this.setLoop(loop); this.updateJsonRepresentation(toscaConverter, service); @@ -141,7 +143,9 @@ public class OperationalPolicy extends Policy implements Serializable { public OperationalPolicy(Loop loop, Service service, PolicyModel policyModel, ToscaConverterWithDictionarySupport toscaConverter) throws IOException { this(Policy.generatePolicyName("OPERATIONAL", service.getName(), service.getVersion(), - RandomStringUtils.randomAlphanumeric(3), RandomStringUtils.randomAlphanumeric(3)), new JsonObject(), + policyModel.getPolicyAcronym() + '_' + policyModel.getVersion(), + RandomStringUtils.randomAlphanumeric(3)), + new JsonObject(), new JsonObject(), policyModel, null, null, null); this.setLoop(loop); this.updateJsonRepresentation(toscaConverter, service); |