From ccb7152d2619a72367ba41dadd18812122425bda Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 16 Mar 2018 19:49:13 +0100 Subject: CsarInstaller introduction This class is introduced to decode/deploy the dcae blueprint from SDC and save it to database. This is done based on json templates. Some unit tests added Issue-ID: CLAMP-81 Change-Id: I3fac5f7ef41d77aa244414407111b9cb602b50bd Signed-off-by: Determe, Sebastien (sd378r) --- .../sdc/controller/installer/CsarInstaller.java | 33 +++ .../controller/installer/CsarInstallerImpl.java | 147 ++++++++++ src/main/resources/application.properties | 1 + .../resources/clds/blueprint-parser-mapping.json | 16 ++ .../resources/clds/templates/bpmn/holmes-img.xml | 315 +++++++++++++++++++++ .../clds/templates/bpmn/holmes-template.xml | 93 ++++++ src/main/resources/clds/templates/bpmn/tca-img.xml | 309 ++++++++++++++++++++ .../resources/clds/templates/bpmn/tca-template.xml | 95 +++++++ 8 files changed, 1009 insertions(+) create mode 100644 src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java create mode 100644 src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java create mode 100644 src/main/resources/clds/blueprint-parser-mapping.json create mode 100644 src/main/resources/clds/templates/bpmn/holmes-img.xml create mode 100644 src/main/resources/clds/templates/bpmn/holmes-template.xml create mode 100644 src/main/resources/clds/templates/bpmn/tca-img.xml create mode 100644 src/main/resources/clds/templates/bpmn/tca-template.xml (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java new file mode 100644 index 000000000..739fc06d0 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * 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 org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; + +public interface CsarInstaller { + + boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException; + + public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException; +} 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 new file mode 100644 index 000000000..c56eed517 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * 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 com.att.aft.dme2.internal.apache.commons.io.IOUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; + +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.service.CldsService; +import org.onap.clamp.clds.service.CldsTemplateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; +import org.yaml.snakeyaml.Yaml; + +@Component +public class CsarInstallerImpl implements CsarInstaller { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class); + private Map bpmnMapping = new HashMap<>(); + public static final String TEMPLATE_NAME_SUFFIX = "-template-dcae-designer"; + public static final String MODEL_NAME_SUFFIX = "-model-dcae-designer"; + /** + * The file name that will be loaded by Spring. + */ + @Value("${clamp.config.sdc.blueprint.parser.mapping:'classpath:/clds/blueprint-parser-mapping.json'}") + protected String blueprintMappingFile; + @Autowired + protected ApplicationContext appContext; + @Autowired + private CldsDao cldsDao; + @Autowired + private ClampProperties refProp; + @Autowired + CldsTemplateService cldsTemplateService; + @Autowired + CldsService cldsService; + + @PostConstruct + public void loadConfiguration() throws IOException { + BlueprintParserMappingConfiguration + .createFromJson(appContext.getResource(blueprintMappingFile).getInputStream()).stream() + .forEach(e -> bpmnMapping.put(e.getBlueprintKey(), e.getFiles())); + } + + @Override + public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { + return false; + } + + @Override + public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException { + try { + BlueprintParserFilesConfiguration configFiles = this.searchForRightMapping(csar); + createFakeCldsModel(csar, configFiles, createFakeCldsTemplate(csar, configFiles)); + } catch (IOException e) { + throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); + } + } + + private BlueprintParserFilesConfiguration searchForRightMapping(CsarHandler csar) + throws SdcArtifactInstallerException { + List listConfig = new ArrayList<>(); + Yaml yaml = new Yaml(); + Map templateNodes = ((Map) ((Map) yaml + .load(csar.getDcaeBlueprint())).get("node_templates")); + bpmnMapping.entrySet().forEach(e -> { + if (templateNodes.keySet().stream().anyMatch(t -> t.contains(e.getKey()))) { + listConfig.add(e.getValue()); + } + }); + if (listConfig.size() > 1) { + throw new SdcArtifactInstallerException( + "The code does not currently support multiple MicroServices in the blueprint"); + } else if (listConfig.isEmpty()) { + throw new SdcArtifactInstallerException("There is no recognized MicroService found in the blueprint"); + } + return listConfig.get(0); + } + + private String createTemplateName(CsarHandler csar) { + return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + TEMPLATE_NAME_SUFFIX; + } + + private String createModelName(CsarHandler csar) { + return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + MODEL_NAME_SUFFIX; + } + + private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles) + throws IOException, SdcArtifactInstallerException { + CldsTemplate template = new CldsTemplate(); + template.setBpmnId("Sdc-Generated"); + template.setBpmnText( + IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); + // ((ObjectNode)refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY)); + template.setPropText(csar.getDcaeBlueprint()); + template.setImageText( + IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); + return cldsTemplateService.putTemplate(createTemplateName(csar), template); + } + + private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintParserFilesConfiguration configFiles, + CldsTemplate cldsTemplate) { + CldsModel cldsModel = new CldsModel(); + cldsModel.setBlueprintText(csar.getDcaeBlueprint()); + cldsModel.setTemplateName(cldsTemplate.getName()); + // cldsModel.set + return cldsService.putModel(createModelName(csar), cldsModel); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f626e1af1..17f85817f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -178,6 +178,7 @@ clamp.config.sdc.InstanceID=X-ECOMP-InstanceID clamp.config.sdc.header.requestId = X-ECOMP-RequestID # clamp.config.sdc.csarFolder = /tmp/sdc-controllers +clamp.config.sdc.blueprint.parser.mapping = classpath:/clds/blueprint-parser-mapping.json # clamp.config.ui.location.default=classpath:/clds/templates/ui-location-default.json clamp.config.ui.alarm.default=classpath:/clds/templates/ui-alarm-default.json diff --git a/src/main/resources/clds/blueprint-parser-mapping.json b/src/main/resources/clds/blueprint-parser-mapping.json new file mode 100644 index 000000000..a16ef0cbc --- /dev/null +++ b/src/main/resources/clds/blueprint-parser-mapping.json @@ -0,0 +1,16 @@ +[ + { + "blueprintKey": "tca_", + "files": { + "bpmnXmlFilePath": "classpath:/clds/templates/bpmn/tca-template.xml", + "svgXmlFilePath": "classpath:/clds/templates/bpmn/tca-img.xml" + } + }, + { + "blueprintKey": "holmes_", + "files": { + "bpmnXmlFilePath": "classpath:/clds/templates/bpmn/holmes-template.xml", + "svgXmlFilePath": "classpath:/clds/templates/bpmn/holmes-img.xml" + } + } +] diff --git a/src/main/resources/clds/templates/bpmn/holmes-img.xml b/src/main/resources/clds/templates/bpmn/holmes-img.xml new file mode 100644 index 000000000..f84b6a10e --- /dev/null +++ b/src/main/resources/clds/templates/bpmn/holmes-img.xml @@ -0,0 +1,315 @@ + +\n +\n +\n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + H + + + Holmes + + + + + + + + + + + + + + V + + + E + + + S + + + VesCollector + + + + + + + + + + + + + Policy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/clds/templates/bpmn/holmes-template.xml b/src/main/resources/clds/templates/bpmn/holmes-template.xml new file mode 100644 index 000000000..0ea1587ce --- /dev/null +++ b/src/main/resources/clds/templates/bpmn/holmes-template.xml @@ -0,0 +1,93 @@ + + + + + SequenceFlow_1c9hzec + + + SequenceFlow_1ig3gix + SequenceFlow_0zwbn2r + + + SequenceFlow_1c9hzec + SequenceFlow_1ig3gix + + + SequenceFlow_0zwbn2r + SequenceFlow_0ox6r95 + + + SequenceFlow_0ox6r95 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/clds/templates/bpmn/tca-img.xml b/src/main/resources/clds/templates/bpmn/tca-img.xml new file mode 100644 index 000000000..a2ec5af23 --- /dev/null +++ b/src/main/resources/clds/templates/bpmn/tca-img.xml @@ -0,0 +1,309 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + V + + + E + + + S + + + VesCollector + + + + + + + + + + + + + TCA + + + + + + + + + + + + + Policy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/clds/templates/bpmn/tca-template.xml b/src/main/resources/clds/templates/bpmn/tca-template.xml new file mode 100644 index 000000000..cc942ef9d --- /dev/null +++ b/src/main/resources/clds/templates/bpmn/tca-template.xml @@ -0,0 +1,95 @@ + + + + + + SequenceFlow_1ahk7jg + + + SequenceFlow_1ahk7jg + SequenceFlow_18ahat1 + + + SequenceFlow_18ahat1 + SequenceFlow_1mo9gxb + + + SequenceFlow_1mo9gxb + SequenceFlow_1dgtrrq + + + SequenceFlow_1dgtrrq + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg