diff options
10 files changed, 70 insertions, 38 deletions
@@ -99,7 +99,7 @@ <docker.skip.tag>true</docker.skip.tag> <skip.staging.artifacts>false</skip.staging.artifacts> <python.http.proxy.param /> - <tomcat.version>9.0.27</tomcat.version> + <tomcat.version>9.0.33</tomcat.version> <ui.react.src>ui-react</ui.react.src> <ui.react.lib.src>ui-react-lib</ui.react.lib.src> <npm.publish.url>https://nexus3.onap.org/repository/npm.snapshot/</npm.publish.url> @@ -428,6 +428,10 @@ <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> </exclusions> </dependency> <dependency> 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 aecc8f4f..260bd1e4 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 89332bbd..8fce5caf 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 99b02194..2d7b807c 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 e997b430..77627a31 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 b5a88b39..18ee84f7 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/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java index fc7e1c90..b42ba987 100644 --- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java @@ -47,7 +47,7 @@ public class DcaeComponentTest { private Loop createTestLoop() { Loop loopTest = new Loop("ControlLoopTest", "<xml></xml>"); loopTest.setGlobalPropertiesJson( - new Gson().fromJson("{\"dcaeDeployParameters\":" + "{\"policy_id\": \"name\"}}", JsonObject.class)); + new Gson().fromJson("{\"dcaeDeployParameters\":{\"loop template blueprint\": {\"policy_id\": \"name\"}}}", JsonObject.class)); loopTest.setLastComputedState(LoopState.DESIGN); loopTest.setDcaeDeploymentId("123456789"); loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085"); diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java index f1d29922..98134e82 100644 --- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java @@ -71,7 +71,8 @@ public class DeployFlowTestItCase { @Test @Transactional public void deployWithSingleBlueprintTest() throws JsonSyntaxException, IOException { - Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}", + Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", + "{\"dcaeDeployParameters\":{\"loop template blueprint\": {\"policy_id\": \"name\"}}}", "UUID-blueprint"); LoopTemplate template = new LoopTemplate(); template.setName("templateName"); 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 ccaa417e..2b3b4825 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")); } } diff --git a/ui-react/src/components/dialogs/Loop/DeployLoopModal.js b/ui-react/src/components/dialogs/Loop/DeployLoopModal.js index 6468e9f9..d034ee5d 100644 --- a/ui-react/src/components/dialogs/Loop/DeployLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/DeployLoopModal.js @@ -75,14 +75,14 @@ export default class DeployLoopModal extends React.Component { } handleClose(){ + this.setState({ show: false }); this.props.history.push('/'); } + handleSave() { const loopName = this.props.loopCache.getLoopName(); // save the global propserties LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => { - this.setState({ show: false }); - LoopActionService.performAction(loopName, "deploy").then(pars => { this.props.showAlert("Action deploy successfully performed"); // refresh status and update loop logs @@ -94,16 +94,16 @@ export default class DeployLoopModal extends React.Component { this.refreshStatus(loopName); }); }); + this.setState({ show: false }); + this.props.history.push('/'); } refreshStatus(loopName) { LoopActionService.refreshStatus(loopName).then(data => { this.props.updateLoopFunction(data); - this.props.history.push('/'); }) .catch(error => { this.props.showAlert("Refresh status failed"); - this.props.history.push('/'); }); } handleChange(event) { |