* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.clamp.clds.sdc.controller.installer;
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;
CldsService cldsService;
@Autowired
DcaeInventoryServices dcaeInventoryService;
+ @Autowired
+ private XslTransformer cldsBpmnTransformer;
+ @Autowired
+ private ClampProperties refProp;
@PostConstruct
public void loadConfiguration() throws IOException {
@Override
public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException {
- return (CldsModel.retrieve(cldsDao, buildModelName(csar), true).getId() != null) ? true : false;
+ boolean alreadyInstalled = true;
+ for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {
+ alreadyInstalled = alreadyInstalled
+ && (CldsModel.retrieve(cldsDao, buildModelName(csar, blueprint.getKey()), true).getId() != null)
+ ? true
+ : false;
+ }
+ return alreadyInstalled;
}
- public static String buildModelName(CsarHandler csar) {
+ public static String buildModelName(CsarHandler csar, String resourceInstanceName) {
return MODEL_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + "_v"
- + csar.getSdcNotification().getServiceVersion().replace('.', '_');
+ + csar.getSdcNotification().getServiceVersion().replace('.', '_') + "_" + resourceInstanceName;
}
@Override
List<String> policyNameList = new ArrayList<>();
Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) yaml
.load(blueprintArtifact.getDcaeBlueprint())).get("node_templates"));
- templateNodes.entrySet().stream().filter(e -> e.getKey().contains("policy_")).forEach(ef -> {
+ templateNodes.entrySet().stream().filter(e -> e.getKey().contains("policy")).forEach(ef -> {
String filteredPolicyName = (String) ((Map<String, Object>) ((Map<String, Object>) ef.getValue())
.get("properties")).get("policy_filter");
if (policyName != null) {
"{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}");
template.setImageText(
IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream()));
- template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar));
+ template.setName(TEMPLATE_NAME_PREFIX
+ + buildModelName(csar, blueprintArtifact.getResourceAttached().getResourceInstanceName()));
template.save(cldsDao, null);
logger.info("Fake Clds Template created for blueprint " + blueprintArtifact.getBlueprintArtifactName()
+ " with name " + template.getName());
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, blueprintArtifact.getResourceAttached().getResourceInstanceName()));
+ 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 = 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;
}
}