From d9c0322b76c48e5f78158cb1a44da7aac9beb2a2 Mon Sep 17 00:00:00 2001 From: dermot123 Date: Mon, 8 Apr 2019 16:31:20 +0000 Subject: Supporting PNFD (SOL001) mapping to Internal AID model This maps the PNF descriptor containing etsi defined types according to SOL001 v2.5.1 to openecomp internal model. The transformation is done in the "Create VSP" stage. As the main PNF type gets mapped to the outer container in internal ecomp model, it is possible to have no "resource instances" when importing the PNF model into the catalog. The code was updated to allow this for PNFs. Change-Id: I961e91746ca638d858dd468e6c82aeb57993f7a3 Issue-ID: SDC-1976 Issue-ID: SDC-2160 Signed-off-by: dermot123 --- .../tosca/AbstractSubstituteToscaEnricher.java | 50 ++--- .../services/impl/etsi/ETSIService.java | 22 +++ .../services/impl/etsi/ETSIServiceImpl.java | 87 ++++++-- .../core/impl/AbstractToscaConverter.java | 213 ++------------------ .../core/impl/AbstractToscaSolConverter.java | 142 +++++++++++++ .../openecomp/core/impl/ToscaConverterImpl.java | 5 + .../openecomp/core/impl/ToscaSolConverterImpl.java | 140 ------------- .../openecomp/core/impl/ToscaSolConverterPnf.java | 147 ++++++++++++++ .../openecomp/core/impl/ToscaSolConverterVnf.java | 35 ++++ .../core/impl/VnfTopologyTemplateConverter.java | 220 +++++++++++++++++++++ .../core/impl/ToscaSolConverterImplTest.java | 105 ---------- ...caSolConverterPnfMultipleNodeTemplatesTest.java | 74 +++++++ .../core/impl/ToscaSolConverterPnfTest.java | 114 +++++++++++ .../core/impl/ToscaSolConverterVnfTest.java | 105 ++++++++++ .../pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml | 26 +++ .../in/pnfDescriptor_PnfAndExtCp.yaml | 26 +++ .../pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml | 19 ++ .../in/pnfDescriptor_withExtraSpaces.yaml | 26 +++ ...scriptor_withInputsAndSubstitutionMappings.yaml | 40 ++++ .../other/pnfDescriptor_PnfAnd2ExtCps.yaml | 33 ++++ ...pologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml | 4 + .../out/topologyTemplate_PnfAndExtCp.yaml | 10 + .../out/topologyTemplate_PnfOnly.yaml | 2 + .../out/topologyTemplate_withExtraSpaces.yaml | 10 + ...Template_withInputsAndSubstitutionMappings.yaml | 10 + 25 files changed, 1180 insertions(+), 485 deletions(-) create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java delete mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java delete mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml create mode 100644 openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java index 658fc98725..a6bb9323ee 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java @@ -16,28 +16,6 @@ package org.openecomp.sdc.enrichment.impl.tosca; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; -import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; -import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE; -import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; -import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; -import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; -import static org.openecomp.sdc.translator.services.heattotosca.Constants.VNF_NODE_TEMPLATE_ID_SUFFIX; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; @@ -45,6 +23,7 @@ import org.onap.sdc.tosca.datatypes.model.NodeType; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -54,6 +33,28 @@ import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; import org.openecomp.sdc.versioning.dao.types.Version; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; +import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; +import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; +import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.VNF_NODE_TEMPLATE_ID_SUFFIX; + public class AbstractSubstituteToscaEnricher { private ToscaAnalyzerService toscaAnalyzerService; @@ -80,6 +81,11 @@ public class AbstractSubstituteToscaEnricher { return errors; } + final TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); + if (topologyTemplate == null) { + return errors; + } + final Map nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); if (nodeTemplates == null) { return errors; diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java index d5dab46533..a6b58167f9 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.tosca.csar.Manifest; import java.io.IOException; @@ -42,4 +43,25 @@ public interface ETSIService { * @param manifest */ void moveNonManoFileToArtifactFolder(FileContentHandler handler, Manifest manifest); + + /** + * Retrieves the manifest file from the CSAR + * @param handler contains csar artifacts + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + Manifest getManifest(FileContentHandler handler) throws IOException; + + /** + * Determmines the type of resource that the CSAR represents + * @param handler contains csar artifacts + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException; + + /** + * Determmines the type of resource that the CSAR represents + * @param manifest contains manifest content + * @throws IOException when TOSCA.meta file or manifest file is invalid + */ + ResourceTypeEnum getResourceType(Manifest manifest) throws IOException; } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java index 6dac3c8f60..1b74b0094f 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java @@ -23,7 +23,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter; import org.openecomp.core.utilities.file.FileContentHandler; - +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; +import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; +import org.openecomp.sdc.tosca.csar.ToscaMetadata; import java.io.IOException; import java.io.InputStream; @@ -31,12 +35,10 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import org.openecomp.sdc.tosca.csar.Manifest; -import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; -import org.openecomp.sdc.tosca.csar.ToscaMetadata; - -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME; import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; @@ -47,7 +49,7 @@ public class ETSIServiceImpl implements ETSIService { public ETSIServiceImpl() throws IOException { InputStream io = getClass().getClassLoader().getResourceAsStream("nonManoConfig.yaml"); - if(io == null){ + if (io == null) { throw new IOException("Non Mano configuration not found"); } String data = IOUtils.toString(io, StandardCharsets.UTF_8); @@ -74,14 +76,6 @@ public class ETSIServiceImpl implements ETSIService { } } - private InputStream getMetadata(FileContentHandler contentHandler) throws IOException{ - if(contentHandler.containsFile(TOSCA_META_PATH_FILE_NAME)){ - return contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME); - }else if(contentHandler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){ - return contentHandler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME); - } - throw new IOException("TOSCA.meta file does not exist"); - } private void updateNonManoLocation(FileContentHandler handler, String nonManoKey, List sources) { Map files = handler.getFiles(); @@ -92,7 +86,7 @@ public class ETSIServiceImpl implements ETSIService { } } - private void updateLocation(String key, String nonManoKey, Map files){ + private void updateLocation(String key, String nonManoKey, Map files) { if (nonManoKey == null || nonManoKey.isEmpty()) { return; } @@ -107,14 +101,11 @@ public class ETSIServiceImpl implements ETSIService { } } - private String getFileName(String key) { return key.substring(key.lastIndexOf('/') + 1); } - private boolean hasMetaMandatoryEntries(InputStream metadataInputStream) throws IOException { - - ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metadataInputStream); + private boolean hasMetaMandatoryEntries(ToscaMetadata toscaMetadata) { Map metaDataEntries = toscaMetadata.getMetaEntries(); return metaDataEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS) && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_MANIFEST) && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_CHANGE_LOG); @@ -123,4 +114,60 @@ public class ETSIServiceImpl implements ETSIService { private boolean isMetaFilePresent(Map handler) { return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME); } + + public ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException { + ToscaMetadata metadata = getMetadata(handler); + Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST)); + return getResourceType(manifest); + } + + public ResourceTypeEnum getResourceType(Manifest manifest) { + // Valid manifest should contain whether vnf or pnf related metadata data exclusively in SOL004 standard, + // validation of manifest done during package upload stage + if (manifest != null && !manifest.getMetadata().isEmpty() + && MANIFEST_PNF_METADATA.stream().anyMatch(e -> manifest.getMetadata().containsKey(e))) { + return ResourceTypeEnum.PNF; + } + // VNF is default resource type + return ResourceTypeEnum.VF; + } + + public Manifest getManifest(FileContentHandler handler) throws IOException { + ToscaMetadata metadata = getMetadata(handler); + return getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST)); + } + + private Manifest getManifest(FileContentHandler handler, String manifestLocation) throws IOException { + try(InputStream manifestInputStream = getManifestInputStream(handler, manifestLocation)) { + Manifest onboardingManifest = new SOL004ManifestOnboarding(); + onboardingManifest.parse(manifestInputStream); + return onboardingManifest; + } + } + + private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException { + ToscaMetadata metadata; + if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) { + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME)); + } else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) { + metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME)); + } else { + throw new IOException("TOSCA.meta file not found!"); + } + return metadata; + } + + private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException { + InputStream io; + if (manifestLocation == null || !handler.containsFile(manifestLocation)) { + io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); + } else { + io = handler.getFileContent(manifestLocation); + } + + if (io == null) { + throw new IOException("Manifest file not found!"); + } + return io; + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java index 0fc65c1f94..859d3da9dc 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java @@ -23,21 +23,12 @@ package org.openecomp.core.impl; import org.apache.commons.collections.MapUtils; -import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition; -import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment; import org.onap.sdc.tosca.datatypes.model.Import; -import org.onap.sdc.tosca.datatypes.model.NodeFilter; -import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.onap.sdc.tosca.datatypes.model.NodeType; -import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; -import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.core.converter.ToscaConverter; -import org.openecomp.core.converter.datatypes.Constants; import org.openecomp.core.converter.datatypes.CsarFileTypes; -import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder; import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; @@ -49,28 +40,23 @@ import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; import org.yaml.snakeyaml.error.YAMLException; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX; -import static org.openecomp.core.converter.datatypes.Constants.capabilities; import static org.openecomp.core.converter.datatypes.Constants.definitionsDir; import static org.openecomp.core.converter.datatypes.Constants.globalStName; import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution; -import static org.openecomp.core.converter.datatypes.Constants.inputs; import static org.openecomp.core.converter.datatypes.Constants.mainStName; -import static org.openecomp.core.converter.datatypes.Constants.nodeType; import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex; -import static org.openecomp.core.converter.datatypes.Constants.outputs; -import static org.openecomp.core.converter.datatypes.Constants.requirements; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE; import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE; @@ -82,6 +68,9 @@ public abstract class AbstractToscaConverter implements ToscaConverter { @Override public abstract ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException; + public abstract void convertTopologyTemplate(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService); + protected void handleMetadataFile(Map csarFiles) { byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME); if (bytes != null) { @@ -105,9 +94,9 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } } - protected String getConcreteArtifactFileName(String fileName){ + protected String getConcreteArtifactFileName(String fileName) { int artifactIndex = fileName.indexOf(CsarFileTypes.Artifacts.name()); - if(artifactIndex < 0){ + if (artifactIndex < 0) { return fileName; } @@ -130,7 +119,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { csarFiles.get(TOSCA_META_ORIG_PATH_FILE_NAME)); toscaServiceModel.setArtifactFiles(externalFilesHandler); - if(MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) { + if (MapUtils.isNotEmpty(globalSubstitutionServiceTemplate.getNode_types())) { serviceTemplates .put(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME, globalSubstitutionServiceTemplate); } @@ -146,8 +135,8 @@ public abstract class AbstractToscaConverter implements ToscaConverter { protected void handleServiceTemplate(String serviceTemplateName, String fileName, Map csarFiles, Map serviceTemplates) { - Optional serviceTemplate = - getServiceTemplateFromCsar(fileName, csarFiles); + final byte[] inputServiceTemplate = getServiceTemplateFromCsar(fileName, csarFiles); + Optional serviceTemplate = convertServiceTemplate(fileName, inputServiceTemplate); serviceTemplate.ifPresent( serviceTemplateValue -> addServiceTemplate(serviceTemplateName, serviceTemplateValue, serviceTemplates)); @@ -159,16 +148,12 @@ public abstract class AbstractToscaConverter implements ToscaConverter { serviceTemplates.put(serviceTemplateName, serviceTemplate); } - private Optional getServiceTemplateFromCsar(String fileName, - Map csarFiles) { - byte[] fileContent = csarFiles.get(fileName); - ServiceTemplate serviceTemplate = convertServiceTemplate(fileName, fileContent); - - return Optional.of(serviceTemplate); + private byte[] getServiceTemplateFromCsar(String fileName, Map csarFiles) { + return csarFiles.get(fileName); } - private ServiceTemplate convertServiceTemplate(String serviceTemplateName, - byte[] fileContent) { + private Optional convertServiceTemplate(String serviceTemplateName, + byte[] fileContent) { ServiceTemplate serviceTemplate = new ServiceTemplate(); try { ServiceTemplateReaderService readerService = @@ -178,7 +163,6 @@ public abstract class AbstractToscaConverter implements ToscaConverter { convertImports(serviceTemplate); convertNodeTypes(serviceTemplate, readerService); convertTopologyTemplate(serviceTemplate, readerService); - } catch (YAMLException ye) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withMessage("Invalid YAML content in file" + serviceTemplateName) @@ -186,7 +170,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } - return serviceTemplate; + return Optional.of(serviceTemplate); } private void convertToscaVersion(ServiceTemplate serviceTemplate, @@ -249,133 +233,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter { } } - private void convertTopologyTemplate(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - - convertInputs(serviceTemplate, readerService); - convertNodeTemplates(serviceTemplate, readerService); - convertOutputs(serviceTemplate, readerService); - convertSubstitutionMappings(serviceTemplate, readerService); - } - - private void convertInputs(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map inputs = readerService.getInputs(); - addInputsOrOutputsToServiceTemplate(serviceTemplate, inputs, Constants.inputs); - } - - private void convertOutputs(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map outputs = readerService.getOutputs(); - addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.outputs); - } - - private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, - Map mapToConvert, - String inputsOrOutputs) { - if (MapUtils.isEmpty(mapToConvert)) { - return; - } - - for (Map.Entry entry : mapToConvert.entrySet()) { - Optional parameterDefinition = - ToscaConverterUtil.createObjectFromClass( - entry.getKey(), entry.getValue(), ParameterDefinition.class); - - parameterDefinition.ifPresent(parameterDefinitionValue -> { - Optional defaultValue = - ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get()); - defaultValue.ifPresent(parameterDefinitionValue::set_default); - addToServiceTemplateAccordingToSection( - serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get()); - }); - } - } - - private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, - String inputsOrOutputs, - String parameterId, - ParameterDefinition parameterDefinition) { - if (inputsOrOutputs.equals(inputs)) { - DataModelUtil - .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); - } else if (inputsOrOutputs.equals(outputs)) { - DataModelUtil - .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); - } - } - - private void convertNodeTemplates(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map nodeTemplates = readerService.getNodeTemplates(); - if (MapUtils.isEmpty(nodeTemplates)) { - return; - } - - for (Map.Entry nodeTemplateEntry : nodeTemplates.entrySet()) { - NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue()); - DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); - } - } - - private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, - ServiceTemplateReaderService readerService) { - Map substitutionMappings = readerService.getSubstitutionMappings(); - if (MapUtils.isEmpty(substitutionMappings)) { - return; - } - SubstitutionMapping substitutionMapping = convertSubstitutionMappings(substitutionMappings); - DataModelUtil.addSubstitutionMapping(serviceTemplate, substitutionMapping); - } - - private SubstitutionMapping convertSubstitutionMappings( - Map substitutionMappings) { - SubstitutionMapping substitutionMapping = new SubstitutionMapping(); - - substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); - substitutionMapping.setCapabilities( - convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities))); - substitutionMapping.setRequirements( - convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements))); - - return substitutionMapping; - } - - private Map> convertSubstitutionMappingsSections(String sectionName, - Object sectionToConvert) { - - if (Objects.isNull(sectionToConvert)) { - return null; - } - - if (!(sectionToConvert instanceof Map)) { - throw new CoreException( - new SubstitutionMappingsConverterErrorBuilder( - sectionName, sectionToConvert.getClass().getSimpleName()).build()); - } - - return convertSection(sectionToConvert); - } - - private Map> convertSection(Object sectionToConvert) { - - Map sectionAsMap = (Map) sectionToConvert; - Map> convertedSection = new HashMap<>(); - - if (MapUtils.isEmpty(sectionAsMap)) { - return null; - } - - for (Map.Entry entry : sectionAsMap.entrySet()) { - if (entry.getValue() instanceof List) { - convertedSection.put(entry.getKey(), (List) entry.getValue()); - } - } - - return convertedSection; - } - - protected CsarFileTypes getFileType(String fileName){ + protected CsarFileTypes getFileType(String fileName) { if (isMainServiceTemplate(fileName)) { return CsarFileTypes.mainServiceTemplate; } else if (isGlobalServiceTemplate(fileName)) { @@ -388,47 +246,6 @@ public abstract class AbstractToscaConverter implements ToscaConverter { return CsarFileTypes.externalFile; } - private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) { - NodeTemplate nodeTemplate = new NodeTemplate(); - - Map nodeTemplateAsMap = (Map) candidateNodeTemplate; - nodeTemplate.setArtifacts((Map) nodeTemplateAsMap.get("artifacts")); - nodeTemplate.setAttributes((Map) nodeTemplateAsMap.get("attributes")); - nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy")); - nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); - nodeTemplate.setDirectives((List) nodeTemplateAsMap.get("directives")); - nodeTemplate.setInterfaces( - (Map) nodeTemplateAsMap.get("interfaces")); - nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); - nodeTemplate.setProperties((Map) nodeTemplateAsMap.get("properties")); - nodeTemplate.setRequirements( - (List>) nodeTemplateAsMap.get("requirements")); - nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); - nodeTemplate.setCapabilities( - convertCapabilities((Map) nodeTemplateAsMap.get("capabilities"))); - - return nodeTemplate; - } - - private Map convertCapabilities(Map capabilities) { - if (MapUtils.isEmpty(capabilities)) { - return null; - } - - Map convertedCapabilities = new HashMap<>(); - for (Map.Entry capabilityAssignmentEntry : capabilities.entrySet()) { - Optional capabilityAssignment = ToscaConverterUtil.createObjectFromClass - (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), - CapabilityAssignment.class); - - capabilityAssignment.ifPresent(capabilityAssignmentValue -> - convertedCapabilities.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue)); - - } - return convertedCapabilities; - } - - protected boolean isMainServiceTemplate(String fileName) { return fileName.endsWith(mainStName); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java new file mode 100644 index 0000000000..6371ba67d9 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java @@ -0,0 +1,142 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; +import org.openecomp.sdc.tosca.csar.ToscaMetadata; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; + +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.openecomp.core.converter.datatypes.Constants.globalStName; +import static org.openecomp.sdc.tosca.csar.CSARConstants.NON_FILE_IMPORT_ATTRIBUTES; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; + +public abstract class AbstractToscaSolConverter extends AbstractToscaConverter { + + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractToscaSolConverter.class); + private final Set handledDefinitionFilesList = new HashSet<>(); + + @Override + public ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException { + Map csarFiles = new HashMap<>(fileContentHandler.getFiles()); + ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); + Map serviceTemplates = new HashMap<>(); + FileContentHandler artifacts = new FileContentHandler(); + GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate(); + String mServiceDefinitionPath = getMainServiceDefinitionFileName(fileContentHandler); + handleMainServiceTemplate(csarFiles, serviceTemplates, gsst, mServiceDefinitionPath); + handleExternalArtifacts(csarFiles, serviceTemplates, artifacts); + handleMetadataFile(csarFiles); + updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles, getSimpleName(mServiceDefinitionPath)); + return toscaServiceModel; + } + + private void handleMainServiceTemplate(Map csarFiles, Map serviceTemplates, + GlobalSubstitutionServiceTemplate gsst, String mServiceDefinitionFileName) { + if (mServiceDefinitionFileName != null) { + handleServiceTemplate(getSimpleName(mServiceDefinitionFileName), mServiceDefinitionFileName, csarFiles, serviceTemplates); + String parentDir = mServiceDefinitionFileName.substring(0, mServiceDefinitionFileName.lastIndexOf("/")); + handleImportDefinitions(mServiceDefinitionFileName, csarFiles, parentDir, gsst); + } + } + + private void handleExternalArtifacts(Map csarFiles, Map serviceTemplates, FileContentHandler artifacts) { + for (Map.Entry fileEntry : csarFiles.entrySet()) { + if (!handledDefinitionFilesList.contains(fileEntry.getKey()) && !isMetadataFile(fileEntry.getKey())) { + if (isGlobalServiceTemplate(fileEntry.getKey())) { + handleServiceTemplate(globalStName, fileEntry.getKey(), csarFiles, serviceTemplates); + } else { + artifacts.addFile( + getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue()); + } + } + } + } + + private void handleImportDefinitions(String fileName, Map csarFiles, String parentDir, GlobalSubstitutionServiceTemplate gsst) { + handledDefinitionFilesList.add(fileName); + ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(csarFiles.get(fileName)); + List imports = (readerService).getImports(); + for (Object o : imports) { + String importPath = getImportedFilePath(o, parentDir); + if (importPath != null && !handledDefinitionFilesList.contains(importPath)) { + handleDefintionTemplate(importPath, csarFiles, gsst); + if (importPath.contains("/")) { + parentDir = importPath.substring(0, importPath.lastIndexOf("/")); + } + handleImportDefinitions(importPath, csarFiles, parentDir, gsst); + } + } + return; + } + + private String getImportedFilePath(Object o, String parentDir) { + if (o instanceof String) { + String fileName = (String) o; + if (!fileName.contains("/")) { + fileName = parentDir + "/" + fileName; + } + return fileName; + } else if (o instanceof Map) { + Map o1 = (Map) o; + for (Map.Entry entry : o1.entrySet()) { + if (NON_FILE_IMPORT_ATTRIBUTES.stream().noneMatch(attr -> entry.getKey().equals(attr))) { + getImportedFilePath(entry.getValue(), parentDir); + } + } + } + return null; + } + + private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException { + try { + ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile( + contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME)); + return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS); + } catch (IOException e) { + LOGGER.error(e.getMessage(), e); + throw new IOException(e.getMessage()); + } + } + + private String getSimpleName(String path) { + if (path != null && path.contains("/")) { + path = path.substring(path.lastIndexOf("/") + 1); + } + return path; + } + +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java index 01738c1f8a..8d4b9850ea 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java @@ -17,6 +17,7 @@ package org.openecomp.core.impl; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; import org.openecomp.core.converter.datatypes.CsarFileTypes; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -66,4 +67,8 @@ public class ToscaConverterImpl extends AbstractToscaConverter { return toscaServiceModel; } + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + new VnfTopologyTemplateConverter().convertTopologyTemplate(serviceTemplate, readerService); + } } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java deleted file mode 100644 index 46a5904299..0000000000 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * - - * * ============LICENSE_START======================================================= - * * Copyright (C) 2019 Nordix Foundation. - * * ================================================================================ - * * 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. - * * - * * SPDX-License-Identifier: Apache-2.0 - * * ============LICENSE_END========================================================= - * - */ - -package org.openecomp.core.impl; - -import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.openecomp.core.converter.ServiceTemplateReaderService; -import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; -import org.openecomp.sdc.tosca.csar.ToscaMetadata; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.openecomp.core.converter.datatypes.Constants.globalStName; -import static org.openecomp.sdc.tosca.csar.CSARConstants.NON_FILE_IMPORT_ATTRIBUTES; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME; - -public class ToscaSolConverterImpl extends AbstractToscaConverter { - - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaSolConverterImpl.class); - private final Set handledDefinitionFilesList = new HashSet<>(); - - @Override - public ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException { - Map csarFiles = new HashMap<>(fileContentHandler.getFiles()); - ToscaServiceModel toscaServiceModel = new ToscaServiceModel(); - Map serviceTemplates = new HashMap<>(); - FileContentHandler artifacts = new FileContentHandler(); - GlobalSubstitutionServiceTemplate gsst = new GlobalSubstitutionServiceTemplate(); - String mServiceDefinitionPath = getMainServiceDefinitionFileName(fileContentHandler); - handleMainServiceTemplate(csarFiles, serviceTemplates, gsst, mServiceDefinitionPath); - handleExternalArtifacts(csarFiles, serviceTemplates, artifacts); - handleMetadataFile(csarFiles); - updateToscaServiceModel(toscaServiceModel, serviceTemplates, artifacts, gsst, csarFiles, getSimpleName(mServiceDefinitionPath)); - return toscaServiceModel; - } - - private void handleMainServiceTemplate(Map csarFiles, Map serviceTemplates, - GlobalSubstitutionServiceTemplate gsst, String mServiceDefinitionFileName) { - if(mServiceDefinitionFileName != null){ - handleServiceTemplate(getSimpleName(mServiceDefinitionFileName), mServiceDefinitionFileName, csarFiles, serviceTemplates); - String parentDir = mServiceDefinitionFileName.substring(0, mServiceDefinitionFileName.lastIndexOf("/")); - handleImportDefinitions(mServiceDefinitionFileName, csarFiles, parentDir, gsst); - } - } - - private void handleExternalArtifacts(Map csarFiles, Map serviceTemplates, FileContentHandler artifacts) { - for(Map.Entry fileEntry: csarFiles.entrySet()){ - if(!handledDefinitionFilesList.contains(fileEntry.getKey()) && !isMetadataFile(fileEntry.getKey())){ - if(isGlobalServiceTemplate(fileEntry.getKey())){ - handleServiceTemplate(globalStName, fileEntry.getKey(), csarFiles, serviceTemplates); - }else{ - artifacts.addFile( - getConcreteArtifactFileName(fileEntry.getKey()), fileEntry.getValue()); - } - } - } - } - - private void handleImportDefinitions(String fileName, Map csarFiles, String parentDir, GlobalSubstitutionServiceTemplate gsst) { - handledDefinitionFilesList.add(fileName); - ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(csarFiles.get(fileName)); - List imports = (readerService).getImports(); - for (Object o : imports) { - String importPath = getImportedFilePath(o, parentDir); - if (importPath != null && !handledDefinitionFilesList.contains(importPath)) { - handleDefintionTemplate(importPath, csarFiles, gsst); - if (importPath.contains("/")) { - parentDir = importPath.substring(0, importPath.lastIndexOf("/")); - } - handleImportDefinitions(importPath, csarFiles, parentDir, gsst); - } - } - return; - } - - private String getImportedFilePath(Object o, String parentDir){ - if(o instanceof String){ - String fileName = (String) o; - if(!fileName.contains("/")){ - fileName = parentDir + "/" + fileName; - } - return fileName; - }else if(o instanceof Map){ - Map o1 = (Map) o; - for(Map.Entry entry: o1.entrySet()){ - if(NON_FILE_IMPORT_ATTRIBUTES.stream().noneMatch(attr -> entry.getKey().equals(attr))){ - getImportedFilePath(entry.getValue(), parentDir); - } - } - } - return null; - } - - private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException { - try { - ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile( - contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME)); - return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS); - }catch (IOException e){ - LOGGER.error(e.getMessage(), e); - throw new IOException(e.getMessage()); - } - } - - private String getSimpleName(String path){ - if(path != null && path.contains("/")){ - path = path.substring(path.lastIndexOf("/") + 1); - } - return path; - } -} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java new file mode 100644 index 0000000000..0258b42a3d --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterPnf.java @@ -0,0 +1,147 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ToscaSolConverterPnf extends AbstractToscaSolConverter { + + private static final String PNF_EXT_CP_TYPE = "tosca.nodes.nfv.PnfExtCp"; + private static final String EXT_CP_TYPE = "org.openecomp.resource.cp.v2.extCP"; + private static final String LAYER_PROTOCOLS = "layer_protocols"; + private static final String IP_V4 = "ipv4"; + private static final String IP_V6 = "ipv6"; + private static final String IP_VERSION = "ip_version"; + private static final String ASSIGNMENT_METHOD = "assingment_method"; + private static final String DHCP = "dhcp"; + + /** + * For PNF the node templates are converted ETSI node types to ecomp node types + * All other data i.e. inputs, substitution mappings and outputs are simply dropped at this stage. The equivalent + * ecomp data will be added when the vsp is imported into the catalog. + * @param serviceTemplate + * @param readerService + */ + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + convertNodeTemplatesToEcompTypes(serviceTemplate, readerService); + addEmptyNodeTemplatesIfNoneDefined(serviceTemplate); + } + + /** + * PNF only has nfv.PNF and nfv.PnfExtCp types defined in ETSI SOL001 v2.5.1. + * - The PNF is mapped to the outer Abstract PNF container in ecomp model and hence nfv.PNF is dropped here. + * - nfv.PnfExtCp is mapped to ecomp v2.extCp type. + * + * @param serviceTemplate + * @param readerService + */ + private void convertNodeTemplatesToEcompTypes(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map nodeTemplates = readerService.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplates)) { + return; + } + + for (Map.Entry nodeTemplateEntry : nodeTemplates.entrySet()) { + Map inputNodeTemplate = (Map) nodeTemplateEntry.getValue(); + if (PNF_EXT_CP_TYPE.equals((String) inputNodeTemplate.get("type"))) { + NodeTemplate nodeTemplate = convertToEcompConnectionPointNodeType(inputNodeTemplate); + DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); + } + } + addEmptyNodeTemplatesIfNoneDefined(serviceTemplate); + } + + + /** + * Converts from the ETSI PnfExtCp node type to ecomp v2.extCP node type + * The following properties are mapped + * - layer_protocols is mapped to ip_requirements if it contains the values ipv4 and/or ipv6 + *

+ * All other data e.g. remaining properties, requirements, capabilities are + * not mapped over to ecomp equivalent + * + * @param pnfExtCp + * @return ecomp v2.extCP node type + */ + private NodeTemplate convertToEcompConnectionPointNodeType(Map pnfExtCp) { + NodeTemplate nodeTemplate = new NodeTemplate(); + nodeTemplate.setType(EXT_CP_TYPE); + Map properties = (Map) pnfExtCp.get("properties"); + for (Map.Entry property : properties.entrySet()) { + final String propertyName = property.getKey(); + if (LAYER_PROTOCOLS.equals(propertyName)) { + List> ipRequirements = convertToIpRequirementsProperty((List) property.getValue()); + if (isNotEmpty(ipRequirements)) { + Map convertedProperties = new HashMap<>(); + convertedProperties.put("ip_requirements", ipRequirements); + nodeTemplate.setProperties(convertedProperties); + } + } + } + return nodeTemplate; + } + + private List> convertToIpRequirementsProperty(List layerProtocols) { + return layerProtocols.stream() + .filter(layerProtocol -> IP_V4.equals(layerProtocol) || IP_V6.equals(layerProtocol)) + .map(this::createIpPropertyElement) + .collect(Collectors.toList()); + } + + private Map createIpPropertyElement(String ipVersion) { + final int version = ipVersion.equals(IP_V4) ? 4 : 6; + Map result = new HashMap<>(); + result.put(IP_VERSION, version); + result.put(ASSIGNMENT_METHOD, DHCP); + return result; + } + + private boolean isNotEmpty(List list) { + return !list.isEmpty(); + } + + private void addEmptyNodeTemplatesIfNoneDefined(ServiceTemplate serviceTemplate) { + TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template(); + if (Objects.isNull(topologyTemplate)) { + topologyTemplate = new TopologyTemplate(); + serviceTemplate.setTopology_template(topologyTemplate); + } + if (topologyTemplate.getNode_templates() == null) { + topologyTemplate.setNode_templates(new HashMap<>()); + } + } + +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java new file mode 100644 index 0000000000..7d2a38f4f0 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaSolConverterVnf.java @@ -0,0 +1,35 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; + +public class ToscaSolConverterVnf extends AbstractToscaSolConverter { + + @Override + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, ServiceTemplateReaderService readerService) { + new VnfTopologyTemplateConverter().convertTopologyTemplate(serviceTemplate, readerService); + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java new file mode 100644 index 0000000000..e6978bcfe1 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/VnfTopologyTemplateConverter.java @@ -0,0 +1,220 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.collections.MapUtils; +import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition; +import org.onap.sdc.tosca.datatypes.model.CapabilityAssignment; +import org.onap.sdc.tosca.datatypes.model.NodeFilter; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.converter.datatypes.Constants; +import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.tosca.services.DataModelUtil; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.core.converter.datatypes.Constants.capabilities; +import static org.openecomp.core.converter.datatypes.Constants.inputs; +import static org.openecomp.core.converter.datatypes.Constants.nodeType; +import static org.openecomp.core.converter.datatypes.Constants.outputs; +import static org.openecomp.core.converter.datatypes.Constants.requirements; + +public class VnfTopologyTemplateConverter { + + public void convertTopologyTemplate(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + + convertInputs(serviceTemplate, readerService); + convertNodeTemplates(serviceTemplate, readerService); + convertOutputs(serviceTemplate, readerService); + convertSubstitutionMappings(serviceTemplate, readerService); + } + + private void convertInputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map inputs = readerService.getInputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, inputs, Constants.inputs); + } + + private void convertOutputs(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map outputs = readerService.getOutputs(); + addInputsOrOutputsToServiceTemplate(serviceTemplate, outputs, Constants.outputs); + } + + private void addInputsOrOutputsToServiceTemplate(ServiceTemplate serviceTemplate, + Map mapToConvert, + String inputsOrOutputs) { + if (MapUtils.isEmpty(mapToConvert)) { + return; + } + + for (Map.Entry entry : mapToConvert.entrySet()) { + Optional parameterDefinition = + ToscaConverterUtil.createObjectFromClass( + entry.getKey(), entry.getValue(), ParameterDefinition.class); + + parameterDefinition.ifPresent(parameterDefinitionValue -> { + Optional defaultValue = + ToscaConverterUtil.getDefaultValue(entry.getValue(), parameterDefinition.get()); + defaultValue.ifPresent(parameterDefinitionValue::set_default); + addToServiceTemplateAccordingToSection( + serviceTemplate, inputsOrOutputs, entry.getKey(), parameterDefinition.get()); + }); + } + } + + private void addToServiceTemplateAccordingToSection(ServiceTemplate serviceTemplate, + String inputsOrOutputs, + String parameterId, + ParameterDefinition parameterDefinition) { + if (inputsOrOutputs.equals(inputs)) { + DataModelUtil + .addInputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + } else if (inputsOrOutputs.equals(outputs)) { + DataModelUtil + .addOutputParameterToTopologyTemplate(serviceTemplate, parameterId, parameterDefinition); + } + } + + private void convertNodeTemplates(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map nodeTemplates = readerService.getNodeTemplates(); + if (MapUtils.isEmpty(nodeTemplates)) { + return; + } + + for (Map.Entry nodeTemplateEntry : nodeTemplates.entrySet()) { + NodeTemplate nodeTemplate = convertNodeTemplate(nodeTemplateEntry.getValue()); + DataModelUtil.addNodeTemplate(serviceTemplate, nodeTemplateEntry.getKey(), nodeTemplate); + } + } + + private NodeTemplate convertNodeTemplate(Object candidateNodeTemplate) { + NodeTemplate nodeTemplate = new NodeTemplate(); + + Map nodeTemplateAsMap = (Map) candidateNodeTemplate; + nodeTemplate.setArtifacts((Map) nodeTemplateAsMap.get("artifacts")); + nodeTemplate.setAttributes((Map) nodeTemplateAsMap.get("attributes")); + nodeTemplate.setCopy((String) nodeTemplateAsMap.get("copy")); + nodeTemplate.setDescription((String) nodeTemplateAsMap.get("description")); + nodeTemplate.setDirectives((List) nodeTemplateAsMap.get("directives")); + nodeTemplate.setInterfaces( + (Map) nodeTemplateAsMap.get("interfaces")); + nodeTemplate.setNode_filter((NodeFilter) nodeTemplateAsMap.get("node_filter")); + nodeTemplate.setProperties((Map) nodeTemplateAsMap.get("properties")); + nodeTemplate.setRequirements( + (List>) nodeTemplateAsMap.get("requirements")); + nodeTemplate.setType((String) nodeTemplateAsMap.get("type")); + nodeTemplate.setCapabilities( + convertCapabilities((Map) nodeTemplateAsMap.get("capabilities"))); + + return nodeTemplate; + } + + private Map convertCapabilities(Map capabilities) { + if (MapUtils.isEmpty(capabilities)) { + return null; + } + + Map convertedCapabilities = new HashMap<>(); + for (Map.Entry capabilityAssignmentEntry : capabilities.entrySet()) { + Optional capabilityAssignment = ToscaConverterUtil.createObjectFromClass + (capabilityAssignmentEntry.getKey(), capabilityAssignmentEntry.getValue(), + CapabilityAssignment.class); + + capabilityAssignment.ifPresent(capabilityAssignmentValue -> + convertedCapabilities.put(capabilityAssignmentEntry.getKey(), capabilityAssignmentValue)); + + } + return convertedCapabilities; + } + + private void convertSubstitutionMappings(ServiceTemplate serviceTemplate, + ServiceTemplateReaderService readerService) { + Map substitutionMappings = readerService.getSubstitutionMappings(); + if (MapUtils.isEmpty(substitutionMappings)) { + return; + } + SubstitutionMapping substitutionMapping = convertSubstitutionMappings(substitutionMappings); + DataModelUtil.addSubstitutionMapping(serviceTemplate, substitutionMapping); + } + + private SubstitutionMapping convertSubstitutionMappings( + Map substitutionMappings) { + SubstitutionMapping substitutionMapping = new SubstitutionMapping(); + + substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType)); + substitutionMapping.setCapabilities( + convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities))); + substitutionMapping.setRequirements( + convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements))); + + return substitutionMapping; + } + + private Map> convertSubstitutionMappingsSections(String sectionName, + Object sectionToConvert) { + + if (Objects.isNull(sectionToConvert)) { + return null; + } + + if (!(sectionToConvert instanceof Map)) { + throw new CoreException( + new SubstitutionMappingsConverterErrorBuilder( + sectionName, sectionToConvert.getClass().getSimpleName()).build()); + } + + return convertSection(sectionToConvert); + } + + private Map> convertSection(Object sectionToConvert) { + + Map sectionAsMap = (Map) sectionToConvert; + Map> convertedSection = new HashMap<>(); + + if (MapUtils.isEmpty(sectionAsMap)) { + return null; + } + + for (Map.Entry entry : sectionAsMap.entrySet()) { + if (entry.getValue() instanceof List) { + convertedSection.put(entry.getKey(), (List) entry.getValue()); + } + } + + return convertedSection; + } + +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java deleted file mode 100644 index 45d6332e06..0000000000 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterImplTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * - - * * ============LICENSE_START======================================================= - * * Copyright (C) 2019 Nordix Foundation. - * * ================================================================================ - * * 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. - * * - * * SPDX-License-Identifier: Apache-2.0 - * * ============LICENSE_END========================================================= - * - */ - -package org.openecomp.core.impl; - -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Map; - - -public class ToscaSolConverterImplTest { - - private ToscaSolConverterImpl toscaSolConverter; - private FileContentHandler fileContentHandler; - - @Before - public void setUp(){ - toscaSolConverter = new ToscaSolConverterImpl(); - fileContentHandler = new FileContentHandler(); - } - - - @Test - public void testGivenSOL004WithMetadataDirectoryPackage_whenToscaSolConverterIsCalled_validToscaServiceModelIsReturned() - throws IOException{ - fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", - ("TOSCA-Meta-File-Version: 1.0\n " + - "CSAR-Version: 1.1\n" + - "Created-by: Ericsson\n" + - "Entry-Definitions: Definitions/Main.yaml\n" + - "Entry-Manifest: Main.mf\n" + - "Entry-Change-Log: Artifacts/ChangeLog.txt") - .getBytes(StandardCharsets.UTF_8)); - - fileContentHandler.addFile("Definitions/Main.yaml", getFileResource("/toscaSOlConverter/Main.yaml")); - fileContentHandler.addFile("Main.mf", "".getBytes()); - fileContentHandler.addFile("Definitions/sample_import1.yaml", getFileResource("/toscaSOlConverter/sample_import1.yaml")); - fileContentHandler.addFile("Definitions/sample_import2.yaml", getFileResource("/toscaSOlConverter/sample_import2.yaml")); - fileContentHandler.addFile("Artifacts/sample_import3.yaml", getFileResource("/toscaSOlConverter/sample_import3.yaml")); - fileContentHandler.addFile("Artifacts/sample_import4.yaml", getFileResource("/toscaSOlConverter/sample_import4.yaml")); - ToscaServiceModel toscaServiceModel = toscaSolConverter.convert(fileContentHandler); - FileContentHandler contentHandler = toscaServiceModel.getArtifactFiles(); - Map serviceTemplateMap = toscaServiceModel.getServiceTemplates(); - String entryDefinitionTemplateName = toscaServiceModel.getEntryDefinitionServiceTemplate(); - Assert.assertTrue("Artifacts should contain external files", contentHandler.containsFile("Main.mf")); - Assert.assertTrue("Main service template should exist", serviceTemplateMap.containsKey("Main.yaml")); - Assert.assertEquals("Entry Definition name should be same as passed in TOSCA.meta", - "Main.yaml", entryDefinitionTemplateName); - } - - @Test(expected = IOException.class) - public void testGivenMetaFileDoesNotExist_thenAnExceptionIsThrown() throws IOException{ - toscaSolConverter.convert(fileContentHandler); - } - - @Test(expected = CoreException.class) - public void testGivenInvalidServiceTemplate_thenAnExceptionIsThrown() throws IOException{ - - fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", - ("TOSCA-Meta-File-Version: 1.0\n " + - "CSAR-Version: 1.1\n" + - "Created-by: Ericsson\n" + - "Entry-Definitions: Definitions/Main.yaml\n" + - "Entry-Manifest: Main.mf\n" + - "Entry-Change-Log: Artifacts/ChangeLog.txt") - .getBytes(StandardCharsets.UTF_8)); - - fileContentHandler.addFile("Definitions/Main.yaml", getFileResource("/toscaSOlConverter/invalidMainService.yaml")); - toscaSolConverter.convert(fileContentHandler); - } - - private byte[] getFileResource(String filePath) throws IOException { - InputStream inputStream = ClassLoader.class.getClass().getResourceAsStream(filePath); - return IOUtils.toByteArray(inputStream); - } - -} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java new file mode 100644 index 0000000000..21394c9c47 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfMultipleNodeTemplatesTest.java @@ -0,0 +1,74 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.onap.sdc.tosca.datatypes.model.NodeTemplate; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ToscaSolConverterPnfMultipleNodeTemplatesTest { + + private static final String PNF_EXT_CP_1 = "pnfExtCp_1"; + private static final String PNF_EXT_CP_2 = "pnfExtCp_2"; + + @Test + public void testGivenDescriptorWithPnfAndTwoPnfExts_WhenConvertTopologyTemplate_ThenTwoExtCpsInOutput() throws IOException { + // Added this as separate test as data-driven tests compare strings and as order of nodeTemplates + // can be different in hashMap and hence test may fail + final byte[] descriptor = getFileResource("pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml"); + ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf(); + toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService); + Map nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); + assertEquals(2, nodeTemplates.size()); + + nodeTemplates.entrySet().stream() + .map(Map.Entry::getKey) + .forEach((key -> assertTrue(getErrorString(), hasCorrectName(key)))); + } + + private byte[] getFileResource(String filePath) throws IOException { + try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath)) { + return IOUtils.toByteArray(inputStream); + } + } + + private boolean hasCorrectName(String name) { + return PNF_EXT_CP_1.equals(name) || PNF_EXT_CP_2.equals(name); + } + + private String getErrorString() { + return "node template name should be either " + PNF_EXT_CP_1 + " or " + PNF_EXT_CP_2; + } +} diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java new file mode 100644 index 0000000000..c3f38fe3cd --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java @@ -0,0 +1,114 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; +import org.onap.sdc.tosca.services.YamlUtil; +import org.openecomp.core.converter.ServiceTemplateReaderService; +import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +@RunWith(Parameterized.class) +public class ToscaSolConverterPnfTest { + + public static final String INPUT_DIR = "pnfDescriptor/in/"; + public static final String OUTPUT_DIR = "pnfDescriptor/out/"; + private String inputFilename; + private YamlUtil yamlUtil = new YamlUtil(); + private ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + + public ToscaSolConverterPnfTest(String inputFilename) { + this.inputFilename = inputFilename; + } + + @Parameterized.Parameters(name = "{index}: {0}") + public static Collection input() throws IOException { + try (Stream files = Files.list(getPathFromClasspath(INPUT_DIR))) { + return files.map(path -> path.getFileName().toString()) + .collect(Collectors.toList()); + } + } + + @Test + public void testTopologyTemplateConversions() throws IOException { + final byte[] descriptor = getInputFileResource(inputFilename); + ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf(); + toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService); + + String result = yamlUtil.objectToYaml(serviceTemplate); + String expectedResult = getExpectedResultFor(inputFilename); + assertEquals(expectedResult, result); + } + + private String getExpectedResultFor(String inputFilename) throws IOException { + try (InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) { + ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class); + return yamlUtil.objectToYaml(serviceTemplate); + } + } + + private static Path getPathFromClasspath(String location) { + return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath()); + } + + private byte[] getInputFileResource(String inputFilename) throws IOException { + return getFileResource(INPUT_DIR + inputFilename); + } + + private InputStream getOutputFileResourceCorrespondingTo(String inputFilename) { + String outputFilename = getOutputFilenameFrom(inputFilename); + return getFileResourceAsInputStream(OUTPUT_DIR + outputFilename); + } + + private String getOutputFilenameFrom(String inputFilename) { + return inputFilename.replace("pnfDescriptor", "topologyTemplate"); + } + + private byte[] getFileResource(String filePath) throws IOException { + try (InputStream inputStream = getFileResourceAsInputStream(filePath)) { + return IOUtils.toByteArray(inputStream); + } + } + + private InputStream getFileResourceAsInputStream(String filePath) { + return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); + } + +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java new file mode 100644 index 0000000000..bfc1fa9d85 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterVnfTest.java @@ -0,0 +1,105 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.core.impl; + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.Map; + + +public class ToscaSolConverterVnfTest { + + private AbstractToscaSolConverter toscaSolConverter; + private FileContentHandler fileContentHandler; + + @Before + public void setUp(){ + toscaSolConverter = new ToscaSolConverterVnf(); + fileContentHandler = new FileContentHandler(); + } + + + @Test + public void testGivenSOL004WithMetadataDirectoryPackage_whenToscaSolConverterIsCalled_validToscaServiceModelIsReturned() + throws IOException{ + fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", + ("TOSCA-Meta-File-Version: 1.0\n " + + "CSAR-Version: 1.1\n" + + "Created-by: Ericsson\n" + + "Entry-Definitions: Definitions/Main.yaml\n" + + "Entry-Manifest: Main.mf\n" + + "Entry-Change-Log: Artifacts/ChangeLog.txt") + .getBytes(StandardCharsets.UTF_8)); + + fileContentHandler.addFile("Definitions/Main.yaml", getFileResource("/toscaSOlConverter/Main.yaml")); + fileContentHandler.addFile("Main.mf", "".getBytes()); + fileContentHandler.addFile("Definitions/sample_import1.yaml", getFileResource("/toscaSOlConverter/sample_import1.yaml")); + fileContentHandler.addFile("Definitions/sample_import2.yaml", getFileResource("/toscaSOlConverter/sample_import2.yaml")); + fileContentHandler.addFile("Artifacts/sample_import3.yaml", getFileResource("/toscaSOlConverter/sample_import3.yaml")); + fileContentHandler.addFile("Artifacts/sample_import4.yaml", getFileResource("/toscaSOlConverter/sample_import4.yaml")); + ToscaServiceModel toscaServiceModel = toscaSolConverter.convert(fileContentHandler); + FileContentHandler contentHandler = toscaServiceModel.getArtifactFiles(); + Map serviceTemplateMap = toscaServiceModel.getServiceTemplates(); + String entryDefinitionTemplateName = toscaServiceModel.getEntryDefinitionServiceTemplate(); + Assert.assertTrue("Artifacts should contain external files", contentHandler.containsFile("Main.mf")); + Assert.assertTrue("Main service template should exist", serviceTemplateMap.containsKey("Main.yaml")); + Assert.assertEquals("Entry Definition name should be same as passed in TOSCA.meta", + "Main.yaml", entryDefinitionTemplateName); + } + + @Test(expected = IOException.class) + public void testGivenMetaFileDoesNotExist_thenAnExceptionIsThrown() throws IOException{ + toscaSolConverter.convert(fileContentHandler); + } + + @Test(expected = CoreException.class) + public void testGivenInvalidServiceTemplate_thenAnExceptionIsThrown() throws IOException{ + + fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", + ("TOSCA-Meta-File-Version: 1.0\n " + + "CSAR-Version: 1.1\n" + + "Created-by: Ericsson\n" + + "Entry-Definitions: Definitions/Main.yaml\n" + + "Entry-Manifest: Main.mf\n" + + "Entry-Change-Log: Artifacts/ChangeLog.txt") + .getBytes(StandardCharsets.UTF_8)); + + fileContentHandler.addFile("Definitions/Main.yaml", getFileResource("/toscaSOlConverter/invalidMainService.yaml")); + toscaSolConverter.convert(fileContentHandler); + } + + private byte[] getFileResource(String filePath) throws IOException { + InputStream inputStream = ClassLoader.class.getClass().getResourceAsStream(filePath); + return IOUtils.toByteArray(inputStream); + } + +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml new file mode 100644 index 0000000000..f78b763672 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_ExtCpWithNoIpv4OrIpv6Values.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ otherProtocol ] + role: leaf + description: External connection point to access this pnf \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml new file mode 100644 index 0000000000..83c7d9c0d4 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfAndExtCp.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml new file mode 100644 index 0000000000..1b6ab8b95f --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_PnfOnly.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml new file mode 100644 index 0000000000..913e200ead --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withExtraSpaces.yaml @@ -0,0 +1,26 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF # This is a comment + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: # This is another comment here + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4 , ipv6 , otherProtocol ] + role: leaf + description: External connection point to access this pnf \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml new file mode 100644 index 0000000000..79108d9084 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withInputsAndSubstitutionMappings.yaml @@ -0,0 +1,40 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + inputs: + my_input1: + type: string + description: this is input1 + default: defaultValue + my_input2: + type: string + description: this is input2 + default: defaultValue2 + + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf + requirements: + - virtual_link: + + substitution_mappings: + node_type: tosca.nodes.nfv.PNF + requirements: + virtual_link: [ pnfExtCp_1, virtual_link ] \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml new file mode 100644 index 0000000000..26255ddd84 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml @@ -0,0 +1,33 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: service template of a PNF + +topology_template: + node_templates: + pnf_mainPart: + type: tosca.nodes.nfv.PNF + properties: + descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233 + function_description: an example PNF + provider: Mycompany + version: 1.0 + descriptor_invariant_id: 1111-2222-ccaa-bbdd + name: ExamplePnf + requirements: + - virtual_link: + capability: tosca.capabilities.nfv.VirtualLinkable + node: pnfExtCp_1 + pnfExtCp_1: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf + pnfExtCp_2: + type: tosca.nodes.nfv.PnfExtCp + properties: + trunk_mode: false + layer_protocols: [ ipv4, ipv6, otherProtocol ] + role: leaf + description: External connection point to access this pnf \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml new file mode 100644 index 0000000000..6b1c45b6c9 --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_ExtCpWithNoIpv4OrIpv6Values.yaml @@ -0,0 +1,4 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfAndExtCp.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml new file mode 100644 index 0000000000..d47ce66ace --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_PnfOnly.yaml @@ -0,0 +1,2 @@ +topology_template: + node_templates: {} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withExtraSpaces.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml new file mode 100644 index 0000000000..d04b06a89a --- /dev/null +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withInputsAndSubstitutionMappings.yaml @@ -0,0 +1,10 @@ +topology_template: + node_templates: + pnfExtCp_1: + type: org.openecomp.resource.cp.v2.extCP + properties: + ip_requirements: + - assingment_method: dhcp + ip_version: 4 + - assingment_method: dhcp + ip_version: 6 \ No newline at end of file -- cgit 1.2.3-korg