From 87511869a3e3ca3c147f072b49371874e1336d74 Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 8 May 2017 13:19:36 +0300 Subject: [SDC-16] JTosca support of input complex types Change-Id: Id146b4da662c0aab5edcf637206e8d2c922c9b81 Signed-off-by: Pavel Aharoni --- jtosca/pom.xml | 2 +- .../sdc/toscaparser/api/TopologyTemplate.java | 44 +++++---------------- .../sdc/toscaparser/api/parameters/Input.java | 31 ++++++++++----- sdc-tosca-parser/pom.xml | 2 +- .../sdc/impl/ToscaParserNodeTemplateTest.java | 11 +++++- .../csars/service-ServiceFdnt-with-allotted.csar | Bin 44991 -> 44976 bytes 6 files changed, 43 insertions(+), 47 deletions(-) diff --git a/jtosca/pom.xml b/jtosca/pom.xml index 847579c..f74988b 100644 --- a/jtosca/pom.xml +++ b/jtosca/pom.xml @@ -9,7 +9,7 @@ jtosca - 0.1.1-SNAPSHOT + 0.1.2-SNAPSHOT diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java index bf1851c..39536ca 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -5,11 +5,8 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; -import org.openecomp.sdc.toscaparser.api.SubstitutionMappings; -import org.openecomp.sdc.toscaparser.api.ToscaGraph; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.elements.RelationshipType; import org.openecomp.sdc.toscaparser.api.functions.Function; @@ -17,12 +14,9 @@ import org.openecomp.sdc.toscaparser.api.functions.GetAttribute; import org.openecomp.sdc.toscaparser.api.functions.GetInput; import org.openecomp.sdc.toscaparser.api.parameters.Input; import org.openecomp.sdc.toscaparser.api.parameters.Output; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class TopologyTemplate { - private static Logger log = LoggerFactory.getLogger(TopologyTemplate.class.getName()); private static final String DESCRIPTION = "description"; private static final String INPUTS = "inputs"; private static final String NODE_TEMPLATES = "node_templates"; @@ -39,7 +33,7 @@ public class TopologyTemplate { }; private LinkedHashMap tpl; - Metadata metaData; + LinkedHashMap metaData; private ArrayList inputs; private ArrayList outputs; private ArrayList relationshipTemplates; @@ -86,10 +80,11 @@ public class TopologyTemplate { @SuppressWarnings("unchecked") private ArrayList _inputs() { + //DumpUtils.dumpYaml(customDefs,0); ArrayList alInputs = new ArrayList<>(); for(String name: _tplInputs().keySet()) { Object attrs = _tplInputs().get(name); - Input input = new Input(name,(LinkedHashMap)attrs); + Input input = new Input(name,(LinkedHashMap)attrs,customDefs);//ATT-CDT if(parsedParams != null && parsedParams.get(name) != null) { input.validate(parsedParams.get(name)); } @@ -101,7 +96,7 @@ public class TopologyTemplate { } if((parsedParams != null && parsedParams.get(input.getName()) == null || parsedParams == null) && input.isRequired() && input.getDefault() == null) { - log.error("Log warning: TopologyTemplate - _inputs - The required parameter {} is not provided", input.getName()); + System.out.format("Log warning: The required parameter \"%s\" is not provided\n",input.getName()); } alInputs.add(input); } @@ -109,12 +104,12 @@ public class TopologyTemplate { } - private Metadata _metaData() { + private LinkedHashMap _metaData() { if(tpl.get(METADATA) != null) { - return (Metadata)tpl.get(METADATA); + return (LinkedHashMap)tpl.get(METADATA); } else { - return new Metadata(new LinkedHashMap<>()); + return new LinkedHashMap(); } } @@ -178,7 +173,7 @@ public class TopologyTemplate { nodeTemplates, inputs, outputs, - groups, + groups, //ATT addition subMappedNodeTemplate, customDefs); } @@ -511,7 +506,7 @@ public class TopologyTemplate { return tpl; } - public Metadata getMetadata() { + public LinkedHashMap getMetadata() { return metaData; } @@ -546,27 +541,6 @@ public class TopologyTemplate { public LinkedHashMap getParsedParams() { return parsedParams; } - - @Override - public String toString() { - return "TopologyTemplate{" + - "tpl=" + tpl + - ", metaData=" + metaData + - ", inputs=" + inputs + - ", outputs=" + outputs + - ", relationshipTemplates=" + relationshipTemplates + - ", nodeTemplates=" + nodeTemplates + - ", customDefs=" + customDefs + - ", relTypes=" + relTypes + - ", subMappedNodeTemplate=" + subMappedNodeTemplate + - ", groups=" + groups + - ", policies=" + policies + - ", parsedParams=" + parsedParams + - ", description='" + description + '\'' + - ", graph=" + graph + - ", substitutionMappings=" + substitutionMappings + - '}'; - } } /*python diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java index bda15dc..2eb64e8 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java @@ -25,11 +25,12 @@ public class Input { private String name; private Schema schema; + private LinkedHashMap customDefs;//ATT-CDT - - public Input(String _name,LinkedHashMap _schemaDict) { + public Input(String _name,LinkedHashMap _schemaDict,LinkedHashMap _customDefs) {//ATT-CDT name = _name; schema = new Schema(_name,_schemaDict); + customDefs = _customDefs;//ATT-CDT } public String getName() { @@ -89,6 +90,13 @@ public class Input { break; } } + //ATT-CDT + if(!bFound) { + if(customDefs.get(inputType) != null) { + bFound = true; + } + } + //ATT-CDT if(!bFound) { ExceptionCollector.appendException(String.format( "ValueError: Invalid type \"%s\"",inputType)); @@ -97,14 +105,19 @@ public class Input { private void _validateValue(Object value) { Object datatype = null; - if (EntityType.TOSCA_DEF != null && EntityType.TOSCA_DEF.size() > 0) { - if(EntityType.TOSCA_DEF.get(getType()) != null) { - datatype = EntityType.TOSCA_DEF.get(getType()); - } - else if(EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()) != null) { - datatype = EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()); - } + if(EntityType.TOSCA_DEF.get(getType()) != null) { + datatype = EntityType.TOSCA_DEF.get(getType()); + } + else if(EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()) != null) { + datatype = EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()); + } + //ATT-CDT + else if(customDefs.get(getType()) != null) { + datatype = customDefs.get(getType()); + DataEntity.validateDatatype(getType(),value,(LinkedHashMap)datatype,customDefs,null); + return; } + //ATT-CDT DataEntity.validateDatatype(getType(),value,null,(LinkedHashMap)datatype,null); } } diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml index f05622f..6b370ce 100644 --- a/sdc-tosca-parser/pom.xml +++ b/sdc-tosca-parser/pom.xml @@ -71,7 +71,7 @@ org.openecomp.sdc.sdc-distribution-client jtosca - 0.1.1-SNAPSHOT + 0.1.2-SNAPSHOT diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index 7c30616..8c748f6 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -45,10 +45,19 @@ public class ToscaParserNodeTemplateTest extends BasicTest { public void testNodeTemplateNestedProperty() throws SdcToscaParserException { List serviceVlList = ToscaParserTestSuite.fdntCsarHelper.getServiceVlList(); NodeTemplate nodeTemplate = serviceVlList.get(0); - System.out.println("node template " + nodeTemplate.toString()); + //System.out.println("node template " + nodeTemplate.toString()); assertEquals("24", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask")); assertEquals("7a6520b-9982354-ee82992c-105720", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding")); } + + @Test + public void testNodeTemplateNestedPropertyFromInput() throws SdcToscaParserException { + List serviceVfList = ToscaParserTestSuite.fdntCsarHelper.getServiceVfList(); + NodeTemplate nodeTemplate = serviceVfList.get(0); + //System.out.println("node template " + nodeTemplate.toString()); + assertEquals("true", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#ecomp_generated_naming")); + assertEquals("FDNT_instance_VF_2", ToscaParserTestSuite.fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#naming_policy")); + } @Test public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException { diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar index 41ee2c7..a343e84 100644 Binary files a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar and b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar differ -- cgit 1.2.3-korg