aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/pom.xml5
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java14
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java12
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java48
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java3
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboardingTest.java23
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/InvalidToscaVersion3.mf19
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/ValidToscaVersion3.mf19
8 files changed, 133 insertions, 10 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/pom.xml b/openecomp-be/lib/openecomp-tosca-lib/pom.xml
index cd0c8092a9..b05313f7c3 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/pom.xml
+++ b/openecomp-be/lib/openecomp-tosca-lib/pom.xml
@@ -31,6 +31,11 @@
<dependencies>
<dependency>
+ <groupId>com.vdurmont</groupId>
+ <artifactId>semver4j</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
<groupId>org.onap.sdc.common</groupId>
<artifactId>onap-tosca-datatype</artifactId>
<version>${project.version}</version>
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
index 783636b3d9..845d36cb4c 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
@@ -18,14 +18,18 @@
package org.openecomp.sdc.tosca.csar;
import static com.google.common.collect.ImmutableSet.of;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_ARCHIVE_VERSION;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_PROVIDER;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_RELEASE_DATE_TIME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PACKAGE_VERSION;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_SOFTWARE_VERSION;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PRODUCT_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PROVIDER_ID;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_RELEASE_DATE_TIME;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFD_ID;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNFM_INFO;
import com.google.common.collect.ImmutableSet;
@@ -41,13 +45,23 @@ public class CSARConstants {
public static final ImmutableSet<String> MANIFEST_PNF_METADATA =
of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(),
PNFD_ARCHIVE_VERSION.getToken());
+ public static final ImmutableSet<String> MANIFEST_PNF_METADATA_VERSION_3 =
+ of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(),
+ PNFD_ARCHIVE_VERSION.getToken(), COMPATIBLE_SPECIFICATION_VERSIONS.getToken());
public static final ImmutableSet<String> MANIFEST_VNF_METADATA =
of(VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), VNF_RELEASE_DATE_TIME.getToken(),
VNF_PACKAGE_VERSION.getToken());
+ public static final ImmutableSet<String> MANIFEST_VNF_METADATA_VERSION_3 =
+ of(COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), VNFD_ID.getToken(), VNF_PROVIDER_ID.getToken(), VNF_PRODUCT_NAME.getToken(), VNF_RELEASE_DATE_TIME.getToken(),
+ VNF_PACKAGE_VERSION.getToken(), VNF_SOFTWARE_VERSION.getToken(), VNFM_INFO.getToken());
public static final int MANIFEST_METADATA_LIMIT = 4;
+ public static final int MANIFEST_VNF_METADATA_LIMIT_VERSION_3 = 8;
+ public static final int MANIFEST_PNF_METADATA_LIMIT_VERSION_3 = 5;
public static final String TOSCA_META_ORIG_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta.original";
public static final String CSAR_VERSION_1_0 = "1.0";
public static final String CSAR_VERSION_1_1 = "1.1";
+ public static final String ETSI_VERSION_2_6_1 = "2.6.1";
+ public static final String ETSI_VERSION_2_7_1 = "2.7.1";
public static final ImmutableSet<String> NON_FILE_IMPORT_ATTRIBUTES =
ImmutableSet.of("repository", "namespace_uri", "namespace_prefix");
public static final String TOSCA_TYPE_PNF = "pnf";
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java
index 2e073a431a..7caa09f954 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ManifestTokenType.java
@@ -36,12 +36,17 @@ public enum ManifestTokenType {
VNF_PROVIDER_ID("vnf_provider_id"),
VNF_PACKAGE_VERSION("vnf_package_version"),
VNF_RELEASE_DATE_TIME("vnf_release_date_time"),
+ VNF_SOFTWARE_VERSION("vnf_software_version"),
+ VNFM_INFO("vnfm_info"),
+ VNFD_ID("vnfd_id"),
PNFD_NAME("pnfd_name"),
PNFD_PROVIDER("pnfd_provider"),
PNFD_ARCHIVE_VERSION("pnfd_archive_version"),
PNFD_RELEASE_DATE_TIME("pnfd_release_date_time"),
SIGNATURE("Signature"),
- CERTIFICATE("Certificate");
+ CERTIFICATE("Certificate"),
+ COMPATIBLE_SPECIFICATION_VERSIONS("compatible_specification_versions");
+
private final String token;
@@ -67,6 +72,10 @@ public enum ManifestTokenType {
case VNF_PROVIDER_ID:
case VNF_PACKAGE_VERSION:
case VNF_RELEASE_DATE_TIME:
+ case VNFD_ID:
+ case VNFM_INFO:
+ case VNF_SOFTWARE_VERSION:
+ case COMPATIBLE_SPECIFICATION_VERSIONS:
return true;
default:
return false;
@@ -79,6 +88,7 @@ public enum ManifestTokenType {
case PNFD_PROVIDER:
case PNFD_ARCHIVE_VERSION:
case PNFD_RELEASE_DATE_TIME:
+ case COMPATIBLE_SPECIFICATION_VERSIONS:
return true;
default:
return false;
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java
index 99ea9a5a13..97f562979f 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboarding.java
@@ -21,18 +21,30 @@
package org.openecomp.sdc.tosca.csar;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_7_1;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_LIMIT_VERSION_3;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_LIMIT_VERSION_3;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS;
+
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
+
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.common.errors.Messages;
+import com.vdurmont.semver4j.Semver;
+
/**
* Processes a SOL004 Manifest.
*/
public class SOL004ManifestOnboarding extends AbstractOnboardingManifest {
+ private int maxAllowedMetaEntries;
+
@Override
protected void processMetadata() {
Optional<String> currentLine = getCurrentLine();
@@ -51,7 +63,7 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest {
final String metadataLine = currentLine.get();
final String metadataEntry = readEntryName(metadataLine).orElse(null);
if (!isMetadataEntry(metadataEntry)) {
- if (metadata.size() < MAX_ALLOWED_MANIFEST_META_ENTRIES) {
+ if (metadata.size() < getMaxAllowedManifestMetaEntries()) {
reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, metadataLine);
continueToProcess = false;
return;
@@ -225,12 +237,11 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest {
reportError(Messages.MANIFEST_NO_METADATA);
return false;
}
-
- final Entry<String, String> firstManifestEntry = metadata.entrySet().iterator().next();
- final ManifestTokenType firstManifestEntryTokenType =
- ManifestTokenType.parse(firstManifestEntry.getKey()).orElse(null);
+ String key = metadata.keySet().stream().filter(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k))
+ .findFirst().orElse(null);
+ final ManifestTokenType firstManifestEntryTokenType = ManifestTokenType.parse(key).orElse(null);
if (firstManifestEntryTokenType == null) {
- reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, firstManifestEntry.getKey());
+ reportError(Messages.MANIFEST_METADATA_INVALID_ENTRY1, key);
return false;
}
for (final Entry<String, String> manifestEntry : metadata.entrySet()) {
@@ -247,8 +258,8 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest {
}
}
- if (metadata.entrySet().size() != MAX_ALLOWED_MANIFEST_META_ENTRIES) {
- reportError(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT, MAX_ALLOWED_MANIFEST_META_ENTRIES);
+ if (metadata.entrySet().size() != getMaxAllowedManifestMetaEntries()) {
+ reportError(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT, getMaxAllowedManifestMetaEntries());
return false;
}
@@ -372,4 +383,25 @@ public class SOL004ManifestOnboarding extends AbstractOnboardingManifest {
readNextNonEmptyLine();
}
+ private int getMaxAllowedManifestMetaEntries() {
+ if (maxAllowedMetaEntries == 0) {
+ boolean isVersion3 = metadata.containsKey(COMPATIBLE_SPECIFICATION_VERSIONS.getToken())
+ && !getHighestCompatibleVersion().isLowerThan(ETSI_VERSION_2_7_1);
+ //Both PNF and VNF share attribute COMPATIBLE_SPECIFICATION_VERSIONS
+ if (isVersion3)
+ maxAllowedMetaEntries = metadata.keySet().stream()
+ .anyMatch(k -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(k)
+ && isMetadataEntry(k) && ManifestTokenType.parse(k).get().isMetadataPnfEntry())
+ ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3;
+ else
+ maxAllowedMetaEntries = MAX_ALLOWED_MANIFEST_META_ENTRIES;
+ }
+ return maxAllowedMetaEntries;
+ }
+
+ private Semver getHighestCompatibleVersion() {
+ return Arrays.asList(metadata.get(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()).split(","))
+ .stream().map(Semver::new).max((v1, v2) -> v1.compareTo(v2))
+ .orElse(new Semver(ETSI_VERSION_2_6_1));
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
index c6ae0d1843..3b669543fd 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
@@ -38,7 +38,8 @@ public enum ToscaMetaEntry {
ETSI_ENTRY_CHANGE_LOG("ETSI-Entry-Change-Log"),
ETSI_ENTRY_TESTS("ETSI-Entry-Tests"),
ETSI_ENTRY_LICENSES("ETSI-Entry-Licenses"),
- ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate");
+ ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate"),
+ OTHER_DEFINITIONS("Other-Definitions");
private final String name;
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboardingTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboardingTest.java
index 288995dfed..beae6af0b4 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboardingTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/SOL004ManifestOnboardingTest.java
@@ -489,6 +489,29 @@ class SOL004ManifestOnboardingTest {
}
}
+ @Test
+ public void testSuccessfulParsingWithCompatibleSpecficationVersion() throws IOException {
+ try (final InputStream manifestAsStream =
+ getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidToscaVersion3.mf")) {
+ manifest.parse(manifestAsStream);
+ assertValidManifest(8, 5, Collections.emptyMap(), ResourceTypeEnum.VF, false);
+ }
+ }
+
+ @Test
+ public void testFailedParsingWithCompatibleSpecficationVersion() throws IOException {
+ try (final InputStream manifestAsStream =
+ getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidToscaVersion3.mf")) {
+ manifest.parse(manifestAsStream);
+ final List<String> errorList = Collections.singletonList(
+ Messages.MANIFEST_ERROR_WITH_LINE.formatMessage(
+ Messages.MANIFEST_METADATA_INVALID_ENTRY1.formatMessage("vnf_test: 1.0"),
+ 4, "vnf_test: 1.0")
+ );
+ assertInvalidManifest(errorList);
+ }
+ }
+
private void assertValidManifest(final int expectedMetadataSize, final int expectedSourcesSize,
final Map<String, Integer> expectedNonManoKeySize,
final ResourceTypeEnum resourceType, final boolean isSigned) {
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/InvalidToscaVersion3.mf b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/InvalidToscaVersion3.mf
new file mode 100644
index 0000000000..c753e7622f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/InvalidToscaVersion3.mf
@@ -0,0 +1,19 @@
+metadata:
+ vnf_product_name: Mock
+ vnf_provider_id: ZTE
+ vnf_test: 1.0
+ vnf_release_date_time: 2017.01.01T10:00+03:00
+ vnf_software_version: 1.0.0
+ vnfd_id: 2116fd24-83f2-416b-bf3c-ca1964793aca
+ compatible_specification_versions: 2.7.1, 3.1.1
+ vnfm_info: etsivnfm:v2.3.1,0:myGreatVnfm-1
+
+Source: MainServiceTemplate.yaml
+
+Source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml
+
+Source: Artifacts/install.sh
+
+Source: Artifacts/create_stack.sh
+
+Source: Licenses/license.xml
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/ValidToscaVersion3.mf b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/ValidToscaVersion3.mf
new file mode 100644
index 0000000000..2cfa9a1eae
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/vspmanager.csar/manifest/ValidToscaVersion3.mf
@@ -0,0 +1,19 @@
+metadata:
+ vnf_product_name: Mock
+ vnf_provider_id: ZTE
+ vnf_package_version: 1.0
+ vnf_release_date_time: 2017.01.01T10:00+03:00
+ vnf_software_version: 1.0.0
+ vnfd_id: 2116fd24-83f2-416b-bf3c-ca1964793aca
+ compatible_specification_versions: 2.7.1, 3.1.1
+ vnfm_info: etsivnfm:v2.3.1,0:myGreatVnfm-1
+
+Source: MainServiceTemplate.yaml
+
+Source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml
+
+Source: Artifacts/install.sh
+
+Source: Artifacts/create_stack.sh
+
+Source: Licenses/license.xml