summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar
diff options
context:
space:
mode:
authorshrek2000 <orenkle@amdocs.com>2017-09-11 15:45:37 +0300
committershrek2000 <orenkle@amdocs.com>2017-09-12 10:38:35 +0300
commitc8a540b3c234449163f6fb1899807bba951113b4 (patch)
treea8aae0dd0f6a0feb27369914e9e3fa321740e7ed /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar
parent82d454fd3e8c9fdf66517d01a99019a379dbfdb6 (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/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java18
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java141
2 files changed, 159 insertions, 0 deletions
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
new file mode 100644
index 0000000000..0d204ef2c0
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java
@@ -0,0 +1,18 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar;
+
+import com.google.common.collect.ImmutableSet;
+import static com.google.common.collect.ImmutableSet.of;
+public class CSARConstants {
+
+ public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/",
+ "Licenses/", "TOSCA-Metadata/");
+
+ 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 ImmutableSet<String> ELIGIBLE_FILES =
+ of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
+
+ public static final String METADATA_MF_ATTRIBUTE = "metadata";
+ public static final String SOURCE_MF_ATTRIBUTE = "source";
+ public static final String SEPERATOR_MF_ATTRIBUTE = ":";
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java
new file mode 100644
index 0000000000..d88d883e67
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java
@@ -0,0 +1,141 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.lang.StringUtils;
+import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*;
+
+public class OnboardingManifest {
+ private static final Logger logger = LoggerFactory.getLogger(OnboardingManifest.class);
+ private Map<String, String> metadata;
+ private List<String> sources;
+ private List<String> errors;
+ private State state;
+ private enum State {
+ Start, ProcessMetadata, ProcessSources, Error
+ }
+
+ public OnboardingManifest(InputStream is) {
+ errors = new ArrayList<>();
+ sources = new ArrayList<>();
+ metadata = new HashMap<>();
+ parseManifest(is);
+ }
+
+ private void parseManifest(InputStream is) {
+ try {
+ ImmutableList<String> lines = readAllLines(is);
+ state = State.Start;
+
+ for (String line : lines) {
+ line = line.trim();
+ if (!StringUtils.isEmpty(line.trim())) {
+ state = processLine(state, line);
+ }
+ }
+ if (errors.isEmpty()) {
+ if (metadata.isEmpty()) {
+ errors.add(Messages.MANIFEST_NO_METADATA.getErrorMessage());
+ }
+ if (sources.isEmpty()) {
+ errors.add(Messages.MANIFEST_NO_SOURCES.getErrorMessage());
+ }
+ }
+ } catch (IOException e){
+ logger.error(e.getMessage(),e);
+ errors.add(Messages.MANIFEST_PARSER_INTERNAL.getErrorMessage());
+ }
+ }
+
+ private State processLine(State state, String line) {
+ switch (state) {
+ case Start:
+ if (line.trim().equals(METADATA_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE)) {
+ state = State.ProcessMetadata;
+ } else {
+ reportError(line);
+ }
+ break;
+ case ProcessMetadata:
+ String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE);
+ if (metaSplit.length < 2){
+ reportError(line);
+ break;
+ }
+ if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){
+ String value = line.replace(metaSplit[0] + SEPERATOR_MF_ATTRIBUTE, "").trim();
+ metadata.put(metaSplit[0],value);
+ } else {
+ state = State.ProcessSources;
+ processSourceLine(line);
+ }
+ break;
+ case ProcessSources:
+ processSourceLine(line);
+
+ break;
+ case Error:
+ break;
+
+ } return state;
+ }
+
+ private void processSourceLine(String line) {
+ if (line.startsWith(SOURCE_MF_ATTRIBUTE+SEPERATOR_MF_ATTRIBUTE)){
+ String value = line.replaceAll(SOURCE_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE, "").trim();
+ sources.add(value);
+ }else {
+ reportError(line);
+ }
+ }
+
+ private void reportError(String line) {
+ errors.add(getErrorWithParameters(Messages.MANIFEST_INVALID_LINE.getErrorMessage(), line));
+ state = State.Error;
+ }
+
+ private ImmutableList<String> readAllLines(InputStream is) throws IOException {
+ ImmutableList.Builder<String> builder = ImmutableList.<String> builder();
+ try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8.newDecoder());
+ BufferedReader bufferedReader = new BufferedReader(reader);) {
+ for (; ; ) {
+ String line = bufferedReader.readLine();
+ if (line == null)
+ break;
+ builder.add(line);
+ }
+ }
+ return builder.build();
+ }
+
+ public Map<String, String> getMetadata() {
+ if (!isValid()){
+ return Collections.EMPTY_MAP;
+ }
+ return ImmutableMap.copyOf(metadata);
+ }
+
+ public List<String> getSources() {
+ if (!isValid()){
+ return Collections.EMPTY_LIST;
+ }
+ return ImmutableList.copyOf(sources);
+ }
+
+ public List<String> getErrors() {
+ return ImmutableList.copyOf(errors);
+ }
+
+ public boolean isValid() {
+ return errors.isEmpty();
+ }
+}