summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main
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/openecomp-sdc-vendor-software-product-core/src/main
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/openecomp-sdc-vendor-software-product-core/src/main')
-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
1 files changed, 38 insertions, 86 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;
}