aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2017-09-11 15:45:37 +0300
committershrek2000 <orenkle@amdocs.com>2017-09-12 10:38:35 +0300
commitc8a540b3c234449163f6fb1899807bba951113b4 (patch)
treea8aae0dd0f6a0feb27369914e9e3fa321740e7ed /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main
parent82d454fd3e8c9fdf66517d01a99019a379dbfdb6 (diff)
Create new VSP, onboard from TOSCA file - UI
Change-Id: I018c6d07a4b9ec7e6b1507ab37e2550865423cfe Issue-ID: SDC-230 Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java5
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java5
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java427
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java100
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java154
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java55
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java29
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java282
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java18
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java141
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java64
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java133
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java184
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java19
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json26
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json3
20 files changed, 1309 insertions, 387 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