summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java51
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java70
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/MetadataParsingTest.java32
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Invalidtosca.meta3
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Validtosca.meta4
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java3
7 files changed, 164 insertions, 1 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
index 182ac04035..4047937059 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
@@ -1,3 +1,23 @@
+/*
+
+ * Copyright (c) 2018 AT&T Intellectual Property.
+
+ * Modifications Copyright (c) 2018 Verizon Property.
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+ * See the License for the specific language governing permissions and
+
+ * limitations under the License.
+
+ */
+
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
import org.apache.commons.lang3.tuple.Pair;
@@ -12,6 +32,7 @@ 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.impl.orchestration.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
@@ -55,10 +76,34 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap,
List<String> folderList) {
validateManifest(uploadFileResponse, contentMap);
- validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
+ validateMetadata(uploadFileResponse, contentMap);
validateNoExtraFiles(uploadFileResponse, contentMap);
validateFolders(uploadFileResponse, folderList);
}
+
+ private void validateMetadata(UploadFileResponse uploadFileResponse,
+ FileContentHandler contentMap){
+ if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) {
+ try (InputStream metaFileContent = contentMap.getFileContent(TOSCA_META_PATH_FILE_NAME)) {
+
+ OnboardingToscaMetadata onboardingToscaMetadata = new OnboardingToscaMetadata(metaFileContent);
+ String entryDefinitionsPath = onboardingToscaMetadata.getEntryDefinitionsPath();
+ if (entryDefinitionsPath != null) {
+ validateFileExist(uploadFileResponse, contentMap, entryDefinitionsPath);
+ } else {
+ uploadFileResponse.addStructureError(
+ SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR,
+ Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()));
+ }
+ } catch (IOException exception) {
+ uploadFileResponse.addStructureError(
+ SdcCommon.UPLOAD_FILE,
+ new ErrorMessage(ErrorLevel.ERROR, Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage()));
+ }
+ } else {
+ validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
+ }
+ }
private void validateManifest(UploadFileResponse uploadFileResponse,
FileContentHandler contentMap) {
@@ -115,6 +160,10 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
private boolean filterFolders(String fileName) {
return ELIGBLE_FOLDERS.stream().noneMatch(fileName::startsWith);
}
+
+ private boolean validateTOSCAYamlFileInRootExist(FileContentHandler contentMap, String fileName) {
+ return contentMap.containsFile(fileName);
+ }
private boolean validateFileExist(UploadFileResponse uploadFileResponse,
FileContentHandler contentMap, String fileName) {
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
index 8bb67988c1..ee81527a18 100644
--- 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
@@ -26,6 +26,8 @@ public class CSARConstants {
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 String TOSCA_META_PATH_FILE_NAME="TOSCA-Metadata/TOSCA.meta";
+ public static final String TOSCA_META_ENTRY_DEFINITIONS="Entry-Definitions";
public static final ImmutableSet<String> ELIGIBLE_FILES =
of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java
new file mode 100644
index 0000000000..037e76aa16
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingToscaMetadata.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar;
+
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import java.io.InputStream;
+import java.io.IOException;
+import org.apache.commons.io.IOUtils;
+import java.util.List;
+
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE;
+
+public class OnboardingToscaMetadata {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(OnboardingToscaMetadata.class);
+ private String entryDefinitionsPath;
+
+ public OnboardingToscaMetadata(InputStream is) throws IOException {
+ parseToscaMetadataFile(is);
+ }
+
+ private void parseToscaMetadataFile(InputStream st) throws IOException {
+
+ try {
+ List<String> metadataLines = IOUtils.readLines(st,"utf-8");
+
+ for (String line : metadataLines) {
+ line = line.trim();
+ if (line.startsWith(TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE)) {
+
+ entryDefinitionsPath = line.replaceAll(TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE, "")
+ .trim();
+ break;
+
+ }
+ }
+
+ } catch (IOException e) {
+ LOGGER.error(e.getMessage(), e);
+ throw new IOException("Invalid TOSCA Metadata file", e);
+
+ }
+
+ }
+
+ public String getEntryDefinitionsPath() {
+ return entryDefinitionsPath;
+ }
+}
+
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/MetadataParsingTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/MetadataParsingTest.java
new file mode 100644
index 0000000000..46a563a25e
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/MetadataParsingTest.java
@@ -0,0 +1,32 @@
+package org.openecomp.sdc.vendorsoftwareproduct.upload.csar;
+
+import org.junit.Test;
+import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingToscaMetadata;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.junit.Assert.assertEquals;
+
+public class MetadataParsingTest {
+
+ @Test
+ public void testNoEntryDefinitions() throws IOException {
+ try (InputStream is = getClass()
+ .getResourceAsStream("/vspmanager.csar/metadata/Invalidtosca.meta")) {
+ OnboardingToscaMetadata onboardingToscaMetadata = new OnboardingToscaMetadata(is);
+ assertEquals(onboardingToscaMetadata.getEntryDefinitionsPath(), null);
+ }
+ }
+
+ @Test
+ public void testValidMetadataFile() throws IOException {
+ try (InputStream is = getClass()
+ .getResourceAsStream("/vspmanager.csar/metadata/Validtosca.meta")) {
+ OnboardingToscaMetadata onboardingToscaMetadata = new OnboardingToscaMetadata(is);
+ assertEquals(onboardingToscaMetadata.getEntryDefinitionsPath(), "Definitions/MainServiceTemplate.yaml");
+ }
+
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Invalidtosca.meta b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Invalidtosca.meta
new file mode 100644
index 0000000000..e9f08025dc
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Invalidtosca.meta
@@ -0,0 +1,3 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Feng yuanxing
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Validtosca.meta b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Validtosca.meta
new file mode 100644
index 0000000000..1f3980547c
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/metadata/Validtosca.meta
@@ -0,0 +1,4 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Feng yuanxing
+Entry-Definitions: Definitions/MainServiceTemplate.yaml
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
index 650eb06211..f1f84231cd 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -33,6 +33,9 @@ public enum Messages {
MANIFEST_NO_METADATA("Manifest must contain metadata"),
MANIFEST_NO_SOURCES("Manifest must contain Source"),
MANIFEST_PARSER_INTERNAL("Invalid manifest file"),
+ METADATA_PARSER_INTERNAL("Invalid Metadata file"),
+ METADATA_NO_ENTRY_DEFINITIONS("TOSCA.meta must contain Entry Definitions"),
+ FAILED_TO_VALIDATE_METADATA("Failed to validate metadata file"),
FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"),
ZIP_NOT_EXIST("Zip file doesn't exist"),