summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java52
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnectionTest.java30
3 files changed, 65 insertions, 19 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 13d1a4957f..f965352da4 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
@@ -109,11 +109,16 @@ public class HeatToToscaUtil {
private static final String GET_ATTR = "get_attr";
private static final String GET_RESOURCE = "get_resource";
private static final String UNDERSCORE = "_";
- private static final String PORT_RESOURCE_ID_REGEX_SUFFIX = "(_\\d)*";
+ private static final String WORDS_REGEX = "(\\w+)";
+ private static final String PORT_RESOURCE_ID_REGEX_SUFFIX = "(_\\d+)*";
private static final String PORT_RESOURCE_ID_REGEX_PREFIX =
- "(\\w+)" + PORT_RESOURCE_ID_REGEX_SUFFIX;
- private static final String PORT_INT_RESOURCE_ID_REGEX_PREFIX =
- PORT_RESOURCE_ID_REGEX_PREFIX + "_" + "int_(\\w+)_";
+ WORDS_REGEX + PORT_RESOURCE_ID_REGEX_SUFFIX;
+ private static final String PORT_INT_RESOURCE_ID_REGEX_PREFIX = PORT_RESOURCE_ID_REGEX_PREFIX
+ + UNDERSCORE + "int_"+ WORDS_REGEX + UNDERSCORE;
+ private static final String SUB_INTERFACE_INT_RESOURCE_ID_REGEX_PREFIX =
+ PORT_RESOURCE_ID_REGEX_PREFIX + UNDERSCORE + "subint_"+ WORDS_REGEX + UNDERSCORE;
+ private static final String SUB_INTERFACE_REGEX = WORDS_REGEX + PORT_RESOURCE_ID_REGEX_SUFFIX
+ + "_subint_(\\w_+)*vmi" + PORT_RESOURCE_ID_REGEX_SUFFIX;
/**
* Load and translate template data translator output.
@@ -1485,8 +1490,8 @@ public class HeatToToscaUtil {
//Method evaluate the network role from sub interface node template id, designed considering
// only single sub interface present in nested file else it will return null
- public static Optional<String> getNetworkRoleFromResource(Resource resource,
- TranslationContext translationContext) {
+ public static Optional<String> getNetworkRoleFromSubInterfaceId(Resource resource,
+ TranslationContext translationContext) {
Optional<String> networkRole = Optional.empty();
Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource);
@@ -1520,30 +1525,43 @@ public class HeatToToscaUtil {
String resourceType) {
if (resourceType.equals(
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) {
- return Optional.ofNullable(extractNetworkRoleFromPortId(resourceId, PortType.VMI));
+ return Optional.ofNullable(extractNetworkRoleFromResourceId(resourceId, PortType.VMI));
}
if (resourceType.equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) {
- return Optional.ofNullable(extractNetworkRoleFromPortId
- (resourceId, PortType.PORT));
+ return Optional.ofNullable(extractNetworkRoleFromResourceId(resourceId, PortType.PORT));
}
return Optional.empty();
}
- private static String extractNetworkRoleFromPortId(String portResourceId, PortType portType) {
+ private static String extractNetworkRoleFromResourceId(String portResourceId, PortType portType) {
+
+ if (portResourceId.matches(SUB_INTERFACE_REGEX)) {
+ return extractNetworkRoleFromSubInterfaceId(portResourceId, portType);
+ }
+
String portResourceIdRegex =
- PORT_RESOURCE_ID_REGEX_PREFIX + "_(\\w+)_" + portType.getPortTypeName() +
- PORT_RESOURCE_ID_REGEX_SUFFIX;
+ 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;
+ PORT_INT_RESOURCE_ID_REGEX_PREFIX + portType.getPortTypeName()
+ + PORT_RESOURCE_ID_REGEX_SUFFIX;
- String portNetworkRole = getPortNetworkRole(portResourceId, portResourceIdRegex);
- String portIntNetworkRole = getPortNetworkRole(portResourceId, portIntResourceIdRegex);
+ String portNetworkRole = getNetworkRole(portResourceId, portResourceIdRegex);
+ String portIntNetworkRole = getNetworkRole(portResourceId, portIntResourceIdRegex);
return Objects.nonNull(portNetworkRole) ? portNetworkRole : portIntNetworkRole;
}
+ private static String extractNetworkRoleFromSubInterfaceId(String resourceId,
+ PortType portType) {
+ String subInterfaceResourceIdRegex =
+ SUB_INTERFACE_INT_RESOURCE_ID_REGEX_PREFIX + portType.getPortTypeName()
+ + PORT_RESOURCE_ID_REGEX_SUFFIX;
+
+ return getNetworkRole(resourceId, subInterfaceResourceIdRegex);
+ }
+
private enum PortType {
PORT("port"),
VMI("vmi");
@@ -1559,7 +1577,7 @@ public class HeatToToscaUtil {
}
}
- private static String getPortNetworkRole(String portResourceId, String portIdRegex) {
+ private static String getNetworkRole(String portResourceId, String portIdRegex) {
Pattern pattern = Pattern.compile(portIdRegex);
Matcher matcher = pattern.matcher(portResourceId);
if (matcher.matches()) {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
index a3b8009868..00acb66706 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNestedImpl.java
@@ -131,7 +131,7 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase {
return;
}
Optional<String> subInterfaceNetworkRole =
- HeatToToscaUtil.getNetworkRoleFromResource(translateTo.getResource(), translateTo.getContext());
+ HeatToToscaUtil.getNetworkRoleFromSubInterfaceId(translateTo.getResource(), translateTo.getContext());
subInterfaceNetworkRole.ifPresent(subInterfaceTemplateConsolidationData.get()::setNetworkRole);
Object count = getSubInterfaceCountFromResourceProperties(translateTo);
subInterfaceTemplateConsolidationData.get().setResourceGroupCount(count);
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnectionTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnectionTest.java
index c7c780cceb..7815824208 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnectionTest.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ContrailV2VlanToInterfaceResourceConnectionTest.java
@@ -108,7 +108,7 @@ public class ContrailV2VlanToInterfaceResourceConnectionTest extends BaseResourc
Resource targetResource = new Resource();
targetResource.setType(NESTED_FILE_NAME_INOUT_ATTR_TEST);
- Optional<String> networkRole = HeatToToscaUtil.getNetworkRoleFromResource(targetResource, this
+ Optional<String> networkRole = HeatToToscaUtil.getNetworkRoleFromSubInterfaceId(targetResource, this
.translationContext);
Assert.assertEquals(NETWORK_ROLE_INOUT_ATTR_TEST,networkRole.get());
@@ -131,6 +131,34 @@ public class ContrailV2VlanToInterfaceResourceConnectionTest extends BaseResourc
}
+ @Test
+ public void testSubInterfaceResourceNetworkRolePositive() throws Exception {
+ List<String> subInterfaceResourceIds=Arrays.asList("vm_type_11_subint_networkrole_vmi_11",
+ "v_subint_networkrole_vmi", "v_1_subint_networkrole_vmi", "v_subint_networkrole_vmi_11",
+ "vm_type_subint_networkrole_vmi_11", "vm_type_11_subint_networkrole_vmi",
+ "vm_type_subint_networkrole_vmi");
+
+ subInterfaceResourceIds.forEach(resourceId -> {
+ Optional<String> networkRole=HeatToToscaUtil.evaluateNetworkRoleFromResourceId(resourceId,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
+ Assert.assertTrue(networkRole.isPresent()
+ && "networkrole".equals(networkRole.get()));
+ }
+ );
+ }
+
+ @Test
+ public void testSubInterfaceResourceNetworkRoleNegative() throws Exception {
+ List<String> subInterfaceResourceIds=Arrays.asList("vm_type_11_subint_vmi_11",
+ "vm_type_11_subint_11_vmi_11");
+
+ subInterfaceResourceIds.forEach(resourceId -> {
+ Optional<String> networkRole=HeatToToscaUtil.evaluateNetworkRoleFromResourceId(resourceId,
+ HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
+ Assert.assertFalse(networkRole.isPresent());
+ }
+ );
+ }
@Test
public void testIsSubInterfaceResourceUtil() throws Exception {