diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-07-17 16:45:26 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-07-17 16:45:41 +0300 |
commit | 3b2a4a9f36d21c0d5519e83551fde633945eb3a7 (patch) | |
tree | 85a981e90872bdb23e181009ea8af940473889e6 /src | |
parent | 9f2d31d8cb8c4e28c3b1bea809867d39df36e502 (diff) |
[SDC-137] update port properties function
Change-Id: I1e2de708ca8fc327941cbb04290d52f07e243ecd
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'src')
5 files changed, 75 insertions, 28 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 6c8f5df..bb5bd25 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 @@ -326,9 +326,21 @@ 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 public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc); + /** + * Get the map of CP-related props from a VFC node template. <br> + * Let's say there are 2 CPs (ports) related to this VFC. Then the output will look like this: <br><br> + * {port_fe_sigtran={ip_requirements={ip_count_required: {count: 1}, dhcp_enabled: true, ip_version: 4}, subnetpoolid: "subnet_1", network_role_tag: "SIGNET_vrf_B1_direct"}<br> + * port_fe_cluster={ip_requirements={ip_count_required: {count: 2}, dhcp_enabled: true, ip_version: 4}}<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>property name</b> - <b> property value as object</b>. + */ + public Map<String, Map<String, Object>> getCpPropertiesFromVfcAsObject(NodeTemplate vfc); + /** * Get customization UUID of a node template * @param nt - node template 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 7b901ec..c927817 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 @@ -90,6 +90,43 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { LinkedHashMap<String, Property> properties = nodeTemplate.getProperties(); return processProperties(split, properties); } + + public Map<String, Map<String, Object>> getCpPropertiesFromVfcAsObject(NodeTemplate vfc) { + if (vfc == null) { + log.error("getCpPropertiesFromVfc - vfc is null"); + return new HashMap<>(); + } + + String presetProperty = "_ip_requirements"; + Map<String, Map<String, Object>> cps = new HashMap<>(); + + Map<String, Property> props = vfc.getProperties(); + if (props != null) { + // find all port names by pre-set property (ip_requirements) + for (Map.Entry<String, Property> entry : props.entrySet()) { + if (entry.getKey().endsWith(presetProperty)) { + String portName = entry.getKey().replaceAll(presetProperty, ""); + cps.put(portName, new HashMap<>()); + } + } + + if (cps.size() > 0) { + // ports found - find all their properties + for (String portName : cps.keySet()) { + for (Map.Entry<String, Property> 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()); + } + } + } + } + } + } + + return cps; + } public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) { diff --git a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java index 471fbc0..817ac92 100644 --- a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java +++ b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java @@ -27,7 +27,8 @@ public abstract class SdcToscaParserBasicTest { static ISdcCsarHelper complexCps; static ISdcCsarHelper fdntCsarHelperWithInputs; static ISdcCsarHelper nfodCsarHlper; - static ISdcCsarHelper nestedVfcCsarHlper; + static ISdcCsarHelper ipAssignCsarHelper; + static ISdcCsarHelper nestedVfcCsarHlper; static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data; @BeforeClass @@ -40,6 +41,7 @@ public abstract class SdcToscaParserBasicTest { complexCps = getCsarHelper("csars/service-consolidated-props-csar.csar"); fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar"); nfodCsarHlper = getCsarHelper("csars/service-NfodService-csar.csar"); + ipAssignCsarHelper = getCsarHelper("csars/service-Ipassignservice-csar.csar"); nestedVfcCsarHlper = getCsarHelper("csars/service-nested-vfc-csar.csar"); fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){ { diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index d8e065b..9818a89 100644 --- a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -331,45 +331,41 @@ public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //region getCpPropertiesFromVfc @Test public void testGetCpPropertiesFromVfc() { - List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef"); + List<NodeTemplate> vfcs = ipAssignCsarHelper.getVfcListByVf("b5190df2-7880-4d6f-836f-56ab17e1b85b"); boolean isChecked = false; - boolean isChecked1 = false; - for (int i = 0; i < vfcs.size(); i++) { - - if(vfcs.get(i).getName().equalsIgnoreCase("abstract_ddc")) - { - isChecked = true; - Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(i)); - - assertEquals(3,cps.size()); - assertEquals(new Integer(1), cps.get("port_ddc_int_imbl__port").get("ip_requirements#ip_count_required#count")); - assertEquals(new Boolean(true), cps.get("port_ddc_int_imbl__port").get("ip_requirements#dhcp_enabled")); - assertEquals(new Integer(6), cps.get("port_ddc_int_imbl__port").get("ip_requirements#ip_version")); - assertEquals("subnetpoolid_test", cps.get("port_ddc_int_imbl__port").get("subnetpoolid")); - assertEquals("int_imbl", cps.get("port_ddc_int_imbl__port").get("network_role_tag")); + for (NodeTemplate vfc: vfcs) { - } - - if(vfcs.get(i).getName().equalsIgnoreCase("abstract_mda")) + if(vfc.getName().equalsIgnoreCase("abstract_pd_server")) { - isChecked1 = true; - Map<String, Map<String, Object>> cps1 = complexCps.getCpPropertiesFromVfc(vfcs.get(i)); - - assertEquals(new Integer(4), cps1.get("port_mda_int_imsp__port").get("ip_requirements#ip_version")); - assertEquals(null, cps1.get("port_mda_int_imsp__port").get("ip_requirements#ip_count_required#count")); - - } + isChecked = true; + Map<String, Map<String, Object>> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(vfc); + + assertEquals(2,cps.size()); + Map<String, Object> pd01 = cps.get("port_pd01_port"); + assertEquals(5, pd01.size()); + + Map<String, Object> firstIpRequirements = (Map<String, Object>) ((List<Object>)pd01.get("ip_requirements")).get(0); + Map<String, Object> secondIpRequirements = (Map<String, Object>) ((List<Object>)pd01.get("ip_requirements")).get(1); + + assertEquals("subnet_role_4", firstIpRequirements.get("subnet_role")); + assertEquals(4, firstIpRequirements.get("ip_version")); + assertEquals(true, ((Map<String, Object>) firstIpRequirements.get("ip_count_required")).get("is_required")); + assertEquals(4, ((Map<String, Object>) firstIpRequirements.get("ip_count_required")).get("count")); + assertEquals(false, ((Map<String, Object>)((Map<String, Object>)pd01.get("mac_requirements")).get("mac_count_required")).get("is_required")); + assertEquals("test_subnetpoolid", pd01.get("subnetpoolid")); + assertEquals("oam", pd01.get("network_role_tag")); + assertEquals(6, secondIpRequirements.get("ip_version")); + } } assertTrue(isChecked); - assertTrue(isChecked1); } @Test public void testGetCpPropertiesFromVfcForNullVFC() { - Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null); + Map<String, Map<String, Object>> cps = ipAssignCsarHelper.getCpPropertiesFromVfcAsObject(null); assertNotNull(cps); assertEquals(0, cps.size()); } diff --git a/src/test/resources/csars/service-Ipassignservice-csar.csar b/src/test/resources/csars/service-Ipassignservice-csar.csar Binary files differnew file mode 100644 index 0000000..0507457 --- /dev/null +++ b/src/test/resources/csars/service-Ipassignservice-csar.csar |