[SDC-242] jtosca resolve get_input
authorPavel Aharoni <pa0916@att.com>
Mon, 21 Aug 2017 14:22:08 +0000 (17:22 +0300)
committerPavel Aharoni <pa0916@att.com>
Mon, 21 Aug 2017 14:22:08 +0000 (17:22 +0300)
Change-Id: Ia0624cb00df47770af0e4514e6c2a35038151667
Signed-off-by: Pavel Aharoni <pa0916@att.com>
pom.xml
src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/extensions/ExtTools.java
src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java
src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java

diff --git a/pom.xml b/pom.xml
index d092e57..6485d2b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,10 +1,10 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-       <modelVersion>4.0.0</modelVersion>
-
-       <groupId>org.openecomp.sdc.jtosca</groupId>
-       <artifactId>jtosca</artifactId>
-       <version>1.1.1-SNAPSHOT</version>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+       <modelVersion>4.0.0</modelVersion>\r
+\r
+       <groupId>org.openecomp.sdc.jtosca</groupId>\r
+       <artifactId>jtosca</artifactId>\r
+       <version>1.1.3-SNAPSHOT</version>\r
 \r
        <properties>\r
 \r
                <releases.path>releases</releases.path>\r
                <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->\r
 \r
-       </properties>
-
-       <dependencies>
-               <!-- YAML parser -->
-               <dependency>
-                       <groupId>org.yaml</groupId>
-                       <artifactId>snakeyaml</artifactId>
-                       <version>1.14</version>
-                       <scope>compile</scope>
-               </dependency>
-
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>slf4j-api</artifactId>
-                       <version>1.7.25</version>
-               </dependency>
-
-               <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> 
-                       <version>1.1.2</version> <scope>test</scope> </dependency> -->
-
-               <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <version>4.12</version>
-               </dependency>
+       </properties>\r
+\r
+       <dependencies>\r
+               <!-- YAML parser -->\r
+               <dependency>\r
+                       <groupId>org.yaml</groupId>\r
+                       <artifactId>snakeyaml</artifactId>\r
+                       <version>1.14</version>\r
+                       <scope>compile</scope>\r
+               </dependency>\r
+\r
+               <dependency>\r
+                       <groupId>org.slf4j</groupId>\r
+                       <artifactId>slf4j-api</artifactId>\r
+                       <version>1.7.25</version>\r
+               </dependency>\r
+\r
+               <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> \r
+                       <version>1.1.2</version> <scope>test</scope> </dependency> -->\r
+\r
+               <dependency>\r
+                       <groupId>junit</groupId>\r
+                       <artifactId>junit</artifactId>\r
+                       <version>4.12</version>\r
+               </dependency>\r
        </dependencies>\r
 \r
        <reporting>\r
                        <id>ecomp-site</id>\r
                        <url>dav:${nexus.proxy}${sitePath}</url>\r
                </site>\r
-       </distributionManagement>
-
+       </distributionManagement>\r
+\r
 </project>
