aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEster Rotstein <er767y@att.com>2017-07-19 14:48:22 +0300
committerEster Rotstein <er767y@att.com>2017-07-19 14:53:20 +0300
commit0810bec2516b1841bfb5500103329b1d578f443f (patch)
tree79be313916b00d55ee3fa2f531ebdd95e546502f
parentdfd01d445981b858b2a215d98da27fd247c2bc40 (diff)
[SDC-142] nested node templates
Change-Id: I602f84218825e59b0780d4786f1f1fe160cf5d44 Signed-off-by: Ester Rotstein <er767y@att.com>
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java15
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java103
2 files changed, 55 insertions, 63 deletions
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
index c8af559..11db32b 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.*;
import org.openecomp.sdc.toscaparser.api.utils.CopyUtils;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -19,7 +18,6 @@ public class NodeTemplate extends EntityTemplate {
private ArrayList<RelationshipTemplate> relationshipTpl;
private LinkedHashMap<RelationshipType,NodeTemplate> _relationships;
private SubstitutionMappings subMappingToscaTemplate;
- private SubstitutionMappings subMappingToscaTemplate2;
private Metadata metadata;
private static final String METADATA = "metadata";
@@ -42,7 +40,6 @@ public class NodeTemplate extends EntityTemplate {
availableRelTypes = ntavailableRelTypes;
_relationships = new LinkedHashMap<RelationshipType,NodeTemplate>();
subMappingToscaTemplate = null;
- subMappingToscaTemplate2 = null;
metadata = _metaData();
}
@@ -440,7 +437,8 @@ public class NodeTemplate extends EntityTemplate {
}
// getter/setter
-
+
+ // multilevel nesting
public SubstitutionMappings getSubMappingToscaTemplate() {
return subMappingToscaTemplate;
}
@@ -449,15 +447,6 @@ public class NodeTemplate extends EntityTemplate {
subMappingToscaTemplate = sm;
}
- // **experimental** (multilevel nesting)
- public SubstitutionMappings getSubMappingToscaTemplate2() {
- return subMappingToscaTemplate2;
- }
-
- public void setSubMappingToscaTemplate2(SubstitutionMappings sm) {
- subMappingToscaTemplate2 = sm;
- }
-
public Metadata getMetaData() {
return metadata;
}
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 b13a2a5..76b86f5 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -6,6 +6,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
@@ -81,7 +82,7 @@ public class ToscaTemplate extends Object {
private ArrayList<NodeTemplate> nodeTemplates;
private ArrayList<Output> outputs;
private ArrayList<Policy> policies;
- private LinkedHashMap<String,Object> nestedToscaTplsWithTopology;
+ private ConcurrentHashMap<String,Object> nestedToscaTplsWithTopology;
private ArrayList<TopologyTemplate> nestedToscaTemplatesWithTopology;
private ToscaGraph graph;
private String csarTempDir;
@@ -113,7 +114,7 @@ public class ToscaTemplate extends Object {
path = null;
tpl = null;
csarTempDir = null;
- nestedToscaTplsWithTopology = new LinkedHashMap<String,Object>();
+ nestedToscaTplsWithTopology = new ConcurrentHashMap<>();
nestedToscaTemplatesWithTopology = new ArrayList<TopologyTemplate>();
if(_path != null && !_path.isEmpty()) {
@@ -179,7 +180,8 @@ public class ToscaTemplate extends Object {
this.nodeTemplates = _nodeTemplates();
this.outputs = _outputs();
this.policies = _policies();
- _handleNestedToscaTemplatesWithTopology();
+// _handleNestedToscaTemplatesWithTopology();
+ _handleNestedToscaTemplatesWithTopology(topologyTemplate);
graph = new ToscaGraph(nodeTemplates);
}
}
@@ -361,10 +363,10 @@ public class ToscaTemplate extends Object {
}
}
- // **experimental** (multi level nesting) RECURSIVE - BEWARE OF INIFINITE LOOPS...
- private void _handleNestedToscaTemplatesWithTopology2(TopologyTemplate tt) {
+ // multi level nesting - RECURSIVE
+ private void _handleNestedToscaTemplatesWithTopology(TopologyTemplate tt) {
if(++nestingLoopCounter > 10) {
- log.error("ToscaTemplate - _handleNestedToscaTemplatesWithTopology2 - Nested Topologies Loop: too many levels, aborting");
+ log.error("ToscaTemplate - _handleNestedToscaTemplatesWithTopology - Nested Topologies Loop: too many levels, aborting");
return;
}
for(Map.Entry<String,Object> me: nestedToscaTplsWithTopology.entrySet()) {
@@ -372,13 +374,14 @@ public class ToscaTemplate extends Object {
LinkedHashMap<String,Object> toscaTpl =
(LinkedHashMap<String,Object>)me.getValue();
for(NodeTemplate nt: tt.getNodeTemplates()) {
- if(_isSubMappedNode2(nt,toscaTpl)) {
+ if(_isSubMappedNode(nt,toscaTpl)) {
parsedParams = _getParamsForNestedTemplate(nt);
+ ArrayList<Object> alim = (ArrayList<Object>)toscaTpl.get(IMPORTS);
LinkedHashMap<String,Object> topologyTpl =
(LinkedHashMap<String,Object>)toscaTpl.get(TOPOLOGY_TEMPLATE);
TopologyTemplate topologyWithSubMapping =
new TopologyTemplate(topologyTpl,
- _getAllCustomDefs(null),
+ _getAllCustomDefs(alim),
relationshipTypes,
parsedParams,
nt);
@@ -386,44 +389,44 @@ public class ToscaTemplate extends Object {
// Record nested topology templates in top level template
//nestedToscaTemplatesWithTopology.add(topologyWithSubMapping);
// Set substitution mapping object for mapped node
- nt.setSubMappingToscaTemplate2(
- topologyWithSubMapping.getSubstitutionMappings());
- _handleNestedToscaTemplatesWithTopology2(topologyWithSubMapping);
- }
- }
- }
- }
- }
-
- private void _handleNestedToscaTemplatesWithTopology() {
- for(Map.Entry<String,Object> me: nestedToscaTplsWithTopology.entrySet()) {
- String fname = me.getKey();
- LinkedHashMap<String,Object> toscaTpl =
- (LinkedHashMap<String,Object>)me.getValue();
- for(NodeTemplate nt: nodeTemplates) {
- if(_isSubMappedNode(nt,toscaTpl)) {
- parsedParams = _getParamsForNestedTemplate(nt);
- ArrayList<Object> alim = (ArrayList<Object>)toscaTpl.get(IMPORTS);
- LinkedHashMap<String,Object> topologyTpl =
- (LinkedHashMap<String,Object>)toscaTpl.get(TOPOLOGY_TEMPLATE);
- TopologyTemplate topologyWithSubMapping =
- new TopologyTemplate(topologyTpl,
- //_getAllCustomDefs(null),
- _getAllCustomDefs(alim),
- relationshipTypes,
- parsedParams,
- nt);
- if(topologyWithSubMapping.getSubstitutionMappings() != null) {
- // Record nested topology templates in top level template
- nestedToscaTemplatesWithTopology.add(topologyWithSubMapping);
- // Set substitution mapping object for mapped node
nt.setSubMappingToscaTemplate(
topologyWithSubMapping.getSubstitutionMappings());
+ _handleNestedToscaTemplatesWithTopology(topologyWithSubMapping);
}
}
}
}
}
+
+// private void _handleNestedToscaTemplatesWithTopology() {
+// for(Map.Entry<String,Object> me: nestedToscaTplsWithTopology.entrySet()) {
+// String fname = me.getKey();
+// LinkedHashMap<String,Object> toscaTpl =
+// (LinkedHashMap<String,Object>)me.getValue();
+// for(NodeTemplate nt: nodeTemplates) {
+// if(_isSubMappedNode(nt,toscaTpl)) {
+// parsedParams = _getParamsForNestedTemplate(nt);
+// ArrayList<Object> alim = (ArrayList<Object>)toscaTpl.get(IMPORTS);
+// LinkedHashMap<String,Object> topologyTpl =
+// (LinkedHashMap<String,Object>)toscaTpl.get(TOPOLOGY_TEMPLATE);
+// TopologyTemplate topologyWithSubMapping =
+// new TopologyTemplate(topologyTpl,
+// //_getAllCustomDefs(null),
+// _getAllCustomDefs(alim),
+// relationshipTypes,
+// parsedParams,
+// nt);
+// if(topologyWithSubMapping.getSubstitutionMappings() != null) {
+// // Record nested topology templates in top level template
+// nestedToscaTemplatesWithTopology.add(topologyWithSubMapping);
+// // Set substitution mapping object for mapped node
+// nt.setSubMappingToscaTemplate(
+// topologyWithSubMapping.getSubstitutionMappings());
+// }
+// }
+// }
+// }
+// }
private void _validateField() {
String sVersion = _tplVersion();
@@ -575,7 +578,17 @@ public class ToscaTemplate extends Object {
return metaProperties.get(propertiesFile);
}
- private boolean _isSubMappedNode(NodeTemplate nt,LinkedHashMap<String,Object> toscaTpl) {
+// private boolean _isSubMappedNode(NodeTemplate nt,LinkedHashMap<String,Object> toscaTpl) {
+// // Return True if the nodetemple is substituted
+// if(nt != null && nt.getSubMappingToscaTemplate() == null &&
+// getSubMappingNodeType(toscaTpl).equals(nt.getType()) &&
+// nt.getInterfaces().size() < 1) {
+// return true;
+// }
+// return false;
+// }
+
+ private boolean _isSubMappedNode(NodeTemplate nt, LinkedHashMap<String,Object> toscaTpl) {
// Return True if the nodetemple is substituted
if(nt != null && nt.getSubMappingToscaTemplate() == null &&
getSubMappingNodeType(toscaTpl).equals(nt.getType()) &&
@@ -585,16 +598,6 @@ public class ToscaTemplate extends Object {
return false;
}
- private boolean _isSubMappedNode2(NodeTemplate nt,LinkedHashMap<String,Object> toscaTpl) {
- // Return True if the nodetemple is substituted
- if(nt != null && nt.getSubMappingToscaTemplate2() == null &&
- getSubMappingNodeType(toscaTpl).equals(nt.getType()) &&
- nt.getInterfaces().size() < 1) {
- return true;
- }
- return false;
- }
-
private LinkedHashMap<String,Object> _getParamsForNestedTemplate(NodeTemplate nt) {
// Return total params for nested_template
LinkedHashMap<String,Object> pparams;