From: sebdet Date: Tue, 31 Mar 2020 11:39:02 +0000 (+0200) Subject: Fix the policy_id not set X-Git-Tag: 5.0.2~3^2~4 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=clamp.git;a=commitdiff_plain;h=a2dbf1f653cba8c2d2835b36e8c89c9e41c5d1bb Fix the policy_id not set Fix the policy_id not set by default when it's a unique blueprint, and when it contains only one microservice Issue-ID: CLAMP-802 Signed-off-by: sebdet Change-Id: Iffe35e461395940567588228ec68ea4b7ff9a409 --- diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java b/src/main/java/org/onap/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java index 3d32ff66..885e755b 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java +++ b/src/main/java/org/onap/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java @@ -51,7 +51,7 @@ public class ToscaMetadataExecutor { private Map mapOfProcesses = new HashMap<>(); /** - * This method executes the required process specified in processInfo + * This method executes the required process specified in processInfo. * * @param processInfo A String containing the process to execute, like "cds/param1:value1/param2:value2" * @param childObject The jsonObject @@ -61,7 +61,8 @@ public class ToscaMetadataExecutor { String[] processParameters = (processInfo + "/ ").split("/"); logger.info("Executing the Tosca clamp process " + processParameters[0] + " with parameters " + processParameters[1].trim()); - mapOfProcesses.get(processParameters[0].trim()).executeProcess(processParameters[1].trim(), childObject, serviceModel); + mapOfProcesses.get(processParameters[0].trim()) + .executeProcess(processParameters[1].trim(), childObject, serviceModel); } /** 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 8fce5caf..3e8cfaf9 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,7 +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"; + public static final String UNIQUE_BLUEPRINT_PARAMETERS = "uniqueBlueprintParameters"; private String name; @@ -132,7 +132,8 @@ public class DcaeComponent extends ExternalComponent { */ public static String getDeployPayload(Loop loop) { JsonObject globalProp = loop.getGlobalPropertiesJson(); - JsonObject deploymentProp = globalProp.getAsJsonObject(DEPLOYMENT_PARAMETER).getAsJsonObject(SINGLE_BLUEPRINT_POLICYID); + JsonObject deploymentProp = globalProp.getAsJsonObject(DEPLOYMENT_PARAMETER).getAsJsonObject( + UNIQUE_BLUEPRINT_PARAMETERS); String serviceTypeId = loop.getLoopTemplate().getDcaeBlueprintId(); diff --git a/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java b/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java index e2b16e62..65506a47 100644 --- a/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java +++ b/src/main/java/org/onap/clamp/loop/deploy/DcaeDeployParameters.java @@ -24,13 +24,12 @@ package org.onap.clamp.loop.deploy; import com.google.gson.JsonObject; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; - import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.loop.Loop; +import org.onap.clamp.loop.components.external.DcaeComponent; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.yaml.snakeyaml.Yaml; @@ -44,8 +43,8 @@ public class DcaeDeployParameters { Set microServiceList = loop.getMicroServicePolicies(); for (MicroServicePolicy microService : microServiceList) { - deploymentParamMap.put(microService.getName(), - generateDcaeDeployParameter(microService)); + deploymentParamMap.put(microService.getName(), + generateDcaeDeployParameter(microService)); } return deploymentParamMap; } @@ -55,7 +54,7 @@ public class DcaeDeployParameters { microService.getName()); } - private static JsonObject generateDcaeDeployParameter(String blueprint, String tabName) { + private static JsonObject generateDcaeDeployParameter(String blueprint, String policyId) { JsonObject deployJsonBody = new JsonObject(); Yaml yaml = new Yaml(); Map inputsNodes = ((Map) ((Map) yaml @@ -64,25 +63,29 @@ public class DcaeDeployParameters { Object defaultValue = ((Map) elem.getValue()).get("default"); if (defaultValue != null) { addPropertyToNode(deployJsonBody, elem.getKey(), defaultValue); - } else { + } + else { deployJsonBody.addProperty(elem.getKey(), ""); } }); - // For Dublin only one micro service is expected - deployJsonBody.addProperty("policy_id", tabName); + deployJsonBody.addProperty("policy_id", policyId); return deployJsonBody; } private static void addPropertyToNode(JsonObject node, String key, Object value) { if (value instanceof String) { node.addProperty(key, (String) value); - } else if (value instanceof Number) { + } + else if (value instanceof Number) { node.addProperty(key, (Number) value); - } else if (value instanceof Boolean) { + } + else if (value instanceof Boolean) { node.addProperty(key, (Boolean) value); - } else if (value instanceof Character) { + } + else if (value instanceof Character) { node.addProperty(key, (Character) value); - } else { + } + else { node.addProperty(key, JsonUtils.GSON.toJson(value)); } } @@ -96,9 +99,14 @@ public class DcaeDeployParameters { JsonObject globalProperties = new JsonObject(); JsonObject deployParamJson = new JsonObject(); if (loop.getLoopTemplate().getUniqueBlueprint()) { - String tabName = "loop template blueprint"; - deployParamJson.add(tabName, generateDcaeDeployParameter(loop.getLoopTemplate().getBlueprint(), tabName)); - } else { + // Normally the unique blueprint could contain multiple microservices but then we can't guess + // the policy id params that will be used, so here we expect only one by default. + deployParamJson.add(DcaeComponent.UNIQUE_BLUEPRINT_PARAMETERS, + generateDcaeDeployParameter(loop.getLoopTemplate().getBlueprint(), + ((MicroServicePolicy) loop.getMicroServicePolicies().toArray()[0]).getName())); + + } + else { LinkedHashMap deploymentParamMap = init(loop); for (Map.Entry mapElement : deploymentParamMap.entrySet()) { deployParamJson.add(mapElement.getKey(), mapElement.getValue()); diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java index b42ba987..7f3b5709 100644 --- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java +++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java @@ -47,13 +47,15 @@ public class DcaeComponentTest { private Loop createTestLoop() { Loop loopTest = new Loop("ControlLoopTest", ""); loopTest.setGlobalPropertiesJson( - new Gson().fromJson("{\"dcaeDeployParameters\":{\"loop template blueprint\": {\"policy_id\": \"name\"}}}", JsonObject.class)); + new Gson().fromJson( + "{\"dcaeDeployParameters\":{\"uniqueBlueprintParameters\": {\"policy_id\": \"name\"}}}", + JsonObject.class)); loopTest.setLastComputedState(LoopState.DESIGN); loopTest.setDcaeDeploymentId("123456789"); loopTest.setDcaeDeploymentStatusUrl("http4://localhost:8085"); MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", new PolicyModel("policy1", - "tosca_definitions_version: tosca_simple_yaml_1_0_0","1.0.0"), true, + "tosca_definitions_version: tosca_simple_yaml_1_0_0", "1.0.0"), true, new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, null, null); microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class)); @@ -67,6 +69,7 @@ public class DcaeComponentTest { /** * Test the DcaeReponse roughly. + * * @throws IOException In case of issues */ @Test @@ -166,7 +169,8 @@ public class DcaeComponentTest { /** * Test the Converter to DcaeInventoryResponse method. - * @throws IOException In case of failure + * + * @throws IOException In case of failure * @throws ParseException In case of failure */ @Test diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java index 98134e82..97fe337d 100644 --- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java +++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java @@ -72,7 +72,7 @@ public class DeployFlowTestItCase { @Transactional public void deployWithSingleBlueprintTest() throws JsonSyntaxException, IOException { Loop loopTest = createLoop("ControlLoopTest", "", "yamlcontent", - "{\"dcaeDeployParameters\":{\"loop template blueprint\": {\"policy_id\": \"name\"}}}", + "{\"dcaeDeployParameters\":{\"uniqueBlueprintParameters\": {\"policy_id\": \"name\"}}}", "UUID-blueprint"); LoopTemplate template = new LoopTemplate(); template.setName("templateName"); diff --git a/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json b/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json index 494c2e4f..7140a474 100644 --- a/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json +++ b/src/test/resources/example/sdc/expected-result/deployment-parameters-single-blueprint.json @@ -1,9 +1,9 @@ { "dcaeDeployParameters": { - "loop template blueprint": { + "uniqueBlueprintParameters": { "location_id": "", "service_id": "", - "policy_id": "loop template blueprint" + "policy_id": "testName1" } } } \ No newline at end of file