diff options
Diffstat (limited to 'src/main')
4 files changed, 144 insertions, 64 deletions
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java new file mode 100644 index 000000000..5a29264f9 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintArtifact.java @@ -0,0 +1,77 @@ +/*- + * ============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. + */ + +/** + * This class is useful to store the information concerning + * blueprint artifact extracted from SDC CSAR + */ +package org.onap.clamp.clds.sdc.controller.installer; + +public class BlueprintArtifact { + + private String dcaeBlueprint; + private String blueprintArtifactName; + private String blueprintInvariantResourceUuid; + private String blueprintInvariantServiceUuid; + private String blueprintResourceInstanceName; + + public String getDcaeBlueprint() { + return dcaeBlueprint; + } + + public void setDcaeBlueprint(String dcaeBlueprint) { + this.dcaeBlueprint = dcaeBlueprint; + } + + public String getBlueprintArtifactName() { + return blueprintArtifactName; + } + + public void setBlueprintArtifactName(String blueprintArtifactName) { + this.blueprintArtifactName = blueprintArtifactName; + } + + public String getBlueprintInvariantResourceUuid() { + return blueprintInvariantResourceUuid; + } + + public void setBlueprintInvariantResourceUuid(String blueprintInvariantResourceUuid) { + this.blueprintInvariantResourceUuid = blueprintInvariantResourceUuid; + } + + public String getBlueprintInvariantServiceUuid() { + return blueprintInvariantServiceUuid; + } + + public void setBlueprintInvariantServiceUuid(String blueprintInvariantServiceUuid) { + this.blueprintInvariantServiceUuid = blueprintInvariantServiceUuid; + } + + public String getBlueprintResourceInstanceName() { + return blueprintResourceInstanceName; + } + + public void setBlueprintResourceInstanceName(String blueprintResourceInstanceName) { + this.blueprintResourceInstanceName = blueprintResourceInstanceName; + } +} diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java index 62169379c..89339733d 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java @@ -33,9 +33,10 @@ import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -61,13 +62,12 @@ public class CsarHandler { private String controllerName; private SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); private ISdcCsarHelper sdcCsarHelper; - private String dcaeBlueprint; - private String blueprintArtifactName; - private String blueprintInvariantResourceUuid; - private String blueprintInvariantServiceUuid; + private Map<String, BlueprintArtifact> mapOfBlueprints = new HashMap<>(); public static final String CSAR_TYPE = "TOSCA_CSAR"; public static final String BLUEPRINT_TYPE = "DCAE_INVENTORY_BLUEPRINT"; private INotificationData sdcNotification; + public static final String RESOURCE_INSTANCE_NAME_PREFIX = "/Artifacts/Resources/"; + public static final String RESOURCE_INSTANCE_NAME_SUFFIX = "/Deployment/"; public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException { this.sdcNotification = iNotif; @@ -103,43 +103,48 @@ public class CsarHandler { } sdcCsarHelper = factory.getSdcCsarHelper(csarFilePath); this.loadDcaeBlueprint(); - this.loadBlueprintArtifactDetails(); } catch (IOException e) { throw new SdcArtifactInstallerException( "Exception caught when trying to write the CSAR on the file system to " + csarFilePath, e); } } - private void loadBlueprintArtifactDetails() { - blueprintInvariantServiceUuid = this.getSdcNotification().getServiceInvariantUUID(); - for (IResourceInstance resource : this.getSdcNotification().getResources()) { - if ("VF".equals(resource.getResourceType())) { - for (IArtifactInfo artifact : resource.getArtifacts()) { - if (BLUEPRINT_TYPE.equals(artifact.getArtifactType())) { - blueprintArtifactName = artifact.getArtifactName(); - blueprintInvariantResourceUuid = resource.getResourceInvariantUUID(); - } - } + private IResourceInstance searchForResourceByInstanceName(String blueprintResourceInstanceName) + throws SdcArtifactInstallerException { + for (IResourceInstance resource : this.sdcNotification.getResources()) { + String filteredString = resource.getResourceInstanceName().replaceAll("-", ""); + filteredString = filteredString.replaceAll(" ", ""); + if (filteredString.equals(blueprintResourceInstanceName)) { + return resource; } } + throw new SdcArtifactInstallerException("Error when searching for " + blueprintResourceInstanceName + + " as ResourceInstanceName in Sdc notification and did not find it"); } private void loadDcaeBlueprint() throws IOException, SdcArtifactInstallerException { - List<ZipEntry> listEntries = new ArrayList<>(); try (ZipFile zipFile = new ZipFile(csarFilePath)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().contains(BLUEPRINT_TYPE)) { - listEntries.add(entry); + BlueprintArtifact blueprintArtifact = new BlueprintArtifact(); + blueprintArtifact.setBlueprintArtifactName( + entry.getName().substring(entry.getName().lastIndexOf('/') + 1, entry.getName().length())); + blueprintArtifact + .setBlueprintInvariantServiceUuid(this.getSdcNotification().getServiceInvariantUUID()); + try (InputStream stream = zipFile.getInputStream(entry)) { + blueprintArtifact.setDcaeBlueprint(IOUtils.toString(stream)); + } + IResourceInstance resource = searchForResourceByInstanceName(entry.getName().substring( + entry.getName().indexOf(RESOURCE_INSTANCE_NAME_PREFIX) + + RESOURCE_INSTANCE_NAME_PREFIX.length(), + entry.getName().indexOf(RESOURCE_INSTANCE_NAME_SUFFIX))); + blueprintArtifact.setBlueprintInvariantResourceUuid(resource.getResourceInvariantUUID()); + blueprintArtifact.setBlueprintResourceInstanceName(resource.getResourceInstanceName()); + this.mapOfBlueprints.put(blueprintArtifact.getBlueprintResourceInstanceName(), blueprintArtifact); } } - if (listEntries.size() > 1) { - throw new SdcArtifactInstallerException("There are multiple entries in the DCAE inventory"); - } - try (InputStream stream = zipFile.getInputStream(listEntries.get(0))) { - this.dcaeBlueprint = IOUtils.toString(stream); - } } } @@ -155,23 +160,11 @@ public class CsarHandler { return sdcCsarHelper; } - public synchronized String getDcaeBlueprint() { - return dcaeBlueprint; - } - public INotificationData getSdcNotification() { return sdcNotification; } - public String getBlueprintArtifactName() { - return blueprintArtifactName; - } - - public String getBlueprintInvariantResourceUuid() { - return blueprintInvariantResourceUuid; - } - - public String getBlueprintInvariantServiceUuid() { - return blueprintInvariantServiceUuid; + public Map<String, BlueprintArtifact> getMapOfBlueprints() { + return mapOfBlueprints; } } 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 cb0da0aa0..d282588bb 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 @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import javax.annotation.PostConstruct; @@ -85,16 +86,23 @@ public class CsarInstallerImpl implements CsarInstaller { @Override public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { - return (CldsModel.retrieve(cldsDao, csar.getSdcCsarHelper().getServiceMetadata().getValue("name"), true) - .getId() != null) ? true : false; + return (CldsModel.retrieve(cldsDao, buildModelName(csar), true).getId() != null) ? true : false; + } + + public static String buildModelName(CsarHandler csar) { + return csar.getSdcCsarHelper().getServiceMetadata().getValue("name") + " v" + + csar.getSdcNotification().getServiceVersion(); } @Override @Transactional public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException { try { - String serviceTypeId = queryDcaeToGetServiceTypeId(csar); - createFakeCldsModel(csar, createFakeCldsTemplate(csar, this.searchForRightMapping(csar)), serviceTypeId); + for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) { + String serviceTypeId = queryDcaeToGetServiceTypeId(blueprint.getValue()); + createFakeCldsModel(csar, blueprint.getValue(), createFakeCldsTemplate(csar, blueprint.getValue(), + this.searchForRightMapping(blueprint.getValue())), serviceTypeId); + } } catch (IOException e) { throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); } catch (ParseException | InterruptedException e) { @@ -102,12 +110,12 @@ public class CsarInstallerImpl implements CsarInstaller { } } - private BlueprintParserFilesConfiguration searchForRightMapping(CsarHandler csar) + private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { List<BlueprintParserFilesConfiguration> listConfig = new ArrayList<>(); Yaml yaml = new Yaml(); Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) yaml - .load(csar.getDcaeBlueprint())).get("node_templates")); + .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); bpmnMapping.entrySet().forEach(e -> { if (templateNodes.keySet().stream().anyMatch(t -> t.contains(e.getKey()))) { listConfig.add(e.getValue()); @@ -122,12 +130,12 @@ public class CsarInstallerImpl implements CsarInstaller { return listConfig.get(0); } - private String searchForPolicyName(CsarHandler csar) throws SdcArtifactInstallerException { + private String searchForPolicyName(BlueprintArtifact blueprintArtifact) throws SdcArtifactInstallerException { String policyName = null; Yaml yaml = new Yaml(); List<String> policyNameList = new ArrayList<>(); Map<String, Object> templateNodes = ((Map<String, Object>) ((Map<String, Object>) yaml - .load(csar.getDcaeBlueprint())).get("node_templates")); + .load(blueprintArtifact.getDcaeBlueprint())).get("node_templates")); 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"); @@ -151,42 +159,44 @@ public class CsarInstallerImpl implements CsarInstaller { return policyNameList.get(0); } - private String queryDcaeToGetServiceTypeId(CsarHandler csar) throws IOException, ParseException, InterruptedException { - return dcaeInventoryService.getDcaeInformation(csar.getBlueprintArtifactName(), - csar.getBlueprintInvariantServiceUuid(), csar.getBlueprintInvariantResourceUuid()).getTypeId(); + private String queryDcaeToGetServiceTypeId(BlueprintArtifact blueprintArtifact) throws IOException, ParseException { + return dcaeInventoryService.getDcaeInformation(blueprintArtifact.getBlueprintArtifactName(), + blueprintArtifact.getBlueprintInvariantServiceUuid(), + blueprintArtifact.getBlueprintInvariantResourceUuid()).getTypeId(); } - private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintParserFilesConfiguration configFiles) - throws IOException { + private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact, + BlueprintParserFilesConfiguration configFiles) throws IOException { CldsTemplate template = new CldsTemplate(); template.setBpmnId("Sdc-Generated"); template.setBpmnText( IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); - template.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + csar.getDcaeBlueprint() + "\"]}]}"); + template.setPropText( + "{\"global\":[{\"name\":\"service\",\"value\":[\"" + blueprintArtifact.getDcaeBlueprint() + "\"]}]}"); template.setImageText( IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); - template.setName(TEMPLATE_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); + template.setName(TEMPLATE_NAME_PREFIX + buildModelName(csar)); template.save(cldsDao, null); return template; } - private CldsModel createFakeCldsModel(CsarHandler csar, CldsTemplate cldsTemplate, String serviceTypeId) - throws SdcArtifactInstallerException { + private CldsModel createFakeCldsModel(CsarHandler csar, BlueprintArtifact blueprintArtifact, + CldsTemplate cldsTemplate, String serviceTypeId) throws SdcArtifactInstallerException { CldsModel cldsModel = new CldsModel(); - String policyName = searchForPolicyName(csar); + String policyName = searchForPolicyName(blueprintArtifact); if (policyName.contains("*")) { // It's a filter must add a specific prefix cldsModel.setControlNamePrefix(policyName); } else { cldsModel.setControlNamePrefix(MODEL_NAME_PREFIX); } - cldsModel.setName(csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); - cldsModel.setBlueprintText(csar.getDcaeBlueprint()); + cldsModel.setName(buildModelName(csar)); + cldsModel.setBlueprintText(blueprintArtifact.getDcaeBlueprint()); cldsModel.setTemplateName(cldsTemplate.getName()); cldsModel.setTemplateId(cldsTemplate.getId()); cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" - + csar.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" - + csar.getBlueprintInvariantResourceUuid() + + blueprintArtifact.getBlueprintInvariantServiceUuid() + "\"]},{\"name\":\"vf\",\"value\":[\"" + + blueprintArtifact.getBlueprintInvariantResourceUuid() + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]},{\"name\":\"deployParameters\",\"value\":{\n" + " \"policy_id\": \"" + "test" + "\"" + " }}]}"); cldsModel.setBpmnText(cldsTemplate.getBpmnText()); diff --git a/src/main/resources/clds/sdc-controllers-config.json b/src/main/resources/clds/sdc-controllers-config.json index d18a161a5..fa1533de0 100644 --- a/src/main/resources/clds/sdc-controllers-config.json +++ b/src/main/resources/clds/sdc-controllers-config.json @@ -2,17 +2,17 @@ "sdc-connections":{ "sdc-controller":{ "user": "clamp", - "consumerGroup": "consumerGroup1", - "consumerId": "consumerId1", + "consumerGroup": "consumerGroup2", + "consumerId": "consumerId2", "environmentName": "AUTO", - "sdcAddress": "sdc.api.simpledemo.onap.org:8443", + "sdcAddress": "10.12.6.0:8443", "password": "b7acccda32b98c5bb7acccda32b98c5b05D511BD6D93626E90D18E9D24D9B78CD34C7EE8012F0A189A28763E82271E50A5D4EC10C7D93E06E0A2D27CAE66B981", "pollingInterval":30, "pollingTimeout":30, "activateServerTLSAuth":"false", "keyStorePassword":"", "keyStorePath":"", - "messageBusAddresses":["ueb.api.simpledemo.onap.org"] + "messageBusAddresses":["10.12.5.235"] } } } |