summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main
diff options
context:
space:
mode:
authorsiddharth0905 <siddharth.singh4@amdocs.com>2018-03-27 19:56:54 +0530
committerOren Kleks <orenkle@amdocs.com>2018-03-28 05:32:09 +0000
commitadca5281550b50d93c7f4259c2f84e21d5681c07 (patch)
treebbef53ec13afefcb0aef882cdc2ab92447a58095 /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main
parent7363f3d875e08d5195cb5e8b7e4f9ac86ec99ef5 (diff)
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 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java61
1 files changed, 32 insertions, 29 deletions
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<String, Resource> vlanSubInterfaceResourceEntry = vlanSubInterfaceResource.get();
- networkRole = evaluateNetworkRoleFromResourceId(vlanSubInterfaceResourceEntry.getKey(),
+ networkRole = extractNetworkRoleFromSubInterfaceId(vlanSubInterfaceResourceEntry.getKey(),
vlanSubInterfaceResourceEntry.getValue().getType());
}
}
@@ -1523,43 +1523,46 @@ public class HeatToToscaUtil {
public static Optional<String> 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> 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<PortType> 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<String> extractNetworkRoleFromSubInterfaceId(String resourceId,
+ String resourceType) {
+ Optional<PortType> 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 {