aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib
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/lib/openecomp-heat-lib
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/lib/openecomp-heat-lib')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/pom.xml27
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java79
2 files changed, 106 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/pom.xml b/openecomp-be/lib/openecomp-heat-lib/pom.xml
index 55ab0623b4..0a4e14f417 100644
--- a/openecomp-be/lib/openecomp-heat-lib/pom.xml
+++ b/openecomp-be/lib/openecomp-heat-lib/pom.xml
@@ -16,6 +16,18 @@
<dependencies>
<dependency>
<groupId>org.openecomp.sdc.common</groupId>
+ <artifactId>openecomp-configuration-management-core</artifactId>
+ <version>${openecomp.sdc.common.version}</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc.common</groupId>
<artifactId>openecomp-tosca-datatype</artifactId>
<version>${openecomp.sdc.common.version}</version>
</dependency>
@@ -52,4 +64,19 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${mvn.surefire.version}</version>
+ <configuration>
+ <skipTests>true</skipTests>
+ <useSystemClassLoader>false</useSystemClassLoader>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java
new file mode 100644
index 0000000000..517c690194
--- /dev/null
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java
@@ -0,0 +1,79 @@
+package org.openecomp.sdc.heat.services.tree;
+
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.heat.datatypes.structure.Artifact;
+import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+public class ToscaTreeManager {
+
+ private static Logger logger = (Logger) LoggerFactory.getLogger(ToscaTreeManager.class);
+
+ private FileContentHandler csarContentMap = new FileContentHandler();
+ private byte[] manifest;
+ private HeatStructureTree tree = new HeatStructureTree();
+ private Map<String, Artifact> artifactRef = new HashMap<>();
+ private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>();
+
+
+ public void addFile(String fileName, byte[] content) {
+ if (fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) {
+ manifest = content;
+
+ } else {
+ csarContentMap.addFile(fileName, content);
+ }
+ }
+
+ public void createTree(){
+ if (manifest == null) {
+ logger.error("Missing manifest file in the zip.");
+ return;
+ }
+
+ for(Map.Entry<String, byte[]> fileEntry : csarContentMap.getFiles().entrySet()){
+ String[] splitFilename = getFullFileNameAsArray(fileEntry.getKey());
+ addFileToTree(splitFilename, 0, tree);
+ }
+
+
+ }
+
+ private void addFileToTree(String[] splitFilename, int startIndex, HeatStructureTree parent){
+ fileTreeRef.putIfAbsent(splitFilename[startIndex], new HeatStructureTree());
+ HeatStructureTree heatStructureTree = fileTreeRef.get(splitFilename[startIndex]);
+ heatStructureTree.setFileName(splitFilename[startIndex]);
+ if(startIndex < splitFilename.length - 1){
+ addFileToTree(splitFilename, startIndex + 1, heatStructureTree);
+ }
+ parent.addHeatStructureTreeToNestedHeatList(heatStructureTree);
+ }
+
+ public void addErrors(Map<String, List<ErrorMessage>> validationErrors){
+ validationErrors.entrySet().stream().filter(entry -> {
+ return fileTreeRef.get(entry.getKey()) != null;
+ }).forEach(entry -> entry.getValue().stream().forEach(error ->
+ fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error)));
+ }
+
+ private String[] getFullFileNameAsArray(String filename){
+ if(filename.contains("/")){
+ return filename.split("/");
+ }
+
+ return filename.split(Pattern.quote(File.separator));
+ }
+
+ public HeatStructureTree getTree(){
+ return tree;
+ }
+}