aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2021-12-14 15:09:50 +0000
committerMichael Morris <michael.morris@est.tech>2021-12-21 16:18:46 +0000
commit8c0c0d7dfe706b8a224368aa066cb5ba4616678c (patch)
treec3eaa48a3322b190ab34cf9c53a3a2e7c2d51577
parent04c4a2a3d7f308bdf6db8883fe16bbc3484f51b5 (diff)
Identify SOL004 packages
Issue-ID: SDC-3819 Signed-off-by: MichaelMorris <michael.morris@est.tech> Change-Id: I7ea36ebc27753e8068791cffc3340db30adc4662 Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java10
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java4
-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.java12
-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.java37
-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.java8
7 files changed, 61 insertions, 16 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index dfc4082b3c..1825dadf7f 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -549,7 +549,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
final FileContentHandler licenseArtifacts = licenseArtifactsService
.createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups());
final ETSIService etsiService = new ETSIServiceImpl();
- if (etsiService.isSol004WithToscaMetaDirectory(toscaServiceModel.getArtifactFiles())) {
+ if (etsiService.hasEtsiSol261Metadata(toscaServiceModel.getArtifactFiles())) {
final FileContentHandler handler = toscaServiceModel.getArtifactFiles();
final Manifest manifest = etsiService.getManifest(handler);
final Optional<Map<String, Path>> fromToMovedPaths = etsiService.moveNonManoFileToArtifactFolder(handler);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
index 91d2705693..d3ac455a56 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
@@ -48,8 +48,8 @@ public class ValidatorFactory {
*/
public Validator getValidator(final FileContentHandler fileContentHandler) throws IOException {
final ETSIService etsiService = new ETSIServiceImpl(null);
- if (!etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) {
- return new ONAPCsarValidator();
+ if (!etsiService.hasEtsiSol261Metadata(fileContentHandler)) {
+ return etsiService.isEtsiPackage(fileContentHandler) ? new EtsiSol004Version251Validator() : new ONAPCsarValidator();
}
if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler).isLowerThan(ETSI_VERSION_2_7_1)) {
if (etsiService.hasCnfEnhancements(fileContentHandler)) {
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
index 144c8fcf8c..08b4b26846 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
@@ -49,6 +49,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService;
import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl;
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
@@ -60,6 +61,11 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
private static final String EXT_SEPARATOR = ".";
private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface();
private final ToscaTreeManager toscaTreeManager = new ToscaTreeManager();
+ private final ETSIService etsiService;
+
+ public OrchestrationTemplateProcessCsarHandler() {
+ etsiService = new ETSIServiceImpl();
+ }
@Override
public OrchestrationTemplateActionResponse process(VspDetails vspDetails, OrchestrationTemplateCandidateData candidateData) {
@@ -118,7 +124,7 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
if (CollectionUtils.isNotEmpty(modelList)) {
return handleToscaModelConversion(modelList, fileContentHandler, candidateData);
}
- if (new ETSIServiceImpl().isSol004WithToscaMetaDirectory(fileContentHandler)) {
+ if (etsiService.isEtsiPackage(fileContentHandler)) {
return getToscaServiceModelSol004(fileContentHandler, candidateData);
}
return new ToscaConverterImpl().convert(fileContentHandler);
@@ -135,7 +141,7 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
private ToscaServiceModel getToscaServiceModelSol004(final FileContentHandler fileContentHandler,
final OrchestrationTemplateCandidateData candidateData) throws IOException {
addOriginalOnboardedPackage(fileContentHandler, candidateData);
- final ResourceTypeEnum resourceType = new ETSIServiceImpl().getResourceType(fileContentHandler);
+ final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler);
return instantiateToscaConverterFor(resourceType).convert(fileContentHandler);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
index 39a62deaa0..c603b7fa6d 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
@@ -76,7 +76,7 @@ class ValidatorFactoryTest {
@Test
void testGivenEmptyBlock0_thenONAPCsarValidatorIsReturned() throws IOException {
- handler.addFile(TOSCA_META_PATH_FILE_NAME, " ".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, "onap_csar: true".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
@@ -88,7 +88,7 @@ class ValidatorFactoryTest {
@Test
void testGivenNonSOL004MetaDirectoryCompliantMetaFile_thenONAPCSARValidatorIsReturned() throws IOException {
metaFile = metaFile +
- ENTRY_DEFINITIONS.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH;
+ ENTRY_DEFINITIONS.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH + "\nonap_csar: true";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
assertEquals(ONAPCsarValidator.class, validatorFactory.getValidator(handler).getClass());
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 dad05b64f2..de51b0bb2c 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
@@ -38,7 +38,16 @@ public interface ETSIService {
* @return true if all condition matched, false otherwise
* @throws IOException when TOSCA.meta file is invalid
*/
- boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) throws IOException;
+ boolean hasEtsiSol261Metadata(FileContentHandler handler) throws IOException;
+
+ /**
+ * Checks if the package is a ETSI package.
+ *
+ * @param fileContentHandler the CSAR file handler
+ * @return {@code true} if the package is a ETSI package, {@code false} otherwise.
+ * @throws IOException when it was not able to parse the TOSCA.meta file
+ */
+ boolean isEtsiPackage(final FileContentHandler fileContentHandler) throws IOException;
/**
* Update file structure. Moves non mano files to the correct folder based on the manifest non mano type.
@@ -96,4 +105,5 @@ public interface ETSIService {
* @return true if manifest files has onap_cnf_helm non mano entry
*/
boolean hasCnfEnhancements(final FileContentHandler fileContentHandler) throws IOException;
+
}
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 c5e7fcd03d..1399ea9765 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
@@ -25,6 +25,7 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_M
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;
@@ -52,6 +53,7 @@ import org.openecomp.sdc.be.config.NonManoConfiguration;
import org.openecomp.sdc.be.config.NonManoConfigurationManager;
import org.openecomp.sdc.be.config.NonManoFolderType;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+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;
@@ -64,6 +66,7 @@ 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";
public ETSIServiceImpl() {
nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration();
@@ -74,12 +77,31 @@ public class ETSIServiceImpl implements ETSIService {
}
@Override
- public boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) throws IOException {
+ public boolean hasEtsiSol261Metadata(FileContentHandler handler) throws IOException {
final Map<String, byte[]> templates = handler.getFiles();
return isMetaFilePresent(templates) && hasMetaMandatoryEntries(getMetadata(handler));
}
@Override
+ public boolean isEtsiPackage(final FileContentHandler fileContentHandler) throws IOException {
+ return hasEtsiSol261Metadata(fileContentHandler) || !hasOnapCsarMetadata(fileContentHandler)
+ && !ONAP_CSAR.equalsIgnoreCase(getDefaultCsarFormat());
+ }
+
+ private boolean hasOnapCsarMetadata(final FileContentHandler fileContentHandler) throws IOException {
+ if (fileContentHandler.containsFile(TOSCA_META_PATH_FILE_NAME)){
+ final ToscaMetadata metadata =
+ OnboardingToscaMetadata.parseToscaMetadataFile(fileContentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
+ return metadata.hasEntry(ONAP_CSAR);
+ }
+ return false;
+ }
+
+ private String getDefaultCsarFormat() {
+ return CommonConfigurationManager.getInstance().getConfigValue("csarFormat", "default", ONAP_CSAR);
+ }
+
+ @Override
public Optional<Map<String, Path>> moveNonManoFileToArtifactFolder(final FileContentHandler handler) throws IOException {
final Manifest manifest = loadManifest(handler);
final Path originalManifestPath;
@@ -226,7 +248,7 @@ public class ETSIServiceImpl implements ETSIService {
public ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
+ Manifest manifest = getManifest(handler, getEntryManifestLocation(metadata));
return getResourceType(manifest);
}
@@ -244,7 +266,13 @@ public class ETSIServiceImpl implements ETSIService {
public Manifest getManifest(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- return getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
+ 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 {
@@ -257,7 +285,7 @@ public class ETSIServiceImpl implements ETSIService {
public Path getOriginalManifestPath(final FileContentHandler handler) throws IOException {
final ToscaMetadata metadata = getOriginalMetadata(handler);
- final String originalMetadataPath = metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName());
+ final String originalMetadataPath = getEntryManifestLocation(metadata);
final Path path = Paths.get(originalMetadataPath);
return path.getParent() == null ? Paths.get("") : path.getParent();
}
@@ -298,4 +326,5 @@ public class ETSIServiceImpl implements ETSIService {
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 4254a56dcb..314db8f323 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
@@ -94,27 +94,27 @@ public class ETSIServiceImplTest {
FileContentHandler fileContentHandler = new FileContentHandler();
fileContentHandler
.addFile("TOSCA-Metadata/TOSCA.meta.original", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
- assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
+ assertTrue(etsiService.hasEtsiSol261Metadata(fileContentHandler));
}
@Test
public void testIsSol004True() throws IOException {
FileContentHandler fileContentHandler = new FileContentHandler();
fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
- assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
+ assertTrue(etsiService.hasEtsiSol261Metadata(fileContentHandler));
}
@Test
public void testIsSol004False() throws IOException {
FileContentHandler fileContentHandler = new FileContentHandler();
fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", metaFile.getBytes(StandardCharsets.UTF_8));
- assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
+ assertFalse(etsiService.hasEtsiSol261Metadata(fileContentHandler));
}
@Test
public void testIsSol004FalseWithNull() throws IOException {
FileContentHandler fileContentHandler = new FileContentHandler();
- assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
+ assertFalse(etsiService.hasEtsiSol261Metadata(fileContentHandler));
}
@Test