diff options
author | shaheen_vz <shaheen.shaik@verizon.com> | 2018-10-19 17:48:18 +0530 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-12-18 08:43:12 +0000 |
commit | a47b9ec93001399802933e6b2f1c30e13a689181 (patch) | |
tree | 83228a8dfa0c3c70e226c0ac87a306f3de56078c /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager | |
parent | c9e7a45f31a60ec51b770febae2213f5b7668960 (diff) |
MainServiceTemplate multiple location support
Issue-ID: SDC-1744
Signed-off-by: Shaheen Shaik<shaheen.shaik@verizon.com>:
Change-Id: I77e4ede6b2177ba66a4de8da824d9c7fd86f5705
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager')
6 files changed, 161 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 |