+/*
+
+ * 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;
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;
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) {
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) {
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);
--- /dev/null
+/*-
+ * ============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;
+ }
+}
+
--- /dev/null
+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");
+ }
+
+ }
+}
--- /dev/null
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Feng yuanxing
--- /dev/null
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-By: Feng yuanxing
+Entry-Definitions: Definitions/MainServiceTemplate.yaml
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"),