summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
diff options
context:
space:
mode:
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/OrchestrationTemplateCSARHandler.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java68
3 files changed, 61 insertions, 11 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
index 16f12bb44d..94638a5876 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
@@ -117,7 +117,7 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
originalOnboardPackage.getFileExtension(),
originalOnboardPackage.getFileContent()));
} catch (final Exception exception) {
- logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
+ logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(),
getHandlerType().toString()), exception);
uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
new ErrorMessage(ErrorLevel.ERROR, exception.getMessage()));
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
index 056f1a4478..3e54260e8b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
@@ -63,7 +63,7 @@ public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHa
candidateService
.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
} catch (final Exception exception) {
- logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
+ logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(),
getHandlerType().toString()), exception);
uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
new ErrorMessage(ErrorLevel.ERROR, exception.getMessage()));
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 b0b8971e71..8a297142b6 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
@@ -22,6 +22,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validati
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;
import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_0;
import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_1;
@@ -56,6 +57,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openecomp.core.impl.ToscaDefinitionImportHandler;
import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.be.config.NonManoArtifactType;
+import org.openecomp.sdc.be.csar.pnf.PnfSoftwareInformation;
+import org.openecomp.sdc.be.csar.pnf.SoftwareInformationArtifactYamlParser;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.utils.SdcCommon;
@@ -86,11 +90,20 @@ class SOL004MetaDirectoryValidator implements Validator {
private static final String MANIFEST_SOURCE = "Source";
private static final String MANIFEST_NON_MANO_SOURCE = "Non-MANO Source";
private final List<ErrorMessage> errorsByFile = new CopyOnWriteArrayList<>();
- private final SecurityManager securityManager = SecurityManager.getInstance();
+ private final SecurityManager securityManager;
private OnboardingPackageContentHandler contentHandler;
private Set<String> folderList;
private ToscaMetadata toscaMetadata;
+ public SOL004MetaDirectoryValidator() {
+ securityManager = SecurityManager.getInstance();
+ }
+
+ //for tests purpose
+ SOL004MetaDirectoryValidator(final SecurityManager securityManager) {
+ this.securityManager = securityManager;
+ }
+
@Override
public Map<String, List<ErrorMessage>> validateContent(final FileContentHandler fileContentHandler) {
this.contentHandler = (OnboardingPackageContentHandler) fileContentHandler;
@@ -369,8 +382,11 @@ class SOL004MetaDirectoryValidator implements Validator {
nonManoArtifacts.forEach((nonManoType, files) -> {
final List<String> internalNonManoFileList = filterSources(files);
nonManoValidFilePaths.addAll(internalNonManoFileList);
- if (ONAP_PM_DICTIONARY.getType().equals(nonManoType) || ONAP_VES_EVENTS.getType().equals(nonManoType)) {
+ final NonManoArtifactType nonManoArtifactType = NonManoArtifactType.parse(nonManoType).orElse(null);
+ if (nonManoArtifactType == ONAP_PM_DICTIONARY || nonManoArtifactType == ONAP_VES_EVENTS) {
internalNonManoFileList.forEach(this::validateYaml);
+ } else if (nonManoArtifactType == ONAP_SW_INFORMATION) {
+ validateSoftwareInformationNonManoArtifact(files);
}
});
@@ -382,6 +398,35 @@ class SOL004MetaDirectoryValidator implements Validator {
verifyFilesBeingReferred(allReferredFiles, packageFiles);
}
+ private void validateSoftwareInformationNonManoArtifact(final List<String> files) {
+ if (CollectionUtils.isEmpty(files)) {
+ reportError(ErrorLevel.ERROR, Messages.EMPTY_SW_INFORMATION_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_SW_INFORMATION_NON_MANO_ERROR.formatMessage(formattedFileList));
+ return;
+ }
+ final String swInformationFilePath = files.get(0);
+ final byte[] swInformationYaml = contentHandler.getFileContent(swInformationFilePath);
+ final Optional<PnfSoftwareInformation> parsedYaml = SoftwareInformationArtifactYamlParser
+ .parse(swInformationYaml);
+ if(!parsedYaml.isPresent()) {
+ reportError(ErrorLevel.ERROR,
+ Messages.INVALID_SW_INFORMATION_NON_MANO_ERROR.formatMessage(swInformationFilePath));
+ } else {
+ final PnfSoftwareInformation pnfSoftwareInformation = parsedYaml.get();
+ if (!pnfSoftwareInformation.isValid()) {
+ reportError(ErrorLevel.ERROR,
+ Messages.INCORRECT_SW_INFORMATION_NON_MANO_ERROR.formatMessage(swInformationFilePath));
+ }
+ }
+ }
+
/**
* Validates if a YAML file has the correct extension, is not empty and the content is a valid YAML. Reports each
* error found.
@@ -398,15 +443,20 @@ class SOL004MetaDirectoryValidator implements Validator {
return;
}
- final InputStream fileContent = contentHandler.getFileContentAsStream(filePath);
- if (fileContent == null) {
- reportError(ErrorLevel.ERROR, Messages.EMPTY_YAML_FILE_1.formatMessage(filePath));
- return;
- }
- try {
+ try (final InputStream fileContent = contentHandler.getFileContentAsStream(filePath)) {
+ if (fileContent == null) {
+ reportError(ErrorLevel.ERROR, Messages.EMPTY_YAML_FILE_1.formatMessage(filePath));
+ return;
+ }
new Yaml().loadAll(fileContent).iterator().next();
+ } catch (final IOException e) {
+ final String errorMsg = Messages.FILE_LOAD_CONTENT_ERROR.formatMessage(filePath);
+ reportError(ErrorLevel.ERROR, errorMsg);
+ LOGGER.debug(errorMsg, e);
} catch (final Exception e) {
- reportError(ErrorLevel.ERROR, Messages.INVALID_YAML_FORMAT_1.formatMessage(filePath, e.getMessage()));
+ final String message = Messages.INVALID_YAML_FORMAT_1.formatMessage(filePath, e.getMessage());
+ LOGGER.debug(message, e);
+ reportError(ErrorLevel.ERROR, message);
}
}