aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src
diff options
context:
space:
mode:
authorSithara Nambiar <sitharav.aredath@huawei.com>2020-09-21 20:48:56 +0530
committerChristophe Closset <christophe.closset@intl.att.com>2020-09-22 07:55:27 +0000
commitfa5c81349cbbfd0f66c0c4373ec065366b22946d (patch)
treed045bc77aee968c5e72b5fe7f8d382c54688696f /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src
parenta8d3e1b8c759c21227690a425552a245da883e97 (diff)
SDC changes for adding dummy base heat-new patch
Issue-ID: REQ-341 Signed-off-by: Sithara Nambiar <sitharav.aredath@huawei.com> Change-Id: I1fff1ea7615ed21c769df651e3f1951be802ff65
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java35
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java61
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java35
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/DummyHeatUse.txt5
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.env4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.yaml49
6 files changed, 188 insertions, 1 deletions
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 7de39a4912..052bd78d11 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
@@ -24,8 +24,10 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.file.Path;
@@ -62,8 +64,13 @@ import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
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.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.csar.Manifest;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
@@ -134,7 +141,7 @@ import org.openecomp.sdc.versioning.VersioningUtil;
import org.openecomp.sdc.versioning.dao.types.Version;
public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductManager.class);
private VspMergeDao vspMergeDao;
private OrchestrationTemplateDao orchestrationTemplateDao;
private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
@@ -670,6 +677,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
OnboardingTypesEnum.getOnboardingTypesEnum(orchestrationTemplate.getFileSuffix()),
orchestrationTemplate.getContentData().array());
+ try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
+ addDummyHeatBase(zipFileManifest, fileContentMap);
+ } catch (Exception e) {
+ LOGGER.error("Invalid package content", e);
+ }
+
if (CommonUtil.isFileOriginFromZip(orchestrationTemplate.getFileSuffix())) {
ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap);
validationErrors.putAll(validationManager.validate());
@@ -679,6 +692,26 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
: validationErrors;
}
+ private FileContentHandler addDummyHeatBase(InputStream zipFileManifest, FileContentHandler fileContentMap) {
+ ManifestContent manifestContent =
+ JsonUtil.json2Object(zipFileManifest, ManifestContent.class);
+ for (FileData fileData : manifestContent.getData()) {
+ if ((fileData.getFile()).contains("dummy_ignore.yaml")) {
+ String filePath = new File("").getAbsolutePath();
+ File envFilePath = new File(filePath + "/base_template.env");
+ File baseFilePath = new File(filePath + "/base_template.yaml");
+ try (
+ InputStream envStream = new FileInputStream(envFilePath);
+ InputStream baseStream = new FileInputStream(baseFilePath);) {
+ fileContentMap.addFile("base_template_dummy_ignore.env", envStream);
+ fileContentMap.addFile("base_template_dummy_ignore.yaml", baseStream);
+ } catch (Exception e) {
+ LOGGER.error("File not found error {}", e);
+ }
+ }
+ }
+ return fileContentMap;
+ }
private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
String onboardingMethod) {
// The apis of CompositionEntityDataManager used here are stateful!
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
index 20d8e26cb0..d1b64e213e 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
@@ -28,20 +28,32 @@ import static org.openecomp.sdc.common.errors.Messages.PACKAGE_PROCESS_INTERNAL_
import static org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager.ALLOWED_CERTIFICATE_EXTENSIONS;
import static org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager.ALLOWED_SIGNATURE_EXTENSIONS;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.FilenameUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
+import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.common.utils.CommonUtil;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
@@ -52,6 +64,7 @@ public class OnboardingPackageProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(OnboardingPackageProcessor.class);
private static final String CSAR_EXTENSION = "csar";
private static final String ZIP_EXTENSION = "zip";
+ private static boolean helmBase = false;
private final String packageFileName;
private final byte[] packageFileContent;
@@ -96,6 +109,7 @@ public class OnboardingPackageProcessor {
ByteBuffer.wrap(packageFileContent), new OnboardingPackageContentHandler(onboardPackageContentHandler));
return new OnboardPackageInfo(onboardPackage, OnboardingTypesEnum.CSAR);
} else if (packageExtension.equalsIgnoreCase(ZIP_EXTENSION)) {
+ addDummyHeat();
final OnboardPackage onboardPackage = new OnboardPackage(packageName, packageExtension,
ByteBuffer.wrap(packageFileContent), onboardPackageContentHandler);
return new OnboardPackageInfo(onboardPackage, OnboardingTypesEnum.ZIP);
@@ -106,6 +120,53 @@ public class OnboardingPackageProcessor {
return null;
}
+ private void addDummyHeat() {
+ // temporary fix for adding dummy base
+ List<FileData> newfiledata = new ArrayList<>();
+ try (InputStream zipFileManifest = onboardPackageContentHandler.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
+ ManifestContent manifestContent =
+ JsonUtil.json2Object(zipFileManifest, ManifestContent.class);
+ for (FileData fileData : manifestContent.getData()) {
+ if (Objects.nonNull(fileData.getType()) &&
+ fileData.getType().equals(FileData.Type.HELM) && fileData.getBase()) {
+ helmBase = true;
+ fileData.setBase(false);
+ FileData dummyHeat = new FileData();
+ dummyHeat.setBase(true);
+ dummyHeat.setFile("base_template_dummy_ignore.yaml");
+ dummyHeat.setType(FileData.Type.HEAT);
+ FileData dummyEnv = new FileData();
+ dummyEnv.setBase(false);
+ dummyEnv.setFile("base_template_dummy_ignore.env");
+ dummyEnv.setType(FileData.Type.HEAT_ENV);
+ List<FileData> dataEnvList = new ArrayList<>();
+ dataEnvList.add(dummyEnv);
+ dummyHeat.setData(dataEnvList);
+ newfiledata.add(dummyHeat);
+ String filePath = new File("").getAbsolutePath();
+ File envFilePath = new File(filePath + "/base_template.env");
+ File baseFilePath = new File(filePath + "/base_template.yaml");
+ try (
+ InputStream envStream = new FileInputStream(envFilePath);
+ InputStream baseStream = new FileInputStream(baseFilePath);) {
+ onboardPackageContentHandler.addFile("base_template_dummy_ignore.env", envStream);
+ onboardPackageContentHandler.addFile("base_template_dummy_ignore.yaml", baseStream);
+ } catch (Exception e) {
+ LOGGER.error("Failed creating input stream {}", e);
+ }
+ }
+ }
+ if (helmBase) {
+ manifestContent.getData().addAll(newfiledata);
+ InputStream manifestContentStream = new ByteArrayInputStream((JsonUtil.object2Json(manifestContent)).getBytes(StandardCharsets.UTF_8));
+ onboardPackageContentHandler.remove(SdcCommon.MANIFEST_NAME);
+ onboardPackageContentHandler.addFile(SdcCommon.MANIFEST_NAME, manifestContentStream);
+ }
+ } catch (Exception e) {
+ final String message = PACKAGE_INVALID_ERROR.formatMessage(packageFileName);
+ LOGGER.error(message, e);
+ }
+ }
private boolean hasValidExtension() {
final String packageExtension = FilenameUtils.getExtension(packageFileName);
return packageExtension.equalsIgnoreCase(CSAR_EXTENSION) || packageExtension.equalsIgnoreCase(ZIP_EXTENSION);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
index bff9791aeb..45dc5faac5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java
@@ -27,8 +27,12 @@ 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.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
import org.openecomp.sdc.validation.util.ValidationManagerUtil;
@@ -43,9 +47,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils;
import org.openecomp.sdc.versioning.dao.types.Version;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
import java.util.*;
public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemplateProcessHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class);
private final CandidateService candidateService =
CandidateServiceFactory.getInstance().createInterface();
@@ -67,6 +75,11 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp
Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors();
FileContentHandler fileContentMap = fileContent.get();
+ try (InputStream zipFileManifest = fileContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
+ addDummyHeatBase(zipFileManifest ,fileContentMap);
+ } catch (Exception e) {
+ LOGGER.error("Invalid package content", e);
+ }
FilesDataStructure structure =
JsonUtil.json2Object(candidateData.getFilesDataStructure(), FilesDataStructure.class);
@@ -131,6 +144,28 @@ public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemp
return response;
}
+ private FileContentHandler addDummyHeatBase(InputStream zipFileManifest, FileContentHandler fileContentMap) {
+ ManifestContent manifestContent =
+ JsonUtil.json2Object(zipFileManifest, ManifestContent.class);
+ for (FileData fileData : manifestContent.getData()) {
+ if (Objects.nonNull(fileData.getType()) &&
+ fileData.getType().equals(FileData.Type.HELM) && fileData.getBase()) {
+ String filePath = new File("").getAbsolutePath();
+ File envFilePath = new File(filePath + "/base_template.env");
+ File baseFilePath = new File(filePath + "/base_template.yaml");
+ try (
+ InputStream envStream = new FileInputStream(envFilePath);
+ InputStream baseStream = new FileInputStream(baseFilePath);) {
+ fileContentMap.addFile("base_template_dummy_ignore.env", envStream);
+ fileContentMap.addFile("base_template_dummy_ignore.yaml", baseStream);
+ } catch (Exception e) {
+ LOGGER.error("File not found error {}", e);
+ }
+ }
+ }
+ return fileContentMap;
+ }
+
private Map<String, List<ErrorMessage>> getErrors(OrchestrationTemplateActionResponse
orchestrationTemplateActionResponse) {
Map<String, List<ErrorMessage>> errors =
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/DummyHeatUse.txt b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/DummyHeatUse.txt
new file mode 100644
index 0000000000..ff8c3e9e32
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/DummyHeatUse.txt
@@ -0,0 +1,5 @@
+In case we are uploading a zip file which has a non heat type base (temporary fix by creating a dummy heat):
+
+Copy the base_template.yaml and base_template.env from this folder to the onboard-be pod , where its running in the environment.
+
+The onboard-be pod is run in the path, /var/lib/jetty. Copy the env and yaml to this path. \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.env b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.env
new file mode 100644
index 0000000000..1b96230a96
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.env
@@ -0,0 +1,4 @@
+parameters:
+ vnf_name: demo_vnf_ignore
+ vnf_id: demo_app
+ vf_module_id: demo_module_id \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.yaml
new file mode 100644
index 0000000000..eb6962b95e
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/base_template.yaml
@@ -0,0 +1,49 @@
+
+
+heat_template_version: 2013-05-23
+
+description: Dummy base heat template
+
+##############
+# #
+# PARAMETERS #
+# #
+##############
+
+parameters:
+ vnf_name:
+ type: string
+ description: VNF_NAME
+ vnf_id:
+ type: string
+ label: VNF ID
+ description: The VNF ID is provided by ONAP
+ vf_module_id:
+ type: string
+ label: VF Module ID
+ description: The VF Module ID is provided by ONAP
+
+#############
+# #
+# RESOURCES #
+# #
+#############
+
+resources:
+ dummy:
+ type: OS::Heat::None
+ properties:
+ vnf_name:
+ get_param: vnf_name
+ vnf_id:
+ get_param: vnf_id
+ vf_module_id:
+ get_param: vf_module_id
+
+ #SDC won't allow too dummy resource as it has to find 'topology_template' TOSCA equivalent in heat templates
+ dummy_base:
+ type: OS::Nova::Server
+ properties:
+ name: test
+ image: test
+ flavor: test \ No newline at end of file