summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-translator-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java12
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java22
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java109
-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.java20
4 files changed, 37 insertions, 126 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
index 9335dd4a97..3aaf47cae5 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationData.java
@@ -23,7 +23,7 @@ import java.util.Optional;
import java.util.Set;
import org.openecomp.sdc.heat.datatypes.model.Resource;
-import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.heat.services.HeatResourceUtil;
public class FilePortConsolidationData {
@@ -93,16 +93,14 @@ public class FilePortConsolidationData {
return consolidationData;
}
- private PortTemplateConsolidationData createPortTemplateConsolidationData(
- String portNodeTemplateId, String portResourceId, String portResourceType) {
+ public PortTemplateConsolidationData createPortTemplateConsolidationData(String portNodeTemplateId,
+ String portResourceId,
+ String portResourceType) {
PortTemplateConsolidationData consolidationData = new PortTemplateConsolidationData();
consolidationData.setNodeTemplateId(portNodeTemplateId);
- Optional<String> portNetworkRole = HeatToToscaUtil.evaluateNetworkRoleFromResourceId(portResourceId,
+ Optional<String> portNetworkRole = HeatResourceUtil.evaluateNetworkRoleFromResourceId(portResourceId,
portResourceType);
portNetworkRole.ifPresent(consolidationData::setNetworkRole);
return consolidationData;
}
-
-
-
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
index 64c2168241..0d8a07a41f 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
@@ -142,8 +143,8 @@ public class ConsolidationDataUtil {
PortTemplateConsolidationData portTemplateConsolidationData =
filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId);
if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = getInitPortTemplateConsolidationData(portNodeTemplateId,
- portResourceId, portResourceType);
+ portTemplateConsolidationData = filePortConsolidationData
+ .createPortTemplateConsolidationData(portNodeTemplateId, portResourceId, portResourceType);
filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId,
portTemplateConsolidationData);
}
@@ -151,18 +152,6 @@ public class ConsolidationDataUtil {
return portTemplateConsolidationData;
}
- private static PortTemplateConsolidationData getInitPortTemplateConsolidationData(String portNodeTemplateId,
- String portResourceId,
- String portResourceType) {
- PortTemplateConsolidationData portTemplateConsolidationData = new PortTemplateConsolidationData();
- portTemplateConsolidationData.setNodeTemplateId(portNodeTemplateId);
- Optional<String> portNetworkRole = HeatToToscaUtil.evaluateNetworkRoleFromResourceId(portResourceId,
- portResourceType);
- portNetworkRole.ifPresent(portTemplateConsolidationData::setNetworkRole);
- return portTemplateConsolidationData;
- }
-
-
public static Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
TranslateTo subInterfaceTo, String subInterfaceNodeTemplateId) {
@@ -197,8 +186,9 @@ public class ConsolidationDataUtil {
Optional<String> portResourceId = getSubInterfaceParentPortResourceId(parentPortNodeTemplateId,
subInterfaceTo);
if (portResourceId.isPresent()) {
- portTemplateConsolidationData = getInitPortTemplateConsolidationData(parentPortNodeTemplateId,
- portResourceId.get(), HeatToToscaUtil.getResourceType(portResourceId.get(), subInterfaceTo
+ portTemplateConsolidationData = filePortConsolidationData.createPortTemplateConsolidationData(
+ parentPortNodeTemplateId, portResourceId.get(),
+ HeatToToscaUtil.getResourceType(portResourceId.get(), subInterfaceTo
.getHeatOrchestrationTemplate(), subInterfaceTo.getHeatFileName()));
} else {
portTemplateConsolidationData = new PortTemplateConsolidationData();
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 dd23e2ddbb..f2773ae01f 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
@@ -16,6 +16,7 @@
package org.openecomp.sdc.translator.services.heattotosca;
+import static org.openecomp.sdc.heat.services.HeatResourceUtil.extractNetworkRoleFromSubInterfaceId;
import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
import java.io.IOException;
@@ -29,8 +30,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
@@ -59,6 +58,7 @@ import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.core.validation.util.MessageContainerUtil;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
@@ -110,15 +110,6 @@ 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 WORDS_REGEX = "(\\w+)";
- private static final String PORT_RESOURCE_ID_REGEX_SUFFIX = "(_\\d+)*";
- private static final String PORT_RESOURCE_ID_REGEX_PREFIX = 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.
@@ -132,7 +123,7 @@ public class HeatToToscaUtil {
try (InputStream fileContent = fileNameContentMap.getFileContent(SdcCommon.MANIFEST_NAME)) {
heatToToscaTranslator.addManifest(SdcCommon.MANIFEST_NAME, FileUtils.toByteArray(fileContent));
} catch (IOException e) {
- throw new RuntimeException("Failed to read manifest", e);
+ throw new SdcRuntimeException("Failed to read manifest", e);
}
fileNameContentMap.getFileList().stream().filter(fileName -> !(fileName.equals(SdcCommon.MANIFEST_NAME)))
@@ -151,7 +142,7 @@ public class HeatToToscaUtil {
return heatToToscaTranslator.translate();
} catch (IOException e) {
// rethrow as a RuntimeException to keep the signature backward compatible
- throw new RuntimeException("Failed to read Heat template tree", e);
+ throw new SdcRuntimeException("Failed to read Heat template tree", e);
}
}
@@ -348,7 +339,7 @@ public class HeatToToscaUtil {
Object propertyValue) {
Object entity;
- Object translatedId;
+ Object translatedId = null;
if (Objects.isNull(propertyValue)) {
return Optional.empty();
@@ -362,19 +353,16 @@ public class HeatToToscaUtil {
String key = entry.getKey();
referenceType = getReferenceTypeFromAttachedResouce(key);
- if (!FunctionTranslationFactory.getInstance(entry.getKey()).isPresent()) {
- translatedId = null;
- } else {
- FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null,
- heatFileName, heatOrchestrationTemplate, context), null, entry.getValue(), null);
- translatedId = FunctionTranslationFactory.getInstance(entry.getKey()).get()
- .translateFunction(functionTranslator);
- }
- if (translatedId instanceof String
- && !new FunctionTranslator().isResourceSupported((String) translatedId)) {
- translatedId = null;
- }
-
+ if (FunctionTranslationFactory.getInstance(entry.getKey()).isPresent()) {
+ FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null,
+ heatFileName, heatOrchestrationTemplate, context), null, entry.getValue(), null);
+ translatedId = FunctionTranslationFactory.getInstance(entry.getKey()).get()
+ .translateFunction(functionTranslator);
+ if (translatedId instanceof String
+ && !new FunctionTranslator().isResourceSupported((String) translatedId)) {
+ translatedId = null;
+ }
+ }
} else {
translatedId = propertyValue;
entity = propertyValue;
@@ -1412,71 +1400,4 @@ public class HeatToToscaUtil {
return networkRole;
}
- public static Optional<String> evaluateNetworkRoleFromResourceId(String resourceId, String resourceType) {
- 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);
-
- return Optional.ofNullable(Objects.nonNull(portNetworkRole) ? portNetworkRole : portIntNetworkRole);
- }
- return Optional.empty();
- }
-
- 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);
- }
- return Optional.empty();
- }
-
- 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 Optional.ofNullable(getNetworkRole(resourceId, subInterfaceResourceIdRegex));
- }
- return Optional.empty();
- }
-
- private enum PortType {
- PORT("port"), VMI("vmi");
-
- private String portTypeName;
-
- PortType(String portTypeName) {
- this.portTypeName = portTypeName;
- }
-
- public String getPortTypeName() {
- return portTypeName;
- }
- }
-
- private static String getNetworkRole(String portResourceId, String portIdRegex) {
- Pattern pattern = Pattern.compile(portIdRegex);
- Matcher matcher = pattern.matcher(portResourceId);
- if (matcher.matches()) {
- String networkRole = matcher.group(3);
- //Assuming network role will not contain ONLY digits
- if (!networkRole.matches("\\d+")) {
- return matcher.group(3);
- }
- }
- return null;
- }
-
}
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 4a0615da1c..ada0a2caf5 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
@@ -18,24 +18,26 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslati
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatConstants;
+import org.openecomp.sdc.heat.services.HeatResourceUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortTemplateConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
public class ContrailV2VlanToInterfaceResourceConnectionTest extends BaseResourceTranslationTest {
private static final String PORT_NODE_TEMPLATE_ID_FOR_ATTR_TEST = "vdbe_untr_vmi";
@@ -136,7 +138,7 @@ public class ContrailV2VlanToInterfaceResourceConnectionTest extends BaseResourc
"vm_type_subint_networkrole_vmi");
subInterfaceResourceIds.forEach(resourceId -> {
- Optional<String> networkRole = HeatToToscaUtil.extractNetworkRoleFromSubInterfaceId(
+ Optional<String> networkRole = HeatResourceUtil.extractNetworkRoleFromSubInterfaceId(
resourceId,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
Assert.assertTrue(networkRole.isPresent()
@@ -151,7 +153,7 @@ public class ContrailV2VlanToInterfaceResourceConnectionTest extends BaseResourc
"vm_type_11_subint_11_vmi_11");
subInterfaceResourceIds.forEach(resourceId -> {
- Optional<String> networkRole = HeatToToscaUtil.extractNetworkRoleFromSubInterfaceId(
+ Optional<String> networkRole = HeatResourceUtil.extractNetworkRoleFromSubInterfaceId(
resourceId,
HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource());
Assert.assertFalse(networkRole.isPresent());