diff options
author | Sheshukov, Natalia (ns019t) <ns019t@intl.att.com> | 2018-04-09 15:03:06 +0300 |
---|---|---|
committer | Sheshukov, Natalia (ns019t) <ns019t@intl.att.com> | 2018-04-09 16:53:45 +0300 |
commit | a5a24ad0f22bdb06e3194f392df322b48b1b2316 (patch) | |
tree | 940d9aeb7f6c43616447d396280649406fe139af /src | |
parent | b0ed12f587f7f87dedb0b838664800662bc4ca8e (diff) |
vLAN Tagging
Support Tosca Groups - TOSCA parser (refactoring)
Change-Id: I10c6b8e5356bea0e85e8b448c23d9f05ac3ab837
Issue-ID: SDC-1199
Signed-off-by: Sheshukov, Natalia (ns019t) <ns019t@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java | 34 | ||||
-rw-r--r-- | src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 282 | ||||
-rw-r--r-- | src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java | 3 | ||||
-rw-r--r-- | src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java | 10 | ||||
-rw-r--r-- | src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java | 133 | ||||
-rw-r--r-- | src/test/resources/csars/resource-Policy-csar.csar | bin | 27747 -> 27745 bytes | |||
-rw-r--r-- | src/test/resources/csars/resource-Vdbe-csar.csar | bin | 0 -> 68955 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-AlService-csar.csar | bin | 37565 -> 37564 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-Groupstest-csar.csar | bin | 0 -> 177826 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-VdbePx-csar.csar | bin | 0 -> 39145 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-VdbeSrv-csar.csar | bin | 0 -> 75330 bytes | |||
-rw-r--r-- | src/test/resources/csars/service-VlanD2dSrv-csar.csar | bin | 0 -> 75442 bytes |
12 files changed, 262 insertions, 200 deletions
diff --git a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java index b5eed35..4f2ef29 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/onap/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -19,6 +19,7 @@ package org.onap.sdc.tosca.parser.api; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -455,21 +456,21 @@ public interface ISdcCsarHelper { * Get all the policies of the main topology template (either VF or service) * @return the list of the policies */ - public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplate(); + public List<Policy> getPoliciesOfTopologyTemplate(); /** * Get all the policies of the main topology template (either VF or service) specified by policy type * @param policyTypeName the name of the policy type * @return the list of the policies */ - public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName); + public List<Policy> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName); /** * Get all the policies of the origin component (nested topology template) of the node template * @param nodeTemplate the node template * @return the list of the policies */ - public List<Map<String,Object>> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate); + public List<Policy> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate); /** * Get all the policies of the origin component (nested topology template) of the node template specified by policy type @@ -477,7 +478,7 @@ public interface ISdcCsarHelper { * @param policyTypeName the name of the policy type * @return the list of the policies */ - public List<Map<String, Object>> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName); + public List<Policy> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName); /** * Get all the node templates of the topology template, which are the targets of the policy specified by name @@ -492,7 +493,7 @@ public interface ISdcCsarHelper { * @param policyName the name of the policy * @return the list of the node templates */ - public List<Map<String, Object>> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName); + public List<NodeTemplate> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName); /** * Get the node template of the topology template specified by name @@ -506,7 +507,7 @@ public interface ISdcCsarHelper { * @param targetNode the node template * @return the list of the policies */ - public List<Map<String, Map<String, Object>>> getPoliciesOfTarget(NodeTemplate targetNode); + public List<Policy> getPoliciesOfTarget(NodeTemplate targetNode); /** * Get all the policies of the specified type, which contain the specified node template as a target @@ -514,28 +515,27 @@ public interface ISdcCsarHelper { * @param policyTypeName the name of the policy type * @return the list of the policies */ - public List<Map<String, Map<String, Object>>> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName); - - /** - * Get all groups of this of the main topology template (either VF or service) - * @return the list of the groups - */ - public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplate(); + public List<Policy> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName); /** * Get all the groups of the origin component (nested topology template) of the node template * @param nodeTemplate the node template * @return the list of the groups */ - public List<Map<String,Object>> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate); + public ArrayList<Group> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate); /** * Get all groups of this of the main topology template (either VF or service) by specified tosca group type * @param groupType the group type * @return the list of the groups */ - public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType); + public ArrayList<Group> getGroupsOfTopologyTemplateByToscaGroupType(String groupType); + /** + * Get all groups of this of the main topology template (either VF or service) + * @return the list of the groups + */ + public ArrayList<Group> getGroupsOfTopologyTemplate(); /** * Get all groups of this of the origin component (nested topology template) of the node template by specified tosca group type @@ -543,7 +543,7 @@ public interface ISdcCsarHelper { * @param groupType the group type * @return the list of the groups */ - public List<Map<String, Object>> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType); + public ArrayList<Group> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType); /** * Get members of the group belongs to the main topology template (either VF or service) by group name @@ -558,6 +558,6 @@ public interface ISdcCsarHelper { * @param groupName the name of the group * @return the list of the node templates */ - public List<Map<String, Object>> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName); + public List<NodeTemplate> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName); }
\ No newline at end of file diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index 8675d5e..8e16c14 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -20,16 +20,34 @@ package org.onap.sdc.tosca.parser.impl; -import java.util.*; -import java.util.Map.Entry; import static java.util.stream.Collectors.toList; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.config.ConfigurationManager; import org.onap.sdc.tosca.parser.utils.GeneralUtility; import org.onap.sdc.tosca.parser.utils.SdcToscaUtility; -import org.onap.sdc.toscaparser.api.*; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; +import org.onap.sdc.toscaparser.api.Group; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.Property; +import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.RequirementAssignments; +import org.onap.sdc.toscaparser.api.SubstitutionMappings; +import org.onap.sdc.toscaparser.api.TopologyTemplate; +import org.onap.sdc.toscaparser.api.ToscaTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.sdc.toscaparser.api.elements.NodeType; import org.onap.sdc.toscaparser.api.functions.Function; @@ -37,8 +55,6 @@ import org.onap.sdc.toscaparser.api.parameters.Input; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.onap.sdc.tosca.parser.impl.SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID; - public class SdcCsarHelperImpl implements ISdcCsarHelper { private static final String PATH_DELIMITER = "#"; @@ -57,47 +73,36 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override - public List<Map<String, Map<String, Object>>> getPoliciesOfTarget(NodeTemplate nodeTemplate) { + public List<Policy> getPoliciesOfTarget(NodeTemplate nodeTemplate) { return getPoliciesOfNodeTemplate(nodeTemplate.getName()) .stream() .sorted(Policy::compareTo) - .map(this::convertPolicyToMap) .collect(toList()); } @Override - public List<Map<String,Object>> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { - List<Map<String,Object>> policies = new ArrayList<>(); - if(toscaTemplate.getNestedTopologyTemplates() != null && !toscaTemplate.getNestedTopologyTemplates().isEmpty()){ - String invariantUUID = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); - Optional<Object> nestedTopTmpl = toscaTemplate.getNestedTopologyTemplates() - .values() - .stream() - .filter(nt->invariantUuidEqualsTo(invariantUUID, nt)) - .findFirst(); - if(nestedTopTmpl.isPresent()){ - policies = getPoliciesSection(nestedTopTmpl.get()); - } - } - return policies; + public List<Policy> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { + if(StringUtils.isNotEmpty(nodeTemplate.getName())){ + return getNodeTemplateByName(nodeTemplate.getName()).getOriginComponentTemplate().getPolicies(); + } + return new ArrayList<>(); } @Override - public List<Map<String, Map<String, Object>>> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) { + public List<Policy> getPoliciesOfTargetByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) { return getPoliciesOfNodeTemplate(nodeTemplate.getName()) .stream() .filter(p->p.getType().equals(policyTypeName)) .sorted(Policy::compareTo) - .map(this::convertPolicyToMap) .collect(toList()); } @Override - public List<Map<String, Object>> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) { + public List<Policy> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) { return getPoliciesOfOriginOfNodeTemplate(nodeTemplate) .stream() - .filter(p->typeEqualsTo(p, policyTypeName)) - .sorted(this::comparePolicyMapObjects) + .filter(p->p.getType().equals(policyTypeName)) + .sorted(Policy::compareTo) .collect(toList()); } @@ -113,63 +118,40 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override - public List<Map<String, Object>> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName) { - List<String> targets = getTargetsOfPolicyOfNestedTopologyTemplate(nodeTemplate, policyName); - if(targets.isEmpty()){ - return new ArrayList<>(); + public List<NodeTemplate> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName) { + Optional<Policy> policyOpt = null; + if(StringUtils.isNotEmpty(nodeTemplate.getName())){ + policyOpt = getNodeTemplateByName(nodeTemplate.getName()).getOriginComponentTemplate().getPolicies().stream().filter(p -> p.getName().equals(policyName)).findFirst(); } - return toscaTemplate.getNestedTopologyTemplates() - .values() - .stream() - .map(this::getNodeTemplatesSection) - .filter(nt->targets.contains(nt.keySet().iterator().next())) - .collect(toList()); + if(policyOpt.isPresent()){ + List<String> targets = policyOpt.get().getTargets(); + return nodeTemplate.getOriginComponentTemplate().getNodeTemplates() + .stream() + .filter(nt -> targets.contains(nt.getName())).collect(Collectors.toList()); + } + return new ArrayList<>(); } @Override - public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplate(){ + public List<Policy> getPoliciesOfTopologyTemplate(){ if(toscaTemplate.getPolicies() == null) return new ArrayList<>(); return toscaTemplate.getPolicies() .stream() .sorted(Policy::compareTo) - .map(this::convertPolicyToMap) .collect(toList()); } @Override - public List<Map<String, Map<String, Object>>> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName){ + public List<Policy> getPoliciesOfTopologyTemplateByToscaPolicyType(String policyTypeName){ if(toscaTemplate.getPolicies() == null) return new ArrayList<>(); return toscaTemplate.getPolicies() .stream() .filter(p->p.getType().equals(policyTypeName)) .sorted(Policy::compareTo) - .map(this::convertPolicyToMap) .collect(toList()); } - - - private List<String> getTargetsOfPolicyOfNestedTopologyTemplate(NodeTemplate nodeTemplate, String policyName) { - if(toscaTemplate.getNodeTemplates() == null){ - return new ArrayList<>(); - } - Optional<Map<String, Object>> policy = getPolicyOfNestedTopologyTemplateByName(nodeTemplate, policyName); - if(!policy.isPresent()){ - return new ArrayList<>(); - } - return getTargetsSection(policy.get()); - } - - private Optional<Map<String, Object>> getPolicyOfNestedTopologyTemplateByName(NodeTemplate nodeTemplate, String policyName) { - return getPoliciesOfOriginOfNodeTemplate(nodeTemplate).stream() - .filter(p->policyNameEqualsTo(p, policyName)) - .findFirst(); - } - - private boolean policyNameEqualsTo(Map<String, Object> policy, String policyName) { - return policy != null && !policy.isEmpty() && policy.keySet().iterator().next().equals(policyName); - } public NodeTemplate getNodeTemplateByName(String nodeTemplateName) { if(toscaTemplate.getNodeTemplates() == null) @@ -180,86 +162,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { .findFirst().orElse(null); } - - private int comparePolicyMapObjects(Map<String,Object> policy, Map<String,Object> otherPolicy){ - if(policy.equals(otherPolicy)) - return 0; - return getTypeSection(policy).compareTo(getTypeSection(otherPolicy)) == 0 ? getNameSection(policy).compareTo(getNameSection(otherPolicy)) : getTypeSection(policy).compareTo(getTypeSection(otherPolicy)); - } - - @SuppressWarnings("unchecked") - private List<String> getTargetsSection(Map<String, Object> policy) { - if(policy == null || policy.isEmpty()){ - return new ArrayList<>(); - } - List<String> targets = (List<String>) ((Map<String, Object>)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TARGETS); - if(targets == null){ - return new ArrayList<>(); - } - return targets; - } - @SuppressWarnings("unchecked") - private boolean typeEqualsTo(Map<String, Object> policy, String policyTypeName) { - if(policy.values().iterator().hasNext()){ - return ((Map<String, Object>)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(policyTypeName); - } - return false; - } - - private String getNameSection(Map<String, Object> policy) { - Object name = policy.get(SdcPropertyNames.PROPERTY_NAME_NAME); - if(name == null) - return ""; - return (String)name; - } - - private String getTypeSection(Map<String, Object> policy) { - Object type = policy.get(SdcPropertyNames.PROPERTY_NAME_TYPE); - if(type == null) - return ""; - return (String)type; - } - - @SuppressWarnings("unchecked") - private List<Map<String,Object>> getPoliciesSection(Object nestedTopTmpl) { - List<Map<String,Object>> policies = (List<Map<String,Object>>)getTopologyTemplateSection(nestedTopTmpl).get(SdcPropertyNames.PROPERTY_NAME_POLICIES); - if(policies == null || policies.isEmpty()) - return new ArrayList<>(); - return policies; - } - - @SuppressWarnings("unchecked") - private Map<String,Object> getNodeTemplatesSection(Object topologyTemplate) { - Map<String,Object> nodeTemplates = (Map<String,Object>)getTopologyTemplateSection(topologyTemplate).get(SdcPropertyNames.PROPERTY_NAME_NODE_TEMPLATES); - if(nodeTemplates == null || nodeTemplates.isEmpty()) - return new HashMap<>(); - return nodeTemplates; - } - - @SuppressWarnings("unchecked") - private Map<String,Object> getTopologyTemplateSection(Object topologyTemplate) { - Map<String,Object> topologyTemplateSection = (Map<String,Object>)((Map<String,Object>)topologyTemplate).get(SdcPropertyNames.PROPERTY_NAME_TOPOLOGY_TEMPLATE); - if(topologyTemplateSection == null || topologyTemplateSection.isEmpty()) - return new HashMap<>(); - return topologyTemplateSection; - } - - @SuppressWarnings("unchecked") - private boolean invariantUuidEqualsTo(String invariantUUID, Object nt) { - return ((Map<String,Object>)((Map<String,Object>)nt).get(SdcPropertyNames.PROPERTY_NAME_METADATA)).get(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).equals(invariantUUID); - } - - private Map<String, Map<String, Object>> convertPolicyToMap(Policy policy){ - Map<String, Map<String, Object>> policyMap = new HashMap<>(); - Map<String, Object> policyValue = new HashMap<>(); - policyMap.put(policy.getName(), policyValue); - policyValue.put(SdcPropertyNames.PROPERTY_NAME_TYPE, policy.getType()); - policyValue.put(SdcPropertyNames.PROPERTY_NAME_METADATA, policy.getmetadata()); - policyValue.put(SdcPropertyNames.PROPERTY_NAME_TARGETS, policy.getTargets()); - policyValue.put(SdcPropertyNames.PROPERTY_NAME_PROPERTIES, policy.getPolicyProperties()); - return policyMap; - } - private List<Policy> getPoliciesOfNodeTemplate(String nodeTemplateName) { if(toscaTemplate.getPolicies() == null) return new ArrayList<>(); @@ -273,6 +175,10 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return getPolicyByName(policyName).map(Policy::getTargets).orElse(new ArrayList<>()); } + private List<String> getGroupMembers(String groupName) { + return getGroupByName(groupName).map(Group::getMembers).orElse(new ArrayList<>()); + } + private Optional<Policy> getPolicyByName(String policyName) { if(toscaTemplate.getPolicies() == null) return Optional.empty(); @@ -281,6 +187,14 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { .filter(p -> p.getName().equals(policyName)).findFirst(); } + private Optional<Group> getGroupByName(String groupName) { + if(toscaTemplate.getGroups() == null) + return Optional.empty(); + return toscaTemplate.getGroups() + .stream() + .filter(g -> g.getName().equals(groupName)).findFirst(); + } + @Override //Sunny flow - covered with UT, flat and nested public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) { @@ -1029,44 +943,75 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override - public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplate() { - // TODO Auto-generated method stub - return null; + public ArrayList<Group> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { + if(StringUtils.isNotEmpty(nodeTemplate.getName())){ + return getNodeTemplateByName(nodeTemplate.getName()).getSubMappingToscaTemplate().getGroups(); + } + return new ArrayList<>(); } - + @Override - public List<Map<String, Object>> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { - // TODO Auto-generated method stub - return null; + public ArrayList<Group> getGroupsOfTopologyTemplateByToscaGroupType(String groupType) { + if(toscaTemplate.getGroups() == null) + return new ArrayList<>(); + return (ArrayList<Group>) toscaTemplate.getGroups() + .stream() + .filter(g->g.getType().equals(groupType)) + .sorted(Group::compareTo) + .collect(toList()); } - + @Override - public List<Map<String, Map<String, Object>>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType) { - // TODO Auto-generated method stub - return null; + public ArrayList<Group> getGroupsOfTopologyTemplate() { + return toscaTemplate.getGroups() == null ? new ArrayList<>() : toscaTemplate.getGroups(); } @Override - public List<Map<String, Object>> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType) { - // TODO Auto-generated method stub - return null; + public ArrayList<Group> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType) { + return (ArrayList<Group>) getGroupsOfOriginOfNodeTemplate(nodeTemplate) + .stream() + .filter(g->g.getType().equals(groupType)) + .sorted(Group::compareTo) + .collect(toList()); } @Override public List<NodeTemplate> getGroupMembersFromTopologyTemplate(String groupName) { - // TODO Auto-generated method stub - return null; + if(toscaTemplate.getNodeTemplates() == null){ + return new ArrayList<>(); + } + List<String> membersNames = getGroupMembers(groupName); + return toscaTemplate.getNodeTemplates().stream() + .filter(nt->membersNames.contains(nt.getName())) + .collect(toList()); } @Override - public List<Map<String, Object>> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName) { - // TODO Auto-generated method stub - return null; + public List<NodeTemplate> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName) { + ArrayList<Group> groups = getGroupsOfOriginOfNodeTemplate(nodeTemplate); + if(!groups.isEmpty()){ + Optional<Group> group = groups.stream().filter(g -> g.getName().equals(groupName)).findFirst(); + if(group.isPresent()){ + return nodeTemplate.getSubMappingToscaTemplate().getNodeTemplates().stream() + .filter(nt -> group.get().getMembers().contains(nt.getName())) + .collect(toList()); + } + } + return new ArrayList<>(); + } + + public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) { + if (sdcType == null) { + log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty"); + return new ArrayList<>(); + } + + TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); + return getNodeTemplateBySdcType(topologyTemplate, sdcType); } - - /************************************* helper functions ***********************************/ + /************************************* helper functions ***********************************/ private boolean isVNFType(NodeTemplate nt) { return nt.getType().endsWith("VnfConfiguration"); } @@ -1091,18 +1036,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return filterMap; } - - public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) { - if (sdcType == null) { - log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty"); - return new ArrayList<>(); - } - - TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); - return getNodeTemplateBySdcType(topologyTemplate, sdcType); - } - /************************************* helper functions ***********************************/ private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, SdcTypes sdcType) { if (sdcType == null) { diff --git a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java index db4d167..6f7e568 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java +++ b/src/main/java/org/onap/sdc/tosca/parser/impl/SdcPropertyNames.java @@ -111,7 +111,10 @@ public class SdcPropertyNames { public static String PROPERTY_NAME_TOPOLOGY_TEMPLATE = "topology_template"; public static String PROPERTY_NAME_NODE_TEMPLATES = "node_templates"; public static String PROPERTY_NAME_POLICIES = "policies"; + public static String PROPERTY_NAME_GROUPS = "groups"; public static String PROPERTY_NAME_METADATA = "metadata"; public static String PROPERTY_NAME_PROPERTIES = "properties"; public static String PROPERTY_NAME_TARGETS = "targets"; + public static String PROPERTY_NAME_MEMBERS = "members"; + public static String PROPERTY_NAME_CAPABILITIES = "capabilities"; } diff --git a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java index e1ea39f..ff4f3db 100644 --- a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java +++ b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java @@ -37,6 +37,11 @@ public abstract class SdcToscaParserBasicTest { static ISdcCsarHelper csarHelperServiceWithCrs; static ISdcCsarHelper csarHelperServicePolicy; static ISdcCsarHelper csarHelperVfPolicy; + static ISdcCsarHelper csarHelperServiceGroups; + static ISdcCsarHelper csarHelperServiceGroupsInputs; + static ISdcCsarHelper csarHelperServiceGroupsCapabilities; + static ISdcCsarHelper csarHelperVfGroupsPolicies; + static ISdcCsarHelper csarHelperServiceGroupsPolicies; static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data; @@ -61,6 +66,11 @@ public abstract class SdcToscaParserBasicTest { csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.csar"); csarHelperVfPolicy = getCsarHelper("csars/resource-Policy-csar.csar"); csarHelperServicePolicy = getCsarHelper("csars/service-AlService-csar.csar"); + csarHelperServiceGroups = getCsarHelper("csars/service-Groupstest-csar.csar"); + csarHelperServiceGroupsInputs = getCsarHelper("csars/service-VdbeSrv-csar.csar"); + csarHelperServiceGroupsCapabilities = getCsarHelper("csars/service-VdbePx-csar.csar"); + csarHelperVfGroupsPolicies = getCsarHelper("csars/resource-Vdbe-csar.csar"); + csarHelperServiceGroupsPolicies = getCsarHelper("csars/service-VlanD2dSrv-csar.csar"); fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){ { diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java index 9cd56c4..0acfdf6 100644 --- a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java @@ -5,18 +5,21 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import java.util.*; +import java.util.stream.Collectors; + import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.tuple.Pair; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.FilterType; import org.onap.sdc.tosca.parser.impl.SdcTypes; +import org.onap.sdc.toscaparser.api.CapabilityAssignment; +import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.Policy; import org.onap.sdc.toscaparser.api.Property; import org.testng.annotations.Test; -import fj.data.fingertrees.Node; - public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //region getServiceVfList @@ -334,6 +337,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //endregion //region getCpPropertiesFromVfc + @SuppressWarnings("unchecked") @Test public void testGetCpPropertiesFromVfc() { List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); @@ -759,6 +763,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //endregion //region resolve get_input + @SuppressWarnings("rawtypes") @Test public void testResolveGetInputForComplexTypeAndList() { //port_pd01_port_ip_requirements is of type list<org.openecomp.datatypes.network.IpRequirements> @@ -793,6 +798,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { assertEquals("1", propertyAsObject); } + @SuppressWarnings("rawtypes") @Test public void testResolveGetInputForMap() { //This test covers "default" resolving of primitive - as Map @@ -835,6 +841,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { // region Added by QA - Continue with testings of resolve get_input + @SuppressWarnings("rawtypes") @Test public void testResolveGetInputForComplexTypeAndListWithFalseValue() { @@ -926,6 +933,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { // endregion Added by QA - Continue with testings of resolve get_input + @SuppressWarnings("rawtypes") @Test public void testResolveGetInputArrayStructure() { List<NodeTemplate> vfcs = resolveGetInputCsarQA.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); @@ -968,7 +976,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { public void testGetPoliciesOfOriginOfNodeTemplate() { NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0"); NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"); - List<Map<String, Object>> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt0); + List<Policy> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt0); assertNotNull(policies); assertEquals(policies.size(), 3); policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt1); @@ -980,7 +988,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { public void testGetPoliciesOfOriginOfNodeTemplateByToscaPolicyType() { NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0"); NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"); - List<Map<String, Object>> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); + List<Policy> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); assertNotNull(policies); assertEquals(policies.size(), 1); @@ -1007,7 +1015,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { @Test public void testGetPolicyTargetNodeTemplatesFromOrigin() { - List<Map<String, Object>> nodeTemplates = csarHelperServicePolicy.getPolicyTargetsFromOrigin(csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"),"policy..Colocate..0"); + List<NodeTemplate> nodeTemplates = csarHelperServicePolicy.getPolicyTargetsFromOrigin(csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"),"policy..Colocate..0"); assertNotNull(nodeTemplates); assertEquals(nodeTemplates.size(), 2); } @@ -1015,7 +1023,7 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { @Test public void testGetPoliciesOfNodeTemplate() { NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1"); - List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTarget(nt0); + List<Policy> policies = csarHelperVfPolicy.getPoliciesOfTarget(nt0); assertNotNull(policies); assertEquals(policies.size(), 1); } @@ -1023,14 +1031,14 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { @Test public void testGetPoliciesOfNodeTemplateByToscaPolicyType() { NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1"); - List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTargetByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); + List<Policy> policies = csarHelperVfPolicy.getPoliciesOfTargetByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); assertNotNull(policies); assertEquals(policies.size(), 1); } @Test public void testGetPoliciesOfTopologyTemplate() { - List<Map<String, Map<String, Object>>> policies = csarHelperVfPolicy.getPoliciesOfTopologyTemplate(); + List<Policy> policies = csarHelperVfPolicy.getPoliciesOfTopologyTemplate(); assertNotNull(policies); assertEquals(policies.size(), 1); } @@ -1041,7 +1049,114 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { assertNotNull(nodeTemplates); assertEquals(nodeTemplates.size(), 2); } - + + @Test + public void testGetGroups() { + NodeTemplate groupsVf = csarHelperServiceGroups.getNodeTemplateByName("GroupsVf 0"); + NodeTemplate vlanGroups = csarHelperServiceGroups.getNodeTemplateByName("VlanGroups 0"); + + ArrayList<Group> groups = csarHelperServiceGroups.getGroupsOfOriginOfNodeTemplate(groupsVf); + assertNotNull(groups); + assertEquals(groups.size(), 5); + + groups = csarHelperServiceGroups.getGroupsOfOriginOfNodeTemplate(vlanGroups); + assertNotNull(groups); + assertEquals(groups.size(), 4); + + groups = csarHelperServiceGroups.getGroupsOfOriginOfNodeTemplateByToscaGroupType(groupsVf, "org.openecomp.groups.VfcInstanceGroup"); + assertNotNull(groups); + assertEquals(groups.size(), 1); + + groups = csarHelperServiceGroups.getGroupsOfOriginOfNodeTemplateByToscaGroupType(vlanGroups, "org.openecomp.groups.VfcInstanceGroup"); + assertNotNull(groups); + assertEquals(groups.size(), 2); + + List<NodeTemplate> members = csarHelperServiceGroups.getGroupMembersOfOriginOfNodeTemplate(groupsVf, "x_group"); + + assertNotNull(members); + assertEquals(members.size(), 3); + Optional<NodeTemplate> memberOpt = (members.stream().filter(m -> m.getName().equals("lb_1"))).findFirst(); + assertTrue(memberOpt.isPresent()); + memberOpt = (members.stream().filter(m -> m.getName().equals("lb_2"))).findFirst(); + assertTrue(memberOpt.isPresent()); + memberOpt = (members.stream().filter(m -> m.getName().equals("mg_4"))).findFirst(); + assertTrue(memberOpt.isPresent()); + + members = csarHelperServiceGroups.getGroupMembersOfOriginOfNodeTemplate(vlanGroups, "oam_group"); + assertNotNull(members); + assertEquals(members.size(), 1); + memberOpt = (members.stream().filter(m -> m.getName().equals("abstract_vdbe_1"))).findFirst(); + assertTrue(memberOpt.isPresent()); + + members = csarHelperServiceGroups.getGroupMembersOfOriginOfNodeTemplate(vlanGroups, "untr_group"); + assertNotNull(members); + assertEquals(members.size(), 1); + memberOpt = (members.stream().filter(m -> m.getName().equals("abstract_vdbe"))).findFirst(); + assertTrue(memberOpt.isPresent()); + } + + @Test + public void testGetGroupsInputsProperties() { + NodeTemplate vdbe0 = csarHelperServiceGroupsInputs.getNodeTemplateByName("vDBE 0"); + ArrayList<Group> groups = csarHelperServiceGroupsInputs.getGroupsOfOriginOfNodeTemplate(vdbe0); + assertNotNull(groups); + assertEquals(groups.size(), 4); + + Optional<Group> groupOpt = (groups.stream().filter(g -> g.getName().equals("oam_group"))).findFirst(); + assertTrue(groupOpt.isPresent()); + Group group = groupOpt.get(); + validateInputsProperties(vdbe0, group); + + groupOpt = (groups.stream().filter(g -> g.getName().equals("untr_group"))).findFirst(); + assertTrue(groupOpt.isPresent()); + group = groupOpt.get(); + validateInputsProperties(vdbe0, group); + } + + @Test + public void testGetGroupsInputsCapabilities() { + NodeTemplate vdbe = csarHelperServiceGroupsCapabilities.getNodeTemplateByName("vdbe_srv_proxy 0"); + CapabilityAssignments capabilities = csarHelperServiceGroupsCapabilities.getCapabilitiesOf(vdbe); + CapabilityAssignment capability = capabilities.getCapabilityByName("vdbe0.oam_group.vlan_assignment"); + assertNotNull(capability); + } + + @SuppressWarnings("unchecked") + private void validateInputsProperties(NodeTemplate vdbe0, Group group) { + assertNotNull(group.getPropertiesObjects()); + ArrayList<Property> properties = group.getPropertiesObjects(); + + List<String> inputs = properties.stream() + .filter(p -> p.getValue() instanceof Map) + .map(p -> ((Map<String, String>)p.getValue()).get("get_input")) + .collect(Collectors.toList()); + + assertEquals(inputs.size(), 2); + + inputs.forEach(i -> assertTrue(vdbe0.getProperties().containsKey(i))); + + List<Object> list = vdbe0.getProperties().entrySet().stream() + .filter(e -> inputs.contains(e.getKey())) + .map(e -> e.getValue().getValue()) + .collect(Collectors.toList()); + assertEquals(list.size(), 2); + } + + @Test + public void testGetVfGroupsPolicies() { + List<Policy> policies = csarHelperVfGroupsPolicies.getPoliciesOfTopologyTemplate(); + assertNotNull(policies); + List<Group> groups = csarHelperVfGroupsPolicies.getGroupsOfTopologyTemplate(); + assertNotNull(groups); + } + @Test + public void testGetServiceGroupsPolicies() { + NodeTemplate nt = csarHelperServiceGroupsPolicies.getNodeTemplateByName("vDBE 0"); + List<Policy> policies = csarHelperServiceGroupsPolicies.getPoliciesOfOriginOfNodeTemplate(nt); + assertNotNull(policies); + List<Group> groups = csarHelperServiceGroupsPolicies.getGroupsOfOriginOfNodeTemplate(nt); + assertNotNull(groups); + } } diff --git a/src/test/resources/csars/resource-Policy-csar.csar b/src/test/resources/csars/resource-Policy-csar.csar Binary files differindex d6d7b42..67cc528 100644 --- a/src/test/resources/csars/resource-Policy-csar.csar +++ b/src/test/resources/csars/resource-Policy-csar.csar diff --git a/src/test/resources/csars/resource-Vdbe-csar.csar b/src/test/resources/csars/resource-Vdbe-csar.csar Binary files differnew file mode 100644 index 0000000..3bf878c --- /dev/null +++ b/src/test/resources/csars/resource-Vdbe-csar.csar diff --git a/src/test/resources/csars/service-AlService-csar.csar b/src/test/resources/csars/service-AlService-csar.csar Binary files differindex 2532683..c02097d 100644 --- a/src/test/resources/csars/service-AlService-csar.csar +++ b/src/test/resources/csars/service-AlService-csar.csar diff --git a/src/test/resources/csars/service-Groupstest-csar.csar b/src/test/resources/csars/service-Groupstest-csar.csar Binary files differnew file mode 100644 index 0000000..2428c03 --- /dev/null +++ b/src/test/resources/csars/service-Groupstest-csar.csar diff --git a/src/test/resources/csars/service-VdbePx-csar.csar b/src/test/resources/csars/service-VdbePx-csar.csar Binary files differnew file mode 100644 index 0000000..3032768 --- /dev/null +++ b/src/test/resources/csars/service-VdbePx-csar.csar diff --git a/src/test/resources/csars/service-VdbeSrv-csar.csar b/src/test/resources/csars/service-VdbeSrv-csar.csar Binary files differnew file mode 100644 index 0000000..2958cfc --- /dev/null +++ b/src/test/resources/csars/service-VdbeSrv-csar.csar diff --git a/src/test/resources/csars/service-VlanD2dSrv-csar.csar b/src/test/resources/csars/service-VlanD2dSrv-csar.csar Binary files differnew file mode 100644 index 0000000..cbe355f --- /dev/null +++ b/src/test/resources/csars/service-VlanD2dSrv-csar.csar |