From 45497ffff524a82e4e5d41c2272409c5b7fca2df Mon Sep 17 00:00:00 2001 From: Rokhvarg David Date: Sun, 11 Mar 2018 16:40:55 +0200 Subject: extend policy and group api Change-Id: I6ffdcdc1057ea53d7211008abd6c1ae0e2a9f54d Issue-ID: SDC-1056 Signed-off-by: Rokhvarg David --- pom.xml | 4 +- .../onap/sdc/tosca/parser/api/ISdcCsarHelper.java | 109 ++++++ .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 389 +++++++++++++++++---- .../sdc/tosca/parser/impl/SdcPropertyNames.java | 8 + src/main/resources/config/configuration.yaml | 2 +- .../org/onap/sdc/impl/SdcToscaParserBasicTest.java | 9 +- .../org/onap/sdc/impl/ToscaParserMetadataTest.java | 4 +- .../onap/sdc/impl/ToscaParserNodeTemplateTest.java | 81 ++++- src/test/resources/csars/resource-Policy-csar.csar | Bin 0 -> 27747 bytes .../resources/csars/service-AlService-csar.csar | Bin 0 -> 37565 bytes version.properties | 2 +- 11 files changed, 523 insertions(+), 85 deletions(-) create mode 100644 src/test/resources/csars/resource-Policy-csar.csar create mode 100644 src/test/resources/csars/service-AlService-csar.csar diff --git a/pom.xml b/pom.xml index dd7ee59..009d39e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ sdc-tosca sdc-sdc-tosca SDC Tosca Parser JAR file for use by consumers - 1.3.0-SNAPSHOT + 1.3.1-SNAPSHOT jar @@ -112,7 +112,7 @@ org.onap.sdc.jtosca jtosca - 1.3.0 + 1.3.1-SNAPSHOT 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 76798d5..b5eed35 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 @@ -450,5 +450,114 @@ public interface ISdcCsarHelper { * @return the leaf value as String, or null if there's no such property, or it's not a leaf. */ public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue); + + /** + * Get all the policies of the main topology template (either VF or service) + * @return the list of the policies + */ + public List>> 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>> 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> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate); + + /** + * Get all the policies of the origin component (nested topology template) of the node template specified by policy type + * @param nodeTemplate the node template + * @param policyTypeName the name of the policy type + * @return the list of the policies + */ + public List> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName); + + /** + * Get all the node templates of the topology template, which are the targets of the policy specified by name + * @param policyName the name of the policy + * @return the list of the node templates + */ + public List getPolicyTargetsFromTopologyTemplate(String policyName); + + /** + * Get all the node templates of the origin component (nested topology template) of node template, which are the targets of the policy specified by name + * @param nodeTemplate the node template + * @param policyName the name of the policy + * @return the list of the node templates + */ + public List> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName); + + /** + * Get the node template of the topology template specified by name + * @param nodeTemplateName the name of the node template + * @return the node template + */ + public NodeTemplate getNodeTemplateByName(String nodeTemplateName); + + /** + * Get all the policies, which contain the specified node template as a target + * @param targetNode the node template + * @return the list of the policies + */ + public List>> getPoliciesOfTarget(NodeTemplate targetNode); + + /** + * Get all the policies of the specified type, which contain the specified node template as a target + * @param nodeTemplate the node template + * @param policyTypeName the name of the policy type + * @return the list of the policies + */ + public List>> 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>> getGroupsOfTopologyTemplate(); + + /** + * 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> 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>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType); + + + /** + * Get all groups of this of the origin component (nested topology template) of the node template by specified tosca group type + * @param nodeTemplate the node template + * @param groupType the group type + * @return the list of the groups + */ + public List> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType); + + /** + * Get members of the group belongs to the main topology template (either VF or service) by group name + * @param groupName the name of the group + * @return the list of the node templates + */ + public List getGroupMembersFromTopologyTemplate(String groupName); + + /** + * Get members of the group belongs to the origin component (nested topology template) of the node template by group name + * @param nodeTemplate the node template + * @param groupName the name of the group + * @return the list of the node templates + */ + public List> 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 0c42a4f..8675d5e 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 @@ -22,8 +22,7 @@ package org.onap.sdc.tosca.parser.impl; import java.util.*; import java.util.Map.Entry; -import java.util.stream.Collectors; - +import static java.util.stream.Collectors.toList; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; @@ -38,6 +37,8 @@ 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 = "#"; @@ -54,7 +55,232 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { this.toscaTemplate = toscaTemplate; this.configurationManager = configurationManager; } + + @Override + public List>> getPoliciesOfTarget(NodeTemplate nodeTemplate) { + return getPoliciesOfNodeTemplate(nodeTemplate.getName()) + .stream() + .sorted(Policy::compareTo) + .map(this::convertPolicyToMap) + .collect(toList()); + } + + @Override + public List> getPoliciesOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { + List> policies = new ArrayList<>(); + if(toscaTemplate.getNestedTopologyTemplates() != null && !toscaTemplate.getNestedTopologyTemplates().isEmpty()){ + String invariantUUID = nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + Optional nestedTopTmpl = toscaTemplate.getNestedTopologyTemplates() + .values() + .stream() + .filter(nt->invariantUuidEqualsTo(invariantUUID, nt)) + .findFirst(); + if(nestedTopTmpl.isPresent()){ + policies = getPoliciesSection(nestedTopTmpl.get()); + } + } + return policies; + } + + @Override + public List>> 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> getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(NodeTemplate nodeTemplate, String policyTypeName) { + return getPoliciesOfOriginOfNodeTemplate(nodeTemplate) + .stream() + .filter(p->typeEqualsTo(p, policyTypeName)) + .sorted(this::comparePolicyMapObjects) + .collect(toList()); + } + + @Override + public List getPolicyTargetsFromTopologyTemplate(String policyName) { + if(toscaTemplate.getNodeTemplates() == null){ + return new ArrayList<>(); + } + List targetNames = getPolicyTargets(policyName); + return toscaTemplate.getNodeTemplates().stream() + .filter(nt->targetNames.contains(nt.getName())) + .collect(toList()); + } + + @Override + public List> getPolicyTargetsFromOrigin(NodeTemplate nodeTemplate, String policyName) { + List targets = getTargetsOfPolicyOfNestedTopologyTemplate(nodeTemplate, policyName); + if(targets.isEmpty()){ + return new ArrayList<>(); + } + return toscaTemplate.getNestedTopologyTemplates() + .values() + .stream() + .map(this::getNodeTemplatesSection) + .filter(nt->targets.contains(nt.keySet().iterator().next())) + .collect(toList()); + } + + @Override + public List>> getPoliciesOfTopologyTemplate(){ + if(toscaTemplate.getPolicies() == null) + return new ArrayList<>(); + return toscaTemplate.getPolicies() + .stream() + .sorted(Policy::compareTo) + .map(this::convertPolicyToMap) + .collect(toList()); + } + + @Override + public List>> 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 getTargetsOfPolicyOfNestedTopologyTemplate(NodeTemplate nodeTemplate, String policyName) { + if(toscaTemplate.getNodeTemplates() == null){ + return new ArrayList<>(); + } + Optional> policy = getPolicyOfNestedTopologyTemplateByName(nodeTemplate, policyName); + if(!policy.isPresent()){ + return new ArrayList<>(); + } + return getTargetsSection(policy.get()); + } + + private Optional> getPolicyOfNestedTopologyTemplateByName(NodeTemplate nodeTemplate, String policyName) { + return getPoliciesOfOriginOfNodeTemplate(nodeTemplate).stream() + .filter(p->policyNameEqualsTo(p, policyName)) + .findFirst(); + } + + private boolean policyNameEqualsTo(Map policy, String policyName) { + return policy != null && !policy.isEmpty() && policy.keySet().iterator().next().equals(policyName); + } + + public NodeTemplate getNodeTemplateByName(String nodeTemplateName) { + if(toscaTemplate.getNodeTemplates() == null) + return null; + return toscaTemplate.getNodeTemplates() + .stream() + .filter(nt -> nt.getName().equals(nodeTemplateName)) + .findFirst().orElse(null); + } + + + private int comparePolicyMapObjects(Map policy, Map 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 getTargetsSection(Map policy) { + if(policy == null || policy.isEmpty()){ + return new ArrayList<>(); + } + List targets = (List) ((Map)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TARGETS); + if(targets == null){ + return new ArrayList<>(); + } + return targets; + } + @SuppressWarnings("unchecked") + private boolean typeEqualsTo(Map policy, String policyTypeName) { + if(policy.values().iterator().hasNext()){ + return ((Map)policy.values().iterator().next()).get(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(policyTypeName); + } + return false; + } + + private String getNameSection(Map policy) { + Object name = policy.get(SdcPropertyNames.PROPERTY_NAME_NAME); + if(name == null) + return ""; + return (String)name; + } + + private String getTypeSection(Map policy) { + Object type = policy.get(SdcPropertyNames.PROPERTY_NAME_TYPE); + if(type == null) + return ""; + return (String)type; + } + + @SuppressWarnings("unchecked") + private List> getPoliciesSection(Object nestedTopTmpl) { + List> policies = (List>)getTopologyTemplateSection(nestedTopTmpl).get(SdcPropertyNames.PROPERTY_NAME_POLICIES); + if(policies == null || policies.isEmpty()) + return new ArrayList<>(); + return policies; + } + + @SuppressWarnings("unchecked") + private Map getNodeTemplatesSection(Object topologyTemplate) { + Map nodeTemplates = (Map)getTopologyTemplateSection(topologyTemplate).get(SdcPropertyNames.PROPERTY_NAME_NODE_TEMPLATES); + if(nodeTemplates == null || nodeTemplates.isEmpty()) + return new HashMap<>(); + return nodeTemplates; + } + + @SuppressWarnings("unchecked") + private Map getTopologyTemplateSection(Object topologyTemplate) { + Map topologyTemplateSection = (Map)((Map)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)((Map)nt).get(SdcPropertyNames.PROPERTY_NAME_METADATA)).get(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID).equals(invariantUUID); + } + + private Map> convertPolicyToMap(Policy policy){ + Map> policyMap = new HashMap<>(); + Map 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 getPoliciesOfNodeTemplate(String nodeTemplateName) { + if(toscaTemplate.getPolicies() == null) + return new ArrayList<>(); + return toscaTemplate.getPolicies() + .stream() + .filter(p -> p.getTargets().contains(nodeTemplateName)) + .collect(toList()); + } + + private List getPolicyTargets(String policyName) { + return getPolicyByName(policyName).map(Policy::getTargets).orElse(new ArrayList<>()); + } + + private Optional getPolicyByName(String policyName) { + if(toscaTemplate.getPolicies() == null) + return Optional.empty(); + return toscaTemplate.getPolicies() + .stream() + .filter(p -> p.getName().equals(policyName)).findFirst(); + } + @Override //Sunny flow - covered with UT, flat and nested public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) { @@ -106,24 +332,27 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } } - if (cps.size() > 0) { - // ports found - find all their properties - for (String portName : cps.keySet()) { - for (Map.Entry property: props.entrySet()) { - if (property.getKey().startsWith(portName)) { - String portProperty = property.getKey().replaceFirst(portName + "_", ""); - if (property.getValue() != null) { - cps.get(portName).put(portProperty, property.getValue().getValue()); - } - } - } - } - } + findPutAllPortsProperties(cps, props); } return cps; } + private void findPutAllPortsProperties(Map> cps, Map props) { + if (!cps.isEmpty()) { + for (Entry> port : cps.entrySet()) { + for (Map.Entry property: props.entrySet()) { + if (property.getKey().startsWith(port.getKey())) { + String portProperty = property.getKey().replaceFirst(port.getKey() + "_", ""); + if (property.getValue() != null) { + cps.get(port.getKey()).put(portProperty, property.getValue().getValue()); + } + } + } + } + } + } + public Map> getCpPropertiesFromVfc(NodeTemplate vfc) { if (vfc == null) { @@ -143,26 +372,27 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { cps.put(portName, new HashMap<>()); } } - - if (cps.size() > 0) { - // ports found - find all their properties - for (String portName : cps.keySet()) { - for (Map.Entry property: props.entrySet()) { - if (property.getKey().startsWith(portName)) { - Map portPaths = new HashMap<>(); - String portProperty = property.getKey().replaceFirst(portName + "_", ""); - buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths); - - cps.get(portName).putAll(portPaths); - } - } - } - } + findBuildPutAllPortsProperties(cps, props); } return cps; } + private void findBuildPutAllPortsProperties(Map> cps, Map props) { + if (!cps.isEmpty()) { + for (Entry> port : cps.entrySet()) { + for (Map.Entry property: props.entrySet()) { + if (property.getKey().startsWith(port.getKey())) { + Map portPaths = new HashMap<>(); + String portProperty = property.getKey().replaceFirst(port.getKey() + "_", ""); + buildPathMappedToValue(portProperty, property.getValue().getValue(), portPaths); + cps.get(port.getKey()).putAll(portPaths); + } + } + } + } + } + @SuppressWarnings("unchecked") private void buildPathMappedToValue(String path, Object property, Map pathsMap) { if (property instanceof Map) { @@ -186,15 +416,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override //Sunny flow - covered with UT public List getServiceVlList() { - List serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL); - return serviceVlList; + return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VL); } @Override //Sunny flow - covered with UT public List getServiceVfList() { - List serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF); - return serviceVfList; + return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), SdcTypes.VF); } @Override @@ -208,8 +436,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { log.error("getMetadataPropertyValue - the metadata is null"); return null; } - String metadataPropertyValue = metadata.getValue(metadataPropertyName); - return metadataPropertyValue; + return metadata.getValue(metadataPropertyName); } @@ -235,8 +462,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override public List getServiceNodeTemplates() { - List nodeTemplates = toscaTemplate.getNodeTemplates(); - return nodeTemplates; + return toscaTemplate.getNodeTemplates(); } @Override @@ -261,25 +487,15 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { List serviceVfList = getServiceVfList(); NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); if (nodeTemplateByCustomizationUuid != null) { - /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings(); - if (substitutionMappings != null){ - List groups = substitutionMappings.getGroups(); - if (groups != null){ - List collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList()); - log.debug("getVfModulesByVf - VfModules are {}", collect); - return collect; - } - }*/ String name = nodeTemplateByCustomizationUuid.getName(); String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name); List serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups(); log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName); if (serviceLevelGroups != null) { - List collect = serviceLevelGroups + return serviceLevelGroups .stream() .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName)) - .collect(Collectors.toList()); - return collect; + .collect(toList()); } } return new ArrayList<>(); @@ -464,7 +680,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } List serviceVfList = getServiceVfList(); - if (serviceVfList == null || serviceVfList.size() == 0) { + if (serviceVfList == null || serviceVfList.isEmpty()) { log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId); return cpList; } @@ -474,7 +690,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return cpList; } cpList = getNodeTemplateBySdcType(vfInstance, SdcTypes.CP); - if (cpList == null || cpList.size() == 0) + if (cpList == null || cpList.isEmpty()) log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId); return cpList; } @@ -503,8 +719,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { if (findFirst.isPresent()) { List members = findFirst.get().getMembers(); if (members != null) { - List collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList()); - return collect; + return substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(toList()); } } } @@ -513,8 +728,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } @Override - //Sunny flow - covered with UT - @SuppressWarnings("unchecked") public List> getNodeTemplatePairsByReqName( List listOfReqNodeTemplates, List listOfCapNodeTemplates, String reqName) { @@ -553,7 +766,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override //Sunny flow - covered with UT - //TODO constant strings public List getAllottedResources() { List nodeTemplates = null; nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates(); @@ -562,12 +774,10 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { } nodeTemplates = nodeTemplates.stream().filter( x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource")) - .collect(Collectors.toList()); + .collect(toList()); if (nodeTemplates.isEmpty()) { log.debug("getAllottedResources - allotted resources not exist"); - } else { } - return nodeTemplates; } @@ -649,18 +859,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { if (substitutionMappings != null) { List nodeTemplates = substitutionMappings.getNodeTemplates(); - if (nodeTemplates != null && nodeTemplates.size() > 0) { + if (nodeTemplates != null && !nodeTemplates.isEmpty()) { if (sdcType.equals(SdcTypes.VFC) && isVNF) { return nodeTemplates.stream() .filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && isVNFType(x)) - .collect(Collectors.toList()); + .collect(toList()); } else { return nodeTemplates.stream() .filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))) && !isVNFType(x)) - .collect(Collectors.toList()); + .collect(toList()); } } else { @@ -713,8 +923,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { List serviceVfList = getServiceVfList(); NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid); - NodeTemplate vnfConfig = getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null); - return vnfConfig; + return getNodeTemplateBySdcType(vfInstance, SdcTypes.VFC, true).stream().findAny().orElse(null); } @Override @@ -743,11 +952,11 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate(); if (substitutionMappings != null) { List nodeTemplates = substitutionMappings.getNodeTemplates(); - if (nodeTemplates != null && nodeTemplates.size() > 0) { + if (nodeTemplates != null && !nodeTemplates.isEmpty()) { return nodeTemplates.stream() .filter(x -> !isVNFType(x)) - .collect(Collectors.toList()); + .collect(toList()); } else { log.debug("getNodeTemplateChildren - SubstitutionMappings' node Templates not exist"); @@ -818,6 +1027,44 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { Object property = processProperties(split, properties); return property == null || property instanceof Function ? null : String.valueOf(property); } + + @Override + public List>> getGroupsOfTopologyTemplate() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List> getGroupsOfOriginOfNodeTemplate(NodeTemplate nodeTemplate) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List>> getGroupsOfTopologyTemplateByToscaGroupType(String groupType) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List> getGroupsOfOriginOfNodeTemplateByToscaGroupType(NodeTemplate nodeTemplate, String groupType) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getGroupMembersFromTopologyTemplate(String groupName) { + // TODO Auto-generated method stub + return null; + } + + + @Override + public List> getGroupMembersOfOriginOfNodeTemplate(NodeTemplate nodeTemplate, String groupName) { + // TODO Auto-generated method stub + return null; + } + /************************************* helper functions ***********************************/ private boolean isVNFType(NodeTemplate nt) { @@ -870,8 +1117,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { List nodeTemplates = topologyTemplate.getNodeTemplates(); - if (nodeTemplates != null && nodeTemplates.size() > 0) - return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList()); + if (nodeTemplates != null && !nodeTemplates.isEmpty()) + return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.getValue().equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(toList()); log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist"); return new ArrayList<>(); @@ -901,8 +1148,4 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return 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 7235593..db4d167 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 @@ -106,4 +106,12 @@ public class SdcPropertyNames { public static String PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN="network_flows#is_bound_to_vpn"; public static String PROPERTY_NAME_NETWORKFLOWS_VPNBINDING="network_flows#vpn_binding"; + + //Policy + 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_METADATA = "metadata"; + public static String PROPERTY_NAME_PROPERTIES = "properties"; + public static String PROPERTY_NAME_TARGETS = "targets"; } diff --git a/src/main/resources/config/configuration.yaml b/src/main/resources/config/configuration.yaml index f070c1d..e5e28f2 100644 --- a/src/main/resources/config/configuration.yaml +++ b/src/main/resources/config/configuration.yaml @@ -1,3 +1,3 @@ conformanceLevel: minVersion: '3.0' - maxVersion: '7.0' \ No newline at end of file + maxVersion: '8.0' \ No newline at end of file diff --git a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java index 39f5190..e1ea39f 100644 --- a/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java +++ b/src/test/java/org/onap/sdc/impl/SdcToscaParserBasicTest.java @@ -35,7 +35,8 @@ public abstract class SdcToscaParserBasicTest { static ISdcCsarHelper resolveReqsCapsCsarQA; static ISdcCsarHelper portMirroring; static ISdcCsarHelper csarHelperServiceWithCrs; - + static ISdcCsarHelper csarHelperServicePolicy; + static ISdcCsarHelper csarHelperVfPolicy; static Map>> fdntCsarHelper_Data; @@ -58,8 +59,10 @@ public abstract class SdcToscaParserBasicTest { resolveReqsCapsCsarQA = getCsarHelper("csars/service-sunny-flow2.csar"); portMirroring = getCsarHelper("csars/service-PortMirroring.csar"); csarHelperServiceWithCrs = getCsarHelper("csars/service-CrTestService-csar.csar"); - - fdntCsarHelper_Data = new HashMap>>(){ + csarHelperVfPolicy = getCsarHelper("csars/resource-Policy-csar.csar"); + csarHelperServicePolicy = getCsarHelper("csars/service-AlService-csar.csar"); + + fdntCsarHelper_Data = new HashMap>>(){ { HashMap> FDNT ; diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java index 8487dec..db28e79 100644 --- a/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java +++ b/src/test/java/org/onap/sdc/impl/ToscaParserMetadataTest.java @@ -210,7 +210,7 @@ public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { ConfigurationManager configurationManager = ConfigurationManager.getInstance(); try { configurationManager.setErrorConfiguration("error-configuration-test.yaml"); - factory.setConfigurationManager(configurationManager); + SdcToscaParserFactory.setConfigurationManager(configurationManager); ISdcCsarHelper missingCSARMetaCsarCustomConfig = getCsarHelper ("csars/service-missing-csar-meta-file.csar"); String conformanceLevel = missingCSARMetaCsarCustomConfig.getConformanceLevel(); @@ -220,7 +220,7 @@ public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { } finally { configurationManager.setErrorConfiguration("error-configuration.yaml"); - factory.setConfigurationManager(configurationManager); + SdcToscaParserFactory.setConfigurationManager(configurationManager); } } diff --git a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java index 0692ebe..9cd56c4 100644 --- a/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/onap/sdc/impl/ToscaParserNodeTemplateTest.java @@ -5,8 +5,6 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import java.util.*; -import static org.hamcrest.CoreMatchers.is; - import com.google.common.collect.ImmutableMap; import org.apache.commons.lang3.tuple.Pair; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; @@ -965,7 +963,84 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { assertEquals(crTemplate.getPropertyValue("nf_naming").toString(), ImmutableMap.of("ecomp_generated_naming", "true").toString()); assertEquals(crTemplate.getPropertyValue("contrailport0_virtual_network"), "chaya"); } - + + @Test + public void testGetPoliciesOfOriginOfNodeTemplate() { + NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0"); + NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"); + List> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt0); + assertNotNull(policies); + assertEquals(policies.size(), 3); + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplate(nt1); + assertNotNull(policies); + assertEquals(policies.size(), 3); + } + + @Test + public void testGetPoliciesOfOriginOfNodeTemplateByToscaPolicyType() { + NodeTemplate nt0 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 0"); + NodeTemplate nt1 = csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"); + List> policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.Antilocate"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt0, "org.openecomp.policies.placement.valet.Diversity"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.Colocate"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.Antilocate"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + + policies = csarHelperServicePolicy.getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(nt1, "org.openecomp.policies.placement.valet.Diversity"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + } + + @Test + public void testGetPolicyTargetNodeTemplatesFromOrigin() { + List> nodeTemplates = csarHelperServicePolicy.getPolicyTargetsFromOrigin(csarHelperServicePolicy.getNodeTemplateByName("al_vf 1"),"policy..Colocate..0"); + assertNotNull(nodeTemplates); + assertEquals(nodeTemplates.size(), 2); + } + + @Test + public void testGetPoliciesOfNodeTemplate() { + NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1"); + List>> policies = csarHelperVfPolicy.getPoliciesOfTarget(nt0); + assertNotNull(policies); + assertEquals(policies.size(), 1); + } + + @Test + public void testGetPoliciesOfNodeTemplateByToscaPolicyType() { + NodeTemplate nt0 = csarHelperVfPolicy.getNodeTemplateByName("al_vfc 1"); + List>> policies = csarHelperVfPolicy.getPoliciesOfTargetByToscaPolicyType(nt0, "org.openecomp.policies.placement.Colocate"); + assertNotNull(policies); + assertEquals(policies.size(), 1); + } + + @Test + public void testGetPoliciesOfTopologyTemplate() { + List>> policies = csarHelperVfPolicy.getPoliciesOfTopologyTemplate(); + assertNotNull(policies); + assertEquals(policies.size(), 1); + } + + @Test + public void testGetPolicyTargetNodeTemplates() { + List nodeTemplates = csarHelperVfPolicy.getPolicyTargetsFromTopologyTemplate("policy..Colocate..0"); + assertNotNull(nodeTemplates); + assertEquals(nodeTemplates.size(), 2); + } } diff --git a/src/test/resources/csars/resource-Policy-csar.csar b/src/test/resources/csars/resource-Policy-csar.csar new file mode 100644 index 0000000..d6d7b42 Binary files /dev/null and b/src/test/resources/csars/resource-Policy-csar.csar differ diff --git a/src/test/resources/csars/service-AlService-csar.csar b/src/test/resources/csars/service-AlService-csar.csar new file mode 100644 index 0000000..2532683 Binary files /dev/null and b/src/test/resources/csars/service-AlService-csar.csar differ diff --git a/version.properties b/version.properties index 235314e..a61846b 100644 --- a/version.properties +++ b/version.properties @@ -5,7 +5,7 @@ major=1 minor=3 -patch=0 +patch=1 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg