From c0d03886fbf71cbc843e9a7c7d47221ae4f8d2eb Mon Sep 17 00:00:00 2001 From: Pavel Aharoni Date: Mon, 21 Aug 2017 21:37:17 +0300 Subject: [SDC-243] sdc-tosca for port mirroring Change-Id: I9fc74a79a6fd5c6f4bafc4767b78241c3ebcc021 Signed-off-by: Pavel Aharoni --- .../sdc/tosca/parser/api/ISdcCsarHelper.java | 73 +++++++++++-- .../sdc/tosca/parser/impl/SdcCsarHelperImpl.java | 121 ++++++++++++++++----- .../openecomp/sdc/tosca/parser/impl/SdcTypes.java | 2 +- 3 files changed, 162 insertions(+), 34 deletions(-) (limited to 'src/main/java') 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,17 +202,29 @@ public interface ISdcCsarHelper { public String getServiceSubstitutionMappingsTypeName(); /** - * Get the CSAR service metadata - * @return - the service metadata object. + * Get service Metadata object.
+ * 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.
+ * Tosca defines the Metadata section as map of string (not map of object).
+ * This function is targeted to be removed as part of 1802.
+ * Please use {@link #getServiceMetadataAllProperties() getServiceMetadataAllProperties()}. */ + @Deprecated public Map getServiceMetadataProperties(); + /** + * Get the CSAR service metadata as map + * @return - the service metadata object as Map + */ + public Map getServiceMetadataAllProperties(); + /** * Get all VFC node templates from a specified VF. * @param vfCustomizationId - customizationUuid of the VF node template. @@ -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"}}

* @param vfc - VFC node template to look for CP-related props. * @return map CP node template name to a map of full path to a property on this CP - value of this property on this CP. - * @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> getCpPropertiesFromVfc(NodeTemplate vfc); @@ -367,9 +379,9 @@ public interface ISdcCsarHelper { public List 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 getServiceNodeTemplateBySdcType(SdcTypes sdcType); @@ -394,4 +406,49 @@ public interface ISdcCsarHelper { * @return return list of children node templates for node template. */ public List 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.
+ * 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.
+ * This should be an entry point function for working with capability assignments of node template.
+ * This object allows filtering capability assignments objects.
+ * @param nt - Node Template to get its capability assignments. + * @return CapabilitiesAssignments that contains list of capability assignments for the node template.
+ * If none found, an empty list will be returned. + */ + public CapabilityAssignments getCapabilitiesOf(NodeTemplate nt); + + /** + * Get RequirementAssignments object for this node template.
+ * This should be an entry point function for working with requirement assignments of node template.
+ * This object allows filtering requirement assignments objects.
+ * @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 getServiceMetadataProperties() { - if (toscaTemplate.getMetaData()==null){ + if (toscaTemplate.getMetaData() == null){ return null; } - return toscaTemplate.getMetaData().getPropertyMap(); + return new HashMap<>(toscaTemplate.getMetaData().getAllProperties()); + } + + @Override + public Map 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> getNodeTemplatePairsByReqName( List listOfReqNodeTemplates, List 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> pairsList = new ArrayList<>(); - if (listOfReqNodeTemplates != null) { - for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { - List requirements = reqNodeTemplate.getRequirements(); - for (Object reqEntry : requirements) { - LinkedHashMap reqEntryHash = (LinkedHashMap) reqEntry; - Map reqEntryMap = (Map) reqEntryHash.get(reqName); - if (reqEntryMap != null) { - Object node = reqEntryMap.get("node"); - if (node != null) { - String nodeString = (String) node; - Optional findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst(); - if (findFirst.isPresent()) { - pairsList.add(new ImmutablePair(reqNodeTemplate, findFirst.get())); - } - } + for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) { + List requirements = reqNodeTemplate.getRequirements().getRequirementsByName(reqName).getAll(); + for (RequirementAssignment reqEntry : requirements) { + String node = reqEntry.getNodeTemplateName(); + if (node != null) { + Optional findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(node)).findFirst(); + if (findFirst.isPresent()) { + pairsList.add(new ImmutablePair(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 nodeTemplates = getServiceNodeTemplates(); + Optional 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 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 complexTypes = Arrays.asList(VF, PNF, SERVICE, CVFC); -- cgit 1.2.3-korg