\ No newline at end of file
index 25f118b..709dc81 100644 (file)
@@ -48,13 +48,15 @@ public class TopologyTemplate {
     private String description;
     private ToscaGraph graph;
     private SubstitutionMappings substitutionMappings;
+       private boolean resolveGetInput;
        
        public TopologyTemplate(
                        LinkedHashMap<String,Object> _template, 
                        LinkedHashMap<String,Object> _customDefs,
                        LinkedHashMap<String,Object> _relTypes,//TYPE
             LinkedHashMap<String, Object> _parsedParams,
-            NodeTemplate  _subMappedNodeTemplate) {
+            NodeTemplate  _subMappedNodeTemplate,
+                       boolean _resolveGetInput) {
 
                tpl = _template;
                if(tpl != null) {
@@ -63,6 +65,7 @@ public class TopologyTemplate {
                        customDefs = _customDefs;
                        relTypes = _relTypes;
                        parsedParams = _parsedParams;
+                       resolveGetInput = _resolveGetInput;
                        _validateField();
                        description = _tplDescription();
                        inputs = _inputs();
@@ -400,14 +403,14 @@ public class TopologyTemplate {
        if(nodeTemplates != null) {
                for(NodeTemplate nt: nodeTemplates) {
                        for(Property prop: nt.getPropertiesObjects()) {
-                               prop.setValue(Function.getFunction(this,nt,prop.getValue()));
+                               prop.setValue(Function.getFunction(this,nt,prop.getValue(), resolveGetInput));
                        }
                        for(InterfacesDef ifd: nt.getInterfaces()) {
                                LinkedHashMap<String,Object> ifin = ifd.getInputs();
                                if(ifin != null) {
                                        for(Map.Entry<String,Object> me: ifin.entrySet()) {
                                                String name = me.getKey();
-                                               Object value = Function.getFunction(this,nt,me.getValue());
+                                               Object value = Function.getFunction(this,nt,me.getValue(), resolveGetInput);
                                                ifd.setInput(name,value);
                                        }
                                }
@@ -438,7 +441,7 @@ public class TopologyTemplate {
                                                                (LinkedHashMap<String,Object>)rel.get("properties");
                                                for(String key: relprops.keySet()) {
                                                        Object value = relprops.get(key);
-                                                       Object func = Function.getFunction(this,req,value);
+                                                       Object func = Function.getFunction(this,req,value, resolveGetInput);
                                                        relprops.put(key,func);
                                                }
                                        }
@@ -448,7 +451,7 @@ public class TopologyTemplate {
                                for(Capability cap: nt.getCapabilitiesObjects()) {
                                        if(cap.getPropertiesObjects() != null) {
                                                for(Property prop: cap.getPropertiesObjects()) {
-                                                       Object propvalue = Function.getFunction(this,nt,prop.getValue());
+                                                       Object propvalue = Function.getFunction(this,nt,prop.getValue(), resolveGetInput);
                                                        if(propvalue instanceof GetInput) {
                                                                propvalue = ((GetInput)propvalue).result();
                                                                for(String p: cap.getProperties().keySet()) {
@@ -475,7 +478,8 @@ public class TopologyTemplate {
                                                                        Object func = Function.getFunction(
                                                                                        this,
                                                                                        relTpl,
-                                                                                       value);
+                                                                                       value,
+                                                                                               resolveGetInput);
                                                                        iface.setInput(name,func);
                                                                }
                                                        }
@@ -486,7 +490,7 @@ public class TopologyTemplate {
                }
        }
        for(Output output: outputs) {
-               Object func = Function.getFunction(this,outputs,output.getValue());
+               Object func = Function.getFunction(this,outputs,output.getValue(), resolveGetInput);
                if(func instanceof GetAttribute) {
                        output.setAttr(Output.VALUE,func);
                }
@@ -542,6 +546,10 @@ public class TopologyTemplate {
        public LinkedHashMap<String,Object> getParsedParams() {
                return parsedParams;
        }
+
+       public boolean getResolveGetInput() {
+               return resolveGetInput;
+       }
 }
 
 /*python
index 76b86f5..5d5cb87 100644 (file)
@@ -69,6 +69,7 @@ public class ToscaTemplate extends Object {
        private String path;
        private String inputPath;
        private LinkedHashMap<String,Object> parsedParams;
+       private boolean resolveGetInput;
        private LinkedHashMap<String,Object> tpl;
     private String version;
     private ArrayList<Object> imports;
@@ -89,11 +90,25 @@ public class ToscaTemplate extends Object {
     private int nestingLoopCounter;
        private LinkedHashMap<String, LinkedHashMap<String, Object>> metaProperties;
 
-       @SuppressWarnings("unchecked")
        public ToscaTemplate(String _path,
-                                                LinkedHashMap<String,Object> _parsedParams,
+                                               LinkedHashMap<String,Object> _parsedParams,
+                                               boolean aFile,
+                                               LinkedHashMap<String,Object> yamlDictTpl) throws JToscaException {
+               init(_path, _parsedParams, aFile, yamlDictTpl, true);
+       }
+
+       public ToscaTemplate(String _path,
+                                                LinkedHashMap<String,Object> _parsedParams,
                                                 boolean aFile,
-                                                LinkedHashMap<String,Object> yamlDictTpl) throws JToscaException {
+                                                LinkedHashMap<String,Object> yamlDictTpl, boolean resolveGetInput) throws JToscaException {
+               init(_path, _parsedParams, aFile, yamlDictTpl, resolveGetInput);
+       }
+
+       @SuppressWarnings("unchecked")
+       private void init(String _path,
+                                         LinkedHashMap<String, Object> _parsedParams,
+                                         boolean aFile,
+                                         LinkedHashMap<String, Object> yamlDictTpl, boolean _resolveGetInput) throws JToscaException {
 
                ThreadLocalsHolder.setCollector(new ExceptionCollector(_path));
 
@@ -116,6 +131,7 @@ public class ToscaTemplate extends Object {
                csarTempDir = null;
                nestedToscaTplsWithTopology = new ConcurrentHashMap<>();
                nestedToscaTemplatesWithTopology = new ArrayList<TopologyTemplate>();
+               resolveGetInput = _resolveGetInput;
 
                if(_path != null && !_path.isEmpty()) {
                        // save the original input path
@@ -206,7 +222,8 @@ public class ToscaTemplate extends Object {
                                _getAllCustomDefs(imports),
                                relationshipTypes,
                                parsedParams,
-                               null);
+                               null,
+                               resolveGetInput);
        }
 
        private ArrayList<Input> _inputs() {
@@ -384,7 +401,8 @@ public class ToscaTemplate extends Object {
                                                                                         _getAllCustomDefs(alim),
                                                                                         relationshipTypes, 
                                                                                         parsedParams,
-                                                                                        nt);
+                                                                                        nt,
+                                                                                        resolveGetInput);
                                        if(topologyWithSubMapping.getSubstitutionMappings() != null) {
                         // Record nested topology templates in top level template
                         //nestedToscaTemplatesWithTopology.add(topologyWithSubMapping);
index 6403d6e..90aa35c 100644 (file)
@@ -37,10 +37,6 @@ public class ExtTools {
            // for all folders in extdir
            File extDir = new File(extdir);
            File extDirList[] = extDir.listFiles();
-           if (extDirList == null)  {
-               String a = "aaaa";
-               
-           }
            if (extDirList != null) {
                    for(File f: extDirList) {
                        if(f.isDirectory()) {
index 85fa62e..7615a00 100644 (file)
@@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.functions;
 import java.util.*;
 
 import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
 
 public abstract class Function {
 
@@ -77,7 +78,7 @@ public abstract class Function {
        }
        
        @SuppressWarnings("unchecked")
-       public static Object getFunction(TopologyTemplate ttpl,Object context,Object rawFunctionObj) {
+       public static Object getFunction(TopologyTemplate ttpl,Object context,Object rawFunctionObj, boolean resolveGetInput) {
            // Gets a Function instance representing the provided template function.
 
            // If the format provided raw_function format is not relevant for template
@@ -98,13 +99,13 @@ public abstract class Function {
         if (rawFunctionObj instanceof LinkedHashMap) { // In map type case
                        LinkedHashMap rawFunction = ((LinkedHashMap) rawFunctionObj);
                        if(rawFunction.size() == 1) { // End point
-                               return getFunctionForObjectItem(ttpl, context, rawFunction);
+                               return getFunctionForObjectItem(ttpl, context, rawFunction, resolveGetInput);
                        } else {
                            // iterate over map nested properties in recursion, convert leaves to function,
                 // and collect them in the same hierarchy as the original map.
                                LinkedHashMap rawFunctionObjMap = new LinkedHashMap();
                                for (Object rawFunctionObjItem: rawFunction.entrySet()) {
-                                       Object itemValue = getFunction(ttpl, context, ((Map.Entry)rawFunctionObjItem).getValue());
+                                       Object itemValue = getFunction(ttpl, context, ((Map.Entry)rawFunctionObjItem).getValue(), resolveGetInput);
                                        rawFunctionObjMap.put(((Map.Entry)rawFunctionObjItem).getKey(), itemValue);
                                }
                                return rawFunctionObjMap;
@@ -114,7 +115,7 @@ public abstract class Function {
             // and collect them in the same hierarchy as the original list.
                        ArrayList<Object> rawFunctionObjList = new ArrayList<>();
                        for (Object rawFunctionObjItem: (ArrayList) rawFunctionObj) {
-                               rawFunctionObjList.add(getFunction(ttpl, context, rawFunctionObjItem));
+                               rawFunctionObjList.add(getFunction(ttpl, context, rawFunctionObjItem, resolveGetInput));
                        }
                        return rawFunctionObjList;
                }
@@ -122,7 +123,7 @@ public abstract class Function {
            return rawFunctionObj;
        }
 
-       private static Object getFunctionForObjectItem(TopologyTemplate ttpl, Object context, Object rawFunctionObjItem) {
+       private static Object getFunctionForObjectItem(TopologyTemplate ttpl, Object context, Object rawFunctionObjItem, boolean resolveGetInput) {
                if(isFunction(rawFunctionObjItem)) {
                        LinkedHashMap<String, Object> rawFunction = (LinkedHashMap<String, Object>) rawFunctionObjItem;
                        String funcName = (new ArrayList<String>(rawFunction.keySet())).get(0);
@@ -137,18 +138,23 @@ public abstract class Function {
                                        funcArgs.add(oargs);
                                }
 
-                               if (funcType.equals("GetInput")) {
-                                       return new GetInput(ttpl, context, funcName, funcArgs);
-                               } else if (funcType.equals("GetAttribute")) {
-                                       return new GetAttribute(ttpl, context, funcName, funcArgs);
-                               } else if (funcType.equals("GetProperty")) {
-                                       return new GetProperty(ttpl, context, funcName, funcArgs);
-                               } else if (funcType.equals("GetOperationOutput")) {
-                                       return new GetOperationOutput(ttpl, context, funcName, funcArgs);
-                               } else if (funcType.equals("Concat")) {
-                                       return new Concat(ttpl, context, funcName, funcArgs);
-                               } else if (funcType.equals("Token")) {
-                                       return new Token(ttpl, context, funcName, funcArgs);
+                               switch (funcType) {
+                                       case "GetInput":
+                                               if (resolveGetInput) {
+                                                       GetInput input = new GetInput(ttpl, context, funcName, funcArgs);
+                                                       return input.result();
+                                               }
+                                               return new GetInput(ttpl, context, funcName, funcArgs);
+                                       case "GetAttribute":
+                                               return new GetAttribute(ttpl, context, funcName, funcArgs);
+                                       case "GetProperty":
+                                               return new GetProperty(ttpl, context, funcName, funcArgs);
+                                       case "GetOperationOutput":
+                                               return new GetOperationOutput(ttpl, context, funcName, funcArgs);
+                                       case "Concat":
+                                               return new Concat(ttpl, context, funcName, funcArgs);
+                                       case "Token":
+                                               return new Token(ttpl, context, funcName, funcArgs);
                                }
                        }
                }
index 3550542..71420e8 100644 (file)
@@ -58,7 +58,7 @@ public class GetProperty extends Function {
                }
                Object prop = foundProp.getValue();
                if(prop instanceof Function) {
-                   Function.getFunction(toscaTpl,context, prop);
+                   Function.getFunction(toscaTpl,context, prop, toscaTpl.getResolveGetInput());
                }
            }
            else if(args.size() >= 3) {
@@ -336,7 +336,7 @@ public class GetProperty extends Function {
         if(propertyValue instanceof Function) {
             return ((Function)propertyValue).result();
         }
-        return Function.getFunction(toscaTpl,context,propertyValue);
+        return Function.getFunction(toscaTpl,context,propertyValue, toscaTpl.getResolveGetInput());
        }
 
        public String getNodeTemplateName() {