From c1b666ef958fed2ab60df66d71f5f9cfed244a34 Mon Sep 17 00:00:00 2001 From: eleonorali Date: Mon, 12 Mar 2018 11:54:42 +0200 Subject: Support Dual stuck - for difference version (2) E2E Defect 430981 - ip_requirments for multiple ports with difference version wasn't supported Change-Id: If3e93f099900bc078de6da9092b9d1460609e232 Issue-ID: SDC-1096 Signed-off-by: eleonorali --- .../ResourceTranslationNeutronPortHelper.java | 196 +++++++++++---------- 1 file changed, 107 insertions(+), 89 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java') diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ResourceTranslationNeutronPortHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ResourceTranslationNeutronPortHelper.java index 23f8e3695d..c6d59ff1fd 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ResourceTranslationNeutronPortHelper.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ResourceTranslationNeutronPortHelper.java @@ -32,36 +32,47 @@ public class ResourceTranslationNeutronPortHelper { public static final String MAC_REQUIREMENTS = "mac_requirements"; public void setAdditionalProperties(Map properties) { - setNetworkRoleTag(properties); + properties.putAll(createDefaultRequirments()); + populateFixedIpCount(properties); + populateFloatingIpCount(properties); + populateMacCount(properties); + populateNetworkRoleTag(properties); + + } + + private Map createDefaultRequirments() { + Map properties = new HashMap(); + List> ipRequirementsList = new ArrayList<>(); + ipRequirementsList.add(createIPRequirment(4)); + ipRequirementsList.add(createIPRequirment(6)); + properties.put(IP_REQUIREMENTS, ipRequirementsList); + properties.put(MAC_REQUIREMENTS, createMacRequirment()); + return properties; + + } + + private Map createIPRequirment(Object version) { Map ipRequirements = new HashMap(); - Map macRequirements = new HashMap(); Map isRequired = new HashMap(); Map floatingIsRequired = new HashMap(); - Map macIsRequired = new HashMap(); - isRequired.put(IS_REQUIRED, Boolean.FALSE); floatingIsRequired.put(IS_REQUIRED, Boolean.FALSE); - macIsRequired.put(IS_REQUIRED, Boolean.FALSE); - ipRequirements.put(IP_COUNT_REQUIRED, isRequired); ipRequirements.put(FLOATING_IP_COUNT_REQUIRED, floatingIsRequired); - ipRequirements.put(IP_VERSION, 4); - macRequirements.put(MAC_COUNT_REQUIRED, macIsRequired); - - List> ipRequirementsList = new ArrayList<>(); - ipRequirementsList.add(ipRequirements); - properties.put(IP_REQUIREMENTS , ipRequirementsList); - - properties.put(MAC_REQUIREMENTS , macRequirements); - - setIpVersion(properties); - setFloatingIpVersion(properties); + ipRequirements.put(IP_VERSION, version); + return ipRequirements; + } - setMacCount(properties); + private Map createMacRequirment() { + Map macRequirements = new HashMap(); + Map macIsRequired = new HashMap(); + macIsRequired.put(IS_REQUIRED, Boolean.FALSE); + macRequirements.put(MAC_COUNT_REQUIRED, macIsRequired); + return macRequirements; } - private void setMacCount(Map properties) { - if(properties.containsKey(MAC_ADDRESS)) { + private void populateMacCount(Map properties) { + if (properties.containsKey(MAC_ADDRESS)) { Map macRequirements = (Map) properties.get(MAC_REQUIREMENTS); Map macIsRequired = new HashMap(); macIsRequired.put(IS_REQUIRED, Boolean.TRUE); @@ -70,95 +81,102 @@ public class ResourceTranslationNeutronPortHelper { } } - private void setFloatingIpVersion(Map properties) { - List> ipRequirementsList = - (List>) properties.get(IP_REQUIREMENTS); - Map ipRequirements = ipRequirementsList.get(0); - Object propertyValue; - Map isRequired = new HashMap(); - isRequired.put(IS_REQUIRED, Boolean.TRUE); + private void populateFloatingIpCount(Map properties) { + populateIpCountRequired(properties, ALLOWED_ADDRESS_PAIRS, FLOATING_IP_COUNT_REQUIRED ); + } + + private void populateFixedIpCount(Map properties) { + populateIpCountRequired(properties, FIXED_IPS, IP_COUNT_REQUIRED ); + } - propertyValue = properties.get(ALLOWED_ADDRESS_PAIRS); + private void populateIpCountRequired(Map properties, String ipType, String ipCountRequired ){ + + HashMap > ipRequirmentsMap = getIPRequirments(properties); + Object propertyValue = properties.get(ipType); if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { - Map.Entry mapEntry = - (Map.Entry) ((Map) propertyValue).entrySet().iterator().next(); - if (getFloatingIpVersion(mapEntry.getValue()) != null) { - ipRequirements.put(IP_VERSION, getFloatingIpVersion(mapEntry.getValue())); - ipRequirements.put(FLOATING_IP_COUNT_REQUIRED, isRequired); - } + handleMapProperty(ipType, ipCountRequired, ipRequirmentsMap, (Map.Entry) ((Map) propertyValue).entrySet().iterator().next()); } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) { - for (int i = 0; i < ((List) propertyValue).size(); i++) { - Object ipMap = ((List) propertyValue).get(i); - if(ipMap instanceof Map && !((Map) ipMap).isEmpty()) { - Object ipAddressMap = ((Map) ipMap).get(IP_ADDRESS); - if (ipAddressMap instanceof Map && !((Map) ipAddressMap).isEmpty()) { - Object ipList = ((Map) ipAddressMap).get(GET_INPUT); - if (ipList instanceof String && !((String) ipList).isEmpty()) { - if (getFloatingIpVersion(ipList) != null) { - ipRequirements.put(IP_VERSION, getFloatingIpVersion(ipList)); - ipRequirements.put(FLOATING_IP_COUNT_REQUIRED, isRequired); - } - } - } - } - } + handleListProperty(ipType, ipCountRequired, ipRequirmentsMap, (List) propertyValue); } } - private void setIpVersion(Map properties) { - List> ipRequirementsList = - (List>) properties.get(IP_REQUIREMENTS); - Map ipRequirements = ipRequirementsList.get(0); - Object propertyValue; - Map isRequired = new HashMap(); - isRequired.put(IS_REQUIRED, Boolean.TRUE); + private void handleListProperty(String ipType, String ipCountRequired, HashMap> ipRequirmentsMap, List propertyValue) { + for (int i = 0; i < propertyValue.size(); i++) { + handleIpAddress(ipType, ipCountRequired, ipRequirmentsMap, propertyValue.get(i)); + } + } - propertyValue = properties.get(FIXED_IPS); - if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { - Map.Entry mapEntry = - (Map.Entry) ((Map) propertyValue).entrySet().iterator().next(); - if (getIpVersion(mapEntry.getValue()) != null) { - ipRequirements.put(IP_VERSION, getIpVersion(mapEntry.getValue())); - ipRequirements.put(IP_COUNT_REQUIRED, isRequired); + private void handleMapProperty(String ipType, String ipCountRequired, HashMap> ipRequirmentsMap, Map.Entry mapEntry) { + updateIpCountRequired(ipType, ipCountRequired, ipRequirmentsMap, mapEntry.getValue()); + } + + private void handleIpAddress(String ipType, String ipCountRequired, HashMap> ipRequirmentsMap, Object ipMap) { + if(ipMap instanceof Map && !((Map) ipMap).isEmpty()) { + Object ipAddressMap = ((Map) ipMap).get(IP_ADDRESS); + if (ipAddressMap instanceof Map && !((Map) ipAddressMap).isEmpty()) { + Object ipList = ((Map) ipAddressMap).get(GET_INPUT); + handleIpCountRequired(ipType, ipCountRequired, ipRequirmentsMap, ipList); } } - else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) { - for (int i = 0; i < ((List) propertyValue).size(); i++) { - Object ipMap = ((List) propertyValue).get(i); - if(ipMap instanceof Map && !((Map) ipMap).isEmpty()) { - Object ipAddressMap = ((Map) ipMap).get(IP_ADDRESS); - if (ipAddressMap instanceof Map && !((Map) ipAddressMap).isEmpty()) { - Object ipList = ((Map) ipAddressMap).get(GET_INPUT); - if (ipList instanceof List && !((List) ipList).isEmpty()) { - if (getIpVersion(((List) ipList).get(0)) != null) { - ipRequirements.put(IP_VERSION, getIpVersion(((List) ipList).get(0))); - ipRequirements.put(IP_COUNT_REQUIRED, isRequired); - } - } - else if (ipList instanceof String && !((String) ipList).isEmpty()) { - if (getIpVersion(ipList) != null) { - ipRequirements.put(IP_VERSION, getIpVersion(ipList)); - ipRequirements.put(IP_COUNT_REQUIRED, isRequired); - } - } - } - } + } + + private void handleIpCountRequired(String ipType, String ipCountRequired, HashMap> ipRequirmentsMap, Object ipList) { + if (ipList instanceof List && !((List) ipList).isEmpty()) { + updateIpCountRequired(ipType, ipCountRequired, ipRequirmentsMap, ((List) ipList).get(0)); + } + else if (ipList instanceof String && !((String) ipList).isEmpty()) { + updateIpCountRequired(ipType, ipCountRequired, ipRequirmentsMap, ipList); + } + } + + private void updateIpCountRequired(String ipType, String ipCountRequired, HashMap> ipRequirmentsMap, Object ipList) { + Object ipVersion = getVersion(ipList, ipType); + updateIpCountRequiredForVersion(ipCountRequired, ipRequirmentsMap, ipVersion); + } + + private void updateIpCountRequiredForVersion(String ipCountRequired, HashMap> ipRequirmentsMap, Object ipVersion) { + Map ipRequirement; + if (ipVersion != null) { + ipRequirement = ipRequirmentsMap.get(ipVersion); + if (ipRequirement != null) { + Map isIPCountRequired = (Map)ipRequirement.get(ipCountRequired); + isIPCountRequired.put(IS_REQUIRED, Boolean.TRUE); } } } - private void setNetworkRoleTag(Map properties) { + private HashMap > getIPRequirments (Map properties) { + + HashMap> ipRequirmentsMap = new HashMap(); + List> ipRequirmentsList = ((List>) properties.get(IP_REQUIREMENTS)); + ipRequirmentsList.stream().forEach(e->ipRequirmentsMap.put(e.get(IP_VERSION),e)); + return ipRequirmentsMap; + } + + private void populateNetworkRoleTag(Map properties) { Object propertyValue = properties.get(NETWORK); if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { Map.Entry mapEntry = - (Map.Entry) ((Map) propertyValue).entrySet().iterator().next(); + (Map.Entry) ((Map) propertyValue).entrySet().iterator().next(); if (mapEntry.getValue() instanceof String && getNetworkRole(mapEntry.getValue())!=null) { properties.put(NETWORK_ROLE_TAG, getNetworkRole(mapEntry.getValue())); } } } + private Object getVersion(Object value, String type) { + + Object version = null; + if(type.equals(FIXED_IPS)){ + version = getIpVersion(value); + } + else if(type.equals(ALLOWED_ADDRESS_PAIRS)){ + version = getFloatingIpVersion(value); + } + return version; + } + private Object getFloatingIpVersion(Object value) { Object ipVersion = null; if(value instanceof String) { @@ -188,13 +206,13 @@ public class ResourceTranslationNeutronPortHelper { private Object getNetworkRole(String value) { Object networkRole = null; if(value.endsWith(NET_NAME)) { - networkRole = (Object) value.substring(0, value.length() - NET_NAME.length()); + networkRole = value.substring(0, value.length() - NET_NAME.length()); } else if(value.endsWith(NET_ID)) { - networkRole = (Object) value.substring(0, value.length() - NET_ID.length()); + networkRole = value.substring(0, value.length() - NET_ID.length()); } else if(value.endsWith(NET_FQDN)) { - networkRole = (Object) value.substring(0, value.length() - NET_FQDN.length()); + networkRole = value.substring(0, value.length() - NET_FQDN.length()); } return networkRole; } -- cgit 1.2.3-korg