diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ResourceTranslationNeutronPortHelper.java')
1 files changed, 38 insertions, 53 deletions
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 ac6d317722..ec33420085 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 @@ -18,6 +18,7 @@ * ============LICENSE_END========================================================= */ package org.openecomp.sdc.translator.services.heattotosca.helper; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -73,7 +74,6 @@ public class ResourceTranslationNeutronPortHelper { properties.put(IP_REQUIREMENTS, ipRequirementsList); properties.put(MAC_REQUIREMENTS, createMacRequirement()); return properties; - } private Map<String, Object> createMacRequirement() { @@ -85,7 +85,7 @@ public class ResourceTranslationNeutronPortHelper { } private void setMacRequirements(Map<String, Object> properties) { - updateMacCountRequired(properties); + updateMacCountRequired(properties); } private void updateMacCountRequired(Map<String, Object> properties) { @@ -97,17 +97,16 @@ public class ResourceTranslationNeutronPortHelper { } private void setFloatingIpCount(Map<String, Object> properties) { - handleIpCountRequired(properties, ALLOWED_ADDRESS_PAIRS, FLOATING_IP_COUNT_REQUIRED ); + handleIpCountRequired(properties, ALLOWED_ADDRESS_PAIRS, FLOATING_IP_COUNT_REQUIRED); } private void setFixedIpCount(Map<String, Object> properties) { - handleIpCountRequired(properties, FIXED_IPS, IP_COUNT_REQUIRED ); + handleIpCountRequired(properties, FIXED_IPS, IP_COUNT_REQUIRED); } - private void addDefaultIpRequirement(Map<String, Object> properties) { List<Map<String, Object>> ipRequirementsList = ((List<Map<String, Object>>) properties.get(IP_REQUIREMENTS)); - if(ipRequirementsList.isEmpty()) { + if (ipRequirementsList.isEmpty()) { ipRequirementsList.add(createIPRequirement(DEFAULT_IP_VERSION)); } } @@ -124,52 +123,48 @@ public class ResourceTranslationNeutronPortHelper { return ipRequirements; } - private void handleIpCountRequired(Map<String, Object> properties, String ipType, String ipCountRequired ){ - + private void handleIpCountRequired(Map<String, Object> properties, String ipType, String ipCountRequired) { Object propertyValue = properties.get(ipType); - if(propertyValue == null){ + if (propertyValue == null) { return; } - if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { handleMapProperty(ipType, ipCountRequired, properties, (Map.Entry<String, Object>) ((Map) propertyValue).entrySet().iterator().next()); + } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) { + handleListProperty(ipType, ipCountRequired, properties, (List) propertyValue); } - else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) { - handleListProperty(ipType, ipCountRequired, properties, (List) propertyValue); - } - } - private void handleListProperty(String ipType, String ipCountRequired, Map<String, Object> properties, List propertyValue) { + private void handleListProperty(String ipType, String ipCountRequired, Map<String, Object> properties, List propertyValue) { for (int i = 0; i < propertyValue.size(); i++) { - handleIpAddress(ipType, ipCountRequired, properties, propertyValue.get(i)); + handleIpAddress(ipType, ipCountRequired, properties, propertyValue.get(i)); } } private void handleMapProperty(String ipType, String ipCountRequired, Map<String, Object> properties, Map.Entry<String, Object> mapEntry) { - updateIpCountRequired(ipType, ipCountRequired, properties, mapEntry.getValue()); + updateIpCountRequired(ipType, ipCountRequired, properties, mapEntry.getValue()); } private void handleIpAddress(String ipType, String ipCountRequired, Map<String, Object> properties, Object ipMap) { - if(ipMap instanceof Map && !((Map) ipMap).isEmpty()) { + if (ipMap instanceof Map && !((Map) ipMap).isEmpty()) { Object ipAddressMap = ((Map) ipMap).get(IP_ADDRESS); if (ipAddressMap instanceof Map && !((Map) ipAddressMap).isEmpty()) { Object ipInput = ((Map) ipAddressMap).get(GET_INPUT); - updateIpCountRequired(ipType, ipCountRequired, properties, ipInput); + updateIpCountRequired(ipType, ipCountRequired, properties, ipInput); } } } private void updateIpCountRequired(String ipType, String ipCountRequired, Map<String, Object> properties, Object ipInput) { Object ipVersion = getVersion(ipInput, ipType); - updateIpCountRequiredForVersion(ipCountRequired, properties, ipVersion); + updateIpCountRequiredForVersion(ipCountRequired, properties, ipVersion); } - private void updateIpCountRequiredForVersion(String ipCountRequired, Map<String, Object> properties, Object ipVersion) { + private void updateIpCountRequiredForVersion(String ipCountRequired, Map<String, Object> properties, Object ipVersion) { if (ipVersion != null) { HashMap<Object, Map<String, Object>> ipRequirementsMap = getIPRequirements(properties); - Map<String, Object> ipRequirement = ipRequirementsMap.get(ipVersion); - if (ipRequirement == null){ + Map<String, Object> ipRequirement = ipRequirementsMap.get(ipVersion); + if (ipRequirement == null) { ipRequirement = addIPRequirement(properties, ipVersion); } updateIpCountRequired(ipCountRequired, ipRequirement); @@ -177,56 +172,51 @@ public class ResourceTranslationNeutronPortHelper { } private Map<String, Object> addIPRequirement(Map<String, Object> properties, Object ipVersion) { - List<Map<String, Object>> ipRequirementsList = ((List<Map<String,Object>>) properties.get(IP_REQUIREMENTS)); + List<Map<String, Object>> ipRequirementsList = ((List<Map<String, Object>>) properties.get(IP_REQUIREMENTS)); Map<String, Object> newIpRequirement = createIPRequirement(ipVersion); ipRequirementsList.add(newIpRequirement); return newIpRequirement; } private void updateIpCountRequired(String ipCountRequired, Map<String, Object> ipRequirement) { - Map<String, Object> isIPCountRequired = (Map<String, Object>)ipRequirement.get(ipCountRequired); + Map<String, Object> isIPCountRequired = (Map<String, Object>) ipRequirement.get(ipCountRequired); isIPCountRequired.put(IS_REQUIRED, Boolean.TRUE); } - private HashMap <Object, Map<String, Object>> getIPRequirements (Map<String, Object> properties) { + private HashMap<Object, Map<String, Object>> getIPRequirements(Map<String, Object> properties) { HashMap<Object, Map<String, Object>> ipRequirementsMap = new HashMap<>(); - List<Map<String, Object>> ipRequirementsList = ((List<Map<String,Object>>) properties.get(IP_REQUIREMENTS)); - ipRequirementsList.stream().forEach(e->ipRequirementsMap.put(e.get(IP_VERSION),e)); + List<Map<String, Object>> ipRequirementsList = ((List<Map<String, Object>>) properties.get(IP_REQUIREMENTS)); + ipRequirementsList.stream().forEach(e -> ipRequirementsMap.put(e.get(IP_VERSION), e)); return ipRequirementsMap; } private void setNetworkRoleTag(Map<String, Object> properties) { Object propertyValue = properties.get(NETWORK); if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { - Map.Entry<String, String> mapEntry = - (Map.Entry<String, String>) ((Map) propertyValue).entrySet().iterator().next(); - if (mapEntry.getValue() instanceof String && getNetworkRole(mapEntry.getValue())!=null) { + Map.Entry<String, String> mapEntry = (Map.Entry<String, String>) ((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); + 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; - // Allowed ONLY String parameter - if(value instanceof String) { + if (value instanceof String) { if (((String) value).endsWith(FLOATING_V6_IP)) { ipVersion = 6; - } - else if (((String) value).endsWith(FLOATING_IP)){ + } else if (((String) value).endsWith(FLOATING_IP)) { ipVersion = 4; } } @@ -234,18 +224,15 @@ public class ResourceTranslationNeutronPortHelper { } private Object getIpVersion(Object value) { - // Allowed List or String parameter Object ipVersion = null; - if (value instanceof List && !((List) value).isEmpty()){ + if (value instanceof List && !((List) value).isEmpty()) { value = ((List) value).get(0); } - - if(value instanceof String) { + if (value instanceof String) { if (((String) value).endsWith(V6_IPS) || ((String) value).matches(IPV6_REGEX)) { ipVersion = 6; - } - else { + } else { ipVersion = 4; } } @@ -254,15 +241,13 @@ public class ResourceTranslationNeutronPortHelper { private Object getNetworkRole(String value) { Object networkRole = null; - if(value.endsWith(NET_NAME)) { + if (value.endsWith(NET_NAME)) { networkRole = value.substring(0, value.length() - NET_NAME.length()); - } - else if(value.endsWith(NET_ID)) { + } else if (value.endsWith(NET_ID)) { networkRole = value.substring(0, value.length() - NET_ID.length()); - } - else if(value.endsWith(NET_FQDN)) { + } else if (value.endsWith(NET_FQDN)) { networkRole = value.substring(0, value.length() - NET_FQDN.length()); } return networkRole; } -}
\ No newline at end of file +} |