From: aribeiro Date: Mon, 8 Feb 2021 14:41:39 +0000 (+0000) Subject: Add new SOL004 ETSI Validator X-Git-Tag: 1.8.2~10 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=1e12c6b9b28c49ed02ab8d2f156a6cf52cc305d7;p=sdc.git Add new SOL004 ETSI Validator Support for onboarding ETSI v3.3.1 SOL004 VNF CSAR Packages with minimum CNF enhancements from 4.1.1 Issue-ID: SDC-3337 Signed-off-by: aribeiro Change-Id: I0fefb43b8462133ae82d10418c79f9e2b126defb --- diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java index 8f35b60bf8..02dcb3591b 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoArtifactType.java @@ -37,7 +37,8 @@ public enum NonManoArtifactType { ONAP_ANSIBLE_PLAYBOOKS("onap_ansible_playbooks"), ONAP_SCRIPTS("onap_scripts"), ONAP_OTHERS("onap_others"), - ONAP_SW_INFORMATION("onap_pnf_sw_information"); + ONAP_SW_INFORMATION("onap_pnf_sw_information"), + ONAP_CNF_HELM("onap_cnf_helm"); private final String type; diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java index 93d09a2e7a..2b2602240a 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoConfiguration.java @@ -19,9 +19,13 @@ package org.openecomp.sdc.be.config; +import java.util.Collections; +import java.util.Map.Entry; +import java.util.stream.Collectors; import lombok.Data; import java.util.Map; +import org.apache.commons.collections.MapUtils; /** * Represents the non-mano configuration yaml. @@ -39,4 +43,14 @@ public class NonManoConfiguration { public NonManoFolderType getNonManoType(final NonManoArtifactType nonManoArtifactType) { return nonManoKeyFolderMapping.get(nonManoArtifactType.getType()); } + + public Map getNonManoKeyFolderMapping() { + if (MapUtils.isEmpty(nonManoKeyFolderMapping)) { + return Collections.emptyMap(); + } + + return nonManoKeyFolderMapping.entrySet().stream() + .filter(entry -> entry.getValue().isValid()) + .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + } } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java index 4d815e3f57..4ad6c31fd5 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/config/NonManoFolderType.java @@ -19,6 +19,7 @@ package org.openecomp.sdc.be.config; import lombok.Data; +import org.apache.commons.lang.StringUtils; @Data public class NonManoFolderType { @@ -32,4 +33,9 @@ public class NonManoFolderType { public String getPath() { return String.format("Artifacts/%s/%s", type, location); } + + + public boolean isValid() { + return StringUtils.isNotBlank(location) && StringUtils.isNotBlank(type); + } } diff --git a/common-be/src/main/resources/config/nonManoConfig.yaml b/common-be/src/main/resources/config/nonManoConfig.yaml index 4ace330392..04485a4b11 100644 --- a/common-be/src/main/resources/config/nonManoConfig.yaml +++ b/common-be/src/main/resources/config/nonManoConfig.yaml @@ -19,4 +19,7 @@ nonManoKeyFolderMapping: type: Informational onap_pnf_sw_information: location: PNF_SW_INFORMATION - type: Informational \ No newline at end of file + type: Informational + onap_cnf_helm: + location: + type: diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java index 5f81910417..22ab4f45a6 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; +import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_CNF_HELM; import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_PM_DICTIONARY; import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_SW_INFORMATION; import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_VES_EVENTS; @@ -81,6 +82,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackage import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.exception.MissingCertificateException; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils.FileExtractor; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils.InternalFilesFilter; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils.ValidatorUtils; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.InvalidManifestMetadataException; import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException; @@ -102,6 +104,7 @@ class SOL004MetaDirectoryValidator implements Validator { private Set folderList; private ToscaMetadata toscaMetadata; private final InternalFilesFilter internalFilesFilter = new InternalFilesFilter(); + protected final ValidatorUtils validatorUtils = new ValidatorUtils(); public SOL004MetaDirectoryValidator() { securityManager = SecurityManager.getInstance(); @@ -122,7 +125,7 @@ class SOL004MetaDirectoryValidator implements Validator { if (packageHasCertificate()) { verifySignedFiles(); } - validatePMDictionaryContentsAgainstSchema(); + validatePmDictionaryContentsAgainstSchema(); return Collections.unmodifiableMap(getAnyValidationErrors()); } @@ -390,6 +393,8 @@ class SOL004MetaDirectoryValidator implements Validator { internalNonManoFileList.forEach(this::validateYaml); } else if (nonManoArtifactType == ONAP_SW_INFORMATION) { validateSoftwareInformationNonManoArtifact(files); + } else if (nonManoArtifactType == ONAP_CNF_HELM) { + validateOnapCnfHelmNonManoEntry(files); } }); @@ -546,7 +551,7 @@ class SOL004MetaDirectoryValidator implements Validator { return errors; } - private void validatePMDictionaryContentsAgainstSchema() { + private void validatePmDictionaryContentsAgainstSchema() { final Stream pmDictionaryFiles = new FileExtractor(getEtsiEntryManifestPath(), contentHandler) .findFiles(ONAP_PM_DICTIONARY); new PMDictionaryValidator() @@ -556,4 +561,22 @@ class SOL004MetaDirectoryValidator implements Validator { private String getEtsiEntryManifestPath() { return toscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()); } + + /** + * Validates if onap_cnf_helm non_mano type points to a file + * @param files + */ + private void validateOnapCnfHelmNonManoEntry(final List files) { + if (CollectionUtils.isEmpty(files)) { + reportError(ErrorLevel.ERROR, Messages.EMPTY_ONAP_CNF_HELM_NON_MANO_ERROR.getErrorMessage()); + return; + } + if (files.size() != 1) { + final String formattedFileList = files.stream() + .map(filePath -> String.format("'%s'", filePath)) + .collect(Collectors.joining(", ")); + reportError(ErrorLevel.ERROR, + Messages.UNIQUE_ONAP_CNF_HELM_NON_MANO_ERROR.formatMessage(formattedFileList)); + } + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java index 473d68e49a..9e380a355c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java @@ -23,24 +23,18 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_L import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_VERSION_3; import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_LIMIT_VERSION_3; import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_VERSION_3; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_PNF; -import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_VNF; -import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS; +import com.google.common.collect.ImmutableSet; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.csar.ToscaMetaEntry; -import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.InvalidManifestMetadataException; import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; -import com.google.common.collect.ImmutableSet; - /** * Validates the contents of the package to ensure it complies with the "CSAR with TOSCA-Metadata directory" structure * as defined in ETSI GS NFV-SOL 004 v3.3.1. @@ -81,13 +75,6 @@ class SOL004Version3MetaDirectoryValidator extends SOL004MetaDirectoryValidator protected boolean isPnfMetadata(final Map metadata) { List keys = metadata.keySet().stream().collect(Collectors.toList()); //Both VNF and PNF share this attribute - keys.remove(COMPATIBLE_SPECIFICATION_VERSIONS.getToken()); - final String expectedMetadataType = - keys.get(0).contains(TOSCA_TYPE_PNF) ? TOSCA_TYPE_PNF : TOSCA_TYPE_VNF; - if (keys.stream() - .anyMatch(k -> !k.contains(expectedMetadataType))) { - throw new InvalidManifestMetadataException(Messages.MANIFEST_METADATA_INVALID_ENTRY.getErrorMessage()); - } - return expectedMetadataType.equals(TOSCA_TYPE_PNF); + return validatorUtils.isPnfMetadata(keys); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidator.java new file mode 100644 index 0000000000..701abfc677 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidator.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; + +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_LIMIT_VERSION_3; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_VERSION_3; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_LIMIT_VERSION_3; +import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_VERSION_3; + +import com.google.common.collect.ImmutableSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.tosca.csar.ToscaMetaEntry; +import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; + +/** + * Validates the contents of the package to ensure it complies with the "CSAR with TOSCA-Metadata directory" structure + * as defined in ETSI GS NFV-SOL 004 v3.3.1 with CNF Enhancements from ETSI GS NFV-SOL 004 v4.1.1 + */ +class SOL004Version4MetaDirectoryValidator extends SOL004MetaDirectoryValidator { + + private static final Logger LOGGER = LoggerFactory.getLogger(SOL004Version4MetaDirectoryValidator.class); + + public SOL004Version4MetaDirectoryValidator() { + super(); + } + + SOL004Version4MetaDirectoryValidator(final SecurityManager securityManager) { + super(securityManager); + } + + @Override + protected boolean validMetaLimit(Map metadata) { + int maxAllowedEntries = isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3; + return metadata.size() == maxAllowedEntries; + } + + @Override + protected ImmutableSet getManifestMetadata(final Map metadata) { + return isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_VERSION_3 : MANIFEST_VNF_METADATA_VERSION_3; + } + + @Override + protected boolean isPnfMetadata(final Map metadata) { + final List keys = metadata.keySet().stream().collect(Collectors.toList()); + //Both VNF and PNF share this attribute + return validatorUtils.isPnfMetadata(keys); + } + + @Override + protected void handleOtherEntry(final Map.Entry entry) { + if (!ToscaMetaEntry.OTHER_DEFINITIONS.getName().equals(entry.getKey())) { + reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(entry.getKey())); + LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry.getKey()); + } else { + validateDefinitionFile(entry.getValue()); + } + } + +} 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 38c28f88ec..9d218190d8 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 @@ -23,7 +23,6 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validati import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_7_1; import java.io.IOException; - import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl; @@ -43,13 +42,15 @@ public class ValidatorFactory { */ public static Validator getValidator(final FileContentHandler fileContentHandler) throws IOException { final ETSIService etsiService = new ETSIServiceImpl(null); - if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { - if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler) - .isLowerThan(ETSI_VERSION_2_7_1)){ - return new SOL004Version3MetaDirectoryValidator(); + if (!etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { + return new ONAPCsarValidator(); + } + if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler).isLowerThan(ETSI_VERSION_2_7_1)){ + if (etsiService.hasCnfEnhancements(fileContentHandler)) { + return new SOL004Version4MetaDirectoryValidator(); } - return new SOL004MetaDirectoryValidator(); + return new SOL004Version3MetaDirectoryValidator(); } - return new ONAPCsarValidator(); + return new SOL004MetaDirectoryValidator(); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/ValidatorUtils.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/ValidatorUtils.java new file mode 100644 index 0000000000..cfdd53774f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/ValidatorUtils.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils; + +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_PNF; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_VNF; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS; + +import java.util.List; +import java.util.stream.Collectors; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.InvalidManifestMetadataException; + +public class ValidatorUtils { + + public boolean isPnfMetadata(List keys) { + keys = keys.stream().filter(key -> !COMPATIBLE_SPECIFICATION_VERSIONS.getToken().equals(key)) + .collect(Collectors.toList()); + final String expectedMetadataType = + keys.get(0).contains(TOSCA_TYPE_PNF) ? TOSCA_TYPE_PNF : TOSCA_TYPE_VNF; + if (keys.stream() + .anyMatch(k -> !k.startsWith(expectedMetadataType))) { + throw new InvalidManifestMetadataException(Messages.MANIFEST_METADATA_INVALID_ENTRY.getErrorMessage()); + } + return expectedMetadataType.equals(TOSCA_TYPE_PNF); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java index b91a1156ce..e966a12b65 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java @@ -36,8 +36,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.tosca.csar.Manifest; import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; @@ -45,7 +45,7 @@ public class ManifestBuilderTest { private ManifestBuilder manifestBuilder; - @Before + @BeforeEach public void setUp() { manifestBuilder = new ManifestBuilder(); } @@ -162,4 +162,4 @@ public class ManifestBuilderTest { private void mockManifestSource() { manifestBuilder.withSource("/test.yaml"); } -} \ No newline at end of file +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java index 15a7d6c9f9..c3c220079b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java @@ -26,8 +26,8 @@ import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceByt import java.io.IOException; import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -38,7 +38,7 @@ public class ONAPCsarValidatorTest { private ONAPCsarValidator onapCsarValidator; private FileContentHandler contentHandler; - @Before + @BeforeEach public void setUp() throws IOException{ onapCsarValidator = new ONAPCsarValidator(); contentHandler = new FileContentHandler(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java index 9461648d2e..2053373dce 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java @@ -61,6 +61,7 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH; import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; @@ -68,10 +69,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.commons.collections.CollectionUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -89,7 +89,7 @@ public class SOL004MetaDirectoryValidatorTest { protected OnboardingPackageContentHandler handler; protected StringBuilder metaFileBuilder; - @Before + @BeforeEach public void setUp() { sol004MetaDirectoryValidator = getSOL004MetaDirectoryValidator(); handler = new OnboardingPackageContentHandler(); @@ -140,7 +140,7 @@ public class SOL004MetaDirectoryValidatorTest { * ETSI Version 2.7.1 below contains one Definition File reference * ETSI Version 2.7.1 onwards contains two possible Definition File reference */ - protected int getManifestDefintionErrorCount() { + protected int getManifestDefinitionErrorCount() { return MANIFEST_DEFINITION_ERROR_COUNT; } @@ -259,7 +259,7 @@ public class SOL004MetaDirectoryValidatorTest { final Map> errors = sol004MetaDirectoryValidator.validateContent(handler); assertThat("Total of errors should be as expected", errors.size(), is(1)); final List errorMessages = errors.get(SdcCommon.UPLOAD_FILE); - assertThat("Total of errors messages should be as expected", errorMessages.size(), is((2 + getManifestDefintionErrorCount()))); + assertThat("Total of errors messages should be as expected", errorMessages.size(), is((2 + getManifestDefinitionErrorCount()))); } @@ -349,7 +349,7 @@ public class SOL004MetaDirectoryValidatorTest { handler.addFile(TOSCA_MANIFEST_FILEPATH, manifest.getBytes(StandardCharsets.UTF_8)); final Map> errors = sol004MetaDirectoryValidator.validateContent(handler); - assertExpectedErrors("", errors, getManifestDefintionErrorCount()); + assertExpectedErrors("", errors, getManifestDefinitionErrorCount()); } /** @@ -379,7 +379,7 @@ public class SOL004MetaDirectoryValidatorTest { handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8)); final Map> errors = sol004MetaDirectoryValidator.validateContent(handler); - assertExpectedErrors("Manifest referenced import file missing", errors, getManifestDefintionErrorCount()); + assertExpectedErrors("Manifest referenced import file missing", errors, getManifestDefinitionErrorCount()); } @Test @@ -461,11 +461,11 @@ public class SOL004MetaDirectoryValidatorTest { handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8)); final Map> errors = sol004MetaDirectoryValidator.validateContent(handler); - assertExpectedErrors("Reference with invalid YAML format", errors, getManifestDefintionErrorCount()); + assertExpectedErrors("Reference with invalid YAML format", errors, getManifestDefinitionErrorCount()); } @Test - public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() { + public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException { final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); @@ -498,7 +498,7 @@ public class SOL004MetaDirectoryValidatorTest { * Manifest with non existent source files should return error. */ @Test - public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() { + public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException { final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); //non existent reference manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml"); @@ -862,7 +862,7 @@ public class SOL004MetaDirectoryValidatorTest { final Map> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler); final List expectedErrorList = new ArrayList<>(); - for (int i =0;i < getManifestDefintionErrorCount();i++) + for (int i =0;i < getManifestDefinitionErrorCount();i++) expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR , Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml")) ); @@ -901,7 +901,7 @@ public class SOL004MetaDirectoryValidatorTest { final Map> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler); final List expectedErrorList = new ArrayList<>(); - for (int i =0;i < getManifestDefintionErrorCount();i++) + for (int i =0;i < getManifestDefinitionErrorCount();i++) expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR , Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null")) ); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java index 02ea3f2af3..75047aa2f0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java @@ -61,7 +61,7 @@ public class SOL004Version3MetaDirectoryValidatorTest extends SOL004MetaDirector } @Override - protected int getManifestDefintionErrorCount() { + protected int getManifestDefinitionErrorCount() { return MANIFEST_DEFINITION_ERROR_COUNT_VERSION_3; } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java new file mode 100644 index 0000000000..ee62f91226 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; + +import static org.junit.Assert.assertEquals; +import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_CNF_HELM; +import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail; +import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.OTHER_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_FILE_PATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_IMPORT_FILE_PATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_SOURCE; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.tosca.csar.ManifestTokenType; +import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; + +public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirectoryValidatorTest { + + private static int manifestDefinitionErrorCountVersion4 = 2; + + @Override + public SOL004MetaDirectoryValidator getSOL004MetaDirectoryValidator() { + return new SOL004Version4MetaDirectoryValidator(); + } + + @Override + public StringBuilder getMetaFileBuilder() { + return super.getMetaFileBuilder().append(OTHER_DEFINITIONS.getName()) + .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n"); + } + + @Override + protected SOL004MetaDirectoryValidator getSol004WithSecurity(SecurityManager securityManagerMock) { + return new SOL004Version4MetaDirectoryValidator(securityManagerMock); + } + + @Override + protected ManifestBuilder getVnfManifestSampleBuilder() { + return super.getVnfManifestSampleBuilder() + .withMetaData(ManifestTokenType.VNF_SOFTWARE_VERSION.getToken(), "1.0.0") + .withMetaData(ManifestTokenType.VNFD_ID.getToken(), "2116fd24-83f2-416b-bf3c-ca1964793aca") + .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1") + .withMetaData(ManifestTokenType.VNF_PROVIDER_ID.getToken(), "ACME") + .withMetaData(ManifestTokenType.VNF_RELEASE_DATE_TIME.getToken(), "2021-02-11T11:25:00+00:00") + .withMetaData(ManifestTokenType.VNF_PACKAGE_VERSION.getToken(), "1.0") + .withMetaData(ManifestTokenType.VNFM_INFO.getToken(), "etsivnfm:v2.3.1,0:myGreatVnfm-1") + .withMetaData(ManifestTokenType.VNF_PRODUCT_NAME.getToken(), "RadioNode"); + } + + @Override + protected ManifestBuilder getPnfManifestSampleBuilder() { + return super.getPnfManifestSampleBuilder() + .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1"); + } + + @Override + protected int getManifestDefinitionErrorCount() { + return manifestDefinitionErrorCountVersion4; + } + + @Test + public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder(); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_SOURCE, "".getBytes()); + manifestBuilder.withSource(SAMPLE_SOURCE); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml"; + handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml")); + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8)); + + final Validator validator = ValidatorFactory.getValidator(handler); + final Map> errors = validator.validateContent(handler); + assertEquals(0, errors.size()); + + + } + + @Test + public void testGivenManifestFile_withNotReferencedNonManoSources_thenErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder(); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_SOURCE, "".getBytes()); + manifestBuilder.withSource(SAMPLE_SOURCE); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + //non existent reference + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), "validation.files/notReferencedFile.yaml"); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8)); + + final Validator validator = ValidatorFactory.getValidator(handler); + final Map> errors = validator.validateContent(handler); + assertExpectedErrors("Non-MANO file does not exist", errors, 1); + } + + @Test + public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); + //non existent reference + manifestBuilder.withSource("Artifacts/Deployment/non-mano/RadioNode.yaml"); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes()); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml"; + handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml")); + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8)); + + final Validator validator = ValidatorFactory.getValidator(handler); + final Map> errors = validator.validateContent(handler); + assertExpectedErrors("Manifest with non existent source files", errors, 1); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml new file mode 100644 index 0000000000..08b7c2d1ad --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml @@ -0,0 +1,3 @@ +description: "ONAP CNF Helm Test Sample" +provider: "Ericsson" +version: "1.0" diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java index ab088a4dda..d9186bc3b2 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java @@ -92,6 +92,10 @@ public enum Messages { INCORRECT_SW_INFORMATION_NON_MANO_ERROR( "Incorrect software information non-mano artifact. The software version information is missing " + "or it has one or more incorrect software version entries: '%s'"), + EMPTY_ONAP_CNF_HELM_NON_MANO_ERROR( + "Non-mano onap_cnf_helm artifact was declared in the manifest, but not provided"), + UNIQUE_ONAP_CNF_HELM_NON_MANO_ERROR("Only one onap_cnf_helm non-mano artifact is allowed. " + + "Found %s."), FAILED_TO_VALIDATE_METADATA("Failed to validate metadata file"), ARTIFACT_INVALID_SIGNATURE("Invalid signature '%s' provided for artifact '%s'"), ARTIFACT_SIGNATURE_VALIDATION_ERROR( 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 7332505b25..8b56b3fbc0 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 @@ -92,4 +92,10 @@ public interface ETSIService { * @return Semver representing highest compatible specification version */ Semver getHighestCompatibleSpecificationVersion(final FileContentHandler handler); + + /** + * Verifies if SOL004 3.3.1 manifest file has onap_cnf_helm non mano entry + * @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 8ec76fe14b..951cfc7d1f 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 @@ -21,6 +21,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; @@ -29,8 +30,8 @@ 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 com.vdurmont.semver4j.Semver; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; @@ -42,11 +43,11 @@ 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; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.be.config.NonManoArtifactType; import org.openecomp.sdc.be.config.NonManoConfiguration; import org.openecomp.sdc.be.config.NonManoConfigurationManager; import org.openecomp.sdc.be.config.NonManoFolderType; @@ -59,8 +60,6 @@ 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); @@ -83,15 +82,7 @@ public class ETSIServiceImpl implements ETSIService { @Override public Optional> moveNonManoFileToArtifactFolder(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; - } + final Manifest manifest = loadManifest(handler); final Path originalManifestPath; try { originalManifestPath = getOriginalManifestPath(handler); @@ -224,6 +215,27 @@ public class ETSIServiceImpl implements ETSIService { } + @Override + public boolean hasCnfEnhancements(final FileContentHandler fileContentHandler) throws IOException { + final Manifest manifest = loadManifest(fileContentHandler); + 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 handler) { return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME); }