summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-02-05 13:12:57 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-02-20 07:12:05 +0000
commitb1660e1be36e1f6572253f871dd5defa4030c98a (patch)
treecc856617ca244e651b139b4d61b7e7057b52dcb8 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
parent372c2470e613128f1e33cfc581ea2c5b1b732d2b (diff)
Add new SOL004 validator
New validator for onboarding SOL 004 version 3.3.1 Issue-ID: SDC-2611 Signed-off-by: davsad <david.sadlier@est.tech> Change-Id: I4f41d2fbd913011f42a8319a6594c973c735d2a0
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java41
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java93
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java16
3 files changed, 131 insertions, 19 deletions
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 6107383485..5f81910417 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
@@ -55,8 +55,9 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
-
import java.util.stream.Stream;
+
+import com.google.common.collect.ImmutableSet;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openecomp.core.impl.ToscaDefinitionImportHandler;
@@ -257,13 +258,12 @@ class SOL004MetaDirectoryValidator implements Validator {
validateCertificate(value);
break;
default:
- reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(key));
- LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), key);
+ handleOtherEntry(entry);
break;
}
}
- private void validateOtherEntries(final Map.Entry entry) {
+ private void validateOtherEntries(final Map.Entry<String, String> entry) {
final String manifestFile = toscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName());
if (verifyFileExists(contentHandler.getFileList(), manifestFile)) {
final Manifest onboardingManifest = new SOL004ManifestOnboarding();
@@ -299,7 +299,7 @@ class SOL004MetaDirectoryValidator implements Validator {
|| CSAR_VERSION_1_0.equals(version));
}
- private void validateDefinitionFile(final String filePath) {
+ protected void validateDefinitionFile(final String filePath) {
final Set<String> existingFiles = contentHandler.getFileList();
if (verifyFileExists(existingFiles, filePath)) {
@@ -341,19 +341,15 @@ class SOL004MetaDirectoryValidator implements Validator {
}
private void verifyManifestMetadata(final Map<String, String> metadata) {
- if (metadata.size() != MANIFEST_METADATA_LIMIT) {
+ if (!validMetaLimit(metadata)) {
reportError(ErrorLevel.ERROR,
String.format(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT.getErrorMessage(),
MANIFEST_METADATA_LIMIT));
}
- if (isPnfMetadata(metadata)) {
- handleMetadataEntries(metadata, MANIFEST_PNF_METADATA);
- } else {
- handleMetadataEntries(metadata, MANIFEST_VNF_METADATA);
- }
+ handleMetadataEntries(metadata);
}
- private boolean isPnfMetadata(final Map<String, String> metadata) {
+ protected boolean isPnfMetadata(final Map<String, String> metadata) {
final String firstMetadataDefinition = metadata.keySet().iterator().next();
final String expectedMetadataType =
firstMetadataDefinition.contains(TOSCA_TYPE_PNF) ? TOSCA_TYPE_PNF : TOSCA_TYPE_VNF;
@@ -365,12 +361,12 @@ class SOL004MetaDirectoryValidator implements Validator {
return TOSCA_TYPE_PNF.equals(expectedMetadataType);
}
- private void handleMetadataEntries(final Map<String, String> metadata, final Set<String> manifestMetadata) {
- manifestMetadata.stream()
+ private void handleMetadataEntries(final Map<String, String> metadata) {
+ getManifestMetadata(metadata).stream()
.filter(requiredEntry -> !metadata.containsKey(requiredEntry))
.forEach(requiredEntry ->
reportError(ErrorLevel.ERROR,
- String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
+ String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
}
/**
@@ -524,10 +520,23 @@ class SOL004MetaDirectoryValidator implements Validator {
}
}
- private void reportError(final ErrorLevel errorLevel, final String errorMessage) {
+ protected void reportError(final ErrorLevel errorLevel, final String errorMessage) {
errorsByFile.add(new ErrorMessage(errorLevel, errorMessage));
}
+ protected boolean validMetaLimit(Map<String, String> metadata) {
+ return metadata.size() == MANIFEST_METADATA_LIMIT;
+ }
+
+ protected ImmutableSet<String> getManifestMetadata(final Map<String, String> metadata) {
+ return isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA : MANIFEST_VNF_METADATA;
+ }
+
+ protected void handleOtherEntry(final Map.Entry<String, String> entry) {
+ reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(entry.getKey()));
+ LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry.getKey());
+ }
+
private Map<String, List<ErrorMessage>> getAnyValidationErrors() {
if (errorsByFile.isEmpty()) {
return Collections.emptyMap();
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
new file mode 100644
index 0000000000..473d68e49a
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidator.java
@@ -0,0 +1,93 @@
+/*-
+ * ============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 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.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.
+ */
+class SOL004Version3MetaDirectoryValidator extends SOL004MetaDirectoryValidator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SOL004Version3MetaDirectoryValidator.class);
+
+ public SOL004Version3MetaDirectoryValidator() {
+ super();
+ }
+
+ SOL004Version3MetaDirectoryValidator(final SecurityManager securityManager) {
+ super(securityManager);
+ }
+
+ @Override
+ protected void handleOtherEntry(final Map.Entry<String, String> 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());
+ }
+
+ @Override
+ protected boolean validMetaLimit(Map<String, String> metadata) {
+ int maxAllowedEntries = isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3;
+ return metadata.size() == maxAllowedEntries;
+ }
+
+ @Override
+ protected ImmutableSet<String> getManifestMetadata(final Map<String, String> metadata) {
+ return isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_VERSION_3 : MANIFEST_VNF_METADATA_VERSION_3;
+ }
+
+ @Override
+ protected boolean isPnfMetadata(final Map<String, String> metadata) {
+ List<String> 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);
+ }
+}
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 064a1c66ab..38c28f88ec 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
@@ -20,10 +20,13 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+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;
-import java.io.IOException;
public class ValidatorFactory {
@@ -39,7 +42,14 @@ public class ValidatorFactory {
* @throws IOException when metafile is invalid
*/
public static Validator getValidator(final FileContentHandler fileContentHandler) throws IOException {
- ETSIService etsiService = new ETSIServiceImpl(null);
- return etsiService.isSol004WithToscaMetaDirectory(fileContentHandler) ? new SOL004MetaDirectoryValidator() : new ONAPCsarValidator();
+ final ETSIService etsiService = new ETSIServiceImpl(null);
+ if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) {
+ if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler)
+ .isLowerThan(ETSI_VERSION_2_7_1)){
+ return new SOL004Version3MetaDirectoryValidator();
+ }
+ return new SOL004MetaDirectoryValidator();
+ }
+ return new ONAPCsarValidator();
}
}