diff options
author | Sheshukov, Natalia (ns019t) <ns019t@intl.att.com> | 2018-04-09 14:59:52 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-04-09 14:21:56 +0000 |
commit | 86ada8c4d4b683737f01e2fb491ee278ca3f8033 (patch) | |
tree | 0552b18bbd2e4e6c756917a69e4fe373f4fd299c /src/main/java/org | |
parent | a8e5af36724128683fce5793a4c6641f03dcebf6 (diff) |
vLAN Tagging
Support Tosca Groups - TOSCA parser (refactoring)
Change-Id: Ia2609bc7a73bfc0d928f4099a717b31109aa4586
Issue-ID: SDC-1199
Signed-off-by: Sheshukov, Natalia (ns019t) <ns019t@intl.att.com>
Diffstat (limited to 'src/main/java/org')
6 files changed, 79 insertions, 37 deletions
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java index 95c97dd..078dc44 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java @@ -255,7 +255,12 @@ public abstract class EntityTemplate { ((EntityType)typeDefinition).getValue(CAPABILITIES,entityTpl,true); if(caps != null) { //?!? getCapabilities defined only for NodeType... - LinkedHashMap<String,CapabilityTypeDef> capabilities = ((NodeType)typeDefinition).getCapabilities(); + LinkedHashMap<String,CapabilityTypeDef> capabilities = null; + if(typeDefinition instanceof NodeType){ + capabilities = ((NodeType)typeDefinition).getCapabilities(); + } else if (typeDefinition instanceof GroupType){ + capabilities = ((GroupType)typeDefinition).getCapabilities(); + } for(Map.Entry<String,Object> me: caps.entrySet()) { String name = me. getKey(); LinkedHashMap<String,Object> props = (LinkedHashMap<String,Object>)me.getValue(); diff --git a/src/main/java/org/onap/sdc/toscaparser/api/Group.java b/src/main/java/org/onap/sdc/toscaparser/api/Group.java index d96b4a9..de031e6 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/Group.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/Group.java @@ -41,6 +41,7 @@ public class Group extends EntityTemplate { } memberNodes = _memberNodes; _validateKeys(); + getCapabilities(); } public Metadata getMetadata() { diff --git a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java index 250ef42..20bc210 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java @@ -21,6 +21,7 @@ public class NodeTemplate extends EntityTemplate { private ArrayList<RelationshipTemplate> relationshipTpl; private LinkedHashMap<RelationshipType,NodeTemplate> _relationships; private SubstitutionMappings subMappingToscaTemplate; + private TopologyTemplate originComponentTemplate; private Metadata metadata; private static final String METADATA = "metadata"; @@ -453,6 +454,14 @@ public class NodeTemplate extends EntityTemplate { return getName(); } + public TopologyTemplate getOriginComponentTemplate() { + return originComponentTemplate; + } + + public void setOriginComponentTemplate(TopologyTemplate originComponentTemplate) { + this.originComponentTemplate = originComponentTemplate; + } + } /*python diff --git a/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java index e2c268e..e3d3538 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/TopologyTemplate.java @@ -12,6 +12,7 @@ import org.onap.sdc.toscaparser.api.parameters.Output; import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; @@ -188,39 +189,35 @@ public class TopologyTemplate { @SuppressWarnings("unchecked") private ArrayList<Policy> _policies() { ArrayList<Policy> alPolicies = new ArrayList<>(); - for(Object po: _tplPolicies()) { - LinkedHashMap<String,Object> policy = (LinkedHashMap<String,Object>)po; - for(Map.Entry<String,Object> me: policy.entrySet()) { - String policyName = me.getKey(); - LinkedHashMap<String,Object> policyTpl = (LinkedHashMap<String,Object>)me.getValue(); - ArrayList<String> targetList = (ArrayList<String>)policyTpl.get("targets"); - //ArrayList<Object> targetObjects = new ArrayList<>(); - ArrayList<NodeTemplate> targetNodes = new ArrayList<>(); - ArrayList<Object> targetObjects = new ArrayList<>(); - ArrayList<Group> targetGroups = new ArrayList<>(); - String targetsType = "groups"; - if(targetList != null && targetList.size() >= 1) { - targetGroups = _getPolicyGroups(targetList); - if(targetGroups == null) { - targetsType = "node_templates"; - targetNodes = _getGroupMembers(targetList); - for(NodeTemplate nt: targetNodes) { - targetObjects.add(nt); - } - } - else { - for(Group gr: targetGroups) { - targetObjects.add(gr); - } - } - } - Policy policyObj = new Policy(policyName, - policyTpl, - targetObjects, - targetsType, - customDefs); - alPolicies.add(policyObj); + for(Map.Entry<String,Object> me: _tplPolicies().entrySet()) { + String policyName = me.getKey(); + LinkedHashMap<String,Object> policyTpl = (LinkedHashMap<String,Object>)me.getValue(); + ArrayList<String> targetList = (ArrayList<String>)policyTpl.get("targets"); + ArrayList<NodeTemplate> targetNodes = new ArrayList<>(); + ArrayList<Object> targetObjects = new ArrayList<>(); + ArrayList<Group> targetGroups = new ArrayList<>(); + String targetsType = "groups"; + if(targetList != null && targetList.size() >= 1) { + targetGroups = _getPolicyGroups(targetList); + if(targetGroups == null || targetGroups.isEmpty()) { + targetsType = "node_templates"; + targetNodes = _getGroupMembers(targetList); + for(NodeTemplate nt: targetNodes) { + targetObjects.add(nt); + } + } + else { + for(Group gr: targetGroups) { + targetObjects.add(gr); + } + } } + Policy policyObj = new Policy(policyName, + policyTpl, + targetObjects, + targetsType, + customDefs); + alPolicies.add(policyObj); } return alPolicies; } @@ -368,12 +365,12 @@ public class TopologyTemplate { } @SuppressWarnings("unchecked") - private ArrayList<Object> _tplPolicies() { + private LinkedHashMap<String,Object> _tplPolicies() { if(tpl.get(POLICIES) != null) { - return (ArrayList<Object>)tpl.get(POLICIES); + return (LinkedHashMap<String,Object>)tpl.get(POLICIES); } else { - return new ArrayList<Object>(); + return new LinkedHashMap<>(); } } diff --git a/src/main/java/org/onap/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/ToscaTemplate.java index bdf962b..ea76a09 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/ToscaTemplate.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/ToscaTemplate.java @@ -599,6 +599,7 @@ public class ToscaTemplate extends Object { parsedParams, nt, resolveGetInput); + nt.setOriginComponentTemplate(topologyWithSubMapping); if(topologyWithSubMapping.getSubstitutionMappings() != null) { // Record nested topology templates in top level template //nestedToscaTemplatesWithTopology.add(topologyWithSubMapping); diff --git a/src/main/java/org/onap/sdc/toscaparser/api/elements/GroupType.java b/src/main/java/org/onap/sdc/toscaparser/api/elements/GroupType.java index 1419461..2f8c1e0 100644 --- a/src/main/java/org/onap/sdc/toscaparser/api/elements/GroupType.java +++ b/src/main/java/org/onap/sdc/toscaparser/api/elements/GroupType.java @@ -3,7 +3,9 @@ package org.onap.sdc.toscaparser.api.elements; import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue; import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder; +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.Map; public class GroupType extends StatefulEntityType { @@ -124,7 +126,34 @@ public class GroupType extends StatefulEntityType { public String getType() { return groupType; } - + + @SuppressWarnings("unchecked") + public ArrayList<CapabilityTypeDef> getCapabilitiesObjects() { + // Return a list of capability objects + ArrayList<CapabilityTypeDef> typecapabilities = new ArrayList<>(); + LinkedHashMap<String,Object> caps = (LinkedHashMap<String,Object>)getValue(CAPABILITIES, null, true); + if(caps != null) { + // 'cname' is symbolic name of the capability + // 'cvalue' is a dict { 'type': <capability type name> } + for(Map.Entry<String,Object> me: caps.entrySet()) { + String cname = me.getKey(); + LinkedHashMap<String,String> cvalue = (LinkedHashMap<String,String>)me.getValue(); + String ctype = cvalue.get("type"); + CapabilityTypeDef cap = new CapabilityTypeDef(cname,ctype,type,customDef); + typecapabilities.add(cap); + } + } + return typecapabilities; + } + + public LinkedHashMap<String,CapabilityTypeDef> getCapabilities() { + // Return a dictionary of capability name-objects pairs + LinkedHashMap<String,CapabilityTypeDef> caps = new LinkedHashMap<>(); + for(CapabilityTypeDef ctd: getCapabilitiesObjects()) { + caps.put(ctd.getName(),ctd); + } + return caps; + } } |