aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-02-05 13:12:57 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-02-20 07:12:05 +0000
commitb1660e1be36e1f6572253f871dd5defa4030c98a (patch)
treecc856617ca244e651b139b4d61b7e7057b52dcb8 /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
parent372c2470e613128f1e33cfc581ea2c5b1b732d2b (diff)
Add new SOL004 validator
New validator for onboarding SOL 004 version 3.3.1 Issue-ID: SDC-2611 Signed-off-by: davsad <david.sadlier@est.tech> Change-Id: I4f41d2fbd913011f42a8319a6594c973c735d2a0
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib')
-rw-r--r--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.java15
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml6
-rw-r--r--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.java22
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java12
4 files changed, 53 insertions, 2 deletions
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 0a271c9d87..7332505b25 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
@@ -24,11 +24,14 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
+
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.datatypes.ToscaServiceModel;
+import com.vdurmont.semver4j.Semver;
+
public interface ETSIService {
@@ -67,18 +70,26 @@ public interface ETSIService {
Manifest getManifest(FileContentHandler handler) throws IOException;
/**
- * Determmines the type of resource that the CSAR represents
+ * Determines 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
+ * Determines 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;
Path getOriginalManifestPath(final FileContentHandler handler) throws IOException;
+
+
+ /**
+ * Determines the highest compatible specification version based on ETSI manifest file
+ * @param handler contains csar artifacts
+ * @return Semver representing highest compatible specification version
+ */
+ Semver getHighestCompatibleSpecificationVersion(final FileContentHandler handler);
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml
index ad52562b36..e6b686e31a 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/pom.xml
@@ -107,6 +107,12 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>com.vdurmont</groupId>
+ <artifactId>semver4j</artifactId>
+ <version>2.0.1</version>
+ </dependency>
+
</dependencies>
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 1281d611cb..8ec76fe14b 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
@@ -24,21 +24,25 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER;
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_ORIG_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
+
import org.apache.commons.collections.MapUtils;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.YamlUtil;
@@ -55,6 +59,8 @@ import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import com.vdurmont.semver4j.Semver;
+
public class ETSIServiceImpl implements ETSIService {
private static final Logger LOGGER = LoggerFactory.getLogger(ETSIServiceImpl.class);
@@ -202,6 +208,22 @@ public class ETSIServiceImpl implements ETSIService {
&& metaDataEntries.containsKey(ETSI_ENTRY_CHANGE_LOG.getName());
}
+ @Override
+ public Semver getHighestCompatibleSpecificationVersion(final FileContentHandler handler) {
+ try {
+ Map<String, String> metadata = getManifest(handler).getMetadata();
+ if (metadata.containsKey(COMPATIBLE_SPECIFICATION_VERSIONS.getToken())) {
+ 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));
+ }
+ } catch (Exception ex) {
+ LOGGER.error("An error occurred while getting highest compatible version from manifest file", ex);
+ }
+ return new Semver(ETSI_VERSION_2_6_1);
+
+ }
+
private boolean isMetaFilePresent(Map<String, byte[]> handler) {
return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME);
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
index f5570ae4e1..4254a56dcb 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1;
import java.io.File;
import java.io.IOException;
@@ -45,6 +46,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,6 +59,8 @@ import org.openecomp.sdc.tosca.csar.Manifest;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.yaml.snakeyaml.Yaml;
+import com.vdurmont.semver4j.Semver;
+
public class ETSIServiceImplTest {
private ETSIService etsiService;
@@ -291,6 +295,14 @@ public class ETSIServiceImplTest {
containsString(file2Path.toString()));
}
+ @Test
+ public void extractETSIPackageVersionTest() {
+ final List<String> versions = Arrays.asList("2.6.1", "2.7.1", "1.1.1", "3.3.1", "3.1.1", "1.1.2", "2.2.1");
+ assertThat(versions.stream().map(Semver::new).max((v1, v2) -> v1.compareTo(v2))
+ .orElse(new Semver(ETSI_VERSION_2_6_1)),
+ is(new Semver("3.3.1")));
+ }
+
private <T> T convert(final String fullFileName, final Class<T> className) throws IOException {
assertTrue((new File(fullFileName)).exists());