diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration')
25 files changed, 697 insertions, 961 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java index 68309106cd..6e810eefbd 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; import java.io.ByteArrayInputStream; @@ -35,73 +34,60 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { - protected static final Logger logger = LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); - - @Override - public UploadFileResponse upload(final VspDetails vspDetails, - final OnboardPackageInfo onboardPackageInfo, - final CandidateService candidateService) { - final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); - final UploadFileResponse uploadFileResponse = new UploadFileResponse(); - uploadFileResponse.setOnboardingType(getHandlerType()); - if (isFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) { - return uploadFileResponse; - } - - final byte[] fileContentByteArray = onboardPackage.getFileContent().array(); - if (isInvalidRawZipData(onboardPackage.getFileExtension(), - uploadFileResponse, fileContentByteArray, candidateService)) { - return uploadFileResponse; - } - - final UploadFileResponse validateResponse = validate(onboardPackageInfo); - if (!MapUtils.isEmpty(validateResponse.getErrors())) { - uploadFileResponse.addStructureErrors(validateResponse.getErrors()); - return uploadFileResponse; - } + protected static final Logger logger = LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); - final UploadFileResponse responseFromUpdate = updateCandidateData(vspDetails, onboardPackageInfo, - candidateService); - if (!MapUtils.isEmpty(responseFromUpdate.getErrors())) { - uploadFileResponse.addStructureErrors(responseFromUpdate.getErrors()); + @Override + public UploadFileResponse upload(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService) { + final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); + final UploadFileResponse uploadFileResponse = new UploadFileResponse(); + uploadFileResponse.setOnboardingType(getHandlerType()); + if (isFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) { + return uploadFileResponse; + } + final byte[] fileContentByteArray = onboardPackage.getFileContent().array(); + if (isInvalidRawZipData(onboardPackage.getFileExtension(), uploadFileResponse, fileContentByteArray, candidateService)) { + return uploadFileResponse; + } + final UploadFileResponse validateResponse = validate(onboardPackageInfo); + if (!MapUtils.isEmpty(validateResponse.getErrors())) { + uploadFileResponse.addStructureErrors(validateResponse.getErrors()); + return uploadFileResponse; + } + final UploadFileResponse responseFromUpdate = updateCandidateData(vspDetails, onboardPackageInfo, candidateService); + if (!MapUtils.isEmpty(responseFromUpdate.getErrors())) { + uploadFileResponse.addStructureErrors(responseFromUpdate.getErrors()); + } + return uploadFileResponse; } - return uploadFileResponse; - } - - protected abstract UploadFileResponse updateCandidateData(final VspDetails vspDetails, - final OnboardPackageInfo onboardPackageInfo, - final CandidateService candidateService); + protected abstract UploadFileResponse updateCandidateData(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService); - private boolean isFileToUploadEmpty(final OnboardPackage onboardPackage, - final UploadFileResponse uploadFileResponse, - final CandidateService candidateService) { - final ByteArrayInputStream fileToUpload = new ByteArrayInputStream( - onboardPackage.getFileContent().array()); - Optional<ErrorMessage> errorMessage = - candidateService.validateNonEmptyFileToUpload(fileToUpload, onboardPackage.getFileExtension()); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; + private boolean isFileToUploadEmpty(final OnboardPackage onboardPackage, final UploadFileResponse uploadFileResponse, + final CandidateService candidateService) { + final ByteArrayInputStream fileToUpload = new ByteArrayInputStream(onboardPackage.getFileContent().array()); + Optional<ErrorMessage> errorMessage = candidateService.validateNonEmptyFileToUpload(fileToUpload, onboardPackage.getFileExtension()); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; } - return false; - } - protected boolean isInvalidRawZipData(String fileSuffix, - UploadFileResponse uploadFileResponse, - byte[] uploadedFileData, - CandidateService candidateService) { - Optional<ErrorMessage> errorMessage; - errorMessage = candidateService.validateRawZipData(fileSuffix, uploadedFileData); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; + protected boolean isInvalidRawZipData(String fileSuffix, UploadFileResponse uploadFileResponse, byte[] uploadedFileData, + CandidateService candidateService) { + Optional<ErrorMessage> errorMessage; + errorMessage = candidateService.validateRawZipData(fileSuffix, uploadedFileData); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; } - return false; - } - public abstract UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo); + public abstract UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo); - protected abstract OnboardingTypesEnum getHandlerType(); + protected abstract OnboardingTypesEnum getHandlerType(); } 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 94638a5876..e7367c2a49 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 @@ -1,8 +1,8 @@ /* * Copyright (c) 2018 AT&T Intellectual Property. - * Modifications Copyright (c) 2018 Verizon Property. - * Modifications Copyright (c) 2019 Nordix Foundation. + * Modifications Copyright (c) 2018 Verizon Property. + * Modifications Copyright (c) 2019 Nordix Foundation. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; @@ -43,42 +42,35 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardSignedPackage; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler - implements OrchestrationTemplateFileHandler { +public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { @Override public UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo) { final UploadFileResponse uploadFileResponse = new UploadFileResponse(); if (onboardPackageInfo.getPackageType() == OnboardingTypesEnum.SIGNED_CSAR) { - final OnboardSignedPackage originalOnboardPackage = - (OnboardSignedPackage) onboardPackageInfo.getOriginalOnboardPackage(); + final OnboardSignedPackage originalOnboardPackage = (OnboardSignedPackage) onboardPackageInfo.getOriginalOnboardPackage(); validatePackageSecurity(originalOnboardPackage).ifPresent(packageSignatureResponse -> { if (packageSignatureResponse.hasErrors()) { uploadFileResponse.addStructureErrors(packageSignatureResponse.getErrors()); } }); - if (uploadFileResponse.hasErrors()) { return uploadFileResponse; } } final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); final FileContentHandler fileContentHandler = onboardPackage.getFileContentHandler(); - try { final Validator validator = ValidatorFactory.getValidator(fileContentHandler); uploadFileResponse.addStructureErrors(validator.validateContent(fileContentHandler)); } catch (IOException exception) { logger.error(exception.getMessage(), exception); - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); + uploadFileResponse + .addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); } catch (CoreException coreException) { logger.error(coreException.getMessage(), coreException); - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); } - return uploadFileResponse; } @@ -87,8 +79,7 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH try { final CsarSecurityValidator csarSecurityValidator = new CsarSecurityValidator(); if (!csarSecurityValidator.verifyPackageSignature(originalOnboardPackage)) { - final ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, - Messages.FAILED_TO_VERIFY_SIGNATURE.getErrorMessage()); + final ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, Messages.FAILED_TO_VERIFY_SIGNATURE.getErrorMessage()); logger.error(errorMessage.getMessage()); uploadFileResponseDto.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage); return Optional.of(uploadFileResponseDto); @@ -103,31 +94,24 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH } @Override - protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, - final OnboardPackageInfo onboardPackageInfo, + protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo, final CandidateService candidateService) { final UploadFileResponse uploadFileResponse = new UploadFileResponse(); final OnboardPackage csarPackage = onboardPackageInfo.getOnboardPackage(); final OnboardPackage originalOnboardPackage = onboardPackageInfo.getOriginalOnboardPackage(); try { candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), - new OrchestrationTemplateCandidateData(csarPackage.getFileContent(), - "", csarPackage.getFileExtension(), - csarPackage.getFilename(), originalOnboardPackage.getFilename(), - originalOnboardPackage.getFileExtension(), - originalOnboardPackage.getFileContent())); + new OrchestrationTemplateCandidateData(csarPackage.getFileContent(), "", csarPackage.getFileExtension(), csarPackage.getFilename(), + originalOnboardPackage.getFilename(), originalOnboardPackage.getFileExtension(), originalOnboardPackage.getFileContent())); } catch (final Exception exception) { - logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(), - getHandlerType().toString()), exception); - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(), getHandlerType().toString()), exception); + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); } return uploadFileResponse; } - @Override - protected OnboardingTypesEnum getHandlerType() { - return OnboardingTypesEnum.CSAR; - } - + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.CSAR; + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java index 2d2f1ae92b..9bd1b2ea22 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; @@ -24,7 +23,5 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; @FunctionalInterface public interface OrchestrationTemplateFileHandler { - UploadFileResponse upload(final VspDetails vspDetails, - final OnboardPackageInfo onboardPackageInfo, - final CandidateService candidateService); + UploadFileResponse upload(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo, final CandidateService candidateService); } 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 3e54260e8b..65ce2f5397 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 @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; @@ -35,44 +34,37 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage; import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler - implements OrchestrationTemplateFileHandler { +public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { @Override public UploadFileResponse validate(final OnboardPackageInfo onboardPackageInfo) { final UploadFileResponse uploadFileResponse = new UploadFileResponse(); final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); - OrchestrationUtil - .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, onboardPackage.getFileContent().array()); + OrchestrationUtil.getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, onboardPackage.getFileContent().array()); return uploadFileResponse; } - @Override - protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, - final OnboardPackageInfo onboardPackageInfo, - final CandidateService candidateService) { - final UploadFileResponse uploadFileResponse = new UploadFileResponse(); - try { - final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage(); - final OrchestrationTemplateCandidateData candidateData = - new CandidateEntityBuilder(candidateService) - .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), zipPackage.getFileContentHandler(), - uploadFileResponse.getErrors()); - candidateData.setFileName(zipPackage.getFilename()); - candidateData.setFileSuffix(zipPackage.getFileExtension()); - candidateService - .updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData); - } catch (final Exception exception) { - logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(), - getHandlerType().toString()), exception); - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + @Override + protected UploadFileResponse updateCandidateData(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService) { + final UploadFileResponse uploadFileResponse = new UploadFileResponse(); + try { + final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage(); + final OrchestrationTemplateCandidateData candidateData = new CandidateEntityBuilder(candidateService) + .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), zipPackage.getFileContentHandler(), + uploadFileResponse.getErrors()); + candidateData.setFileName(zipPackage.getFilename()); + candidateData.setFileSuffix(zipPackage.getFileExtension()); + candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData); + } catch (final Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_LOAD_CONTENT_ERROR.getErrorMessage(), getHandlerType().toString()), exception); + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + } + return uploadFileResponse; } - return uploadFileResponse; - } - @Override - protected OnboardingTypesEnum getHandlerType() { - return OnboardingTypesEnum.ZIP; - } + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.ZIP; + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java index 4b2decd412..9c881be75e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY; + +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; import org.onap.config.api.Configuration; import org.onap.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; @@ -24,35 +29,24 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.OrchestrationTemplateFileExtensionErrorBuilder; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; - -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY; - public class OrchestrationUploadFactory { + private static final Map<String, ImplementationConfiguration> FILE_HANLDERS; - private OrchestrationUploadFactory() { - } static { Configuration config = ConfigurationManager.lookup(); - FILE_HANLDERS = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, - ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class)); + FILE_HANLDERS = new ConcurrentHashMap<>( + config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class)); + } + private OrchestrationUploadFactory() { } - public static OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler( - final OnboardingTypesEnum onboardingType) { + public static OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(final OnboardingTypesEnum onboardingType) { final ImplementationConfiguration orchestrationTemplateFileHandler = FILE_HANLDERS.get(onboardingType.toString()); - - if(Objects.isNull(orchestrationTemplateFileHandler)){ - throw new CoreException(new OrchestrationTemplateFileExtensionErrorBuilder - ().build()); + if (Objects.isNull(orchestrationTemplateFileHandler)) { + throw new CoreException(new OrchestrationTemplateFileExtensionErrorBuilder().build()); } - - return CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(), - OrchestrationTemplateFileHandler.class); + return CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(), OrchestrationTemplateFileHandler.class); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java index ef41262621..bc84e89e74 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -13,9 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.dao.UniqueValueDaoFactory; @@ -41,366 +53,290 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManagerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.*; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MonitoringUploadDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.versioning.dao.types.Version; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.*; -import java.util.stream.Collectors; - -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; - public class OrchestrationUtil { - private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationUtil.class); - public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration"; - public static final String ORCHESTRATION_IMPL_KEY = "orchestration_impl"; - - private final NicDao nicDao; - private final ComponentArtifactDao componentArtifactDao; - private final ProcessDao processDao; - private final OrchestrationTemplateDao orchestrationTemplateDataDao; - private final ComponentDao componentDao; - private final ServiceModelDao serviceModelDao; - private final ComponentDependencyModelDao componentDependencyModelDao; - private final CompositionEntityDataManager compositionEntityDataManager; - private final CompositionDataExtractor compositionDataExtractor; - - public OrchestrationUtil() { - this(NicDaoFactory.getInstance().createInterface(), - MonitoringUploadDaoFactory.getInstance().createInterface(), - ProcessDaoFactory.getInstance().createInterface(), - OrchestrationTemplateDaoFactory.getInstance().createInterface(), - ComponentDaoFactory.getInstance().createInterface(), - ServiceModelDaoFactory.getInstance().createInterface(), - ComponentDependencyModelDaoFactory.getInstance().createInterface(), - CompositionEntityDataManagerFactory.getInstance().createInterface(), + public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration"; + public static final String ORCHESTRATION_IMPL_KEY = "orchestration_impl"; + private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationUtil.class); + private final NicDao nicDao; + private final ComponentArtifactDao componentArtifactDao; + private final ProcessDao processDao; + private final OrchestrationTemplateDao orchestrationTemplateDataDao; + private final ComponentDao componentDao; + private final ServiceModelDao serviceModelDao; + private final ComponentDependencyModelDao componentDependencyModelDao; + private final CompositionEntityDataManager compositionEntityDataManager; + private final CompositionDataExtractor compositionDataExtractor; + + public OrchestrationUtil() { + this(NicDaoFactory.getInstance().createInterface(), MonitoringUploadDaoFactory.getInstance().createInterface(), + ProcessDaoFactory.getInstance().createInterface(), OrchestrationTemplateDaoFactory.getInstance().createInterface(), + ComponentDaoFactory.getInstance().createInterface(), ServiceModelDaoFactory.getInstance().createInterface(), + ComponentDependencyModelDaoFactory.getInstance().createInterface(), CompositionEntityDataManagerFactory.getInstance().createInterface(), CompositionDataExtractorFactory.getInstance().createInterface()); - } - - private OrchestrationUtil( - NicDao nicDao, - ComponentArtifactDao componentArtifactDao, - ProcessDao processDao, - OrchestrationTemplateDao orchestrationTemplateDataDao, - ComponentDao componentDao, - ServiceModelDao serviceModelDao, - ComponentDependencyModelDao componentDependencyModelDao, - CompositionEntityDataManager compositionEntityDataManager, - CompositionDataExtractor compositionDataExtractor) { - this.nicDao = nicDao; - this.componentArtifactDao = componentArtifactDao; - this.processDao = processDao; - this.orchestrationTemplateDataDao = orchestrationTemplateDataDao; - this.componentDao = componentDao; - this.serviceModelDao = serviceModelDao; - this.componentDependencyModelDao = componentDependencyModelDao; - this.compositionEntityDataManager = compositionEntityDataManager; - this.compositionDataExtractor = compositionDataExtractor; - } - - public static Optional<FileContentHandler> getFileContentMap(OnboardingTypesEnum type, - UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - FileContentHandler contentMap = null; - try { - contentMap = CommonUtil.validateAndUploadFileContent(type, uploadedFileData); - } catch (IOException exception) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); - LOGGER.error("{}\n{}", Messages.INVALID_ZIP_FILE.getErrorMessage(), - exception.getMessage(), exception); - } catch (CoreException coreException) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); - LOGGER.error(coreException.getMessage(), coreException); } - return Optional.ofNullable(contentMap); - } - - public void backupComponentsQuestionnaireBeforeDelete(String vspId, Version version, - Map<String, String> componentsQustanniare, - Map<String, Map<String, String>> - componentNicsQustanniare, - Map<String, Collection<ComponentMonitoringUploadEntity>> - componentMibList, - Map<String, Collection<ProcessEntity>> - componentProcesses, - Map<String, ProcessEntity> processArtifact) { - Collection<ComponentEntity> componentsCompositionAndQuestionnaire = - componentDao.listCompositionAndQuestionnaire(vspId, version); - componentsCompositionAndQuestionnaire.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - componentsQustanniare.put(componentName, componentEntity.getQuestionnaireData()); - backupMibData(vspId, version, componentEntity, componentName, componentMibList); - backupProcess(vspId, version, componentEntity.getId(), componentName, componentProcesses, - processArtifact); - backupNicsQuestionnaire(vspId, version, componentEntity, componentName, - componentNicsQustanniare); - }); - } - - private void backupMibData(String vspId, Version version, ComponentEntity componentEntity, - String componentName, - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList) { - Collection<ComponentMonitoringUploadEntity> componentMib = - componentArtifactDao.listArtifacts(new - ComponentMonitoringUploadEntity(vspId, version, componentEntity.getId(), - null)); - if (CollectionUtils.isNotEmpty(componentMib)) { - componentMibList.put(componentName, componentMib); + private OrchestrationUtil(NicDao nicDao, ComponentArtifactDao componentArtifactDao, ProcessDao processDao, + OrchestrationTemplateDao orchestrationTemplateDataDao, ComponentDao componentDao, ServiceModelDao serviceModelDao, + ComponentDependencyModelDao componentDependencyModelDao, CompositionEntityDataManager compositionEntityDataManager, + CompositionDataExtractor compositionDataExtractor) { + this.nicDao = nicDao; + this.componentArtifactDao = componentArtifactDao; + this.processDao = processDao; + this.orchestrationTemplateDataDao = orchestrationTemplateDataDao; + this.componentDao = componentDao; + this.serviceModelDao = serviceModelDao; + this.componentDependencyModelDao = componentDependencyModelDao; + this.compositionEntityDataManager = compositionEntityDataManager; + this.compositionDataExtractor = compositionDataExtractor; } - } - private void backupProcess(String vspId, Version version, String componentId, - String componentName, Map<String, - Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - Collection<ProcessEntity> processList = - processDao.list(new ProcessEntity(vspId, version, componentId, null)); - if (!processList.isEmpty()) { - processes.put(componentName, processList); - processList.forEach(process -> { - ProcessEntity artifact = processDao - .getArtifact(new ProcessEntity(vspId, version, componentId, process.getId())); - if (artifact.getArtifact() != null) { - processArtifact.put(process.getId(), artifact); + public static Optional<FileContentHandler> getFileContentMap(OnboardingTypesEnum type, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + try { + contentMap = CommonUtil.validateAndUploadFileContent(type, uploadedFileData); + } catch (IOException exception) { + uploadFileResponse + .addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); + LOGGER.error("{}\n{}", Messages.INVALID_ZIP_FILE.getErrorMessage(), exception.getMessage(), exception); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + LOGGER.error(coreException.getMessage(), coreException); } - }); + return Optional.ofNullable(contentMap); } - } - private void backupNicsQuestionnaire(String vspId, Version version, - ComponentEntity componentEntity, - String componentName, - Map<String, Map<String, String>> componentNicsQustanniare) { - Collection<NicEntity> - nics = nicDao.list(new NicEntity(vspId, version, componentEntity.getId(), null)); - if (CollectionUtils.isNotEmpty(nics)) { - Map<String, String> nicsQuestionnaire = new HashMap<>(); - nics.forEach(nicEntity -> { - NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, version, - componentEntity.getId(), nicEntity.getId()); + public static HeatStructureTree createHeatTree(FileContentHandler fileContentMap, Map<String, List<ErrorMessage>> validationErrors) { + HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); + heatTreeManager.createTree(); + heatTreeManager.addErrors(validationErrors); + return heatTreeManager.getTree(); + } - nicsQuestionnaire.put(nicEntity.getNicCompositionData().getName(), - nicQuestionnaire.getQuestionnaireData()); - }); - componentNicsQustanniare.put(componentName, nicsQuestionnaire); + public void backupComponentsQuestionnaireBeforeDelete(String vspId, Version version, Map<String, String> componentsQustanniare, + Map<String, Map<String, String>> componentNicsQustanniare, + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList, + Map<String, Collection<ProcessEntity>> componentProcesses, + Map<String, ProcessEntity> processArtifact) { + Collection<ComponentEntity> componentsCompositionAndQuestionnaire = componentDao.listCompositionAndQuestionnaire(vspId, version); + componentsCompositionAndQuestionnaire.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + componentsQustanniare.put(componentName, componentEntity.getQuestionnaireData()); + backupMibData(vspId, version, componentEntity, componentName, componentMibList); + backupProcess(vspId, version, componentEntity.getId(), componentName, componentProcesses, processArtifact); + backupNicsQuestionnaire(vspId, version, componentEntity, componentName, componentNicsQustanniare); + }); } - } - public void retainComponentQuestionnaireData(String vspId, Version version, - Map<String, String> componentsQustanniare, - Map<String, Map<String, String>> - componentNicsQustanniare, - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList, - Map<String, Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - //VSP processes - restoreProcess(vspId, version, null, null, processes, processArtifact); - Collection<ComponentEntity> components = - componentDao.list(new ComponentEntity(vspId, version, null)); - components.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - if (componentsQustanniare.containsKey(componentName)) { - componentDao.updateQuestionnaireData(vspId, version, - componentEntity.getId(), - componentsQustanniare.get(componentEntity.getComponentCompositionData() - .getName())); - if (componentNicsQustanniare.containsKey(componentName)) { - restoreComponentNicQuestionnaire(vspId, version, componentName, componentEntity, - componentNicsQustanniare); + private void backupMibData(String vspId, Version version, ComponentEntity componentEntity, String componentName, + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList) { + Collection<ComponentMonitoringUploadEntity> componentMib = componentArtifactDao + .listArtifacts(new ComponentMonitoringUploadEntity(vspId, version, componentEntity.getId(), null)); + if (CollectionUtils.isNotEmpty(componentMib)) { + componentMibList.put(componentName, componentMib); } - //MIB //todo add for VES_EVENTS - if (componentMibList.containsKey(componentName)) { - restoreComponentMibData(componentName, componentEntity, componentMibList); - } - //VFC processes - restoreProcess(vspId, version, componentEntity.getId(), componentName, processes, - processArtifact); - } - }); - } - - private void restoreComponentNicQuestionnaire(String vspId, Version version, - String componentName, - ComponentEntity componentEntity, - Map<String, Map<String, String>> componentNicsQustanniare) { - Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); - Collection<NicEntity> nics = - nicDao.list(new NicEntity(vspId, version, componentEntity.getId(), null)); - nics.forEach(nicEntity -> { - if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { - nicDao.updateQuestionnaireData(vspId, version, - componentEntity.getId(), nicEntity.getId(), - nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); - } - }); - } - - private void restoreComponentMibData(String componentName, ComponentEntity componentEntity, - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList) { - Collection<ComponentMonitoringUploadEntity> mibList = componentMibList.get(componentName); - mibList.forEach(mib -> { - mib.setComponentId(componentEntity.getId()); - componentArtifactDao.create(mib); - }); - } + } - private void restoreProcess(String vspId, Version version, String componentId, - String componentName, - Map<String, Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - if (processes.containsKey(componentName)) { - Collection<ProcessEntity> processList = processes.get(componentName); - processList.forEach(process -> { - process.setComponentId(componentId); - UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance() - .createInterface()); - uniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, version.getId(), componentId, - process.getName()); - processDao.create(process); - if (processArtifact.containsKey(process.getId())) { - ProcessEntity artifact = processArtifact.get(process.getId()); - processDao.uploadArtifact(artifact); + private void backupProcess(String vspId, Version version, String componentId, String componentName, + Map<String, Collection<ProcessEntity>> processes, Map<String, ProcessEntity> processArtifact) { + Collection<ProcessEntity> processList = processDao.list(new ProcessEntity(vspId, version, componentId, null)); + if (!processList.isEmpty()) { + processes.put(componentName, processList); + processList.forEach(process -> { + ProcessEntity artifact = processDao.getArtifact(new ProcessEntity(vspId, version, componentId, process.getId())); + if (artifact.getArtifact() != null) { + processArtifact.put(process.getId(), artifact); + } + }); } - }); } - } - public void deleteUploadDataAndContent(String vspId, Version version) { - VendorSoftwareProductInfoDaoFactory.getInstance().createInterface() - .delete(new VspDetails(vspId, version)); - } + private void backupNicsQuestionnaire(String vspId, Version version, ComponentEntity componentEntity, String componentName, + Map<String, Map<String, String>> componentNicsQustanniare) { + Collection<NicEntity> nics = nicDao.list(new NicEntity(vspId, version, componentEntity.getId(), null)); + if (CollectionUtils.isNotEmpty(nics)) { + Map<String, String> nicsQuestionnaire = new HashMap<>(); + nics.forEach(nicEntity -> { + NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, version, componentEntity.getId(), nicEntity.getId()); + nicsQuestionnaire.put(nicEntity.getNicCompositionData().getName(), nicQuestionnaire.getQuestionnaireData()); + }); + componentNicsQustanniare.put(componentName, nicsQuestionnaire); + } + } - public void saveUploadData(VspDetails vspDetails, - OrchestrationTemplateCandidateData candidateData, - InputStream uploadedFileData, - FileContentHandler fileContentMap, HeatStructureTree tree) { - Map<String, Object> manifestAsMap = - fileContentMap.containsFile(SdcCommon.MANIFEST_NAME) - ? (Map<String, Object>) JsonUtil.json2Object(fileContentMap.getFileContentAsStream( - SdcCommon.MANIFEST_NAME), Map.class) - : new HashMap<>(); + public void retainComponentQuestionnaireData(String vspId, Version version, Map<String, String> componentsQustanniare, + Map<String, Map<String, String>> componentNicsQustanniare, + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList, + Map<String, Collection<ProcessEntity>> processes, Map<String, ProcessEntity> processArtifact) { + //VSP processes + restoreProcess(vspId, version, null, null, processes, processArtifact); + Collection<ComponentEntity> components = componentDao.list(new ComponentEntity(vspId, version, null)); + components.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + if (componentsQustanniare.containsKey(componentName)) { + componentDao.updateQuestionnaireData(vspId, version, componentEntity.getId(), + componentsQustanniare.get(componentEntity.getComponentCompositionData().getName())); + if (componentNicsQustanniare.containsKey(componentName)) { + restoreComponentNicQuestionnaire(vspId, version, componentName, componentEntity, componentNicsQustanniare); + } + //MIB //todo add for VES_EVENTS + if (componentMibList.containsKey(componentName)) { + restoreComponentMibData(componentName, componentEntity, componentMibList); + } + //VFC processes + restoreProcess(vspId, version, componentEntity.getId(), componentName, processes, processArtifact); + } + }); + } - OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(); - uploadData.setFileSuffix(candidateData.getFileSuffix()); - uploadData.setFileName(candidateData.getFileName()); - uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); - uploadData.setValidationDataStructure(new ValidationStructureList(tree)); - uploadData.setPackageName(Objects.isNull(manifestAsMap.get("name")) ? null : - (String) manifestAsMap.get("name")); - uploadData.setPackageVersion(Objects.isNull(manifestAsMap.get("version")) ? null : - (String) manifestAsMap.get("version")); - uploadData.setFilesDataStructure(candidateData.getFilesDataStructure()); - orchestrationTemplateDataDao.update(vspDetails.getId(), vspDetails.getVersion(), uploadData); + private void restoreComponentNicQuestionnaire(String vspId, Version version, String componentName, ComponentEntity componentEntity, + Map<String, Map<String, String>> componentNicsQustanniare) { + Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); + Collection<NicEntity> nics = nicDao.list(new NicEntity(vspId, version, componentEntity.getId(), null)); + nics.forEach(nicEntity -> { + if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { + nicDao.updateQuestionnaireData(vspId, version, componentEntity.getId(), nicEntity.getId(), + nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); + } + }); + } - VspMergeDaoFactory.getInstance().createInterface() - .updateHint(vspDetails.getId(), vspDetails.getVersion()); - } + private void restoreComponentMibData(String componentName, ComponentEntity componentEntity, + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList) { + Collection<ComponentMonitoringUploadEntity> mibList = componentMibList.get(componentName); + mibList.forEach(mib -> { + mib.setComponentId(componentEntity.getId()); + componentArtifactDao.create(mib); + }); + } - public void saveServiceModel(String vspId, Version version, - ToscaServiceModel serviceModelToExtract, - ToscaServiceModel serviceModelToStore) { - if (serviceModelToExtract != null) { - serviceModelDao.storeServiceModel(vspId, version, serviceModelToStore); - //Extracting the compostion data from the output service model of the first phase of - // translation - compositionEntityDataManager.saveCompositionData(vspId, version, - compositionDataExtractor.extractServiceCompositionData(serviceModelToExtract)); + private void restoreProcess(String vspId, Version version, String componentId, String componentName, + Map<String, Collection<ProcessEntity>> processes, Map<String, ProcessEntity> processArtifact) { + if (processes.containsKey(componentName)) { + Collection<ProcessEntity> processList = processes.get(componentName); + processList.forEach(process -> { + process.setComponentId(componentId); + UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + uniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, version.getId(), componentId, process.getName()); + processDao.create(process); + if (processArtifact.containsKey(process.getId())) { + ProcessEntity artifact = processArtifact.get(process.getId()); + processDao.uploadArtifact(artifact); + } + }); + } } - } - public static HeatStructureTree createHeatTree(FileContentHandler fileContentMap, - Map<String, List<ErrorMessage>> validationErrors) { - HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); - heatTreeManager.createTree(); - heatTreeManager.addErrors(validationErrors); - return heatTreeManager.getTree(); - } + public void deleteUploadDataAndContent(String vspId, Version version) { + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface().delete(new VspDetails(vspId, version)); + } - public void updateVspComponentDependencies(String vspId, Version version, - Map<String, String> - vspComponentIdNameInfoBeforeProcess, - Collection<ComponentDependencyModelEntity> - componentDependenciesBeforeDelete) { - Map<String, String> updatedVspComponentNameIdInfo = getVspComponentNameIdInfo(vspId, version); - if (MapUtils.isNotEmpty(updatedVspComponentNameIdInfo)) { - Set<String> updatedVspComponentNames = updatedVspComponentNameIdInfo.keySet(); - if (CollectionUtils.isNotEmpty(componentDependenciesBeforeDelete)) { - restoreComponentDependencies(vspId, version, vspComponentIdNameInfoBeforeProcess, - componentDependenciesBeforeDelete, updatedVspComponentNames, - updatedVspComponentNameIdInfo); - } + public void saveUploadData(VspDetails vspDetails, OrchestrationTemplateCandidateData candidateData, InputStream uploadedFileData, + FileContentHandler fileContentMap, HeatStructureTree tree) { + Map<String, Object> manifestAsMap = fileContentMap.containsFile(SdcCommon.MANIFEST_NAME) ? (Map<String, Object>) JsonUtil + .json2Object(fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME), Map.class) : new HashMap<>(); + OrchestrationTemplateEntity uploadData = new OrchestrationTemplateEntity(); + uploadData.setFileSuffix(candidateData.getFileSuffix()); + uploadData.setFileName(candidateData.getFileName()); + uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); + uploadData.setValidationDataStructure(new ValidationStructureList(tree)); + uploadData.setPackageName(Objects.isNull(manifestAsMap.get("name")) ? null : (String) manifestAsMap.get("name")); + uploadData.setPackageVersion(Objects.isNull(manifestAsMap.get("version")) ? null : (String) manifestAsMap.get("version")); + uploadData.setFilesDataStructure(candidateData.getFilesDataStructure()); + orchestrationTemplateDataDao.update(vspDetails.getId(), vspDetails.getVersion(), uploadData); + VspMergeDaoFactory.getInstance().createInterface().updateHint(vspDetails.getId(), vspDetails.getVersion()); } - } - private void restoreComponentDependencies(String vspId, Version version, - Map<String, String> vspComponentIdNameInfoBeforeProcess, - Collection<ComponentDependencyModelEntity> - componentDependenciesBeforeDelete, - Set<String> updatedVspComponentNames, - Map<String, String> updatedVspComponentNameIdInfo) { - for (ComponentDependencyModelEntity componentDependency : componentDependenciesBeforeDelete) { - String sourceComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency - .getSourceComponentId()); - String targetComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency - .getTargetComponentId()); - if (updatedVspComponentNames.contains(sourceComponentName) - && (updatedVspComponentNames.contains(targetComponentName))) { - ComponentDependencyModelEntity restoredDependency = - new ComponentDependencyModelEntity(vspId, version, null); - String newSourceComponentId = updatedVspComponentNameIdInfo.get(sourceComponentName); - restoredDependency.setSourceComponentId(newSourceComponentId); - String newTargetComponentId = updatedVspComponentNameIdInfo.get(targetComponentName); - restoredDependency.setTargetComponentId(newTargetComponentId); - restoredDependency.setRelation(componentDependency.getRelation()); - componentDependencyModelDao.create(restoredDependency); - } + public void saveServiceModel(String vspId, Version version, ToscaServiceModel serviceModelToExtract, ToscaServiceModel serviceModelToStore) { + if (serviceModelToExtract != null) { + serviceModelDao.storeServiceModel(vspId, version, serviceModelToStore); + //Extracting the compostion data from the output service model of the first phase of + + // translation + compositionEntityDataManager + .saveCompositionData(vspId, version, compositionDataExtractor.extractServiceCompositionData(serviceModelToExtract)); + } } - } - public Map<String, String> getVspComponentIdNameInfo(String vspId, Version version) { - Collection<ComponentEntity> updatedVspComponents = - componentDao.list(new ComponentEntity(vspId, version, null)); - Map<String, String> vspComponentIdNameMap = new HashMap<>(); - if (CollectionUtils.isNotEmpty(updatedVspComponents)) { - vspComponentIdNameMap = updatedVspComponents.stream() - .filter(componentEntity -> componentEntity.getComponentCompositionData() != null) - .collect(Collectors.toMap(ComponentEntity::getId, - componentEntity -> componentEntity.getComponentCompositionData().getName())); + public void updateVspComponentDependencies(String vspId, Version version, Map<String, String> vspComponentIdNameInfoBeforeProcess, + Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete) { + Map<String, String> updatedVspComponentNameIdInfo = getVspComponentNameIdInfo(vspId, version); + if (MapUtils.isNotEmpty(updatedVspComponentNameIdInfo)) { + Set<String> updatedVspComponentNames = updatedVspComponentNameIdInfo.keySet(); + if (CollectionUtils.isNotEmpty(componentDependenciesBeforeDelete)) { + restoreComponentDependencies(vspId, version, vspComponentIdNameInfoBeforeProcess, componentDependenciesBeforeDelete, + updatedVspComponentNames, updatedVspComponentNameIdInfo); + } + } + } + private void restoreComponentDependencies(String vspId, Version version, Map<String, String> vspComponentIdNameInfoBeforeProcess, + Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete, + Set<String> updatedVspComponentNames, Map<String, String> updatedVspComponentNameIdInfo) { + for (ComponentDependencyModelEntity componentDependency : componentDependenciesBeforeDelete) { + String sourceComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency.getSourceComponentId()); + String targetComponentName = vspComponentIdNameInfoBeforeProcess.get(componentDependency.getTargetComponentId()); + if (updatedVspComponentNames.contains(sourceComponentName) && (updatedVspComponentNames.contains(targetComponentName))) { + ComponentDependencyModelEntity restoredDependency = new ComponentDependencyModelEntity(vspId, version, null); + String newSourceComponentId = updatedVspComponentNameIdInfo.get(sourceComponentName); + restoredDependency.setSourceComponentId(newSourceComponentId); + String newTargetComponentId = updatedVspComponentNameIdInfo.get(targetComponentName); + restoredDependency.setTargetComponentId(newTargetComponentId); + restoredDependency.setRelation(componentDependency.getRelation()); + componentDependencyModelDao.create(restoredDependency); + } + } } - return vspComponentIdNameMap; - } - public Collection<ComponentDependencyModelEntity> getComponentDependenciesBeforeDelete(String - vspId, Version version) { - return componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, - version, null)); - } + public Map<String, String> getVspComponentIdNameInfo(String vspId, Version version) { + Collection<ComponentEntity> updatedVspComponents = componentDao.list(new ComponentEntity(vspId, version, null)); + Map<String, String> vspComponentIdNameMap = new HashMap<>(); + if (CollectionUtils.isNotEmpty(updatedVspComponents)) { + vspComponentIdNameMap = updatedVspComponents.stream().filter(componentEntity -> componentEntity.getComponentCompositionData() != null) + .collect(Collectors.toMap(ComponentEntity::getId, componentEntity -> componentEntity.getComponentCompositionData().getName())); + } + return vspComponentIdNameMap; + } - private Map<String, String> getVspComponentNameIdInfo(String vspId, - Version version) { - Collection<ComponentEntity> updatedVspComponents = - componentDao.list(new ComponentEntity(vspId, version, null)); - Map<String, String> vspComponentNameIdMap = new HashMap<>(); - if (CollectionUtils.isNotEmpty(updatedVspComponents)) { - vspComponentNameIdMap = updatedVspComponents.stream() - .filter(componentEntity -> componentEntity.getComponentCompositionData() != null) - .collect(Collectors - .toMap(componentEntity -> componentEntity.getComponentCompositionData().getName(), - ComponentEntity::getId)); + public Collection<ComponentDependencyModelEntity> getComponentDependenciesBeforeDelete(String vspId, Version version) { + return componentDependencyModelDao.list(new ComponentDependencyModelEntity(vspId, version, null)); } - return vspComponentNameIdMap; - } + private Map<String, String> getVspComponentNameIdInfo(String vspId, Version version) { + Collection<ComponentEntity> updatedVspComponents = componentDao.list(new ComponentEntity(vspId, version, null)); + Map<String, String> vspComponentNameIdMap = new HashMap<>(); + if (CollectionUtils.isNotEmpty(updatedVspComponents)) { + vspComponentNameIdMap = updatedVspComponents.stream().filter(componentEntity -> componentEntity.getComponentCompositionData() != null) + .collect(Collectors.toMap(componentEntity -> componentEntity.getComponentCompositionData().getName(), ComponentEntity::getId)); + } + return vspComponentNameIdMap; + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidator.java index 0efe65b3b6..81a17f333b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidator.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; import java.util.Optional; @@ -55,7 +54,6 @@ public class CsarSecurityValidator { if (certificateFilePath.isPresent()) { certificateBytes = fileContentHandler.getFileContent(certificateFilePath.get()); } - return securityManager.verifySignedData(signatureBytes, certificateBytes, archiveBytes); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java index eff1fb31cd..ee708b4176 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ALGORITHM; @@ -36,19 +35,18 @@ import java.util.TreeMap; */ public class ManifestBuilder { + private static final String PROPERTY_FORMAT = "%s: %s%n"; + private static final String SECTION_FORMAT = "%s:%n"; private final Map<String, Map<String, String>> sourceWithPropertiesMap = new TreeMap<>(); private final Map<String, List<String>> nonManoArtifactMap = new TreeMap<>(); private final Map<String, String> metadataMap = new TreeMap<>(); - private static final String PROPERTY_FORMAT = "%s: %s%n"; - private static final String SECTION_FORMAT = "%s:%n"; /** * Adds a metadata property. * - * @param metadataProperty the property name - * @param value the property value - * @return - * a reference to this object. + * @param metadataProperty the property name + * @param value the property value + * @return a reference to this object. */ public ManifestBuilder withMetaData(final String metadataProperty, final String value) { metadataMap.put(metadataProperty, value); @@ -58,9 +56,8 @@ public class ManifestBuilder { /** * Adds a manifest source path. * - * @param sourcePath The source path - * @return - * a reference to this object. + * @param sourcePath The source path + * @return a reference to this object. */ public ManifestBuilder withSource(final String sourcePath) { sourceWithPropertiesMap.put(sourcePath, null); @@ -71,10 +68,9 @@ public class ManifestBuilder { * Adds a manifest source path with the source sign. * * @param sourcePath The source path - * @param hashAlgorithm The hash algorithm + * @param hashAlgorithm The hash algorithm * @param hash The hash representing the sign - * @return - * a reference to this object. + * @return a reference to this object. */ public ManifestBuilder withSignedSource(final String sourcePath, final String hashAlgorithm, final String hash) { TreeMap<String, String> sourcePropertiesMap = new TreeMap<>(); @@ -87,10 +83,9 @@ public class ManifestBuilder { /** * Adds a non mano artifact. * - * @param artifactType the artifact type - * @param sourcePath the artifact source path - * @return - * a reference to this object. + * @param artifactType the artifact type + * @param sourcePath the artifact source path + * @return a reference to this object. */ public ManifestBuilder withNonManoArtifact(final String artifactType, final String sourcePath) { nonManoArtifactMap.putIfAbsent(artifactType, new ArrayList<>()); @@ -98,27 +93,22 @@ public class ManifestBuilder { return this; } - /** * Builds the String representing the manifest file. - * @return - * The manifest file as String + * + * @return The manifest file as String */ public String build() { final StringBuilder stringBuilder = new StringBuilder(); - if (!metadataMap.isEmpty()) { stringBuilder.append(buildMetadata()); } - if (!sourceWithPropertiesMap.isEmpty()) { stringBuilder.append(buildSource()); } - if (!nonManoArtifactMap.isEmpty()) { stringBuilder.append(buildNonManoArtifact()); } - return stringBuilder.toString(); } @@ -143,7 +133,6 @@ public class ManifestBuilder { if (algorithm != null) { stringBuilder.append(String.format(PROPERTY_FORMAT, ALGORITHM.getToken(), algorithm)); } - final String hash = propertiesMap.get(HASH.getToken()); if (hash != null) { stringBuilder.append(String.format(PROPERTY_FORMAT, HASH.getToken(), hash)); @@ -167,5 +156,4 @@ public class ManifestBuilder { } return stringBuilder.toString(); } - } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java index 0d5aef58ac..486970451f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; @@ -51,7 +50,6 @@ import org.openecomp.sdc.tosca.csar.ToscaMetadata; class ONAPCsarValidator implements Validator { private static Logger logger = LoggerFactory.getLogger(ONAPCsarValidator.class); - private List<ErrorMessage> uploadFileErrors = new ArrayList<>(); @Override @@ -61,30 +59,26 @@ class ONAPCsarValidator implements Validator { validateMetadata(contentHandler); validateNoExtraFiles(contentHandler); validateFolders(contentHandler.getFolderList()); - - if(uploadFileErrors == null || uploadFileErrors.isEmpty()){ + if (uploadFileErrors == null || uploadFileErrors.isEmpty()) { return errors; } errors.put(SdcCommon.UPLOAD_FILE, uploadFileErrors); return errors; } - private void validateMetadata(FileContentHandler contentMap){ + private void validateMetadata(FileContentHandler contentMap) { if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) { try (InputStream metaFileContent = contentMap.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)) { - ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metaFileContent); String entryDefinitionsPath = onboardingToscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName()); if (entryDefinitionsPath != null) { validateFileExist(contentMap, entryDefinitionsPath); } else { - uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, - Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage())); + uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage())); } } catch (IOException exception) { logger.error(exception.getMessage(), exception); - uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, - Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage())); + uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage())); } } else { validateFileExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); @@ -95,40 +89,32 @@ class ONAPCsarValidator implements Validator { if (!validateFileExist(contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { return; } - try (final InputStream fileContent = contentMap.getFileContentAsStream(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { final Manifest onboardingManifest = new ONAPManifestOnboarding(); onboardingManifest.parse(fileContent); if (!onboardingManifest.isValid()) { - onboardingManifest.getErrors() - .forEach(error -> uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, error))); + onboardingManifest.getErrors().forEach(error -> uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, error))); } } catch (final IOException ex) { - final String errorMessage = - Messages.MANIFEST_UNEXPECTED_ERROR.formatMessage(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, ex.getMessage()); + final String errorMessage = Messages.MANIFEST_UNEXPECTED_ERROR.formatMessage(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, ex.getMessage()); uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, errorMessage)); logger.error(errorMessage, ex); } } private void validateNoExtraFiles(FileContentHandler contentMap) { - List<String> unwantedFiles = contentMap.getFileList().stream() - .filter(this::filterFiles).collect(Collectors.toList()); + List<String> unwantedFiles = contentMap.getFileList().stream().filter(this::filterFiles).collect(Collectors.toList()); if (!unwantedFiles.isEmpty()) { - unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> - uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), unwantedFile)))); + unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> uploadFileErrors + .add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), unwantedFile)))); } } private void validateFolders(Set<String> folderList) { - List<String> filterResult = - folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); + List<String> filterResult = folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); if (!filterResult.isEmpty()) { - folderList.stream().filter(this::filterFolders).forEach(unwantedFolder -> - uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), - unwantedFolder)))); + folderList.stream().filter(this::filterFolders).forEach(unwantedFolder -> uploadFileErrors.add( + new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), unwantedFolder)))); } } @@ -146,11 +132,10 @@ class ONAPCsarValidator implements Validator { } private boolean validateFileExist(FileContentHandler contentMap, String fileName) { - boolean containsFile = contentMap.containsFile(fileName); if (!containsFile) { - uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); + uploadFileErrors + .add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); } return containsFile; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidator.java index 90270c2f7e..77c7347e49 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidator.java @@ -30,19 +30,14 @@ import org.onap.validation.yaml.error.YamlDocumentValidationError; public class PMDictionaryValidator { public void validate(Stream<byte[]> pmDictionaryFiles, Consumer<String> errorReporter) { - pmDictionaryFiles - .map(this::validate) - .flatMap(Collection::stream) - .forEach(errorReporter); + pmDictionaryFiles.map(this::validate).flatMap(Collection::stream).forEach(errorReporter); } private List<String> validate(byte[] fileContent) { List<String> errors = new ArrayList<>(); try { List<YamlDocumentValidationError> validationErrors = new YamlContentValidator().validate(fileContent); - validationErrors.stream() - .map(this::formatErrorMessage) - .forEach(errors::add); + validationErrors.stream().map(this::formatErrorMessage).forEach(errors::add); } catch (Exception e) { errors.add(e.getMessage()); } @@ -50,9 +45,6 @@ public class PMDictionaryValidator { } private String formatErrorMessage(YamlDocumentValidationError error) { - return String.format("Document number: %d, Path: %s, Message: %s", - error.getYamlDocumentNumber(), - error.getPath(), - error.getMessage()); + return String.format("Document number: %d, Path: %s, Message: %s", error.getYamlDocumentNumber(), error.getPath(), error.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 22ab4f45a6..d99848ddb8 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 @@ -19,10 +19,8 @@ * * Modifications copyright (c) 2020 Nokia * ================================================================================ */ - 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; @@ -44,6 +42,7 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSIO import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_FILE_VERSION_1_0; import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME; +import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -57,8 +56,6 @@ 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; @@ -89,22 +86,21 @@ import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException import org.yaml.snakeyaml.Yaml; /** - * 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 v2.6.1. + * 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 v2.6.1. */ class SOL004MetaDirectoryValidator implements Validator { private static final Logger LOGGER = LoggerFactory.getLogger(SOL004MetaDirectoryValidator.class); - private static final String MANIFEST_SOURCE = "Source"; private static final String MANIFEST_NON_MANO_SOURCE = "Non-MANO Source"; + protected final ValidatorUtils validatorUtils = new ValidatorUtils(); private final List<ErrorMessage> errorsByFile = new CopyOnWriteArrayList<>(); private final SecurityManager securityManager; + private final InternalFilesFilter internalFilesFilter = new InternalFilesFilter(); private OnboardingPackageContentHandler contentHandler; private Set<String> folderList; private ToscaMetadata toscaMetadata; - private final InternalFilesFilter internalFilesFilter = new InternalFilesFilter(); - protected final ValidatorUtils validatorUtils = new ValidatorUtils(); public SOL004MetaDirectoryValidator() { securityManager = SecurityManager.getInstance(); @@ -121,7 +117,6 @@ class SOL004MetaDirectoryValidator implements Validator { this.folderList = contentHandler.getFolderList(); parseToscaMetadata(); verifyMetadataFile(); - if (packageHasCertificate()) { verifySignedFiles(); } @@ -143,9 +138,7 @@ class SOL004MetaDirectoryValidator implements Validator { */ private void parseToscaMetadata() { try { - toscaMetadata = - OnboardingToscaMetadata - .parseToscaMetadataFile(contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)); + toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)); } catch (final IOException e) { reportError(ErrorLevel.ERROR, Messages.METADATA_PARSER_INTERNAL.getErrorMessage()); LOGGER.error(Messages.METADATA_PARSER_INTERNAL.getErrorMessage(), e.getMessage(), e); @@ -175,12 +168,11 @@ class SOL004MetaDirectoryValidator implements Validator { final byte[] fileSignatureBytes = contentHandler.getFileContent(fileSignaturePath); try { if (!securityManager.verifySignedData(fileSignatureBytes, packageCert, fileBytes)) { - reportError(ErrorLevel.ERROR, - Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fileSignaturePath, filePath)); + reportError(ErrorLevel.ERROR, Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fileSignaturePath, filePath)); } } catch (final SecurityManagerException e) { final String errorMessage = Messages.ARTIFACT_SIGNATURE_VALIDATION_ERROR - .formatMessage(fileSignaturePath, filePath, packageCertificatePath, e.getMessage()); + .formatMessage(fileSignaturePath, filePath, packageCertificatePath, e.getMessage()); reportError(ErrorLevel.ERROR, errorMessage); LOGGER.error(errorMessage, e); } @@ -196,8 +188,7 @@ class SOL004MetaDirectoryValidator implements Validator { reportError(ErrorLevel.ERROR, Messages.MANIFEST_INVALID_EXT.getErrorMessage()); } if (!mainDefinitionFileName.equals(manifestFileName)) { - reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_NAME.getErrorMessage(), - manifestFileName, mainDefinitionFileName)); + reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_NAME.getErrorMessage(), manifestFileName, mainDefinitionFileName)); } } @@ -211,15 +202,13 @@ class SOL004MetaDirectoryValidator implements Validator { private boolean hasETSIMetadata() { final Map<String, String> entries = toscaMetadata.getMetaEntries(); - return hasEntry(entries, TOSCA_META_FILE_VERSION_ENTRY.getName()) - && hasEntry(entries, CSAR_VERSION_ENTRY.getName()) - && hasEntry(entries, CREATED_BY_ENTRY.getName()); + return hasEntry(entries, TOSCA_META_FILE_VERSION_ENTRY.getName()) && hasEntry(entries, CSAR_VERSION_ENTRY.getName()) && hasEntry(entries, + CREATED_BY_ENTRY.getName()); } private boolean hasEntry(final Map<String, String> entries, final String mandatoryEntry) { if (!entries.containsKey(mandatoryEntry)) { - reportError(ErrorLevel.ERROR, - String.format(Messages.METADATA_MISSING_ENTRY.getErrorMessage(), mandatoryEntry)); + reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_ENTRY.getErrorMessage(), mandatoryEntry)); return false; } return true; @@ -237,7 +226,6 @@ class SOL004MetaDirectoryValidator implements Validator { return; } final String value = entry.getValue(); - switch (toscaMetaEntry) { case TOSCA_META_FILE_VERSION_ENTRY: case CSAR_VERSION_ENTRY: @@ -277,18 +265,14 @@ class SOL004MetaDirectoryValidator implements Validator { validateOtherEntries(value); } else { final String key = (String) entry.getKey(); - reportError(ErrorLevel.ERROR, - String.format(Messages.MANIFEST_INVALID_PNF_METADATA.getErrorMessage(), key)); + reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_PNF_METADATA.getErrorMessage(), key)); } - } } private void verifyMetadataEntryVersions(final String key, final String version) { - if (!(isValidTOSCAVersion(key, version) || isValidCSARVersion(key, version) - || CREATED_BY_ENTRY.getName().equals(key))) { - errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR, - String.format(Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version))); + if (!(isValidTOSCAVersion(key, version) || isValidCSARVersion(key, version) || CREATED_BY_ENTRY.getName().equals(key))) { + errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR, String.format(Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version))); LOGGER.error("{}: key {} - value {} ", Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version); } } @@ -298,16 +282,13 @@ class SOL004MetaDirectoryValidator implements Validator { } private boolean isValidCSARVersion(final String value, final String version) { - return CSAR_VERSION_ENTRY.getName().equals(value) && (CSAR_VERSION_1_1.equals(version) - || CSAR_VERSION_1_0.equals(version)); + return CSAR_VERSION_ENTRY.getName().equals(value) && (CSAR_VERSION_1_1.equals(version) || CSAR_VERSION_1_0.equals(version)); } protected void validateDefinitionFile(final String filePath) { final Set<String> existingFiles = contentHandler.getFileList(); - if (verifyFileExists(existingFiles, filePath)) { - final ToscaDefinitionImportHandler toscaDefinitionImportHandler = - new ToscaDefinitionImportHandler(contentHandler.getFiles(), filePath); + final ToscaDefinitionImportHandler toscaDefinitionImportHandler = new ToscaDefinitionImportHandler(contentHandler.getFiles(), filePath); final List<ErrorMessage> validationErrorList = toscaDefinitionImportHandler.getErrors(); if (CollectionUtils.isNotEmpty(validationErrorList)) { errorsByFile.addAll(validationErrorList); @@ -345,31 +326,23 @@ class SOL004MetaDirectoryValidator implements Validator { private void verifyManifestMetadata(final Map<String, String> metadata) { if (!validMetaLimit(metadata)) { - reportError(ErrorLevel.ERROR, - String.format(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT.getErrorMessage(), - MANIFEST_METADATA_LIMIT)); + reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT.getErrorMessage(), MANIFEST_METADATA_LIMIT)); } handleMetadataEntries(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; - if (metadata.keySet().stream() - .anyMatch((final String metadataEntry) -> !metadataEntry.contains(expectedMetadataType))) { + final String expectedMetadataType = firstMetadataDefinition.contains(TOSCA_TYPE_PNF) ? TOSCA_TYPE_PNF : TOSCA_TYPE_VNF; + if (metadata.keySet().stream().anyMatch((final String metadataEntry) -> !metadataEntry.contains(expectedMetadataType))) { throw new InvalidManifestMetadataException(Messages.MANIFEST_METADATA_INVALID_ENTRY.getErrorMessage()); } - return TOSCA_TYPE_PNF.equals(expectedMetadataType); } 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))); + getManifestMetadata(metadata).stream().filter(requiredEntry -> !metadata.containsKey(requiredEntry)).forEach( + requiredEntry -> reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry))); } /** @@ -381,9 +354,7 @@ class SOL004MetaDirectoryValidator implements Validator { final Set<String> packageFiles = contentHandler.getFileList(); final List<String> sources = internalFilesFilter.filter(onboardingManifest.getSources()); verifyFilesExist(packageFiles, sources, MANIFEST_SOURCE); - final Map<String, List<String>> nonManoArtifacts = onboardingManifest.getNonManoSources(); - final List<String> nonManoValidFilePaths = new ArrayList<>(); nonManoArtifacts.forEach((nonManoType, files) -> { final List<String> internalNonManoFileList = internalFilesFilter.filter(files); @@ -397,9 +368,7 @@ class SOL004MetaDirectoryValidator implements Validator { validateOnapCnfHelmNonManoEntry(files); } }); - verifyFilesExist(packageFiles, nonManoValidFilePaths, MANIFEST_NON_MANO_SOURCE); - final Set<String> allReferredFiles = new HashSet<>(); allReferredFiles.addAll(sources); allReferredFiles.addAll(nonManoValidFilePaths); @@ -412,32 +381,25 @@ class SOL004MetaDirectoryValidator implements Validator { 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)); + 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); + final Optional<PnfSoftwareInformation> parsedYaml = SoftwareInformationArtifactYamlParser.parse(swInformationYaml); if (!parsedYaml.isPresent()) { - reportError(ErrorLevel.ERROR, - Messages.INVALID_SW_INFORMATION_NON_MANO_ERROR.formatMessage(swInformationFilePath)); + 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)); + 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. + * Validates if a YAML file has the correct extension, is not empty and the content is a valid YAML. Reports each error found. * * @param filePath the file path inside the package */ @@ -450,7 +412,6 @@ class SOL004MetaDirectoryValidator implements Validator { reportError(ErrorLevel.ERROR, Messages.INVALID_YAML_EXTENSION.formatMessage(filePath)); return; } - try (final InputStream fileContent = contentHandler.getFileContentAsStream(filePath)) { if (fileContent == null) { reportError(ErrorLevel.ERROR, Messages.EMPTY_YAML_FILE_1.formatMessage(filePath)); @@ -477,8 +438,7 @@ class SOL004MetaDirectoryValidator implements Validator { private void verifyFilesBeingReferred(final Set<String> referredFileSet, final Set<String> packageFileSet) { packageFileSet.forEach(filePath -> { if (!isManifestFile(filePath) && !referredFileSet.contains(filePath)) { - reportError(ErrorLevel.ERROR, - String.format(Messages.MISSING_MANIFEST_REFERENCE.getErrorMessage(), filePath)); + reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_MANIFEST_REFERENCE.getErrorMessage(), filePath)); } }); } @@ -489,16 +449,14 @@ class SOL004MetaDirectoryValidator implements Validator { private void validateOtherEntries(final String folderPath) { if (!verifyFoldersExist(folderList, folderPath)) { - reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_OPTIONAL_FOLDERS.getErrorMessage(), - folderPath)); + reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_OPTIONAL_FOLDERS.getErrorMessage(), folderPath)); } } private void validateCertificate(final String file) { final Set<String> packageFiles = contentHandler.getFileList(); if (!verifyFileExist(packageFiles, file)) { - reportError(ErrorLevel.ERROR, - String.format(Messages.MISSING_METADATA_FILES.getErrorMessage(), file, file)); + reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_METADATA_FILES.getErrorMessage(), file, file)); } } @@ -509,8 +467,7 @@ class SOL004MetaDirectoryValidator implements Validator { private void verifyFilesExist(final Set<String> existingFiles, final List<String> sources, final String type) { sources.forEach(file -> { if (!existingFiles.contains(file)) { - reportError(ErrorLevel.ERROR, - String.format(Messages.MISSING_MANIFEST_SOURCE.getErrorMessage(), type, file)); + reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_MANIFEST_SOURCE.getErrorMessage(), type, file)); } }); } @@ -552,10 +509,8 @@ class SOL004MetaDirectoryValidator implements Validator { } private void validatePmDictionaryContentsAgainstSchema() { - final Stream<byte[]> pmDictionaryFiles = new FileExtractor(getEtsiEntryManifestPath(), contentHandler) - .findFiles(ONAP_PM_DICTIONARY); - new PMDictionaryValidator() - .validate(pmDictionaryFiles, (String message) -> reportError(ErrorLevel.ERROR, message)); + final Stream<byte[]> pmDictionaryFiles = new FileExtractor(getEtsiEntryManifestPath(), contentHandler).findFiles(ONAP_PM_DICTIONARY); + new PMDictionaryValidator().validate(pmDictionaryFiles, (String message) -> reportError(ErrorLevel.ERROR, message)); } private String getEtsiEntryManifestPath() { @@ -564,6 +519,7 @@ class SOL004MetaDirectoryValidator implements Validator { /** * Validates if onap_cnf_helm non_mano type points to a file + * * @param files */ private void validateOnapCnfHelmNonManoEntry(final List<String> files) { @@ -572,11 +528,8 @@ class SOL004MetaDirectoryValidator implements Validator { 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)); + 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 9e380a355c..12d5ecfff9 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 @@ -36,8 +36,8 @@ 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. + * 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 { @@ -56,8 +56,9 @@ class SOL004Version3MetaDirectoryValidator extends SOL004MetaDirectoryValidator 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 + } else { validateDefinitionFile(entry.getValue()); + } } @Override 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 index 701abfc677..31c19d7794 100644 --- 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 @@ -36,8 +36,8 @@ 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 + * 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 { @@ -78,5 +78,4 @@ class SOL004Version4MetaDirectoryValidator extends SOL004MetaDirectoryValidator 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/Validator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java index 34386b6d29..e8f88c7eba 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java @@ -17,22 +17,19 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.sdc.datatypes.error.ErrorMessage; import java.util.List; import java.util.Map; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.datatypes.error.ErrorMessage; /** * Validates the contents of the CSAR package uploaded in SDC. */ - public interface Validator { /** - * * @param contentHandler contains file and its data * @return errors Map of errors that occur */ 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 9d218190d8..27a1852644 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 @@ -17,7 +17,6 @@ * 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.ETSI_VERSION_2_7_1; @@ -29,8 +28,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImp public class ValidatorFactory { - private ValidatorFactory(){ - + private ValidatorFactory() { } /** @@ -45,7 +43,7 @@ public class ValidatorFactory { if (!etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { return new ONAPCsarValidator(); } - if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler).isLowerThan(ETSI_VERSION_2_7_1)){ + if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler).isLowerThan(ETSI_VERSION_2_7_1)) { if (etsiService.hasCnfEnhancements(fileContentHandler)) { return new SOL004Version4MetaDirectoryValidator(); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java index 620ff345ad..e3d91e01df 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java @@ -16,7 +16,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.exception; public class MissingCertificateException extends RuntimeException { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractor.java index c6d7d637fa..bfef0b4471 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractor.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractor.java @@ -48,8 +48,7 @@ public class FileExtractor { Map<String, List<String>> nonManoSources = extractNonManoSources(); List<String> pathsToSources = nonManoSources.getOrDefault(fileType.getType(), new ArrayList<>()); List<String> pathsToLocalFiles = internalFilesFilter.filter(pathsToSources); - return pathsToLocalFiles.stream() - .map(contentHandler::getFileContent); + return pathsToLocalFiles.stream().map(contentHandler::getFileContent); } private Map<String, List<String>> extractNonManoSources() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilter.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilter.java index 50dcd0ce29..ce119f6a6f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilter.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilter.java @@ -25,9 +25,7 @@ import java.util.stream.Collectors; public class InternalFilesFilter { public List<String> filter(final List<String> sources) { - return sources.stream() - .filter(this::isInternalFile) - .collect(Collectors.toList()); + return sources.stream().filter(this::isInternalFile).collect(Collectors.toList()); } private boolean isInternalFile(final String filePath) { 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 index cfdd53774f..d260b1272b 100644 --- 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 @@ -17,7 +17,6 @@ * 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; @@ -32,15 +31,11 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.Inv public class ValidatorUtils { public boolean isPnfMetadata(List<String> 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))) { + 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/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java index 137891c0c9..1204a73509 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java @@ -17,12 +17,11 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions; -public class InvalidManifestMetadataException extends RuntimeException{ +public class InvalidManifestMetadataException extends RuntimeException { - public InvalidManifestMetadataException(String message){ + public InvalidManifestMetadataException(String message) { super(message); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/OrchestrationTemplateHandlerException.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/OrchestrationTemplateHandlerException.java index a8a9105254..3f47915fdd 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/OrchestrationTemplateHandlerException.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/OrchestrationTemplateHandlerException.java @@ -17,12 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions; -public class OrchestrationTemplateHandlerException extends RuntimeException{ +public class OrchestrationTemplateHandlerException extends RuntimeException { - public OrchestrationTemplateHandlerException(String message, Throwable throwable){ + public OrchestrationTemplateHandlerException(String message, Throwable throwable) { super(message, throwable); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java index 0ac093240d..0b222fd51d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; + +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import org.onap.config.api.Configuration; import org.onap.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; @@ -23,49 +27,39 @@ import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; public class OrchestrationProcessFactory { - private static final Map<String, ImplementationConfiguration> PROCESS_IMPL_MAP; - private OrchestrationProcessFactory() { - - } - - static { - Configuration config = ConfigurationManager.lookup(); - PROCESS_IMPL_MAP = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, - ConfigConstants.PROCESS_IMPL_KEY, ImplementationConfiguration.class)); + private static final Map<String, ImplementationConfiguration> PROCESS_IMPL_MAP; - } - - public static Optional<OrchestrationTemplateProcessHandler> getInstance(String fileSuffix) { - - if (fileSuffix == null) { - return Optional.empty(); + static { + Configuration config = ConfigurationManager.lookup(); + PROCESS_IMPL_MAP = new ConcurrentHashMap<>( + config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, ConfigConstants.PROCESS_IMPL_KEY, ImplementationConfiguration.class)); } - String updatedFileSuffix = fileSuffix; - updatedFileSuffix = updatedFileSuffix.toLowerCase().trim(); - OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(updatedFileSuffix); - if (onboardingTypesEnum == null) { - return Optional.empty(); + + private OrchestrationProcessFactory() { } - try { - return Optional.of(createInstance(PROCESS_IMPL_MAP.get(onboardingTypesEnum.toString()))); - }catch (Exception e){ - return Optional.empty(); + public static Optional<OrchestrationTemplateProcessHandler> getInstance(String fileSuffix) { + if (fileSuffix == null) { + return Optional.empty(); + } + String updatedFileSuffix = fileSuffix; + updatedFileSuffix = updatedFileSuffix.toLowerCase().trim(); + OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(updatedFileSuffix); + if (onboardingTypesEnum == null) { + return Optional.empty(); + } + try { + return Optional.of(createInstance(PROCESS_IMPL_MAP.get(onboardingTypesEnum.toString()))); + } catch (Exception e) { + return Optional.empty(); + } } - } - private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass) - throws Exception { - OrchestrationTemplateProcessHandler handler; - handler = - CommonMethods.newInstance(implClass.getImplementationClass(), OrchestrationTemplateProcessHandler.class); - return handler; - } + private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass) throws Exception { + OrchestrationTemplateProcessHandler handler; + handler = CommonMethods.newInstance(implClass.getImplementationClass(), OrchestrationTemplateProcessHandler.class); + return handler; + } } 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 38508c6ec3..8778e0b56b 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 @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; import java.io.ByteArrayInputStream; @@ -58,125 +57,107 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); - private static final String SDC_ONBOARDED_PACKAGE_DIR = "Deployment/" + ArtifactTypeEnum.ETSI_PACKAGE.getType() + "/"; - private static final String EXT_SEPARATOR = "."; - private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface(); - private final ToscaTreeManager toscaTreeManager = new ToscaTreeManager(); - - @Override - public OrchestrationTemplateActionResponse process(VspDetails vspDetails, - OrchestrationTemplateCandidateData candidateData) { - - - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - Optional<FileContentHandler> fileContent = OrchestrationUtil - .getFileContentMap(OnboardingTypesEnum.CSAR, uploadFileResponse, - candidateData.getContentData().array()); - - OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); - if (fileContent.isPresent()) { - try { - FileContentHandler fileContentHandler = fileContent.get(); - processCsar(vspDetails, fileContentHandler, candidateData, response); - } catch (CoreException e) { - LOGGER.error(e.getMessage(), e); - response.addErrorMessageToMap(e.code().id(), e.code().message(),ErrorLevel.ERROR); - }catch (IOException e){ - LOGGER.error(e.getMessage(), e); - response.addErrorMessageToMap(SdcCommon.PROCESS_FILE, e.getMessage(), ErrorLevel.ERROR); - } - } else { - if (!uploadFileResponse.getErrors().isEmpty()) { - response.addStructureErrors(uploadFileResponse.getErrors()); - } + private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); + private static final String SDC_ONBOARDED_PACKAGE_DIR = "Deployment/" + ArtifactTypeEnum.ETSI_PACKAGE.getType() + "/"; + private static final String EXT_SEPARATOR = "."; + private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface(); + private final ToscaTreeManager toscaTreeManager = new ToscaTreeManager(); + + @Override + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, OrchestrationTemplateCandidateData candidateData) { + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional<FileContentHandler> fileContent = OrchestrationUtil + .getFileContentMap(OnboardingTypesEnum.CSAR, uploadFileResponse, candidateData.getContentData().array()); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + if (fileContent.isPresent()) { + try { + FileContentHandler fileContentHandler = fileContent.get(); + processCsar(vspDetails, fileContentHandler, candidateData, response); + } catch (CoreException e) { + LOGGER.error(e.getMessage(), e); + response.addErrorMessageToMap(e.code().id(), e.code().message(), ErrorLevel.ERROR); + } catch (IOException e) { + LOGGER.error(e.getMessage(), e); + response.addErrorMessageToMap(SdcCommon.PROCESS_FILE, e.getMessage(), ErrorLevel.ERROR); + } + } else { + if (!uploadFileResponse.getErrors().isEmpty()) { + response.addStructureErrors(uploadFileResponse.getErrors()); + } + } + return response; } - return response; - } - - private void processCsar(VspDetails vspDetails, - FileContentHandler fileContentHandler, - OrchestrationTemplateCandidateData candidateData, - OrchestrationTemplateActionResponse response) throws IOException{ - response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); - Map<String, List<ErrorMessage>> errors = validateCsar(fileContentHandler); - toscaTreeManager.createTree(); - if (!isValid(errors)) { - response.addStructureErrors(errors); - toscaTreeManager.addErrors(errors); - candidateService.updateValidationData(vspDetails.getId(), vspDetails.getVersion(), - new ValidationStructureList(toscaTreeManager.getTree())); - return; + private void processCsar(VspDetails vspDetails, FileContentHandler fileContentHandler, OrchestrationTemplateCandidateData candidateData, + OrchestrationTemplateActionResponse response) throws IOException { + response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); + Map<String, List<ErrorMessage>> errors = validateCsar(fileContentHandler); + toscaTreeManager.createTree(); + if (!isValid(errors)) { + response.addStructureErrors(errors); + toscaTreeManager.addErrors(errors); + candidateService + .updateValidationData(vspDetails.getId(), vspDetails.getVersion(), new ValidationStructureList(toscaTreeManager.getTree())); + return; + } + HeatStructureTree tree = toscaTreeManager.getTree(); + Map<String, String> componentsQuestionnaire = new HashMap<>(); + Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); + Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); + Map<String, ProcessEntity> processArtifact = new HashMap<>(); + OrchestrationUtil orchestrationUtil = new OrchestrationUtil(); + orchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspDetails.getId(), vspDetails.getVersion(), componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream(vspDetails.getId(), candidateData, null, OnboardingTypesEnum.CSAR, errors); + orchestrationUtil.deleteUploadDataAndContent(vspDetails.getId(), vspDetails.getVersion()); + zipByteArrayInputStream.ifPresent( + byteArrayInputStream -> orchestrationUtil.saveUploadData(vspDetails, candidateData, byteArrayInputStream, fileContentHandler, tree)); + ETSIService etsiService = new ETSIServiceImpl(); + ToscaServiceModel toscaServiceModel; + if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { + if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) { + fileContentHandler + .addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getOriginalFileName() + EXT_SEPARATOR + candidateData.getOriginalFileSuffix(), + candidateData.getOriginalFileContentData().array()); + } else { + fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() + EXT_SEPARATOR + candidateData.getFileSuffix(), + candidateData.getContentData().array()); + } + final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler); + toscaServiceModel = instantiateToscaConverterFor(resourceType).convert(fileContentHandler); + } else { + toscaServiceModel = new ToscaConverterImpl().convert(fileContentHandler); + } + orchestrationUtil.saveServiceModel(vspDetails.getId(), vspDetails.getVersion(), toscaServiceModel, toscaServiceModel); + candidateService.deleteOrchestrationTemplateCandidate(vspDetails.getId(), vspDetails.getVersion()); } - HeatStructureTree tree = toscaTreeManager.getTree(); - - Map<String, String> componentsQuestionnaire = new HashMap<>(); - Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); - Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); - Map<String, ProcessEntity> processArtifact = new HashMap<>(); - OrchestrationUtil orchestrationUtil = new OrchestrationUtil(); - orchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspDetails.getId(), - vspDetails.getVersion(), componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService - .fetchZipFileByteArrayInputStream(vspDetails.getId(), candidateData, null, - OnboardingTypesEnum.CSAR, errors); - - orchestrationUtil.deleteUploadDataAndContent(vspDetails.getId(), vspDetails.getVersion()); - zipByteArrayInputStream.ifPresent(byteArrayInputStream -> orchestrationUtil - .saveUploadData(vspDetails, candidateData, byteArrayInputStream, - fileContentHandler, tree)); - - ETSIService etsiService = new ETSIServiceImpl(); - ToscaServiceModel toscaServiceModel; - if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { - if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) { - fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getOriginalFileName() + - EXT_SEPARATOR + candidateData.getOriginalFileSuffix(), candidateData.getOriginalFileContentData().array()); - } else { - fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() + - EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array()); - } - final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler); - toscaServiceModel = instantiateToscaConverterFor(resourceType).convert(fileContentHandler); - } else { - toscaServiceModel = new ToscaConverterImpl().convert(fileContentHandler); + private AbstractToscaSolConverter instantiateToscaConverterFor(ResourceTypeEnum resourceType) { + if (resourceType == ResourceTypeEnum.PNF) { + return new ToscaSolModelDrivenConverterPnf(); + } + // default is VF + return new ToscaSolConverterVnf(); } - orchestrationUtil.saveServiceModel(vspDetails.getId(), - vspDetails.getVersion(), toscaServiceModel, - toscaServiceModel); - candidateService - .deleteOrchestrationTemplateCandidate(vspDetails.getId(), vspDetails.getVersion()); - } - private AbstractToscaSolConverter instantiateToscaConverterFor(ResourceTypeEnum resourceType) { - if (resourceType == ResourceTypeEnum.PNF) { - return new ToscaSolModelDrivenConverterPnf(); + private void addFiles(FileContentHandler fileContentHandler) { + for (Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) { + toscaTreeManager.addFile(fileEntry.getKey(), fileEntry.getValue()); + } } - // default is VF - return new ToscaSolConverterVnf(); - } - private void addFiles(FileContentHandler fileContentHandler) { - for (Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) { - toscaTreeManager.addFile(fileEntry.getKey(), fileEntry.getValue()); + private Map<String, List<ErrorMessage>> validateCsar(FileContentHandler fileContentHandler) { + Map<String, List<ErrorMessage>> errors = new HashMap<>(); + addFiles(fileContentHandler); + toscaTreeManager.createTree(); + toscaTreeManager.addErrors(errors); + //todo - add tosca validation here to the existing validation framework + return errors; } - } - - private Map<String, List<ErrorMessage>> validateCsar(FileContentHandler fileContentHandler) { - Map<String, List<ErrorMessage>> errors = new HashMap<>(); - addFiles(fileContentHandler); - toscaTreeManager.createTree(); - toscaTreeManager.addErrors(errors); - //todo - add tosca validation here to the existing validation framework - return errors; - } - private boolean isValid(Map<String, List<ErrorMessage>> errors) { - return MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors)); - } + private boolean isValid(Map<String, List<ErrorMessage>> errors) { + return MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors)); + } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java index c775ac2c84..ae555b78a0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; - import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; @@ -24,6 +22,5 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateAction @FunctionalInterface public interface OrchestrationTemplateProcessHandler { - OrchestrationTemplateActionResponse process(VspDetails vspDetails, - OrchestrationTemplateCandidateData candidateData); + OrchestrationTemplateActionResponse process(VspDetails vspDetails, OrchestrationTemplateCandidateData candidateData); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java index 2d18a62122..5f18cb2faa 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java @@ -14,9 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.translator.datatypes.TranslatorOutput; @@ -37,7 +46,11 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; import org.openecomp.sdc.validation.util.ValidationManagerUtil; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.*; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +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; @@ -47,157 +60,119 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStru import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.*; - public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemplateProcessHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); - private final CandidateService candidateService = - CandidateServiceFactory.getInstance().createInterface(); - - @Override - public OrchestrationTemplateActionResponse process(VspDetails vspDetails, - OrchestrationTemplateCandidateData candidateData) { - String vspId = vspDetails.getId(); - Version version = vspDetails.getVersion(); - OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - Optional<FileContentHandler> fileContent = OrchestrationUtil - .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, - candidateData.getContentData().array()); - if (!fileContent.isPresent()) { - response.addStructureErrors(uploadFileResponse.getErrors()); - return response; - } - - Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); - FileContentHandler fileContentMap = fileContent.get(); - try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) { - addDummyHeatBase(zipFileManifest ,fileContentMap); - } catch (Exception e) { - LOGGER.error("Invalid package content", e); - } - FilesDataStructure structure = - JsonUtil.json2Object(candidateData.getFilesDataStructure(), FilesDataStructure.class); - - if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { - response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, - Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); - return response; - } - - - ManifestContent zipManifestFile = readManifestFromZip(fileContentMap); - String manifest = null; - if (zipManifestFile == null) { - manifest = candidateService.createManifest(vspDetails, structure); - } else { - manifest = candidateService.createManifestFromExisting(vspDetails, structure, zipManifestFile); + private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); + private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface(); + + @Override + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, OrchestrationTemplateCandidateData candidateData) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional<FileContentHandler> fileContent = OrchestrationUtil + .getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, candidateData.getContentData().array()); + if (!fileContent.isPresent()) { + response.addStructureErrors(uploadFileResponse.getErrors()); + return response; + } + Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); + FileContentHandler fileContentMap = fileContent.get(); + try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) { + addDummyHeatBase(zipFileManifest, fileContentMap); + } catch (Exception e) { + LOGGER.error("Invalid package content", e); + } + FilesDataStructure structure = JsonUtil.json2Object(candidateData.getFilesDataStructure(), FilesDataStructure.class); + if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { + response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); + return response; + } + ManifestContent zipManifestFile = readManifestFromZip(fileContentMap); + String manifest = null; + if (zipManifestFile == null) { + manifest = candidateService.createManifest(vspDetails, structure); + } else { + manifest = candidateService.createManifestFromExisting(vspDetails, structure, zipManifestFile); + } + fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream(vspId, candidateData, manifest, OnboardingTypesEnum.ZIP, uploadErrors); + if (!zipByteArrayInputStream.isPresent()) { + return response; + } + HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); + Map<String, List<ErrorMessage>> errors = getErrors(response); + if (MapUtils.isNotEmpty(errors)) { + response.addStructureErrors(errors); + candidateService.updateValidationData(vspId, version, new ValidationStructureList(tree)); + return response; + } + Map<String, String> componentsQuestionnaire = new HashMap<>(); + Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); + Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); + Map<String, ProcessEntity> processArtifact = new HashMap<>(); + OrchestrationUtil orchestrationUtil = new OrchestrationUtil(); + Map<String, String> vspComponentIdNameInfoBeforeProcess = orchestrationUtil.getVspComponentIdNameInfo(vspId, version); + Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete = orchestrationUtil + .getComponentDependenciesBeforeDelete(vspId, version); + orchestrationUtil + .backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire, componentNicsQuestionnaire, componentMibList, + processes, processArtifact); + orchestrationUtil.deleteUploadDataAndContent(vspId, version); + orchestrationUtil.saveUploadData(vspDetails, candidateData, zipByteArrayInputStream.get(), fileContentMap, tree); + TranslatorOutput translatorOutput = HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); + ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); + orchestrationUtil.saveServiceModel(vspId, version, translatorOutput.getNonUnifiedToscaServiceModel(), toscaServiceModel); + orchestrationUtil + .retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, componentNicsQuestionnaire, componentMibList, processes, + processArtifact); + orchestrationUtil.updateVspComponentDependencies(vspId, version, vspComponentIdNameInfoBeforeProcess, componentDependenciesBeforeDelete); + uploadFileResponse.addStructureErrors(uploadErrors); + candidateService.deleteOrchestrationTemplateCandidate(vspId, version); + return response; } - fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); - Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService - .fetchZipFileByteArrayInputStream( - vspId, candidateData, manifest, OnboardingTypesEnum.ZIP, uploadErrors); - if (!zipByteArrayInputStream.isPresent()) { - return response; + private ManifestContent readManifestFromZip(FileContentHandler fileContentMap) { + ManifestContent zipManifestFile = null; + try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) { + zipManifestFile = JsonUtil.json2Object(zipFileManifest, ManifestContent.class); + } catch (Exception e) { + LOGGER.error("Invalid package content", e); + } + return zipManifestFile; } - HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); - Map<String, List<ErrorMessage>> errors = getErrors(response); - if (MapUtils.isNotEmpty(errors)) { - response.addStructureErrors(errors); - candidateService.updateValidationData(vspId, version, new ValidationStructureList(tree)); - return response; + private FileContentHandler addDummyHeatBase(InputStream zipFileManifest, FileContentHandler fileContentMap) { + ManifestContent manifestContent = JsonUtil.json2Object(zipFileManifest, ManifestContent.class); + for (FileData fileData : manifestContent.getData()) { + if (Objects.nonNull(fileData.getType()) && fileData.getType().equals(FileData.Type.HELM) && fileData.getBase()) { + String filePath = new File("").getAbsolutePath() + "/resources"; + File envFilePath = new File(filePath + "/base_template.env"); + File baseFilePath = new File(filePath + "/base_template.yaml"); + try (InputStream envStream = new FileInputStream(envFilePath); InputStream baseStream = new FileInputStream(baseFilePath);) { + fileContentMap.addFile("base_template_dummy_ignore.env", envStream); + fileContentMap.addFile("base_template_dummy_ignore.yaml", baseStream); + } catch (Exception e) { + LOGGER.error("File not found error {}", e); + } + } + } + return fileContentMap; } - Map<String, String> componentsQuestionnaire = new HashMap<>(); - Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); - Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); - Map<String, ProcessEntity> processArtifact = new HashMap<>(); - - OrchestrationUtil orchestrationUtil = new OrchestrationUtil(); - Map<String, String> vspComponentIdNameInfoBeforeProcess = - orchestrationUtil.getVspComponentIdNameInfo(vspId, version); - Collection<ComponentDependencyModelEntity> componentDependenciesBeforeDelete = - orchestrationUtil.getComponentDependenciesBeforeDelete(vspId, version); - orchestrationUtil - .backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - orchestrationUtil.deleteUploadDataAndContent(vspId, version); - orchestrationUtil - .saveUploadData(vspDetails, candidateData, zipByteArrayInputStream.get(), fileContentMap, - tree); - - TranslatorOutput translatorOutput = - HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); - - ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); - orchestrationUtil - .saveServiceModel(vspId, version, translatorOutput.getNonUnifiedToscaServiceModel(), - toscaServiceModel); - orchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - orchestrationUtil.updateVspComponentDependencies(vspId, version, - vspComponentIdNameInfoBeforeProcess, componentDependenciesBeforeDelete); - - uploadFileResponse.addStructureErrors(uploadErrors); - candidateService.deleteOrchestrationTemplateCandidate(vspId, version); - return response; - } - - private ManifestContent readManifestFromZip(FileContentHandler fileContentMap) { - ManifestContent zipManifestFile = null; - try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) { - zipManifestFile = JsonUtil.json2Object(zipFileManifest, ManifestContent.class); - } catch (Exception e) { - LOGGER.error("Invalid package content", e); + private Map<String, List<ErrorMessage>> getErrors(OrchestrationTemplateActionResponse orchestrationTemplateActionResponse) { + Map<String, List<ErrorMessage>> errors = MessageContainerUtil + .getMessageByLevel(ErrorLevel.ERROR, orchestrationTemplateActionResponse.getErrors()); + return MapUtils.isEmpty(errors) ? null : orchestrationTemplateActionResponse.getErrors(); } - return zipManifestFile; - } - private FileContentHandler addDummyHeatBase(InputStream zipFileManifest, FileContentHandler fileContentMap) { - ManifestContent manifestContent = - JsonUtil.json2Object(zipFileManifest, ManifestContent.class); - for (FileData fileData : manifestContent.getData()) { - if (Objects.nonNull(fileData.getType()) && - fileData.getType().equals(FileData.Type.HELM) && fileData.getBase()) { - String filePath = new File("").getAbsolutePath() + "/resources"; - File envFilePath = new File(filePath + "/base_template.env"); - File baseFilePath = new File(filePath + "/base_template.yaml"); - try ( - InputStream envStream = new FileInputStream(envFilePath); - InputStream baseStream = new FileInputStream(baseFilePath);) { - fileContentMap.addFile("base_template_dummy_ignore.env", envStream); - fileContentMap.addFile("base_template_dummy_ignore.yaml", baseStream); - } catch (Exception e) { - LOGGER.error("File not found error {}", e); - } - } + private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, FileContentHandler fileContentMap) { + VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); + Map<String, List<ErrorMessage>> validationErrors = ValidationManagerUtil.initValidationManager(fileContentMap).validate(); + response.getErrors().putAll(validationErrors); + return OrchestrationUtil.createHeatTree(fileContentMap, validationErrors); } - return fileContentMap; - } - - private Map<String, List<ErrorMessage>> getErrors(OrchestrationTemplateActionResponse - orchestrationTemplateActionResponse) { - Map<String, List<ErrorMessage>> errors = - MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, - orchestrationTemplateActionResponse.getErrors()); - return MapUtils.isEmpty(errors) ? null : orchestrationTemplateActionResponse.getErrors(); - } - - private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, - FileContentHandler fileContentMap) { - VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); - Map<String, List<ErrorMessage>> validationErrors = - ValidationManagerUtil.initValidationManager(fileContentMap).validate(); - response.getErrors().putAll(validationErrors); - - return OrchestrationUtil.createHeatTree(fileContentMap, validationErrors); - } } |