diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-08-21 21:37:17 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-08-21 21:37:17 +0300 |
commit | c0d03886fbf71cbc843e9a7c7d47221ae4f8d2eb (patch) | |
tree | cd42d4b376fd82bee09f07480fb186d259d4e513 /src/main/java | |
parent | 20e20e9cd5d471d505ffcec2b5498f57a1793bc7 (diff) |
[SDC-243] sdc-tosca for port mirroring
Change-Id: I9fc74a79a6fd5c6f4bafc4767b78241c3ebcc021
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'src/main/java')
3 files changed, 162 insertions, 34 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java index 06a66c6..df9e47d 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java @@ -25,8 +25,7 @@ import java.util.Map; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.tosca.parser.impl.FilterType; import org.openecomp.sdc.tosca.parser.impl.SdcTypes; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; +import org.openecomp.sdc.toscaparser.api.*; import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.parameters.Input; @@ -203,18 +202,30 @@ public interface ISdcCsarHelper { public String getServiceSubstitutionMappingsTypeName(); /** - * Get the CSAR service metadata - * @return - the service metadata object. + * Get service Metadata object.<br> + * This object represents the "metadata" section of a CSAR service. + * @return - the service Metadata object. */ public Metadata getServiceMetadata(); /** * Get the CSAR service metadata as map. * @return - the service metadata object as Map. + * @deprecated This function is deprecated since its not tosca compliant. <br> + * Tosca defines the Metadata section as map of string (not map of object).<br> + * This function is targeted to be removed as part of 1802.<br> + * Please use {@link #getServiceMetadataAllProperties() getServiceMetadataAllProperties()}. */ + @Deprecated public Map<String, Object> getServiceMetadataProperties(); /** + * Get the CSAR service metadata as map + * @return - the service metadata object as Map + */ + public Map<String, String> getServiceMetadataAllProperties(); + + /** * Get all VFC node templates from a specified VF. * @param vfCustomizationId - customizationUuid of the VF node template. * @return all VFC node templates from a specified VF @@ -326,7 +337,8 @@ public interface ISdcCsarHelper { * port_fe_oam={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_2", network_role_tag="Mobility_OAM_protected"}}<br><br> * @param vfc - VFC node template to look for CP-related props. * @return map <b>CP node template name</b> to a map of <b>full path to a property on this CP</b> - <b> value of this property on this CP</b>. - * @deprecated This function is deprecated since its flattened form doesn't provide solution for cp properties of type List. + * @deprecated This function is deprecated since its flattened form doesn't provide solution for cp properties of type List. + * Will be removed in 1802. */ @Deprecated public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc); @@ -367,9 +379,9 @@ public interface ISdcCsarHelper { public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType); /** - * Get all node templates by sdcType for this CSAR service. + * Get all node templates by SDC type enum for this CSAR service. * - * @param sdcType - the SDC type of the node. + * @param sdcType - the SDC type of the node (for example, CP, VF...). * @return service node templates of this SDC type. */ public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType); @@ -394,4 +406,49 @@ public interface ISdcCsarHelper { * @return return list of children node templates for node template. */ public List<NodeTemplate> getNodeTemplateChildren(NodeTemplate nodeTemplate); -} + + /** + * Get node template on service level by node template name. + * @param nodeName - the name of the node template. + * @return service-level node template with this name, or null if no such node template was found. + */ + public NodeTemplate getServiceNodeTemplateByNodeName(String nodeName); + + /** + * Get node template Metadata object.<br> + * This object represents the "metadata" section of node template. + * @param nt - Node template to get its Metadata object. + * @return Metadata for this node template, or null if not found. + */ + public Metadata getNodeTemplateMetadata(NodeTemplate nt); + + /** + * Get CapabilityAssignments object for this node template.<br> + * This should be an entry point function for working with capability assignments of node template.<br> + * This object allows filtering capability assignments objects.<br> + * @param nt - Node Template to get its capability assignments. + * @return CapabilitiesAssignments that contains list of capability assignments for the node template.<br> + * If none found, an empty list will be returned. + */ + public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt); + + /** + * Get RequirementAssignments object for this node template.<br> + * This should be an entry point function for working with requirement assignments of node template.<br> + * This object allows filtering requirement assignments objects.<br> + * @param nt - Node Template to get its requirement assignments. + * @return RequirementAssignments that contains list of requirement assignments for the node template. + * If none found, an empty list will be returned. + */ + public RequirementAssignments getRequirementsOf(NodeTemplate nt); + + /** + * Get any property leaf value for capability by full path separated by #. + * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a capability assignment. + * @param capability - capability assignment where the property should be looked up. + * @param pathToPropertyLeafValue - the full path of the required property. + * @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); + +}
\ No newline at end of file diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java index bfbbeee..c320f63 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java @@ -27,14 +27,11 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; +import org.openecomp.sdc.toscaparser.api.CapabilityAssignments; import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; +import org.openecomp.sdc.toscaparser.api.RequirementAssignments; import org.openecomp.sdc.tosca.parser.utils.SdcToscaUtility; -import org.openecomp.sdc.toscaparser.api.Group; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.Property; -import org.openecomp.sdc.toscaparser.api.SubstitutionMappings; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; -import org.openecomp.sdc.toscaparser.api.ToscaTemplate; +import org.openecomp.sdc.toscaparser.api.*; import org.openecomp.sdc.toscaparser.api.elements.Metadata; import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.functions.Function; @@ -398,10 +395,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @Override //Sunny flow - covered with UT public Map<String, Object> getServiceMetadataProperties() { - if (toscaTemplate.getMetaData()==null){ + if (toscaTemplate.getMetaData() == null){ return null; } - return toscaTemplate.getMetaData().getPropertyMap(); + return new HashMap<>(toscaTemplate.getMetaData().getAllProperties()); + } + + @Override + public Map<String, String> getServiceMetadataAllProperties() { + if (toscaTemplate.getMetaData() == null){ + return null; + } + return toscaTemplate.getMetaData().getAllProperties(); } @Override @@ -509,32 +514,37 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { @SuppressWarnings("unchecked") public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName( List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) { - if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null) { - //TODO error message + + if (listOfReqNodeTemplates == null) { + log.error("getNodeTemplatePairsByReqName - listOfReqNodeTemplates is null"); + return new ArrayList<>(); + } + + if (listOfCapNodeTemplates == null) { + log.error("getNodeTemplatePairsByReqName - listOfCapNodeTemplates is null"); + return new ArrayList<>(); + } + + if (GeneralUtility.isEmptyString(reqName)) { + log.error("getNodeTemplatePairsByReqName - reqName is null or empty"); return new ArrayList<>(); } List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>(); - if (listOfReqNodeTemplates != null) { - for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { - List<Object> requirements = reqNodeTemplate.getRequirements(); - for (Object reqEntry : requirements) { - LinkedHashMap<String, Object> reqEntryHash = (LinkedHashMap<String, Object>) reqEntry; - Map<String, Object> reqEntryMap = (Map<String, Object>) reqEntryHash.get(reqName); - if (reqEntryMap != null) { - Object node = reqEntryMap.get("node"); - if (node != null) { - String nodeString = (String) node; - Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst(); - if (findFirst.isPresent()) { - pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get())); - } - } + for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { + List<RequirementAssignment> requirements = reqNodeTemplate.getRequirements().getRequirementsByName(reqName).getAll(); + for (RequirementAssignment reqEntry : requirements) { + String node = reqEntry.getNodeTemplateName(); + if (node != null) { + Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(node)).findFirst(); + if (findFirst.isPresent()) { + pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get())); } } } } + return pairsList; } @@ -729,6 +739,67 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { return new ArrayList<>(); } + @Override + public NodeTemplate getServiceNodeTemplateByNodeName(String nodeName) { + if (GeneralUtility.isEmptyString(nodeName)) { + log.error("getServiceNodeTemplateByNodeName - nodeName - is null or empty"); + return null; + } + + List<NodeTemplate> nodeTemplates = getServiceNodeTemplates(); + Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(nt -> nt.getName().equals(nodeName)).findFirst(); + + return findFirst.isPresent() ? findFirst.get() : null; + } + + @Override + public Metadata getNodeTemplateMetadata(NodeTemplate nt) { + if (nt == null) { + log.error("getNodeTemplateMetadata - nt (node template) - is null"); + return null; + } + + return nt.getMetaData(); + } + + @Override + public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt) { + if (nt == null) { + log.error("getCapabilitiesOf - nt (node template) - is null"); + return null; + } + + return nt.getCapabilities(); + } + + @Override + public RequirementAssignments getRequirementsOf(NodeTemplate nt) { + if (nt == null) { + log.error("getRequirementsOf - nt (node template) - is null"); + return null; + } + + return nt.getRequirements(); + } + + @Override + public String getCapabilityPropertyLeafValue(CapabilityAssignment capability, String pathToPropertyLeafValue) { + if (capability == null) { + log.error("getCapabilityPropertyLeafValue - capability is null"); + return null; + } + + if (GeneralUtility.isEmptyString(pathToPropertyLeafValue)) { + log.error("getCapabilityPropertyLeafValue - pathToPropertyLeafValue is null or empty"); + return null; + } + + String[] split = getSplittedPath(pathToPropertyLeafValue); + LinkedHashMap<String, Property> properties = capability.getProperties(); + Object property = processProperties(split, properties); + return property == null || property instanceof Function ? null : String.valueOf(property); + } + /************************************* helper functions ***********************************/ private boolean isVNFType(NodeTemplate nt) { return nt.getType().endsWith("VnfConfiguration"); diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java index 9f885f4..5dc9101 100644 --- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java +++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcTypes.java @@ -25,7 +25,7 @@ import java.util.List; public enum SdcTypes { - CP, VL, VF, VFC, PNF, SERVICE, CVFC; + CP, VL, VF, VFC, PNF, SERVICE, CVFC, SERVICE_PROXY, CONFIGURATION; public static List<SdcTypes> complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC); |