aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
diff options
context:
space:
mode:
authorfranciscovila <javier.paradela.vila@est.tech>2022-02-04 10:47:33 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-28 08:40:07 +0000
commit55401bf89a8bc1c51f76554faac278186560724a (patch)
tree39abefaee3df7109fe3924816bec7c513f0256b0 /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
parent4307dbb5f0dc5da60e55f3473259cfd059d14770 (diff)
Create onboarding validator for ASD VSPs
Create a new validator in SDC onboarding that will be used for ASD VSPs Issue-ID: SDC-3859 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: Ida192122a95414f7d18855fe2a993b269c55a91d
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-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java124
-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.java67
2 files changed, 78 insertions, 113 deletions
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 a0ab46e589..dbec8f7473 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
@@ -19,31 +19,7 @@
*/
package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1;
-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.ToscaMetaEntryVersion251.ENTRY_MANIFEST;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_MANIFEST;
-import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
-
import com.vdurmont.semver4j.Semver;
-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.Comparator;
-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;
@@ -57,29 +33,56 @@ import org.openecomp.sdc.common.CommonConfigurationManager;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.ManifestUtils;
import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Comparator;
+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 static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_6_1;
+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.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
+
public class ETSIServiceImpl implements ETSIService {
private static final Logger LOGGER = LoggerFactory.getLogger(ETSIServiceImpl.class);
private final NonManoConfiguration nonManoConfiguration;
- private final String ONAP_CSAR = "onap_csar";
+ private final ManifestUtils manifestUtils;
+ private static final String ONAP_CSAR = "onap_csar";
public ETSIServiceImpl() {
nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration();
+ manifestUtils = new ManifestUtils();
}
- public ETSIServiceImpl(final NonManoConfiguration nonManoConfiguration) {
+ public ETSIServiceImpl(final NonManoConfiguration nonManoConfiguration,
+ final ManifestUtils manifestUtils) {
this.nonManoConfiguration = nonManoConfiguration;
+ this.manifestUtils = manifestUtils;
}
@Override
public boolean hasEtsiSol261Metadata(FileContentHandler handler) throws IOException {
final Map<String, byte[]> templates = handler.getFiles();
- return isMetaFilePresent(templates) && hasMetaMandatoryEntries(getMetadata(handler));
+ return isMetaFilePresent(templates) && hasMetaMandatoryEntries(manifestUtils.getMetadata(handler));
}
@Override
@@ -88,6 +91,8 @@ public class ETSIServiceImpl implements ETSIService {
&& !ONAP_CSAR.equalsIgnoreCase(getDefaultCsarFormat());
}
+
+
private boolean hasOnapCsarMetadata(final FileContentHandler fileContentHandler) throws IOException {
if (fileContentHandler.containsFile(TOSCA_META_PATH_FILE_NAME)){
final ToscaMetadata metadata =
@@ -103,7 +108,7 @@ public class ETSIServiceImpl implements ETSIService {
@Override
public Optional<Map<String, Path>> moveNonManoFileToArtifactFolder(final FileContentHandler handler) throws IOException {
- final Manifest manifest = loadManifest(handler);
+ final Manifest manifest = manifestUtils.loadManifest(handler, new SOL004ManifestOnboarding());
final Path originalManifestPath;
try {
originalManifestPath = getOriginalManifestPath(handler);
@@ -223,32 +228,19 @@ public class ETSIServiceImpl implements ETSIService {
@Override
public boolean hasCnfEnhancements(final FileContentHandler fileContentHandler) throws IOException {
- final Manifest manifest = loadManifest(fileContentHandler);
+ final Manifest manifest = manifestUtils.loadManifest(fileContentHandler, new SOL004ManifestOnboarding());
return manifest.getNonManoSources().entrySet().stream()
.filter(manifestNonManoSourceEntry -> NonManoArtifactType.ONAP_CNF_HELM.getType().equalsIgnoreCase(manifestNonManoSourceEntry.getKey()))
.findFirst().isPresent();
}
- private Manifest loadManifest(final FileContentHandler handler) throws IOException {
- final Manifest manifest;
- try {
- manifest = getManifest(handler);
- } catch (final IOException ex) {
- if (LOGGER.isErrorEnabled()) {
- LOGGER.error("An error occurred while getting the manifest file", ex);
- }
- throw ex;
- }
- return manifest;
- }
-
private boolean isMetaFilePresent(Map<String, byte[]> 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, getEntryManifestLocation(metadata));
+ ToscaMetadata metadata = manifestUtils.getMetadata(handler);
+ Manifest manifest = manifestUtils.getManifest(handler, manifestUtils.getEntryManifestLocation(metadata), new SOL004ManifestOnboarding());
return getResourceType(manifest);
}
@@ -265,43 +257,16 @@ public class ETSIServiceImpl implements ETSIService {
}
public Manifest getManifest(FileContentHandler handler) throws IOException {
- ToscaMetadata metadata = getMetadata(handler);
- return getManifest(handler, getEntryManifestLocation(metadata));
- }
-
- private String getEntryManifestLocation(final ToscaMetadata metadata) {
- return metadata.getMetaEntries().containsKey(ETSI_ENTRY_MANIFEST.getName()) ?
- metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()):
- metadata.getMetaEntries().get(ENTRY_MANIFEST.getName());
- }
-
- private Manifest getManifest(FileContentHandler handler, String manifestLocation) throws IOException {
- try (InputStream manifestInputStream = getManifestInputStream(handler, manifestLocation)) {
- Manifest onboardingManifest = new SOL004ManifestOnboarding();
- onboardingManifest.parse(manifestInputStream);
- return onboardingManifest;
- }
+ return manifestUtils.getManifest(handler, new SOL004ManifestOnboarding());
}
public Path getOriginalManifestPath(final FileContentHandler handler) throws IOException {
final ToscaMetadata metadata = getOriginalMetadata(handler);
- final String originalMetadataPath = getEntryManifestLocation(metadata);
+ final String originalMetadataPath = manifestUtils.getEntryManifestLocation(metadata);
final Path path = Paths.get(originalMetadataPath);
return path.getParent() == null ? Paths.get("") : path.getParent();
}
- private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException {
- ToscaMetadata metadata;
- if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) {
- metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
- } else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
- metadata = OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
- } else {
- throw new IOException("TOSCA.meta file not found!");
- }
- return metadata;
- }
-
private ToscaMetadata getOriginalMetadata(final FileContentHandler handler) throws IOException {
if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
return OnboardingToscaMetadata.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
@@ -310,19 +275,6 @@ public class ETSIServiceImpl implements ETSIService {
}
}
- private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException {
- InputStream io;
- if (manifestLocation == null || !handler.containsFile(manifestLocation)) {
- io = handler.getFileContentAsStream(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME);
- } else {
- io = handler.getFileContentAsStream(manifestLocation);
- }
- if (io == null) {
- throw new IOException("Manifest file not found!");
- }
- return io;
- }
-
public NonManoConfiguration getConfiguration() {
return nonManoConfiguration;
}
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 314db8f323..e7a5d56b3e 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
@@ -20,17 +20,20 @@
package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-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 com.vdurmont.semver4j.Semver;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.be.config.NonManoConfiguration;
+import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.ManifestUtils;
+import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
+import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.IOException;
@@ -47,23 +50,23 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.be.config.NonManoConfiguration;
-import org.openecomp.sdc.tosca.csar.Manifest;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import org.yaml.snakeyaml.Yaml;
-
-import com.vdurmont.semver4j.Semver;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+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;
public class ETSIServiceImplTest {
private ETSIService etsiService;
+ private ManifestUtils manifestUtils;
private String sol004MetaFile = "TOSCA-Meta-Version: 1.0\n" +
"CSAR-Version: 1.0\n" +
"Created-By: Kuku\n" +
@@ -77,14 +80,15 @@ public class ETSIServiceImplTest {
private String finalNonManoLocation = "Deployment/VES_EVENTS/test.xml";
- @Before
+ @BeforeEach
public void setUp() throws IOException {
final String fullFileName = Paths.get("src", "test", "resources", "nonManoConfig.yaml").toString();
final NonManoConfiguration configuration = convert(fullFileName, NonManoConfiguration.class);
- etsiService = Mockito.spy(new ETSIServiceImpl(configuration));
+ manifestUtils = Mockito.spy(new ManifestUtils());
+ etsiService = Mockito.spy(new ETSIServiceImpl(configuration, manifestUtils));
}
- @After
+ @AfterEach
public void tearDown() {
etsiService = null;
}
@@ -127,8 +131,10 @@ public class ETSIServiceImplTest {
fileContentHandler.addFile("Some/test.xml", new byte[1]);
fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", new byte[1]);
fileContentHandler.addFile("MainServiceTemplate.mf", new byte[1]);
+ doReturn(manifest).when(manifestUtils).loadManifest(fileContentHandler, new SOL004ManifestOnboarding());
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
assertThat("Should contain moved file", fileContentHandler.getFileList(), hasItem(finalNonManoLocation));
}
@@ -144,6 +150,7 @@ public class ETSIServiceImplTest {
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
when(manifest.getNonManoSources()).thenReturn(nonManoTypeAndSourceMapInManifest);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
assertThat("Should contain moved file", fileContentHandler.getFileList(), hasItem(finalNonManoLocation));
}
@@ -157,7 +164,9 @@ public class ETSIServiceImplTest {
FileContentHandler fileContentHandler = new FileContentHandler();
fileContentHandler.addFile("test.xml", new byte[1]);
Manifest manifest = mock(Manifest.class);
+ //Manifest manifest = etsiService.getManifest(fileContentHandler);
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
when(manifest.getNonManoSources()).thenReturn(nonManoSources);
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
@@ -177,6 +186,7 @@ public class ETSIServiceImplTest {
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
when(manifest.getNonManoSources()).thenReturn(nonManoSources);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
}
@@ -193,6 +203,7 @@ public class ETSIServiceImplTest {
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
when(manifest.getNonManoSources()).thenReturn(nonManoSources);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
}
@@ -216,6 +227,7 @@ public class ETSIServiceImplTest {
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("two/lvlFolder")).when(etsiService).getOriginalManifestPath(fileContentHandler);
when(manifest.getNonManoSources()).thenReturn(nonManoTypeAndSourceMapInManifest);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
//when files are non mano moved
etsiService.moveNonManoFileToArtifactFolder(fileContentHandler);
assertThat("Should contain moved file", fileContentHandler.getFileList(),
@@ -249,6 +261,7 @@ public class ETSIServiceImplTest {
when(manifest.getNonManoSources()).thenReturn(nonManoSourceMap);
doReturn(manifest).when(etsiService).getManifest(fileContentHandler);
doReturn(Paths.get("")).when(etsiService).getOriginalManifestPath(fileContentHandler);
+ doReturn(manifest).when(manifestUtils).loadManifest(any(FileContentHandler.class), any(SOL004ManifestOnboarding.class));
final Optional<Map<String, Path>> fromToPathMap = etsiService
.moveNonManoFileToArtifactFolder(fileContentHandler);
assertThat("Files should be moved", fromToPathMap.isPresent(), is(true));