From 4149de4df046df1f3ee334eff211a0f979cf4cc7 Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 21 Aug 2017 17:22:08 +0300 Subject: [SDC-242] jtosca resolve get_input Change-Id: Ia0624cb00df47770af0e4514e6c2a35038151667 Signed-off-by: Pavel Aharoni --- .../sdc/toscaparser/api/TopologyTemplate.java | 22 ++++++++---- .../sdc/toscaparser/api/ToscaTemplate.java | 28 ++++++++++++--- .../sdc/toscaparser/api/extensions/ExtTools.java | 4 --- .../sdc/toscaparser/api/functions/Function.java | 40 +++++++++++++--------- .../sdc/toscaparser/api/functions/GetProperty.java | 4 +-- 5 files changed, 63 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java index 25f118b..709dc81 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -48,13 +48,15 @@ public class TopologyTemplate { private String description; private ToscaGraph graph; private SubstitutionMappings substitutionMappings; + private boolean resolveGetInput; public TopologyTemplate( LinkedHashMap _template, LinkedHashMap _customDefs, LinkedHashMap _relTypes,//TYPE LinkedHashMap _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 ifin = ifd.getInputs(); if(ifin != null) { for(Map.Entry 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)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 getParsedParams() { return parsedParams; } + + public boolean getResolveGetInput() { + return resolveGetInput; + } } /*python diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java index 76b86f5..5d5cb87 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -69,6 +69,7 @@ public class ToscaTemplate extends Object { private String path; private String inputPath; private LinkedHashMap parsedParams; + private boolean resolveGetInput; private LinkedHashMap tpl; private String version; private ArrayList imports; @@ -89,11 +90,25 @@ public class ToscaTemplate extends Object { private int nestingLoopCounter; private LinkedHashMap> metaProperties; - @SuppressWarnings("unchecked") public ToscaTemplate(String _path, - LinkedHashMap _parsedParams, + LinkedHashMap _parsedParams, + boolean aFile, + LinkedHashMap yamlDictTpl) throws JToscaException { + init(_path, _parsedParams, aFile, yamlDictTpl, true); + } + + public ToscaTemplate(String _path, + LinkedHashMap _parsedParams, boolean aFile, - LinkedHashMap yamlDictTpl) throws JToscaException { + LinkedHashMap yamlDictTpl, boolean resolveGetInput) throws JToscaException { + init(_path, _parsedParams, aFile, yamlDictTpl, resolveGetInput); + } + + @SuppressWarnings("unchecked") + private void init(String _path, + LinkedHashMap _parsedParams, + boolean aFile, + LinkedHashMap 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(); + 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 _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); diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/extensions/ExtTools.java b/src/main/java/org/openecomp/sdc/toscaparser/api/extensions/ExtTools.java index 6403d6e..90aa35c 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/extensions/ExtTools.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/extensions/ExtTools.java @@ -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()) { diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java index 85fa62e..7615a00 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Function.java @@ -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 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 rawFunction = (LinkedHashMap) rawFunctionObjItem; String funcName = (new ArrayList(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); } } } diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java index 3550542..71420e8 100644 --- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java +++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java @@ -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() { -- cgit 1.2.3-korg