diff options
author | Xue Gao <xg353y@intl.att.com> | 2020-03-25 12:12:22 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-25 12:12:22 +0000 |
commit | a8b7177d608d84605dd9971f23a7045ba34370b0 (patch) | |
tree | 8e987b9dcdab8d134fca100f6bd51678f797f3c2 | |
parent | 2dcca5a5b563e7640313e93fe617ca89bf6aa6d6 (diff) | |
parent | 6e1edca8fd50316ac811398ca633adf1bfcb0b65 (diff) |
Merge "Improve the policy name"
5 files changed, 56 insertions, 30 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/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); diff --git a/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java b/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java index ccaa417e4..2b3b48255 100644 --- a/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java +++ b/src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java @@ -27,10 +27,8 @@ package org.onap.clamp.loop.deploy; import com.google.gson.JsonObject; - import java.io.IOException; import java.util.LinkedHashSet; - import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -44,9 +42,15 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; public class BlueprintInputParametersTest { + /** + * getDeploymentParametersinJsonMultiBlueprintsTest. + * + * @throws IOException in case of failure + * @throws SdcToscaParserException in case of failure + */ @Test public void getDeploymentParametersinJsonMultiBlueprintsTest() throws IOException, SdcToscaParserException { - Loop loop = Mockito.mock(Loop.class); + MicroServicePolicy umService1 = Mockito.mock(MicroServicePolicy.class); Mockito.when(umService1.getName()).thenReturn("testName1"); @@ -72,10 +76,11 @@ public class BlueprintInputParametersTest { Mockito.when(loopElement3.getBlueprint()).thenReturn(blueprint3); Mockito.when(umService3.getLoopElementModel()).thenReturn(loopElement3); - LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<MicroServicePolicy>(); + LinkedHashSet<MicroServicePolicy> umServiceSet = new LinkedHashSet<>(); umServiceSet.add(umService1); umServiceSet.add(umService2); umServiceSet.add(umService3); + Loop loop = Mockito.mock(Loop.class); Mockito.when(loop.getMicroServicePolicies()).thenReturn(umServiceSet); LoopTemplate template = Mockito.mock(LoopTemplate.class); @@ -85,9 +90,16 @@ public class BlueprintInputParametersTest { JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop); Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson), - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-multi-blueprints.json")); + ResourceFileUtil.getResourceAsString( + "example/sdc/expected-result/deployment-parameters-multi-blueprints.json")); } + /** + * getDeploymentParametersInJsonSingleBlueprintTest. + * + * @throws IOException In case of failure + * @throws SdcToscaParserException In case of failure + */ @Test public void getDeploymentParametersInJsonSingleBlueprintTest() throws IOException, SdcToscaParserException { Loop loop = Mockito.mock(Loop.class); @@ -107,6 +119,7 @@ public class BlueprintInputParametersTest { JsonObject paramJson = DcaeDeployParameters.getDcaeDeploymentParametersInJson(loop); Assert.assertEquals(JsonUtils.GSON_JPA_MODEL.toJson(paramJson), - ResourceFileUtil.getResourceAsString("example/sdc/expected-result/deployment-parameters-single-blueprint.json")); + ResourceFileUtil.getResourceAsString( + "example/sdc/expected-result/deployment-parameters-single-blueprint.json")); } } |