summaryrefslogtreecommitdiffstats
path: root/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2021-01-20 12:20:40 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-01-25 13:49:59 +0000
commit87eec9a2ad04e1cbe1304f23071ac6d85bdd5503 (patch)
treef85a732f610fa83fe6e82c735c43aa6dc42f4800 /catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java
parentc2db9023e1da5b41b02bff9e5e9396c9a4e2dde7 (diff)
Handle ETSI versions in NSD Plugin
The plugin now considers the ETSI version in the component metadata to generate the correct imports of nsd types, i.e., aligned with the provided version. Change-Id: I54aee04722a4434eac59ea8b70c4f30f5c81645e Issue-ID: SDC-3447 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java')
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilder.java48
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/EtsiNfvNsdCsarGeneratorFactory.java55
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/NsDescriptorGeneratorFactory.java49
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java17
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImpl.java76
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java22
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersion.java58
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorConfig.java35
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorVersionComparator.java50
9 files changed, 359 insertions, 51 deletions
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilder.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilder.java
index 6dc120290c..ed3a7fc4ee 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilder.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/builder/NsdCsarManifestBuilder.java
@@ -22,39 +22,35 @@ package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
-import java.util.HashSet;
import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.TreeSet;
/**
* Builder for the manifest (.mf) file in a NSD CSAR
*/
public class NsdCsarManifestBuilder {
- private static final String METADATA = "metadata";
- private static final String SOURCE = "Source";
+ static final String METADATA = "metadata";
+ static final String SOURCE = "Source";
+ static final String COMPATIBLE_SPECIFICATION_VERSIONS = "compatible_specification_versions";
private static final String NSD_DESIGNER = "nsd_designer";
private static final String NSD_FILE_STRUCTURE_VERSION = "nsd_file_structure_version";
- private static final String NSD_RELEASE_DATE_TIME = "nsd_release_date_time";
+ static final String NSD_RELEASE_DATE_TIME = "nsd_release_date_time";
private static final String NSD_NAME = "nsd_name";
private static final String NSD_INVARIANT_ID = "nsd_invariant_id";
- private static final String ATTRIBUTE_SEPARATOR = ": ";
+ static final String ATTRIBUTE_SEPARATOR = ": ";
private static final String NEW_LINE = "\n";
private static final DateTimeFormatter RFC_3339_DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
- private final StringBuilder builder;
- private final StringBuilder metadataBuilder;
- private final StringBuilder sourceBuilder;
private final MetadataHeader metadataHeader;
- private final HashSet<String> sources;
+ private final Set<String> sources;
+ private final Set<String> compatibleSpecificationVersions;
public NsdCsarManifestBuilder() {
- builder = new StringBuilder();
- metadataBuilder = new StringBuilder();
- sourceBuilder = new StringBuilder();
metadataHeader = new MetadataHeader();
sources = new LinkedHashSet<>();
- metadataBuilder.append(METADATA).append(ATTRIBUTE_SEPARATOR)
- .append(NEW_LINE);
+ compatibleSpecificationVersions = new TreeSet<>();
}
/**
@@ -122,25 +118,49 @@ public class NsdCsarManifestBuilder {
return this;
}
+ public NsdCsarManifestBuilder withCompatibleSpecificationVersion(final String version) {
+ this.compatibleSpecificationVersions.add(version);
+ return this;
+ }
+
/**
* Builds a string representing the manifest content based on provided values.
*
* @return a string representing the manifest content
*/
public String build() {
+ final StringBuilder metadataBuilder = createMetadataBuilder();
appendEntry(metadataBuilder, NSD_DESIGNER, metadataHeader.designer);
appendEntry(metadataBuilder, NSD_INVARIANT_ID, metadataHeader.invariantId);
appendEntry(metadataBuilder, NSD_NAME, metadataHeader.nsdName);
appendEntry(metadataBuilder, NSD_RELEASE_DATE_TIME, metadataHeader.nsdReleaseDateTime);
appendEntry(metadataBuilder, NSD_FILE_STRUCTURE_VERSION, metadataHeader.fileStructureVersion);
+ final StringBuilder sourceBuilder = new StringBuilder();
sources.forEach(source -> appendEntry(sourceBuilder, SOURCE, source));
+ final StringBuilder compatibleSpecificationVersionsBuilder = new StringBuilder();
+ if (!compatibleSpecificationVersions.isEmpty()) {
+ compatibleSpecificationVersionsBuilder.append(COMPATIBLE_SPECIFICATION_VERSIONS)
+ .append(ATTRIBUTE_SEPARATOR)
+ .append(String.join(",", compatibleSpecificationVersions))
+ .append(NEW_LINE);
+ }
+
+ final StringBuilder builder = new StringBuilder();
+
builder.append(metadataBuilder)
+ .append(compatibleSpecificationVersionsBuilder)
.append(NEW_LINE)
.append(sourceBuilder);
return builder.toString();
}
+ private StringBuilder createMetadataBuilder() {
+ final StringBuilder metadataBuilder = new StringBuilder();
+ metadataBuilder.append(METADATA).append(ATTRIBUTE_SEPARATOR).append(NEW_LINE);
+ return metadataBuilder;
+ }
+
private String getNowDateTime() {
return ZonedDateTime.now().format(RFC_3339_DATE_TIME_FORMATTER);
}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/EtsiNfvNsdCsarGeneratorFactory.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/EtsiNfvNsdCsarGeneratorFactory.java
new file mode 100644
index 0000000000..c1c792e443
--- /dev/null
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/EtsiNfvNsdCsarGeneratorFactory.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.sdc.be.plugins.etsi.nfv.nsd.factory;
+
+import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsdCsarGenerator;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.EtsiNfvNsdCsarGeneratorImpl;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.VnfDescriptorGenerator;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.NsDescriptorConfig;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.stereotype.Component;
+
+@Component
+public class EtsiNfvNsdCsarGeneratorFactory {
+
+ private final VnfDescriptorGenerator vnfDescriptorGenerator;
+ private final NsDescriptorGeneratorFactory nsDescriptorGeneratorFactory;
+ private final ArtifactCassandraDao artifactCassandraDao;
+ private final ObjectProvider<EtsiNfvNsdCsarGeneratorImpl> etsiNfvNsdCsarGeneratorObjectProvider;
+
+ public EtsiNfvNsdCsarGeneratorFactory(final VnfDescriptorGenerator vnfDescriptorGenerator,
+ final NsDescriptorGeneratorFactory nsDescriptorGeneratorFactory,
+ final ArtifactCassandraDao artifactCassandraDao,
+ final ObjectProvider<EtsiNfvNsdCsarGeneratorImpl> etsiNfvNsdCsarGeneratorObjectProvider) {
+ this.vnfDescriptorGenerator = vnfDescriptorGenerator;
+ this.nsDescriptorGeneratorFactory = nsDescriptorGeneratorFactory;
+ this.artifactCassandraDao = artifactCassandraDao;
+ this.etsiNfvNsdCsarGeneratorObjectProvider = etsiNfvNsdCsarGeneratorObjectProvider;
+ }
+
+ public EtsiNfvNsdCsarGenerator create(final EtsiVersion version) {
+ final NsDescriptorConfig nsDescriptorConfig = new NsDescriptorConfig(version);
+ return etsiNfvNsdCsarGeneratorObjectProvider
+ .getObject(nsDescriptorConfig, vnfDescriptorGenerator, nsDescriptorGeneratorFactory, artifactCassandraDao);
+ }
+
+}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/NsDescriptorGeneratorFactory.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/NsDescriptorGeneratorFactory.java
new file mode 100644
index 0000000000..5563078964
--- /dev/null
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/factory/NsDescriptorGeneratorFactory.java
@@ -0,0 +1,49 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.sdc.be.plugins.etsi.nfv.nsd.factory;
+
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.NsDescriptorGenerator;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.NsDescriptorGeneratorImpl;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.tosca.yaml.ToscaTemplateYamlGenerator;
+import org.openecomp.sdc.be.tosca.ToscaExportHandler;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NsDescriptorGeneratorFactory {
+
+ private final ToscaExportHandler toscaExportHandler;
+ private final ObjectProvider<ToscaTemplateYamlGenerator> toscaTemplateYamlGeneratorProvider;
+ private final ObjectProvider<NsDescriptorGeneratorImpl> nsDescriptorGeneratorProvider;
+
+ public NsDescriptorGeneratorFactory(final ToscaExportHandler toscaExportHandler,
+ final ObjectProvider<ToscaTemplateYamlGenerator> toscaTemplateYamlGeneratorProvider,
+ final ObjectProvider<NsDescriptorGeneratorImpl> nsDescriptorGeneratorProvider) {
+ this.toscaExportHandler = toscaExportHandler;
+ this.toscaTemplateYamlGeneratorProvider = toscaTemplateYamlGeneratorProvider;
+ this.nsDescriptorGeneratorProvider = nsDescriptorGeneratorProvider;
+ }
+
+ public NsDescriptorGenerator create() {
+ return nsDescriptorGeneratorProvider
+ .getObject(toscaExportHandler, toscaTemplateYamlGeneratorProvider);
+ }
+
+}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
index 217b334f1a..ff20a3e70b 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsCsarEntryGenerator.java
@@ -28,6 +28,8 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.plugins.CsarEntryGenerator;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.factory.EtsiNfvNsdCsarGeneratorFactory;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,11 +42,12 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(EtsiNfvNsCsarEntryGenerator.class);
static final String ETSI_NS_COMPONENT_CATEGORY = "ETSI NFV Network Service";
static final String NSD_FILE_PATH_FORMAT = "Artifacts/%s/%s.csar";
+ static final String ETSI_VERSION_METADATA = "ETSI Version";
- private final EtsiNfvNsdCsarGenerator etsiNfvNsdCsarGenerator;
+ private final EtsiNfvNsdCsarGeneratorFactory etsiNfvNsdCsarGeneratorFactory;
- public EtsiNfvNsCsarEntryGenerator(final EtsiNfvNsdCsarGenerator etsiNfvNsdCsarGenerator) {
- this.etsiNfvNsdCsarGenerator = etsiNfvNsdCsarGenerator;
+ public EtsiNfvNsCsarEntryGenerator(final EtsiNfvNsdCsarGeneratorFactory etsiNfvNsdCsarGeneratorFactory) {
+ this.etsiNfvNsdCsarGeneratorFactory = etsiNfvNsdCsarGeneratorFactory;
}
/**
@@ -72,6 +75,9 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
final byte[] nsdCsar;
try {
+ final EtsiVersion etsiVersion = getComponentEtsiVersion(component);
+ final EtsiNfvNsdCsarGenerator etsiNfvNsdCsarGenerator =
+ etsiNfvNsdCsarGeneratorFactory.create(etsiVersion);
nsdCsar = etsiNfvNsdCsarGenerator.generateNsdCsar(component);
} catch (final NsdException e) {
LOGGER.error("Could not create NSD CSAR entry for component '{}'"
@@ -86,6 +92,11 @@ public class EtsiNfvNsCsarEntryGenerator implements CsarEntryGenerator {
return createEntry(component.getNormalizedName(), nsdCsar);
}
+ private EtsiVersion getComponentEtsiVersion(Component component) {
+ final String etsiVersion = component.getCategorySpecificMetadata().get(ETSI_VERSION_METADATA);
+ return EtsiVersion.convertOrNull(etsiVersion);
+ }
+
private Map<String, byte[]> createEntry(final String csarName, final byte[] nsdCsar) {
final Map<String, byte[]> entryMap = new HashMap<>();
final String entryKey = String.format(NSD_FILE_PATH_FORMAT, ETSI_PACKAGE, csarName);
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImpl.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImpl.java
index 64356ca7aa..efc6ade92d 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImpl.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/EtsiNfvNsdCsarGeneratorImpl.java
@@ -24,8 +24,6 @@ import static org.openecomp.sdc.common.api.ArtifactTypeEnum.ONBOARDED_PACKAGE;
import fj.data.Either;
import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -50,19 +48,26 @@ import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdCsarManifestBuilder;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdToscaMetadataBuilder;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.factory.NsDescriptorGeneratorFactory;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.EtsiVersion;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.NsDescriptorConfig;
+import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator.config.NsDescriptorVersionComparator;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.Nsd;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.VnfDescriptor;
import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.Scope;
import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/**
* Implementation of a ETSI NFV NSD CSAR generator
*/
@org.springframework.stereotype.Component("etsiNfvNsdCsarGenerator")
+@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(EtsiNfvNsdCsarGeneratorImpl.class);
@@ -76,14 +81,17 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
private static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
private final VnfDescriptorGenerator vnfDescriptorGenerator;
- private final NsDescriptorGenerator nsDescriptorGeneratorImpl;
+ private final NsDescriptorGeneratorFactory nsDescriptorGeneratorFactory;
private final ArtifactCassandraDao artifactCassandraDao;
+ private final NsDescriptorConfig nsDescriptorConfig;
- public EtsiNfvNsdCsarGeneratorImpl(final VnfDescriptorGenerator vnfDescriptorGenerator,
- final NsDescriptorGenerator nsDescriptorGenerator,
+ public EtsiNfvNsdCsarGeneratorImpl(final NsDescriptorConfig nsDescriptorConfig,
+ final VnfDescriptorGenerator vnfDescriptorGenerator,
+ final NsDescriptorGeneratorFactory nsDescriptorGeneratorFactory,
final ArtifactCassandraDao artifactCassandraDao) {
+ this.nsDescriptorConfig = nsDescriptorConfig;
this.vnfDescriptorGenerator = vnfDescriptorGenerator;
- this.nsDescriptorGeneratorImpl = nsDescriptorGenerator;
+ this.nsDescriptorGeneratorFactory = nsDescriptorGeneratorFactory;
this.artifactCassandraDao = artifactCassandraDao;
}
@@ -106,17 +114,18 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
vnfDescriptorList.forEach(vnfPackage -> nsdCsarFiles.putAll(vnfPackage.getDefinitionFiles()));
final String nsdFileName = getNsdFileName(component);
+ final EtsiVersion etsiVersion = nsDescriptorConfig.getNsVersion();
final Nsd nsd = generateNsd(component, vnfDescriptorList);
nsdCsarFiles.put(getNsdPath(nsdFileName), nsd.getContents());
nsdCsarFiles.put(TOSCA_META_PATH, buildToscaMetaContent(nsdFileName).getBytes());
- addEtsiSolNsdTypes(nsdCsarFiles);
+ addEtsiSolNsdTypes(etsiVersion, nsdCsarFiles);
for (final String referencedFile : nsd.getArtifactReferences()) {
getReferencedArtifact(component, referencedFile).ifPresent(
artifactDefinition -> nsdCsarFiles.put(referencedFile, artifactDefinition.getPayloadData())
);
}
nsdCsarFiles
- .put(getManifestPath(nsdFileName), getManifestFileContent(nsd, nsdCsarFiles.keySet()).getBytes());
+ .put(getManifestPath(nsdFileName), getManifestFileContent(nsd, etsiVersion, nsdCsarFiles.keySet()).getBytes());
final byte[] csar = buildCsarPackage(nsdCsarFiles);
LOGGER.debug("Successfully generated NSD CSAR package");
@@ -221,33 +230,40 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
.findFirst();
}
- private void addEtsiSolNsdTypes(final Map<String, byte[]> nsdCsarFileMap) {
- final Path baseFolderPath = Paths.get("etsi-nfv-types");
- String nsdTypesFilename = "etsi_nfv_sol001_nsd_2_7_1_types.yaml";
+ private void addEtsiSolNsdTypes(final EtsiVersion etsiVersion,
+ final Map<String, byte[]> nsdCsarFileMap) {
+ final EtsiVersion currentVersion = etsiVersion == null ?
+ EtsiVersion.getDefaultVersion() : etsiVersion;
+
+ final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
- final Resource resource =
- new ClassPathResource(Paths.get(baseFolderPath.toString(), nsdTypesFilename).toString());
- nsdCsarFileMap.put(DEFINITION + "/" + nsdTypesFilename,
- IOUtils.toByteArray(resource.getInputStream()));
- } catch (final IOException exception) {
- LOGGER.error("Error adding {} to NSD CSAR", nsdTypesFilename, exception);
+ final Resource[] resources =
+ resolver.getResources(String.format("classpath:etsi-nfv-types/%s/*.*", currentVersion.getVersion()));
+ if (resources.length > 0) {
+ for (final Resource resource : resources) {
+ addToCsarFileMap(resource, nsdCsarFileMap);
+ }
+ }
+ } catch (final IOException e) {
+ LOGGER.error("Could not find types files for the version '{}'", currentVersion.getVersion(), e);
}
+ }
- String commonTypesFilename = "etsi_nfv_sol001_common_types.yaml";
+ private void addToCsarFileMap(final Resource resource, final Map<String, byte[]> nsdCsarFileMap) {
try {
- final Resource resource =
- new ClassPathResource(Paths.get(baseFolderPath.toString(), commonTypesFilename).toString());
- nsdCsarFileMap.put(DEFINITION + "/" + commonTypesFilename,
+ nsdCsarFileMap.put(DEFINITION + "/" + resource.getFilename(),
IOUtils.toByteArray(resource.getInputStream()));
} catch (final IOException exception) {
- LOGGER.error("Error adding {} to NSD CSAR", commonTypesFilename, exception);
+ LOGGER.error("Error adding '{}' to NSD CSAR", resource.getFilename(), exception);
}
}
private Nsd generateNsd(final Component component,
final List<VnfDescriptor> vnfDescriptorList) throws NsdException {
- return nsDescriptorGeneratorImpl.generate(component, vnfDescriptorList)
+ final NsDescriptorGenerator nsDescriptorGenerator =
+ nsDescriptorGeneratorFactory.create();
+ return nsDescriptorGenerator.generate(component, vnfDescriptorList)
.orElseThrow(() ->
new NsdException(String
.format("Could not generate the Network Service Descriptor for component %s", component.getName()))
@@ -269,7 +285,7 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
if (artifactDefinition.getPayloadData() == null) {
final Optional<byte[]> artifactPayload = loadArtifactPayload(artifactDefinition.getEsId());
- if (!artifactPayload.isPresent()) {
+ if (artifactPayload.isEmpty()) {
throw new NsdException(String.format("Could not load artifact '%s' payload", filePath));
}
artifactDefinition.setPayload(artifactPayload.get());
@@ -307,7 +323,9 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
return toscaMetadata;
}
- private String getManifestFileContent(final Nsd nsd, final Set<String> files) {
+ private String getManifestFileContent(final Nsd nsd,
+ final EtsiVersion nsdVersion,
+ final Set<String> files) {
LOGGER.debug("Creating NS manifest file content");
final NsdCsarManifestBuilder nsdCsarManifestBuilder = new NsdCsarManifestBuilder();
@@ -318,6 +336,12 @@ public class EtsiNfvNsdCsarGeneratorImpl implements EtsiNfvNsdCsarGenerator {
.withFileStructureVersion(nsd.getVersion())
.withSources(files);
+ final NsDescriptorVersionComparator nsdVersionComparator = new NsDescriptorVersionComparator();
+
+ if (nsdVersion != null && nsdVersionComparator.compare(nsdVersion, EtsiVersion.VERSION_3_3_1) >= 0) {
+ nsdCsarManifestBuilder.withCompatibleSpecificationVersion(nsdVersion.getVersion());
+ }
+
final String manifest = nsdCsarManifestBuilder.build();
LOGGER.debug("Successfully created NS CSAR manifest file content:\n {}", manifest);
return manifest;
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java
index 271fc196bf..2a2e2b008a 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java
@@ -19,7 +19,6 @@
package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import fj.data.Either;
import java.util.ArrayList;
@@ -54,19 +53,16 @@ import org.openecomp.sdc.be.tosca.model.ToscaTopolgyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.Scope;
@org.springframework.stereotype.Component("nsDescriptorGenerator")
+@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(NsDescriptorGeneratorImpl.class);
private static final String TOSCA_VERSION = "tosca_simple_yaml_1_1";
private static final String NS_TOSCA_TYPE = "tosca.nodes.nfv.NS";
- private static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS_ETSI_SOL_NSD =
- ImmutableList.of(
- ImmutableMap.of("etsi_nfv_sol001_nsd_2_7_1_types",
- ImmutableMap.of("file", "etsi_nfv_sol001_nsd_2_7_1_types.yaml")
- )
- );
private static final List<Map<String, Map<String, String>>> DEFAULT_IMPORTS = ConfigurationManager
.getConfigurationManager().getConfiguration().getDefaultImports();
private static final List<String> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE = Arrays
@@ -308,7 +304,11 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
private void setDefaultImportsForEtsiSolNsNsd(final ToscaTemplate template,
final List<VnfDescriptor> vnfDescriptorList) {
- final List<Map<String, Map<String, String>>> importEntryMap = new ArrayList<>(DEFAULT_IMPORTS_ETSI_SOL_NSD);
+ final List<Map<String, Map<String, String>>> importEntryMap = new ArrayList<>();
+ final Map<String, Map<String, String>> defaultImportEntryMap = generateDefaultImportEntry();
+ if (MapUtils.isNotEmpty(defaultImportEntryMap)) {
+ importEntryMap.add(defaultImportEntryMap);
+ }
if (CollectionUtils.isNotEmpty(vnfDescriptorList)) {
for (final VnfDescriptor vnfDescriptor : vnfDescriptorList) {
final Map<String, String> vnfImportChildEntry = new HashMap<>();
@@ -322,6 +322,12 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
template.setImports(importEntryMap);
}
+ private Map<String, Map<String, String>> generateDefaultImportEntry() {
+ return ImmutableMap.of("etsi_nfv_sol001_nsd_types",
+ ImmutableMap.of("file", "etsi_nfv_sol001_nsd_types.yaml")
+ );
+ }
+
private ToscaNodeType createEtsiSolNsNodeType(final ToscaNodeType nsNodeType) {
final ToscaNodeType toscaNodeType = new ToscaNodeType();
toscaNodeType.setDerived_from(NS_TOSCA_TYPE);
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersion.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersion.java
new file mode 100644
index 0000000000..d447dc428d
--- /dev/null
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/EtsiVersion.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.sdc.be.plugins.etsi.nfv.nsd.generator.config;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Network Service Descriptor known versions
+ */
+@Getter
+@AllArgsConstructor
+public enum EtsiVersion {
+ VERSION_2_5_1("2.5.1"),
+ VERSION_2_7_1("2.7.1"),
+ VERSION_3_3_1("3.3.1");
+
+ private final String version;
+
+ public static EtsiVersion convertOrNull(final String etsiVersion) {
+ if (StringUtils.isEmpty(etsiVersion)) {
+ return null;
+ }
+ if (VERSION_2_5_1.getVersion().equals(etsiVersion)) {
+ return VERSION_2_5_1;
+ }
+ if (VERSION_2_7_1.getVersion().equals(etsiVersion)) {
+ return VERSION_2_7_1;
+ }
+ if (VERSION_3_3_1.getVersion().equals(etsiVersion)) {
+ return VERSION_3_3_1;
+ }
+
+ return null;
+ }
+
+ public static EtsiVersion getDefaultVersion() {
+ return VERSION_2_5_1;
+ }
+}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorConfig.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorConfig.java
new file mode 100644
index 0000000000..d17b48d158
--- /dev/null
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorConfig.java
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.sdc.be.plugins.etsi.nfv.nsd.generator.config;
+
+import lombok.Getter;
+
+/**
+ * Configuration parameters for the Network Service Descriptor generation
+ */
+@Getter
+public class NsDescriptorConfig {
+
+ final EtsiVersion nsVersion;
+
+ public NsDescriptorConfig(final EtsiVersion etsiVersion) {
+ this.nsVersion = etsiVersion;
+ }
+}
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorVersionComparator.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorVersionComparator.java
new file mode 100644
index 0000000000..40e499c8c7
--- /dev/null
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/config/NsDescriptorVersionComparator.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.sdc.be.plugins.etsi.nfv.nsd.generator.config;
+
+import java.util.Comparator;
+
+public class NsDescriptorVersionComparator implements Comparator<EtsiVersion> {
+
+ @Override
+ public int compare(final EtsiVersion o1, final EtsiVersion o2) {
+ final String[] v1 = o1.getVersion().split("\\.");
+ final String[] v2 = o2.getVersion().split("\\.");
+ if (Integer.parseInt(v1[0]) > Integer.parseInt(v2[0])) {
+ return 1;
+ } else if (Integer.parseInt(v1[0]) < Integer.parseInt(v2[0])) {
+ return -1;
+ }
+
+ if (Integer.parseInt(v1[1]) > Integer.parseInt(v2[1])) {
+ return 1;
+ } else if (Integer.parseInt(v1[1]) < Integer.parseInt(v2[1])) {
+ return -1;
+ }
+
+ if (Integer.parseInt(v1[2]) > Integer.parseInt(v2[2])) {
+ return 1;
+ } else if (Integer.parseInt(v1[2]) < Integer.parseInt(v2[2])) {
+ return -1;
+ }
+
+ return 0;
+ }
+}