diff options
author | Sébastien Determe <sd378r@intl.att.com> | 2018-04-19 16:39:56 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-04-19 16:39:56 +0000 |
commit | e803fb7f42efb66cb2fb05cc568c80ab818798f4 (patch) | |
tree | 89fbfb2b89e26bf2c53f4ec93b9db38f40c44362 /src | |
parent | 1ed00c10c10e743348fae994743821e3413c19c1 (diff) | |
parent | ab284ec6e60c48eb9550c8fae16cc34ec9c3aeae (diff) |
Merge "Fix CsarInstaller"
Diffstat (limited to 'src')
8 files changed, 74 insertions, 35 deletions
diff --git a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java index cc6f02de3..c840bd138 100644 --- a/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java +++ b/src/main/java/org/onap/clamp/clds/model/properties/ModelProperties.java @@ -36,6 +36,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.apache.camel.Exchange; +import org.onap.clamp.clds.client.req.policy.PolicyClient; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.ModelBpmnException; import org.onap.clamp.clds.model.CldsEvent; import org.onap.clamp.clds.model.CldsModel; @@ -223,6 +225,15 @@ public class ModelProperties { } /** + * @return The policyName that wil be used in input parameters of DCAE + * deploy + */ + public String getPolicyNameForDcaeDeploy(ClampProperties refProp) { + return normalizePolicyScopeName(modelName + "." + + refProp.getStringValue(PolicyClient.POLICY_MS_NAME_PREFIX_PROPERTY_NAME) + getCurrentPolicyName()); + } + + /** * @return the policyScopeAndNameWithUniqueId */ public String getPolicyScopeAndNameWithUniqueId() { diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index 10a7cd556..4acbdeee3 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -35,17 +35,21 @@ import java.util.Map; import java.util.Map.Entry; import javax.annotation.PostConstruct; +import javax.xml.transform.TransformerException; import org.json.simple.parser.ParseException; import org.onap.clamp.clds.client.DcaeInventoryServices; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration; import org.onap.clamp.clds.config.sdc.BlueprintParserMappingConfiguration; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.model.CldsModel; import org.onap.clamp.clds.model.CldsTemplate; +import org.onap.clamp.clds.model.properties.ModelProperties; import org.onap.clamp.clds.service.CldsService; import org.onap.clamp.clds.service.CldsTemplateService; +import org.onap.clamp.clds.transform.XslTransformer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; @@ -81,6 +85,10 @@ public class CsarInstallerImpl implements CsarInstaller { CldsService cldsService; @Autowired DcaeInventoryServices dcaeInventoryService; + @Autowired + private XslTransformer cldsBpmnTransformer; + @Autowired + private ClampProperties refProp; @PostConstruct public void loadConfiguration() throws IOException { @@ -197,28 +205,37 @@ public class CsarInstallerImpl implements CsarInstaller { private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, CldsTemplate cldsTemplate, String serviceTypeId) throws SdcArtifactInstallerException { - CldsModel cldsModel = new CldsModel(); - String policyName = searchForPolicyName(blueprintArtifact); - if (policyName.contains("*")) { - // It's a filter must add a specific prefix - cldsModel.setControlNamePrefix(policyName); - } else { - cldsModel.setControlNamePrefix(CONTROL_NAME_PREFIX); + try { + CldsModel cldsModel = new CldsModel(); + cldsModel.setName(buildModelName(csar)); + cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); + cldsModel.setTemplateName(cldsTemplate.getName()); + cldsModel.setTemplateId(cldsTemplate.getId()); + cldsModel.setBpmnText(cldsTemplate.getBpmnText()); + cldsModel.setTypeId(serviceTypeId); + ModelProperties modelProp = new ModelProperties(cldsModel.getName(), "test", "PUT", false, + cldsBpmnTransformer.doXslTransformToString(cldsTemplate.getBpmnText()), "{}"); + String policyName = searchForPolicyName(blueprintArtifact); + String inputParams = ""; + if (policyName.contains("*")) { + // It's a filter must add a specific prefix + cldsModel.setControlNamePrefix(policyName); + } else { + cldsModel.setControlNamePrefix(CONTROL_NAME_PREFIX); + inputParams = "{\"name\":\"deployParameters\",\"value\":{\n" + "\"policy_id\": \"" + + modelProp.getPolicyNameForDcaeDeploy(refProp) + "\"" + "}}"; + } + cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" + + blueprintArtifact.getResourceAttached().getResourceInvariantUUID() + + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]}," + + inputParams + "]}"); + cldsModel.save(cldsDao, null); + logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName() + + " with name " + cldsModel.getName()); + return cldsModel; + } catch (TransformerException e) { + throw new SdcArtifactInstallerException("TransformerException when decoding the BpmnText", e); } - cldsModel.setName(buildModelName(csar)); - cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); - cldsModel.setTemplateName(cldsTemplate.getName()); - cldsModel.setTemplateId(cldsTemplate.getId()); - cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" - + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" - + blueprintArtifact.getResourceAttached().getResourceInvariantUUID() - + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},{\"name\":\"deployParameters\",\"value\":{\n" - + " \"policy_id\": \"" + "test" + "\"" + " }}]}"); - cldsModel.setBpmnText(cldsTemplate.getBpmnText()); - cldsModel.setTypeId(serviceTypeId); - cldsModel.save(cldsDao, null); - logger.info("Fake Clds Model created for blueprint " + blueprintArtifact.getBlueprintArtifactName() - + " with name " + cldsModel.getName()); - return cldsModel; } } diff --git a/src/main/resources/META-INF/resources/designer/partials/portfolios/deploy_parameters.html b/src/main/resources/META-INF/resources/designer/partials/portfolios/deploy_parameters.html index c0cd6c953..ecb0af42f 100644 --- a/src/main/resources/META-INF/resources/designer/partials/portfolios/deploy_parameters.html +++ b/src/main/resources/META-INF/resources/designer/partials/portfolios/deploy_parameters.html @@ -30,7 +30,7 @@ <div style="height: 30px"> Deployment parameters as JSON. </div> - <textarea class="form-control" focus="true" name="deployProperties" id="deployProperties" /> + <textarea class="form-control" focus="true" name="deployProperties" id="deployProperties" ng-init="load_deploy_parameters()"/> </div> <div class="modal-footer"> <button ng-click="deploy()" class="btn btn-primary">Deploy</button> diff --git a/src/main/resources/META-INF/resources/designer/scripts/DeploymentCtrl.js b/src/main/resources/META-INF/resources/designer/scripts/DeploymentCtrl.js index 04ba83a78..4259e66ec 100644 --- a/src/main/resources/META-INF/resources/designer/scripts/DeploymentCtrl.js +++ b/src/main/resources/META-INF/resources/designer/scripts/DeploymentCtrl.js @@ -25,6 +25,16 @@ app.controller('DeploymentCtrl', ['$scope','$rootScope','$modalInstance','data','dialogs', 'cldsModelService', function( $scope, $rootScope, $modalInstance, data, dialogs, cldsModelService) { + function validate_and_set_deploy_parameters () { + var parameters = $("#deployProperties").val(); + try { + parameters = JSON.parse(parameters); + set_deploy_parameters(parameters); + } catch (e) { + console.error("Couldn't parse deploy parameters json"); + } + } + function set_deploy_parameters(parameters) { if (!'global' in elementMap) { elementMap["global"] = []; @@ -38,15 +48,16 @@ app.controller('DeploymentCtrl', } } - $scope.deploy = function() { - var parameters = $("#deployProperties").val(); - try { - parameters = JSON.parse(parameters); - set_deploy_parameters(parameters); - $modalInstance.close(); - } catch (e) { - console.error("Couldn't parse deploy parameters json"); + $scope.load_deploy_parameters = function () { + var index = elementMap["global"].findIndex(function (e) { return (typeof e == "object" && !(e instanceof Array)) && "deployParameters" == e["name"]; }); + if (index != -1) { + $('#deployProperties').val(JSON.stringify(elementMap["global"][index]["value"])) } + } + + $scope.deploy = function() { + validate_and_set_deploy_parameters (); + $modalInstance.close(); }; $scope.close = function() { diff --git a/src/main/resources/clds/templates/dcae-template.json b/src/main/resources/clds/templates/dcae-template.json index 33162971d..b76baf2d4 100644 --- a/src/main/resources/clds/templates/dcae-template.json +++ b/src/main/resources/clds/templates/dcae-template.json @@ -16,7 +16,7 @@ "closedLoopControlName": "", "closedLoopEventClient": "configuration.dcae.microservice.tca.xml", "policyName": "", - "policyScope": "CLAMP", + "policyScope": "DCAE", "policyVersion": "v0.0.1", "serviceConfigurations": { } diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java index 9009d372f..c3ebb5b4a 100644 --- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/installer/CsarInstallerItCase.java @@ -155,6 +155,6 @@ public class CsarInstallerItCase { assertNotNull(modelFromDb.getImageText()); assertNotNull(modelFromDb.getPropText()); assertEquals(CsarInstallerImpl.buildModelName(csar), modelFromDb.getName()); - assertEquals(CsarInstallerImpl.MODEL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); + assertEquals(CsarInstallerImpl.CONTROL_NAME_PREFIX, modelFromDb.getControlNamePrefix()); } } diff --git a/src/test/resources/clds/templates/dcae-template.json b/src/test/resources/clds/templates/dcae-template.json index 33162971d..b76baf2d4 100644 --- a/src/test/resources/clds/templates/dcae-template.json +++ b/src/test/resources/clds/templates/dcae-template.json @@ -16,7 +16,7 @@ "closedLoopControlName": "", "closedLoopEventClient": "configuration.dcae.microservice.tca.xml", "policyName": "", - "policyScope": "CLAMP", + "policyScope": "DCAE", "policyVersion": "v0.0.1", "serviceConfigurations": { } diff --git a/src/test/resources/clds/templates/tca-template.json b/src/test/resources/clds/templates/tca-template.json index d2c04bf11..892fc0d62 100644 --- a/src/test/resources/clds/templates/tca-template.json +++ b/src/test/resources/clds/templates/tca-template.json @@ -4,7 +4,7 @@ { "eventName": "???", "controlLoopSchemaType": "VNF", - "policyScope": "CLAMP", + "policyScope": "DCAE", "policyName": "???", "policyVersion": "v0.0.1", "thresholds": [ |