Merge "Fix the stage builds" 5.0.0
authorSébastien Determe <sebastien.determe@intl.att.com>
Wed, 25 Mar 2020 16:24:27 +0000 (16:24 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 25 Mar 2020 16:24:27 +0000 (16:24 +0000)
pom.xml
src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java
src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java
src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
src/test/java/org/onap/clamp/loop/deploy/BlueprintInputParametersTest.java
ui-react/src/components/dialogs/Loop/DeployLoopModal.js

diff --git a/pom.xml b/pom.xml
index 5ad66d2..a77f9d9 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -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>
                                        <groupId>javax.servlet</groupId>
                                        <artifactId>servlet-api</artifactId>
                                </exclusion>
+                               <exclusion>
+                                       <groupId>log4j</groupId>
+                                       <artifactId>log4j</artifactId>
+                               </exclusion>
                        </exclusions>
                </dependency>
                <dependency>
index aecc8f4..260bd1e 100644 (file)
@@ -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")));
     }
 
     /**
index 89332bb..8fce5ca 100644 (file)
@@ -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();
 
index 99b0219..2d7b807 100644 (file)
@@ -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) {
index e997b43..77627a3 100644 (file)
@@ -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);
     }
index b5a88b3..18ee84f 100644 (file)
@@ -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);
index fc7e1c9..b42ba98 100644 (file)
@@ -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");
index f1d2992..98134e8 100644 (file)
@@ -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");
index ccaa417..2b3b482 100644 (file)
 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"));
     }
 }
index 6468e9f..d034ee5 100644 (file)
@@ -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) {