From adca5281550b50d93c7f4259c2f84e21d5681c07 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Tue, 27 Mar 2018 19:56:54 +0530 Subject: Code change to evaluate Network role Code change to evaluate Network Role of Sub interface resource Change-Id: I0e29c0a1512b76b6db569aaf534f5e59868ae715 Issue-ID: SDC-1072 Signed-off-by: siddharth0905 --- .../services/heattotosca/HeatToToscaUtil.java | 61 ++++++++++++---------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java index f965352da4..016b4b2873 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java @@ -1514,7 +1514,7 @@ public class HeatToToscaUtil { .findFirst(); if (vlanSubInterfaceResource.isPresent()) { Map.Entry vlanSubInterfaceResourceEntry = vlanSubInterfaceResource.get(); - networkRole = evaluateNetworkRoleFromResourceId(vlanSubInterfaceResourceEntry.getKey(), + networkRole = extractNetworkRoleFromSubInterfaceId(vlanSubInterfaceResourceEntry.getKey(), vlanSubInterfaceResourceEntry.getValue().getType()); } } @@ -1523,43 +1523,46 @@ public class HeatToToscaUtil { public static Optional evaluateNetworkRoleFromResourceId(String resourceId, String resourceType) { - if (resourceType.equals( - HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { - return Optional.ofNullable(extractNetworkRoleFromResourceId(resourceId, PortType.VMI)); - } + Optional portType = getPortType(resourceType); + if (portType.isPresent()) { + String portResourceIdRegex = + PORT_RESOURCE_ID_REGEX_PREFIX + UNDERSCORE + WORDS_REGEX + UNDERSCORE + + portType.get().getPortTypeName() + PORT_RESOURCE_ID_REGEX_SUFFIX; + String portIntResourceIdRegex = + PORT_INT_RESOURCE_ID_REGEX_PREFIX + portType.get().getPortTypeName() + + PORT_RESOURCE_ID_REGEX_SUFFIX; + + String portNetworkRole = getNetworkRole(resourceId, portResourceIdRegex); + String portIntNetworkRole = getNetworkRole(resourceId, portIntResourceIdRegex); - if (resourceType.equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) { - return Optional.ofNullable(extractNetworkRoleFromResourceId(resourceId, PortType.PORT)); + return Optional.ofNullable(Objects.nonNull(portNetworkRole) + ? portNetworkRole : portIntNetworkRole); } return Optional.empty(); } - private static String extractNetworkRoleFromResourceId(String portResourceId, PortType portType) { - - if (portResourceId.matches(SUB_INTERFACE_REGEX)) { - return extractNetworkRoleFromSubInterfaceId(portResourceId, portType); + private static Optional getPortType(String resourceType) { + if (resourceType.equals( + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { + return Optional.of(PortType.VMI); + } else if (resourceType.equals( + HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) { + return Optional.of(PortType.PORT); } - - String portResourceIdRegex = - PORT_RESOURCE_ID_REGEX_PREFIX + UNDERSCORE + WORDS_REGEX + UNDERSCORE + portType.getPortTypeName() - + PORT_RESOURCE_ID_REGEX_SUFFIX; - String portIntResourceIdRegex = - PORT_INT_RESOURCE_ID_REGEX_PREFIX + portType.getPortTypeName() - + PORT_RESOURCE_ID_REGEX_SUFFIX; - - String portNetworkRole = getNetworkRole(portResourceId, portResourceIdRegex); - String portIntNetworkRole = getNetworkRole(portResourceId, portIntResourceIdRegex); - - return Objects.nonNull(portNetworkRole) ? portNetworkRole : portIntNetworkRole; + return Optional.empty(); } - private static String extractNetworkRoleFromSubInterfaceId(String resourceId, - PortType portType) { - String subInterfaceResourceIdRegex = - SUB_INTERFACE_INT_RESOURCE_ID_REGEX_PREFIX + portType.getPortTypeName() - + PORT_RESOURCE_ID_REGEX_SUFFIX; + public static Optional extractNetworkRoleFromSubInterfaceId(String resourceId, + String resourceType) { + Optional portType = getPortType(resourceType); + if (portType.isPresent()) { + String subInterfaceResourceIdRegex = + SUB_INTERFACE_INT_RESOURCE_ID_REGEX_PREFIX + portType.get().getPortTypeName() + + PORT_RESOURCE_ID_REGEX_SUFFIX; - return getNetworkRole(resourceId, subInterfaceResourceIdRegex); + return Optional.ofNullable(getNetworkRole(resourceId, subInterfaceResourceIdRegex)); + } + return Optional.empty(); } private enum PortType { -- cgit 1.2.3-korg