diff options
author | shrek2000 <orenkle@amdocs.com> | 2017-09-11 15:45:37 +0300 |
---|---|---|
committer | shrek2000 <orenkle@amdocs.com> | 2017-09-12 10:38:35 +0300 |
commit | c8a540b3c234449163f6fb1899807bba951113b4 (patch) | |
tree | a8aae0dd0f6a0feb27369914e9e3fa321740e7ed /openecomp-be/lib/openecomp-common-lib/src/main/java | |
parent | 82d454fd3e8c9fdf66517d01a99019a379dbfdb6 (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/lib/openecomp-common-lib/src/main/java')
3 files changed, 47 insertions, 15 deletions
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 9fff4bd749..8bcb0a5ffe 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 @@ -28,6 +28,14 @@ public enum Messages { "functionalities"), INVALID_ZIP_FILE("Invalid zip file"), + INVALID_CSAR_FILE("Invalid csar file"), + CSAR_FILE_NOT_FOUND("Each CSAR file must contain %s file."), + CSAR_DIRECTORIES_NOT_ALLOWED("Directory : %s , is not allowed."), + CSAR_FILES_NOT_ALLOWED("File : %s , are not allowed."), + MANIFEST_INVALID_LINE("Manifest contains invalid line : %s"), + MANIFEST_NO_METADATA("Manifest must contain metadata"), + MANIFEST_NO_SOURCES("Manifest must contain source"), + MANIFEST_PARSER_INTERNAL("Invalid manifest file"), FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"), ZIP_NOT_EXIST("Zip file doesn't exist"), @@ -45,7 +53,7 @@ public enum Messages { NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST("no zip file was uploaded or zip file doesn't exist"), MAPPING_OBJECTS_FAILURE("Failed to map object %s to %s. Exception message: %s"), MORE_THEN_ONE_VOL_FOR_HEAT("heat contains more then one vol. selecting only first vol"), - ZIP_CONTENT_MAP("failed to load zip content"), + FILE_CONTENT_MAP("failed to load %s content"), CREATE_MANIFEST_FROM_ZIP("cannot create manifest from the attached zip file"), CANDIDATE_PROCESS_FAILED("Candidate zip file process failed"), FOUND_UNASSIGNED_FILES("cannot process zip since it has unassigned files"), @@ -66,7 +74,9 @@ public enum Messages { INVALID_MANIFEST_FILE("invalid manifest file"), INVALID_FILE_TYPE("Missing or Unknown file type in Manifest"), ENV_NOT_ASSOCIATED_TO_HEAT("ENV file must be associated to a HEAT file"), - + CSAR_MANIFEST_FILE_NOT_EXIST("CSAR manifest file does not exist"), + CSAR_FAILED_TO_READ("CSAR file is not readable"), + TOSCA_PARSING_FAILURE("Invalid tosca file. Error code : %s, Error message : %s/"), /* content errors*/ INVALID_YAML_FORMAT("Invalid YAML format - %s"), INVALID_YAML_FORMAT_REASON("Invalid YAML format Problem - [%s]"), diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java index f4d6209eec..1c5293004d 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java @@ -22,8 +22,11 @@ package org.openecomp.sdc.common.utils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; 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.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; @@ -45,38 +48,54 @@ import java.util.zip.ZipInputStream; public class CommonUtil { - public static FileContentHandler validateAndUploadFileContent(byte[] uploadedFileData) + public static FileContentHandler validateAndUploadFileContent(OnboardingTypesEnum type, + byte[] uploadedFileData) throws IOException { - return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(uploadedFileData); + return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(type, uploadedFileData); } /** * Gets files out of the zip AND validates zip is flat (no folders) * + * + * @param type * @param uploadFileData zip file * @return FileContentHandler if input is valid and has no folders */ private static FileContentHandler getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders( - byte[] uploadFileData) + OnboardingTypesEnum type, byte[] uploadFileData) throws IOException { + Pair<FileContentHandler,List<String> > pair = getFileContentMapFromOrchestrationCandidateZip(uploadFileData); - List<String> folderList = new ArrayList<>(); - FileContentHandler mapFileContent = new FileContentHandler(); + if(type.equals(OnboardingTypesEnum.ZIP)) { + validateNoFolders(pair.getRight()); + } - try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData))) { + return pair.getLeft(); + } + public static Pair<FileContentHandler,List<String> > getFileContentMapFromOrchestrationCandidateZip( + byte[] uploadFileData) + throws IOException { + ZipEntry zipEntry; + List<String> folderList = new ArrayList<>(); + FileContentHandler mapFileContent = new FileContentHandler(); + try ( ByteArrayInputStream in = new ByteArrayInputStream(uploadFileData); + ZipInputStream inputZipStream = new ZipInputStream(in)){ + byte[] fileByteContent; String currentEntryName; - ZipEntry zipEntry; while ((zipEntry = inputZipStream.getNextEntry()) != null) { - currentEntryName = zipEntry.getName(); + // else, get the file content (as byte array) and save it in a map. + fileByteContent = FileUtils.toByteArray(inputZipStream); + int index = lastIndexFileSeparatorIndex(currentEntryName); if (index != -1) { //todo ? folderList.add(currentEntryName); - } else { - // else, get the file content (as byte array) and save it in a map. - mapFileContent.addFile(currentEntryName, FileUtils.toByteArray(inputZipStream)); + } + if(isFile(currentEntryName)) { + mapFileContent.addFile(currentEntryName, fileByteContent); } } @@ -84,9 +103,11 @@ public class CommonUtil { throw new IOException(exception); } - validateNoFolders(folderList); + return new ImmutablePair<>(mapFileContent,folderList); + } - return mapFileContent; + private static boolean isFile(String currentEntryName) { + return !(currentEntryName.endsWith("\\") || currentEntryName.endsWith("/")); } private static void validateNoFolders(List<String> folderList) { diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java index 156a86c841..24da8363c1 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/SdcCommon.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.common.utils; public class SdcCommon { public static final String MANIFEST_NAME = "MANIFEST.json"; + public static final String CSAR_MANIFEST_NAME = "MainServiceTemplate.mf"; public static final String UPLOAD_FILE = "uploadFile"; public static final String PROCESS_FILE = "Process File"; public static final String ILLEGAL_MANIFEST = "Illegal manifest"; |