diff options
author | Avi Gaffa <avi.gaffa@amdocs.com> | 2017-09-12 11:00:02 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-12 11:00:02 +0000 |
commit | e6fc26ab18d1409c490c859398fc5fca71d0518b (patch) | |
tree | 30441a6b43e2507e8cdef3589a5defc74083263f /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src | |
parent | a0858efdab2f9bdc5d46be5655cdbb76708f4763 (diff) | |
parent | c8a540b3c234449163f6fb1899807bba951113b4 (diff) |
Merge "Create new VSP, onboard from TOSCA file - UI"
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src')
36 files changed, 1730 insertions, 648 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java index e648ccef26..e2ef86149b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; @@ -32,7 +33,7 @@ import java.util.Optional; public interface OrchestrationTemplateCandidateManager { UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user); + String user, String filePrefix, String networkPackageName); OrchestrationTemplateActionResponse process(String vspId, Version version, String user); @@ -41,5 +42,5 @@ public interface OrchestrationTemplateCandidateManager { ValidationResponse updateFilesDataStructure(String vspId, Version version, String user, FilesDataStructure fileDataStructure); - Optional<byte[]> get(String vspId, Version version, String user) throws IOException; + Optional<Pair<String, byte[]>> get(String vspId, Version version, String user) throws IOException; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java index 73558b465a..fcf54eef2f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java @@ -25,6 +25,7 @@ import org.openecomp.core.enrichment.types.MonitoringUploadType; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; @@ -44,6 +45,7 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.MonitoringUploadErrorBuilder; @@ -67,6 +69,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private ActivityLogManager activityLogManager; private ComponentArtifactDao componentArtifactDao; + private VendorSoftwareProductDao vendorSoftwareProductDao; private static final Logger logger = LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); @@ -253,7 +256,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { Map<String, List<ErrorMessage>> errors) { FileContentHandler contentMap; try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); + contentMap = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, uploadedFileData); VendorSoftwareProductUtils.validateContentZipData(contentMap, errors); } catch (IOException exception) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java index 07e84803aa..3f6ffcc622 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java @@ -21,29 +21,20 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; -import org.openecomp.core.translator.datatypes.TranslatorOutput; -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; -import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.healing.types.HealCode; -import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; -import org.openecomp.sdc.heat.services.tree.HeatTreeManager; -import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.api.annotations.Metrics; @@ -52,8 +43,6 @@ import org.openecomp.sdc.logging.messages.AuditMessages; import org.openecomp.sdc.logging.types.LoggerServiceName; import org.openecomp.sdc.logging.types.LoggerTragetServiceName; 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.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -62,40 +51,29 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -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.ProcessEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.OrchestrationTemplateNotFoundErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateFileHandler; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessHandler; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; -import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; -import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdcrests.activitylog.types.ActivityType; -import java.io.ByteArrayInputStream; 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.Optional; -import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; - public class OrchestrationTemplateCandidateManagerImpl implements OrchestrationTemplateCandidateManager { private static final Logger logger = @@ -162,65 +140,31 @@ public class OrchestrationTemplateCandidateManagerImpl @Override @Metrics - public UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user) { + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, + String user, String filePrefix, + String networkPackageName) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); - + OrchestrationTemplateFileHandler orchestrationTemplateFileHandler = + OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(filePrefix); VspDetails vspDetails = getVspDetails(vspId, version); + UploadFileResponse uploadResponse = orchestrationTemplateFileHandler + .upload(vspId, version, fileToUpload, user, candidateService, + vspDetails); + vspDetails.setOnboardingOrigin(filePrefix); + vspDetails.setNetworkPackageName(networkPackageName); + vspInfoDao.update(vspDetails); + + uploadResponse.setNetworkPackageName(networkPackageName); + return uploadResponse; + } - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - if (isNotEmptyFileToUpload(heatFileToUpload, uploadFileResponse)) { - return uploadFileResponse; - } - - byte[] uploadedFileData = FileUtils.toByteArray(heatFileToUpload); - if (isInvalidRawZipData(uploadFileResponse, uploadedFileData)) { - return uploadFileResponse; - } - - Optional<FileContentHandler> optionalContentMap = - getZipContentMap(uploadFileResponse, uploadedFileData); - if (!optionalContentMap.isPresent()) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.ZIP_CONTENT_MAP.getErrorMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - - if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - try { - OrchestrationTemplateCandidateData candidateData = - new CandidateEntityBuilder(candidateService) - .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), - uploadFileResponse.getErrors(), user); - candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); - } catch (Exception exception) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } @Override public OrchestrationTemplateActionResponse process(String vspId, Version version, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); Optional<OrchestrationTemplateCandidateData> candidate = fetchCandidateDataEntity(vspId, version); @@ -228,97 +172,15 @@ public class OrchestrationTemplateCandidateManagerImpl throw new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + vspId); - OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - OrchestrationTemplateCandidateData candidateDataEntity = candidate.get(); - Optional<FileContentHandler> fileContent = - getZipContentMap(uploadFileResponse, candidateDataEntity.getContentData().array()); - if (!fileContent.isPresent()) { - response.addStructureErrors(uploadFileResponse.getErrors()); - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); - FileContentHandler fileContentMap = fileContent.get(); - FilesDataStructure structure = - JsonUtil.json2Object(candidateDataEntity.getFilesDataStructure(), FilesDataStructure.class); - - if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { - response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, - Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - VspDetails vspDetails = getVspDetails(vspId, version); + Optional<OrchestrationTemplateProcessHandler> processInstance = + OrchestrationProcessFactory.getInstance(vspDetails.getOnboardingOrigin()); - String manifest = candidateService.createManifest(vspDetails, structure); - fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); - - Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService - .fetchZipFileByteArrayInputStream(vspId, candidateDataEntity, manifest, uploadErrors); - if (!zipByteArrayInputStream.isPresent()) { - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - HeatStructureTree tree = createAndValidateHeatTree(response, 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<>(); - - backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - deleteUploadDataAndContent(vspId, version); - saveHotData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, tree); - - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors - ()))) { - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + if(processInstance.isPresent()){ + response = processInstance.get().process(vspDetails, candidate.get(), user); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); - - TranslatorOutput translatorOutput = - HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); - - ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); - if (toscaServiceModel != null) { - serviceModelDao.storeServiceModel(vspId, version, toscaServiceModel); - //Extracting the compostion data from the output service model of the first phase of - // translation - compositionEntityDataManager.saveCompositionData(vspId, version, - compositionDataExtractor.extractServiceCompositionData(translatorOutput - .getNonUnifiedToscaServiceModel())); - retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); - } - - uploadFileResponse.addStructureErrors(uploadErrors); - - ActivityLogEntity activityLogEntity = - new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), - ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); - activityLogManager.addActionLog(activityLogEntity, user); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return response; } @@ -374,7 +236,7 @@ public class OrchestrationTemplateCandidateManagerImpl @Override - public Optional<byte[]> get(String vspId, Version version, String user) + public Optional<Pair<String, byte[]>> get(String vspId, Version version, String user) throws IOException { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); @@ -393,15 +255,25 @@ public class OrchestrationTemplateCandidateManagerImpl .debugExitMessage("VSP id", vspId); return Optional.empty(); } + OnboardingTypesEnum type = + OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin()); - FilesDataStructure structure = JsonUtil - .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); - String manifest = candidateService.createManifest(vspDetails, structure); + if(vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.toString())) { + FilesDataStructure structure = JsonUtil + .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); + String manifest = candidateService.createManifest(vspDetails, structure); - mdcDataDebugMessage - .debugExitMessage("VSP id", vspId); - return Optional.ofNullable(candidateService - .replaceManifestInZip(candidateDataEntity.get().getContentData(), manifest, vspId)); + mdcDataDebugMessage + .debugExitMessage("VSP id", vspId); + return Optional.ofNullable( + new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService + .replaceManifestInZip(candidateDataEntity.get().getContentData(), + manifest, vspId, type))); + } + + return Optional.ofNullable( + new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get() + .getContentData().array())); } private Optional<OrchestrationTemplateCandidateData> fetchCandidateDataEntity( @@ -410,213 +282,6 @@ public class OrchestrationTemplateCandidateManagerImpl .ofNullable(candidateService.getOrchestrationTemplateCandidate(vspId, version)); } - private void retainComponentQuestionnaireData(String vspId, Version activeVersion, - 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, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, - processArtifact); - Collection<ComponentEntity> - components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); - components.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - if (componentsQustanniare.containsKey(componentName)) { - componentDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), - componentsQustanniare.get(componentEntity.getComponentCompositionData() - .getName())); - if (componentNicsQustanniare.containsKey(componentName)) { - Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); - Collection<NicEntity> - nics = - nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - nics.forEach(nicEntity -> { - if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { - nicDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId(), - nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); - } - }); - } - //MIB //todo add for VES_EVENTS - if (componentMibList.containsKey(componentName)) { - Collection<ComponentMonitoringUploadEntity> mibList = - componentMibList.get(componentName); - mibList.forEach(mib -> { - mib.setComponentId(componentEntity.getId()); - componentArtifactDao.create(mib); - }); - } - //VFC processes - restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, - processArtifact); - } - }); - } - - private void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, - Map<String, String> componentsQustanniare, - Map<String, Map<String, String>> - componentNicsQustanniare, - Map<String, Collection<ComponentMonitoringUploadEntity>> - componentMibList, - Map<String, Collection<ProcessEntity>> - componentProcesses, - Map<String, ProcessEntity> processArtifact) { - //backup VSP processes - backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, - componentProcesses, processArtifact); - Collection<ComponentEntity> componentsCompositionAndQuestionnaire = vendorSoftwareProductDao - .listComponentsCompositionAndQuestionnaire(vspId, - activeVersion); - componentsCompositionAndQuestionnaire.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - componentsQustanniare.put(componentName, componentEntity - .getQuestionnaireData()); - Collection<NicEntity> - nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - //backup mib - Collection<ComponentMonitoringUploadEntity> componentMib = - componentArtifactDao.listArtifacts(new - ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), - null)); - if (CollectionUtils.isNotEmpty(componentMib)) { - componentMibList.put(componentName,componentMib); - } - - //backup component processes - backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, - componentProcesses, processArtifact); - if (CollectionUtils.isNotEmpty(nics)) { - Map<String, String> nicsQustanniare = new HashMap<>(); - nics.forEach(nicEntity -> { - NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), - nicEntity.getId())); - NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId()); - - nicsQustanniare - .put(nicEntity.getNicCompositionData().getName(), - nicQuestionnaire.getQuestionnaireData()); - }); - componentNicsQustanniare.put(componentName, nicsQustanniare); - } - }); - } - - private void backupProcess(String vspId, Version activeVersion, String componentId, - String componentName, Map<String, - Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - Collection<ProcessEntity> processList = vendorSoftwareProductDao.listProcesses(vspId, - activeVersion, componentId); - if (!processList.isEmpty()) { - processes.put(componentName, processList); - processList.forEach(process -> { - //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, - // activeVersion, componentId, process.getId()); - ProcessEntity artifact = - processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); - if (artifact.getArtifact() != null) { - processArtifact.put(process.getId(), artifact); - } - }); - } - } - - private void restoreProcess(String vspId, Version activeVersion, 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 -> { - //Reatin VFC process - if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId - ())) { - ProcessEntity artifact = processArtifact.get(process.getId()); - artifact.setComponentId(componentId); - UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), - componentId, process.getName()); - vendorSoftwareProductDao.createProcess(artifact); - } - }); - } - } - - private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, - FileContentHandler fileContentMap) { - VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); - Map<String, List<ErrorMessage>> validationErrors = - ValidationManagerUtil.initValidationManager(fileContentMap).validate(); - response.getErrors().putAll(validationErrors); - - HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); - heatTreeManager.createTree(); - heatTreeManager.addErrors(validationErrors); - return heatTreeManager.getTree(); - } - - private void saveHotData(String vspId, Version activeVersion, InputStream uploadedFileData, - FileContentHandler fileContentMap, HeatStructureTree tree) { - Map<String, Object> manifestAsMap = - (Map<String, Object>) JsonUtil.json2Object(fileContentMap.getFileContent( - SdcCommon.MANIFEST_NAME), Map.class); - - UploadData uploadData = new UploadData(); - uploadData.setPackageName((String) manifestAsMap.get("name")); - uploadData.setPackageVersion((String) manifestAsMap.get("version")); - uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); - uploadData.setValidationDataStructure(new ValidationStructureList(tree)); - orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); - } - - private void deleteUploadDataAndContent(String vspId, Version version) { - //fixme change this when more tables are zusammenized - vendorSoftwareProductDao.deleteUploadData(vspId, version); - } - - private boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - Optional<ErrorMessage> errorMessage; - errorMessage = candidateService.validateRawZipData(uploadedFileData); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private boolean isNotEmptyFileToUpload(InputStream heatFileToUpload, - UploadFileResponse uploadFileResponse) { - Optional<ErrorMessage> errorMessage = - candidateService.validateNonEmptyFileToUpload(heatFileToUpload); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private Optional<FileContentHandler> getZipContentMap(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - FileContentHandler contentMap = null; - try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); - } catch (IOException exception) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); - } catch (CoreException coreException) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); - } - return Optional.ofNullable(contentMap); - } // todo *************************** move to reusable place! ************************* @@ -646,4 +311,4 @@ public class OrchestrationTemplateCandidateManagerImpl }); } - } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 5163cfde9f..78c4cbf5d9 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.datatypes.Constants; import org.openecomp.core.enrichment.api.EnrichmentManager; import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -31,6 +32,7 @@ import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.api.ValidationManager; import org.openecomp.core.validation.util.MessageContainerUtil; import org.openecomp.sdc.activityLog.ActivityLogManager; @@ -318,7 +320,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails)); validationResponse - .setUploadDataErrors(validateUploadData(uploadData), LoggerServiceName.Submit_VSP, + .setUploadDataErrors(validateUploadData(uploadData,vspDetails), LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); validationResponse.setQuestionnaireValidationResult( @@ -641,6 +643,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa validateUniqueName(vspDetails.getName()); + vspDetails.setOnboardingOrigin(OnboardingTypesEnum.NONE.toString()); + vspInfoDao.create(vspDetails);//id will be set in the dao vspInfoDao.updateQuestionnaireData(vspDetails.getId(), null, new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData()); @@ -771,6 +775,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version)); + if(Objects.isNull(vsp.getOnboardingOrigin())){ + vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString()); + } + + if(Objects.isNull(vsp.getNetworkPackageName())){ + vsp.setNetworkPackageName("Upload File"); + } + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return vsp; } @@ -1044,7 +1056,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } - private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData) + private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData, + VspDetails vspDetails) throws IOException { Map<String, List<ErrorMessage>> validationErrors = new HashMap<>(); @@ -1053,7 +1066,9 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } FileContentHandler fileContentMap = - CommonUtil.validateAndUploadFileContent(uploadData.getContentData().array()); + CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.getOnboardingTypesEnum + (vspDetails.getOnboardingOrigin()), + uploadData.getContentData().array()); //todo - check ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap); 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 new file mode 100644 index 0000000000..c7fb43770d --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java @@ -0,0 +1,100 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +import java.util.Optional; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { + protected static final Logger logger = + LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); + protected static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + @Override + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails) { + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + uploadFileResponse.setOnboardingType(getHandlerType()); + if (isNotEmptyFileToUpload(fileToUpload, uploadFileResponse, candidateService)) { + return uploadFileResponse; + } + + byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload); + if (isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService)) { + return uploadFileResponse; + } + + Optional<FileContentHandler> optionalContentMap = + getFileContentMap(uploadFileResponse, uploadedFileData); + if (!optionalContentMap.isPresent()) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString())); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString()))); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + + if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + if (updateCandidateData(vspId, user, candidateService, vspDetails, uploadFileResponse, + uploadedFileData, optionalContentMap)) + return uploadFileResponse; + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + + } + + protected abstract boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, + Optional<FileContentHandler> optionalContentMap); + + + private boolean isNotEmptyFileToUpload(InputStream fileToUpload, + UploadFileResponse uploadFileResponse, CandidateService candidateService) { + Optional<ErrorMessage> errorMessage = + candidateService.validateNonEmptyFileToUpload(fileToUpload); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + Optional<ErrorMessage> errorMessage; + errorMessage = candidateService.validateRawZipData(uploadedFileData); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + public abstract Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData); + 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 new file mode 100644 index 0000000000..53d34749e7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java @@ -0,0 +1,154 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; +public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + + @Override + public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + List<String> folderList = new ArrayList<>(); + try { + Pair<FileContentHandler, List<String>> fileContentMapFromOrchestrationCandidateZip = CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData); + contentMap = fileContentMapFromOrchestrationCandidateZip.getKey(); + folderList = fileContentMapFromOrchestrationCandidateZip.getRight(); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + validateContent(uploadFileResponse, contentMap, folderList); + return Optional.ofNullable(contentMap); + } + + private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, List<String> folderList) { + validateManifest(uploadFileResponse, contentMap); + validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + validateNoExtraFiles(uploadFileResponse, contentMap); + validateFolders(uploadFileResponse, folderList); + } + + private void validateManifest(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)){ + return; + } + InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); + OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); + if (!onboardingManifest.isValid()){ + onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); + } + } + + private void validateNoExtraFiles(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + List<String> unwantedFiles = contentMap.getFileList().stream() + .filter(this::filterFiles).collect(Collectors.toList()); + if (!unwantedFiles.isEmpty()) { + unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), + unwantedFile)))); + + ; + } + } + + private void validateFolders(UploadFileResponse uploadFileResponse, List<String> folderList) { + List<String> filterResult = folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); + if (!filterResult.isEmpty()) { + folderList.stream().filter(this::filterFolders).forEach( unwantedFolder -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), + unwantedFolder)))); + + } + } + private boolean filterFiles(String inFileName) { + boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName)); + if (valid){ + return !valid; + } + return filterFolders(inFileName); + } + + private boolean filterFolders(String fileName) { + return !ELIGBLE_FOLDERS.stream().anyMatch(dirName -> fileName.startsWith(dirName)); + } + + private boolean validateFileExist(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, String fileName) { + + boolean containsFile = contentMap.containsFile(fileName); + if (!containsFile) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); + } + return containsFile; + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional<FileContentHandler> optionalContentMap) { + try { + candidateService.updateCandidateUploadData(new OrchestrationTemplateCandidateData( + ByteBuffer.wrap(uploadedFileData), ""), vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()), exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.CSAR; + } + + @Override + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); + + } +} 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 new file mode 100644 index 0000000000..3f7d18de9f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java @@ -0,0 +1,12 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +public interface OrchestrationTemplateFileHandler { + UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails); +} 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 new file mode 100644 index 0000000000..626d941911 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java @@ -0,0 +1,55 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.util.Optional; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + @Override + public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + return OrchestrationUtil.getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, uploadedFileData); + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional<FileContentHandler> optionalContentMap) { + try { + OrchestrationTemplateCandidateData candidateData = + new CandidateEntityBuilder(candidateService) + .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), + uploadFileResponse.getErrors(), user); + candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()),exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + @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 new file mode 100644 index 0000000000..104da69ed8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java @@ -0,0 +1,29 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; + +import java.util.Map; +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 Map<String, ImplementationConfiguration> fileHanlders; + + static { + Configuration config = ConfigurationManager.lookup(); + fileHanlders = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ORCHESTRATION_Impl_Key, ImplementationConfiguration.class)); + + } + + public static final OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(String filePrefix) { + ImplementationConfiguration orchestrationTemplateFileHandler = fileHanlders.get(filePrefix); + 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 new file mode 100644 index 0000000000..5d14477339 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -0,0 +1,282 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; +import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +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.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.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +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.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +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.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; + +public class OrchestrationUtil { + + public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration"; + public static final String ORCHESTRATION_Impl_Key = "orchestration_impl"; + + + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static ComponentArtifactDao componentArtifactDao = MonitoringUploadDaoFactory.getInstance().createInterface(); + private static ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface(); + private static OrchestrationTemplateDao orchestrationTemplateDataDao = + OrchestrationTemplateDaoFactory.getInstance().createInterface(); + private static ComponentDao componentDao = + ComponentDaoFactory.getInstance().createInterface(); + private static ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance() + .createInterface(); + private static CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private static CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + + 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())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + return Optional.ofNullable(contentMap); + } + + public static void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, + Map<String, String> componentsQustanniare, + Map<String, Map<String, String>> + componentNicsQustanniare, + Map<String, Collection<ComponentMonitoringUploadEntity>> + componentMibList, + Map<String, Collection<ProcessEntity>> + componentProcesses, + Map<String, ProcessEntity> processArtifact) { + //backup VSP processes + backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, + componentProcesses, processArtifact); + Collection<ComponentEntity> componentsCompositionAndQuestionnaire = vendorSoftwareProductDao + .listComponentsCompositionAndQuestionnaire(vspId, + activeVersion); + componentsCompositionAndQuestionnaire.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + componentsQustanniare.put(componentName, componentEntity + .getQuestionnaireData()); + Collection<NicEntity> + nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + //backup mib + Collection<ComponentMonitoringUploadEntity> componentMib = + componentArtifactDao.listArtifacts(new + ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), + null)); + if (CollectionUtils.isNotEmpty(componentMib)) { + componentMibList.put(componentName,componentMib); + } + + //backup component processes + backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, + componentProcesses, processArtifact); + if (CollectionUtils.isNotEmpty(nics)) { + Map<String, String> nicsQustanniare = new HashMap<>(); + nics.forEach(nicEntity -> { + NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), + nicEntity.getId())); + NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId()); + + nicsQustanniare + .put(nicEntity.getNicCompositionData().getName(), + nicQuestionnaire.getQuestionnaireData()); + }); + componentNicsQustanniare.put(componentName, nicsQustanniare); + } + }); + } + + private static void backupProcess(String vspId, Version activeVersion, String componentId, + String componentName, Map<String, + Collection<ProcessEntity>> processes, + Map<String, ProcessEntity> processArtifact) { + Collection<ProcessEntity> processList = vendorSoftwareProductDao.listProcesses(vspId, + activeVersion, componentId); + if (!processList.isEmpty()) { + processes.put(componentName, processList); + processList.forEach(process -> { + //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, + // activeVersion, componentId, process.getId()); + ProcessEntity artifact = + processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); + if (artifact.getArtifact() != null) { + processArtifact.put(process.getId(), artifact); + } + }); + } + } + + public static void retainComponentQuestionnaireData(String vspId, Version activeVersion, + 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, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, + processArtifact); + Collection<ComponentEntity> + components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); + components.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + if (componentsQustanniare.containsKey(componentName)) { + componentDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), + componentsQustanniare.get(componentEntity.getComponentCompositionData() + .getName())); + if (componentNicsQustanniare.containsKey(componentName)) { + Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); + Collection<NicEntity> + nics = + nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + nics.forEach(nicEntity -> { + if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { + nicDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId(), + nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); + } + }); + } + //MIB //todo add for VES_EVENTS + if (componentMibList.containsKey(componentName)) { + Collection<ComponentMonitoringUploadEntity> mibList = + componentMibList.get(componentName); + mibList.forEach(mib -> { + mib.setComponentId(componentEntity.getId()); + componentArtifactDao.create(mib); + }); + } + //VFC processes + restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, + processArtifact); + } + }); + } + + private static void restoreProcess(String vspId, Version activeVersion, 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 -> { + //Reatin VFC process + if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId + ())) { + ProcessEntity artifact = processArtifact.get(process.getId()); + artifact.setComponentId(componentId); + UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), + componentId, process.getName()); + vendorSoftwareProductDao.createProcess(artifact); + } + }); + } + } + + public static void deleteUploadDataAndContent(String vspId, Version version) { + //fixme change this when more tables are zusammenized + vendorSoftwareProductDao.deleteUploadData(vspId, version); + } + + public static void saveUploadData(String vspId, Version activeVersion, InputStream uploadedFileData, + FileContentHandler fileContentMap, HeatStructureTree tree) { + Map<String, Object> manifestAsMap = + fileContentMap.containsFile(SdcCommon.MANIFEST_NAME) ? + (Map<String, Object>) JsonUtil.json2Object(fileContentMap.getFileContent( + SdcCommon.MANIFEST_NAME), Map.class) + : new HashMap<>(); + + UploadData uploadData = new UploadData(); + 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")); + orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); + } + + public static 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)); +// OrchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, +// componentNicsQuestionnaire, componentMibList, processes, processArtifact); + } + } + + public static HeatStructureTree createHeatTree(FileContentHandler fileContentMap, + Map<String, List<ErrorMessage>> validationErrors){ + HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); + heatTreeManager.createTree(); + heatTreeManager.addErrors(validationErrors); + return heatTreeManager.getTree(); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java new file mode 100644 index 0000000000..0d204ef2c0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java @@ -0,0 +1,18 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableSet; +import static com.google.common.collect.ImmutableSet.of; +public class CSARConstants { + + public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/", + "Licenses/", "TOSCA-Metadata/"); + + public static final String MAIN_SERVICE_TEMPLATE_MF_FILE_NAME = "MainServiceTemplate.mf"; + public static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml"; + public static final ImmutableSet<String> ELIGIBLE_FILES = + of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + + public static final String METADATA_MF_ATTRIBUTE = "metadata"; + public static final String SOURCE_MF_ATTRIBUTE = "source"; + public static final String SEPERATOR_MF_ATTRIBUTE = ":"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java new file mode 100644 index 0000000000..d88d883e67 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java @@ -0,0 +1,141 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang.StringUtils; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; + +public class OnboardingManifest { + private static final Logger logger = LoggerFactory.getLogger(OnboardingManifest.class); + private Map<String, String> metadata; + private List<String> sources; + private List<String> errors; + private State state; + private enum State { + Start, ProcessMetadata, ProcessSources, Error + } + + public OnboardingManifest(InputStream is) { + errors = new ArrayList<>(); + sources = new ArrayList<>(); + metadata = new HashMap<>(); + parseManifest(is); + } + + private void parseManifest(InputStream is) { + try { + ImmutableList<String> lines = readAllLines(is); + state = State.Start; + + for (String line : lines) { + line = line.trim(); + if (!StringUtils.isEmpty(line.trim())) { + state = processLine(state, line); + } + } + if (errors.isEmpty()) { + if (metadata.isEmpty()) { + errors.add(Messages.MANIFEST_NO_METADATA.getErrorMessage()); + } + if (sources.isEmpty()) { + errors.add(Messages.MANIFEST_NO_SOURCES.getErrorMessage()); + } + } + } catch (IOException e){ + logger.error(e.getMessage(),e); + errors.add(Messages.MANIFEST_PARSER_INTERNAL.getErrorMessage()); + } + } + + private State processLine(State state, String line) { + switch (state) { + case Start: + if (line.trim().equals(METADATA_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE)) { + state = State.ProcessMetadata; + } else { + reportError(line); + } + break; + case ProcessMetadata: + String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE); + if (metaSplit.length < 2){ + reportError(line); + break; + } + if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){ + String value = line.replace(metaSplit[0] + SEPERATOR_MF_ATTRIBUTE, "").trim(); + metadata.put(metaSplit[0],value); + } else { + state = State.ProcessSources; + processSourceLine(line); + } + break; + case ProcessSources: + processSourceLine(line); + + break; + case Error: + break; + + } return state; + } + + private void processSourceLine(String line) { + if (line.startsWith(SOURCE_MF_ATTRIBUTE+SEPERATOR_MF_ATTRIBUTE)){ + String value = line.replaceAll(SOURCE_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE, "").trim(); + sources.add(value); + }else { + reportError(line); + } + } + + private void reportError(String line) { + errors.add(getErrorWithParameters(Messages.MANIFEST_INVALID_LINE.getErrorMessage(), line)); + state = State.Error; + } + + private ImmutableList<String> readAllLines(InputStream is) throws IOException { + ImmutableList.Builder<String> builder = ImmutableList.<String> builder(); + try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8.newDecoder()); + BufferedReader bufferedReader = new BufferedReader(reader);) { + for (; ; ) { + String line = bufferedReader.readLine(); + if (line == null) + break; + builder.add(line); + } + } + return builder.build(); + } + + public Map<String, String> getMetadata() { + if (!isValid()){ + return Collections.EMPTY_MAP; + } + return ImmutableMap.copyOf(metadata); + } + + public List<String> getSources() { + if (!isValid()){ + return Collections.EMPTY_LIST; + } + return ImmutableList.copyOf(sources); + } + + public List<String> getErrors() { + return ImmutableList.copyOf(errors); + } + + public boolean isValid() { + return errors.isEmpty(); + } +} 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 new file mode 100644 index 0000000000..5295e6a6d6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -0,0 +1,64 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants; + +import java.util.HashMap; +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 String confFile = "config-orchestration.json"; + private static Map<String, ImplementationConfiguration> processImplMap; + + static { + Configuration config = ConfigurationManager.lookup(); + processImplMap = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ConfigConstants.processImplKey, ImplementationConfiguration.class)); + + } + + public static Optional<OrchestrationTemplateProcessHandler> getInstance(String filePrefix) { + filePrefix = filePrefix == null ? null : filePrefix.toLowerCase().trim(); + if (filePrefix == null) { + return Optional.empty(); + } + + OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(filePrefix); + if (onboardingTypesEnum == null) { + return Optional.empty(); + } + + try { + return Optional.of(createInstance(processImplMap.get(onboardingTypesEnum.toString()))); + }catch (Exception e){ + return Optional.empty(); + } + } + + private static Map<String, String> getOrchestrationImplMap(){ + try { + return FileUtils.readViaInputStream(confFile, + stream -> JsonUtil.json2Object(stream, Map.class)); + }catch (Exception e){ + return new HashMap<>(); + } + } + + 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 new file mode 100644 index 0000000000..4866d93411 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.impl.ToscaConverterImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.services.tree.ToscaTreeManager; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.messages.AuditMessages; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +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; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { + + private static Logger logger = + LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); + private ToscaConverter toscaConverter = new ToscaConverterImpl(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + ToscaTreeManager toscaTreeManager = new ToscaTreeManager(); + + @Override + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CSAR_VALIDATION_STARTED + vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional<FileContentHandler> fileContent = + OrchestrationUtil + .getFileContentMap( + OnboardingTypesEnum.CSAR, uploadFileResponse, candidateData.getContentData().array()); + + if(fileContent.isPresent()){ + try { + FileContentHandler fileContentHandler = fileContent.get(); + processCsar(vspId, version, fileContentHandler, candidateData, response); + } catch (CoreException e){ + logger.error(e.getMessage()); + throw e; + } catch (Exception e){ + logger.error(e.getMessage()); + } + } + + return response; + } + + private void processCsar(String vspId, Version version, + FileContentHandler fileContentHandler, + OrchestrationTemplateCandidateData candidateData, + OrchestrationTemplateActionResponse response) throws IOException { + + + response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); + Map<String, List<ErrorMessage>> errors = validateCsar(fileContentHandler, response); + if(!isValid(errors)){ + 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.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream(vspId, candidateData, null, OnboardingTypesEnum.CSAR, errors); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData( + vspId, version, zipByteArrayInputStream.get(), fileContentHandler, tree); + + ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler); + OrchestrationUtil.saveServiceModel(vspId, version, toscaServiceModel, toscaServiceModel); + + } + + 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, + OrchestrationTemplateActionResponse response){ + + + 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)); + } +} 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 new file mode 100644 index 0000000000..8b513b4347 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java @@ -0,0 +1,12 @@ +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; + +public interface OrchestrationTemplateProcessHandler { + OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user); +} 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 new file mode 100644 index 0000000000..cceacd47b3 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java @@ -0,0 +1,184 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.translator.datatypes.TranslatorOutput; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.activityLog.ActivityLogManagerFactory; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.messages.AuditMessages; +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.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.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdcrests.activitylog.types.ActivityType; + +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; + +public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemplateProcessHandler { + Logger logger = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + private ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface(); + private CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + private ActivityLogManager activityLogManager = + ActivityLogManagerFactory.getInstance().createInterface(); + + + public OrchestrationTemplateProcessZipHandler(){} + + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + + vspId); + 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()); + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); + FileContentHandler fileContentMap = fileContent.get(); + 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); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + + String manifest = candidateService.createManifest(vspDetails, structure); + fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); + + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream( + vspId, candidateData, manifest, OnboardingTypesEnum.ZIP, uploadErrors); + if (!zipByteArrayInputStream.isPresent()) { + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + HeatStructureTree tree = createAndValidateHeatTree(response, 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.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, + tree); + + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors + ()))) { + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + } + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); + + 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); + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); + uploadFileResponse.addStructureErrors(uploadErrors); + + ActivityLogEntity activityLogEntity = + new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), + ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); + activityLogManager.addActionLog(activityLogEntity, user); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return response; + } + + 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); + } + + private void printAuditForErrors(List<ErrorMessage> errorList, String vspId, String auditType) { + + errorList.forEach(errorMessage -> { + if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) { + logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), + vspId)); + } + }); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java new file mode 100644 index 0000000000..5e217d4d60 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorsoftwareproduct.types; + +public class ConfigConstants { + public static final String namespace = "Orchestration"; + public static final String processImplKey = "process_impl"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java index 99f3fa1fdf..ca0eed2153 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.types; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -35,6 +36,8 @@ import java.util.Map; public class UploadFileResponse { private Map<String, List<ErrorMessage>> errors = new HashMap<>(); private UploadFileStatus status = UploadFileStatus.Success; + private OnboardingTypesEnum onboardingType; + private String networkPackageName; public UploadFileStatus getStatus() { return status; @@ -44,6 +47,22 @@ public class UploadFileResponse { this.status = status; } + public OnboardingTypesEnum getOnboardingType() { + return onboardingType; + } + + public void setOnboardingType(OnboardingTypesEnum onboardingTypesEnum) { + this.onboardingType = onboardingTypesEnum; + } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } + /** * Add structure error. * diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json new file mode 100644 index 0000000000..9193b818b7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json @@ -0,0 +1,26 @@ +{ + "orchestration_impl": { + "zip": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateCSARHandler" + } + }, + "process_impl": { + "zip" : { + "enzble": true, + "implementationClass" : "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessCsarHandler" + } + }, + + "_config":{ + "namespace": "orchestration" + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json new file mode 100644 index 0000000000..7509094b56 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json @@ -0,0 +1,3 @@ +{ + "zip" :"org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.orchestrationTemplateProcessZipHandler" +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index 948d46ba10..3e42a23c6a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -48,7 +48,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.Com import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.InputStream; import java.util.List; @@ -112,7 +111,7 @@ public class QuestionnaireDataServiceTest { public void testQuestionnaireDataAfterIllegalUpload() { InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml"); UploadFileResponse uploadFileResponse = candidateManager - .upload(vspId, VERSION, zipInputStream, USER1); + .upload(vspId, VERSION, zipInputStream, USER1, "zip", "missingYml"); InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); @@ -124,7 +123,7 @@ public class QuestionnaireDataServiceTest { InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath); UploadFileResponse uploadFileResponse = candidateManager .upload(vspId, VERSION, - zipInputStream, USER1); + zipInputStream, USER1,"zip", "file"); candidateManager.process(vspId, VERSION, USER1); Assert.assertTrue(MapUtils.isEmpty( diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java index e6d06f2e2c..252e152740 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java @@ -6,6 +6,7 @@ import org.mockito.MockitoAnnotations; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -23,7 +24,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -90,7 +90,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject()); doReturn(Optional.empty()).when(candidateServiceMock) - .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), anyObject()); + .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), OnboardingTypesEnum.ZIP, anyObject()); OrchestrationTemplateActionResponse response = @@ -123,7 +123,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); @@ -136,7 +136,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUploadWithManifest() { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 4ead8a57d2..e0e00f8d9d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -39,7 +39,6 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.errors.ValidationErrorBuilder; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; @@ -54,14 +53,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; @@ -92,7 +87,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -357,7 +351,7 @@ public class VendorSoftwareProductManagerImplTest { "subCategory", "456", fgs); List<String> updFgs = new ArrayList<String>(); - //updFgs.add("fg2"); + updFgs.add("fg2"); VspDetails updatedVsp = createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", "category_updated", @@ -659,7 +653,7 @@ public class VendorSoftwareProductManagerImplTest { InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip"); UploadFileResponse uploadFileResponse = - candidateManager.upload(VSP_ID, VERSION01, zis, USER1); + candidateManager.upload(VSP_ID, VERSION01, zis, USER1, "zip", "missingYml"); Assert.assertEquals(uploadFileResponse.getErrors().size(), 0); } @@ -672,7 +666,7 @@ public class VendorSoftwareProductManagerImplTest { try { candidateManager .upload(VSP_ID, VERSION01, - url.openStream(), USER1); + url.openStream(), USER1, "zip", "notZipFile"); candidateManager.process(VSP_ID, VERSION01, USER1); } catch (Exception ce) { Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); @@ -680,107 +674,7 @@ public class VendorSoftwareProductManagerImplTest { verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); } -/* - @Test - public void testEnrichModelInSubmit() { - UniqueValueUtil - .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - "VSP_syb"); - VspDetails vspDetails = vendorSoftwareProductManager.createVsp( - createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "456", null), USER1); - String id = vspDetails.getId(); - - //upload file - InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); - candidateManager.upload(id, VERSION01, zis, USER1); - OrchestrationTemplateActionResponse uploadFileResponse = - candidateManager.process(id, VERSION01, USER1); - - //check in - vendorSoftwareProductManager.checkin(id, USER1); - //submit - try { - ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); - } catch (IOException exception) { - Assert.fail(); - } - VersionedVendorSoftwareProductInfo details = - vendorSoftwareProductManager.getVsp(id, null, USER1); - Collection<ComponentEntity> components =vendorSoftwareProductManager - .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1); - - ToscaServiceModel model = - (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() - .getServiceModel(id, details.getVersionInfo().getActiveVersion()); - - Map<String, CapabilityDefinition> capabilities = new HashMap<>(); - for (ComponentEntity component : components) { - model.getServiceTemplates(). - entrySet(). - stream(). - filter(entryValue -> entryValue.getValue() != null && - entryValue.getValue().getNode_types() != null && - entryValue.getValue(). - getNode_types(). - containsKey(component.getComponentCompositionData().getName())). - forEach(entryValue -> entryValue.getValue().getNode_types(). - values(). - stream(). - filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). - forEach(type -> type.getCapabilities(). - entrySet(). - forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), - entry.getValue())))); - - } - - Assert.assertNotNull(capabilities); - } - - @Test(dependsOnMethods = {"testCreatePackage"}) - public void testEnrichedFilesDeletedOnNewUpload() throws IOException { - Version activeVersion; - createPackageFromUpload(VSP_ID, USER1, "/fullComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - createPackageFromUpload(VSP_ID, USER1, "/emptyComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts); - Assert.assertNotEquals(firstServiceModel, secondServiceModel); - - } - - @Test(dependsOnMethods = {"testMibsDeletedInCsar"}) - public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException { - String nestedPath = "Definitions" + File.separator + "nested"; - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List<String> nestedFileNamesServiceTemplates = - getWantedFileNamesFromCsar(nestedPath); - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath); - - Assert.assertEquals(emptyNestedNamesList.size(), 0); - Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size()); - }*/ private List<String> getWantedFileNamesFromCsar(String pathInCsar) throws IOException { @@ -806,21 +700,6 @@ public class VendorSoftwareProductManagerImplTest { return fileNames; } - /* - //Disabled for sonar null pointer issue for componentEntities - private Pair<String, String> uploadMib(String vspId, String user, String filePath, - String fileName) { - List<ComponentEntity> componentEntities = null; - //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user); - monitoringUploadsManager.upload(getFileInputStream(filePath), - fileName, vspId, - VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user); - //TODO: add validate of addActionLog() func call - - return new ImmutablePair<>(componentEntities.get(0).getId(), - componentEntities.get(0).getComponentCompositionData() - .getDisplayName()); - }*/ private void createPackageFromUpload(String vspId, String user, String filePath) throws IOException { @@ -830,7 +709,7 @@ public class VendorSoftwareProductManagerImplTest { private void uploadFileAndProcess(String vspId, String user, String filePath) { vendorSoftwareProductManager.checkout(vspId, user); - candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user); + candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user, "zip", "file"); candidateManager.process(vspId, VERSION01, user); } @@ -888,7 +767,7 @@ public class VendorSoftwareProductManagerImplTest { */ private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, VERSION01, upload, USER1); + candidateManager.upload(vspId, VERSION01, upload, USER1, "zip", "file"); candidateManager.process(vspId, VERSION01, user); UploadDataEntity uploadData = @@ -919,23 +798,6 @@ public class VendorSoftwareProductManagerImplTest { } - // private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName) -// throws IOException { -// ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName))); -// boolean isInfoArtifactInZip = false; -// -// ZipEntry zipEntry; -// while ((zipEntry = inputZipStream.getNextEntry()) != null) { -// String currentEntryName = zipEntry.getName(); -// if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" + -// vspId + "_Information.txt")){ -// isInfoArtifactInZip = true; -// break; -// } -// } -// -// Assert.assertTrue(isInfoArtifactInZip); -// } static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, @@ -969,45 +831,7 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups()); } - -// @Test -// public void testDownloadFile() throws IOException { -// VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null); -// VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1); -// -// id005 = createdVsp.getId(); -// Assert.assertNotNull(id005); -// Assert.assertNotNull(createdVsp.getVersion()); -// -// try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) { -// -// UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1); -// vendorSoftwareProductManager.process(id005, USER1); -// Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1); -// -// File latestHeatPackage = fileCandidate.get(); -// -// zipInputStream.reset(); -// byte[] uploaded = IOUtils.toByteArray(zipInputStream); -// -// Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded); -// FileContentHandler fileContentHandler = new FileContentHandler(); -// if(zipContentMap.isPresent()){ -// fileContentHandler = zipContentMap.get(); -// } -// -// uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values()); -// -// byte[] downloaded; -// try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) { -// downloaded = IOUtils.toByteArray(fileStream); -// } -// -// Assert.assertTrue(Arrays.equals(uploaded, downloaded)); -// } -// } - - // todo ********************** move to common ************************************** + // todo ********************** move to common ************************************** private void mockVersioning(VersionableEntityAction action) { VersionInfo versionInfo = new VersionInfo(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index 236b7e7594..dfb7409bd0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -27,6 +27,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; @@ -37,92 +38,86 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; -import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; import java.util.zip.ZipOutputStream; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; +import static org.testng.Assert.assertEquals; public class UploadFileTest { - private static final String USER1 = "vspTestUser1"; - - public static final Version VERSION01 = new Version(0, 1); - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; - @Spy - private CandidateServiceImpl candidateService; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private VendorSoftwareProductInfoDao vspInfoDaoMock; - - @InjectMocks - private OrchestrationTemplateCandidateManagerImpl candidateManager; - - private static String vlm1Id; - public static String id001 = null; - public static String id002 = null; - - public static Version activeVersion002 = null; - - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUploadFile() { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1); - } - - - private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, activeVersion002, upload, user); - - UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); - - } - - public InputStream getZipInputStream(String name) { - URL url = this.getClass().getResource(name); - File templateDir = new File(url.getFile()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ZipOutputStream zos = new ZipOutputStream(baos); - - VSPCommon.zipDir(templateDir, "", zos, true); - try { - zos.close(); - } catch (IOException e) { - e.printStackTrace(); + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + + @InjectMocks + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + private static String vlm1Id; + public static String id001 = null; + public static String id002 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testUploadFile() { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1, OnboardingTypesEnum.ZIP.toString(), "legalUpload"); + } + + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, + upload, user, OnboardingTypesEnum.ZIP.toString(),"file" ); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); + UploadDataEntity uploadData = + orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); + + } + + public InputStream getZipInputStream(String name) { + URL url = this.getClass().getResource(name); + File templateDir = new File(url.getFile()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + VSPCommon.zipDir(templateDir, "", zos, true); + } catch (IOException e) { + e.printStackTrace(); + } + return new ByteArrayInputStream(baos.toByteArray()); } - return new ByteArrayInputStream(baos.toByteArray()); - } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java new file mode 100644 index 0000000000..3332e81e36 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java @@ -0,0 +1,58 @@ +package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; + +import org.junit.Test; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.*; + +public class ManifestParsingTest { + + @Test + public void testSuccessfulParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertTrue(onboardingManifest.isValid()); + assertEquals(onboardingManifest.getMetadata().size(), 4); + assertEquals(onboardingManifest.getSources().size(), 5); + } + } + + @Test + public void testNoMetadataParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testBrokenMDParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testNoMetaParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java new file mode 100644 index 0000000000..a7fc0e1ba0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; + + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.healing.api.HealingManager; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.function.Predicate; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; + +public class UploadCSARFileTest { + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + @Mock + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; + @Mock + private ManifestCreatorNamingConventionImpl manifestCreator; + + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + + public static String id001 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + candidateService = new CandidateServiceImpl(manifestCreator,orchestrationTemplateCandidateDao); + candidateManager = new OrchestrationTemplateCandidateManagerImpl( vendorSoftwareProductDaoMock, + vspInfoDaoMock, + orchestrationTemplateDataDaoMock, + candidateService, healingManagerMock, + compositionDataExtractorMock, + serviceModelDaoMock, + compositionEntityDataManagerMock, + null, + null, + null, + null, + null); + } + + @Test + public void testSuccessfulUploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmock"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(0, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().isEmpty()); + } + } + + @Test + public void testFail1UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail1"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED + .getErrorMessage().substring(0, 7))).findAny().isPresent()); + } + } + + private Predicate<List<ErrorMessage>> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List<ErrorMessage> error) { + return error.iterator().next().getMessage().contains(substring); + } + + @Test + public void testFail2UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail2"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testFail3UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail3"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testUploadFileIsNotZip() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( "Thia is not a zip file".getBytes() );) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertFalse(uploadFileResponse.getErrors().isEmpty()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testUploadFileIsEmpty() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( new byte[]{} )) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, + activeVersion002, is, USER1, "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testMFError() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmockBrokenMF"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors() + .values().stream() + .filter(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage())).findAny().isPresent()); + + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar Binary files differnew file mode 100644 index 0000000000..f69efd2bb8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar Binary files differnew file mode 100644 index 0000000000..02593a1d2f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar Binary files differnew file mode 100644 index 0000000000..5e3ee6f387 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar Binary files differnew file mode 100644 index 0000000000..4874578ad9 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar Binary files differnew file mode 100644 index 0000000000..c009a042e4 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf new file mode 100644 index 0000000000..f28014e2d6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf @@ -0,0 +1,11 @@ + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf new file mode 100644 index 0000000000..95f7a41d68 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf @@ -0,0 +1,18 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + +source: MainServiceTemplate.yaml + + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf new file mode 100644 index 0000000000..64e9445f7f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf @@ -0,0 +1,7 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf new file mode 100644 index 0000000000..a563ddd581 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf @@ -0,0 +1,12 @@ +metadata: + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf new file mode 100644 index 0000000000..88c67517ce --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf @@ -0,0 +1,15 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml |