summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authoreleonorali <eleonoral@amdocs.com>2018-07-23 13:53:48 +0300
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-07-25 15:06:39 +0000
commitd43b4084b8213a35a388ccc3ca159be686762f48 (patch)
tree050606c167401071c0fa30d43a0e48cfa8a6fd4f /openecomp-be
parent924b33856a717a70570e9108596716a781e39ec0 (diff)
TOSCA Consolidation Data - Refactoring Part 4
1) Moving following APIs to relevant Consolidation Data handlers: addNodesGetAttrOut, addNodesGetAttrIn, addOutputParamGetAttrIn 2) Create APIs setNetworkRole, setResourceGroupCount in SubInterfaceConsolidationDataHandler 3) Remove APIs with switch on resource type: - ConsolidationDataUtil getPortTemplateConsolidationData, getComputeTemplateConsolidationData, getSubInterfaceTemplateConsolidationData getNestedTemplateConsolidationData - FunctionTranslationGetAttrImpl getEntityConsolidationData Change-Id: I0490c86ff9804955860eb40ff4be771a77194cc5 Issue-ID: SDC-1330 Signed-off-by: eleonorali <eleonoral@amdocs.com>
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/datatypes/heattotosca/TranslationContext.java2
-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/ComputeConsolidationDataHandler.java88
-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/ConsolidationDataHandler.java10
-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.java33
-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/NestedConsolidationDataHandler.java73
-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/PortConsolidationData.java15
-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/PortConsolidationDataHandler.java57
-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/SubInterfaceConsolidationDataHandler.java142
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java324
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java109
-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.java26
11 files changed, 467 insertions, 412 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
index 2ae64e2566..4da0577248 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
@@ -257,7 +257,7 @@ public class TranslationContext {
return consolidationData.getNestedConsolidationDataHandler();
}
- public SubInterfaceConsolidationDataHandler getSubInterfaceComputeConsolidationDataHandler() {
+ public SubInterfaceConsolidationDataHandler getSubInterfaceConsolidationDataHandler() {
return consolidationData.getSubInterfaceConsolidationDataHandler();
}
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/ComputeConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
index 8e319e96a0..923d7bdcde 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
@@ -27,6 +27,7 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
public class ComputeConsolidationDataHandler implements ConsolidationDataHandler {
@@ -60,7 +61,9 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, dependentNodeTemplateId);
- String nodeType = getNodeType(nodeTemplate, translateTo, targetResourceId, dependentNodeTemplateId);
+ String nodeType = getNodeType(nodeTemplate, translateTo.getHeatOrchestrationTemplate(),
+ targetResourceId, dependentNodeTemplateId, dependentNodeTemplateId);
+
EntityConsolidationData entityConsolidationData =
getComputeTemplateConsolidationData(translateTo, nodeType, dependentNodeTemplateId);
@@ -84,6 +87,46 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
}
}
+ @Override
+ public void addNodesGetAttrOut(FunctionTranslator functionTranslator, String nodeTemplateId,
+ String resourceTranslatedId, String propertyName, String attributeName) {
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(functionTranslator,
+ functionTranslator.getResourceId(), resourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ }
+ }
+
+ @Override
+ public void addNodesGetAttrIn(FunctionTranslator functionTranslator,String nodeTemplateId, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(functionTranslator, targetResourceId, targetResourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrIn(nodeTemplateId, getAttrFuncData);
+ }
+
+ }
+
+ @Override
+ public void addOutputParamGetAttrIn(FunctionTranslator functionTranslator, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(functionTranslator, targetResourceId, targetResourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ }
+ }
+
/**
* Add compute in consolidation data entity base on given keys.
*
@@ -130,6 +173,22 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
consolidationData.addGroupId(translatedGroupId);
}
+ public boolean isNumberOfComputeTypesLegal(String serviceTemplateName) {
+ return computeConsolidationData.isNumberOfComputeTypesLegal(serviceTemplateName);
+ }
+
+ private EntityConsolidationData getComputeTemplateConsolidationData(FunctionTranslator functionTranslator,
+ String resourceId, String computeNodeTemplateId) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
+ TranslationContext context = functionTranslator.getContext();
+ String heatFileName = functionTranslator.getHeatFileName();
+ String translatedId = context.getTranslatedIds().get(heatFileName).get(resourceId);
+ ServiceTemplate serviceTemplate = functionTranslator.getServiceTemplate();
+ String computeType = getNodeType(heatOrchestrationTemplate, resourceId, resourceId, translatedId);
+ return getComputeTemplateConsolidationData(
+ ToscaUtil.getServiceTemplateFileName(serviceTemplate), computeType, computeNodeTemplateId);
+ }
+
private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
TranslateTo translateTo, String computeNodeType, String computeNodeTemplateId) {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
@@ -140,25 +199,32 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
String serviceTemplateFileName, String computeNodeType, String computeNodeTemplateId) {
- return computeConsolidationData.addComputeTemplateConsolidationData(
- serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
+ return computeConsolidationData.addComputeTemplateConsolidationData(serviceTemplateFileName, computeNodeType,
+ computeNodeTemplateId);
}
- private String getNodeType(NodeTemplate computeNodeTemplate, TranslateTo translateTo,
- String targetResourceId, String nodeTemplateId) {
+ private String getNodeType(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String targetResourceId, String nodeTemplateId, String translatedId) {
+ return getNodeType(null, heatOrchestrationTemplate, targetResourceId,
+ nodeTemplateId, translatedId);
+ }
+ private String getNodeType(NodeTemplate computeNodeTemplate, HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String targetResourceId, String nodeTemplateId, String translatedId) {
if (Objects.isNull(computeNodeTemplate)) {
- Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
+ Resource targetResource = heatOrchestrationTemplate.getResources().get(targetResourceId);
NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(targetResource.getType());
- return nodeTypeNameExtractor.extractNodeTypeName(translateTo.getHeatOrchestrationTemplate()
- .getResources().get(nodeTemplateId), nodeTemplateId, nodeTemplateId);
+ return nodeTypeNameExtractor.extractNodeTypeName(heatOrchestrationTemplate.getResources()
+ .get(nodeTemplateId), nodeTemplateId, translatedId);
}
-
return computeNodeTemplate.getType();
}
- public boolean isNumberOfComputeTypesLegal(String serviceTemplateName) {
- return computeConsolidationData.isNumberOfComputeTypesLegal(serviceTemplateName);
+ private GetAttrFuncData createGetAttrFuncData(String propertyName, String attributeName) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(propertyName);
+ getAttrFuncData.setAttributeName(attributeName);
+ return getAttrFuncData;
}
} \ No newline at end of file
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/ConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataHandler.java
index bbd26342b1..ade5fd21f3 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataHandler.java
@@ -20,6 +20,7 @@ import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
public interface ConsolidationDataHandler {
@@ -51,4 +52,13 @@ public interface ConsolidationDataHandler {
HeatOrchestrationTemplate heatOrchestrationTemplate,
String paramName, String contrailSharedResourceId,
String sharedTranslatedResourceId);
+
+ void addNodesGetAttrOut(FunctionTranslator functionTranslator, String nodeTemplateId,
+ String resourceTranslatedId, String propertyName, String attributeName);
+
+ void addNodesGetAttrIn(FunctionTranslator functionTranslator,String nodeTemplateId,
+ String targetResourceId, String targetResourceTranslatedId, String propertyName, String attributeName);
+
+ void addOutputParamGetAttrIn(FunctionTranslator functionTranslator, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName);
}
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 3aaf47cae5..229e680bda 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
@@ -21,11 +21,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatResourceUtil;
-
public class FilePortConsolidationData {
//key - port node template id
@@ -68,6 +66,24 @@ public class FilePortConsolidationData {
}
/**
+ * If entity doesn't exist yet - create subInterface template consolidation data entity
+ * base on given parameters.
+ *
+ * @return subInterface template consolidation data entity
+ */
+ SubInterfaceTemplateConsolidationData addSubInterfaceTemplateConsolidationData(
+ Resource resource, String subInterfaceNodeTemplateId, String parentPortNodeTemplateId,
+ String parentPortResourceId, String parentPortResourceType) {
+
+ PortTemplateConsolidationData consolidationData =
+ addPortTemplateConsolidationData(parentPortNodeTemplateId, parentPortResourceId,
+ parentPortResourceType);
+
+ return consolidationData.addSubInterfaceTemplateConsolidationData(resource,
+ subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ }
+
+ /**
* If entity doesn't exist yet - create port template consolidation data and
* update it's network role according to given resource parameters.
*
@@ -84,18 +100,23 @@ public class FilePortConsolidationData {
return consolidationData;
}
+ /**
+ * If entity doesn't exist yet - create port template consolidation data and.
+ *
+ * @return port template consolidation data entity by given keys
+ */
private PortTemplateConsolidationData addPortTemplateConsolidationData(String portNodeTemplateId) {
PortTemplateConsolidationData consolidationData = getPortTemplateConsolidationData(portNodeTemplateId);
if (consolidationData == null) {
consolidationData = new PortTemplateConsolidationData();
+ consolidationData.setNodeTemplateId(portNodeTemplateId);
setPortTemplateConsolidationData(portNodeTemplateId, consolidationData);
}
return consolidationData;
}
-
- public PortTemplateConsolidationData createPortTemplateConsolidationData(String portNodeTemplateId,
- String portResourceId,
- String portResourceType) {
+
+ private PortTemplateConsolidationData createPortTemplateConsolidationData(String portNodeTemplateId,
+ String portResourceId, String portResourceType) {
PortTemplateConsolidationData consolidationData = new PortTemplateConsolidationData();
consolidationData.setNodeTemplateId(portNodeTemplateId);
Optional<String> portNetworkRole = HeatResourceUtil.evaluateNetworkRoleFromResourceId(portResourceId,
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/NestedConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
index ef1aefd124..62c0164d04 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/NestedConsolidationDataHandler.java
@@ -26,6 +26,8 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
+
public class NestedConsolidationDataHandler implements ConsolidationDataHandler {
@@ -51,14 +53,12 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
public void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
String dependentNodeTemplateId, String targetResourceId,
String requirementId, RequirementAssignment requirementAssignment) {
-
EntityConsolidationData entityConsolidationData =
getNestedTemplateConsolidationData(translateTo, translateTo.getHeatFileName(), dependentNodeTemplateId);
if (Objects.nonNull(entityConsolidationData)) {
entityConsolidationData.addNodesConnectedIn(sourceNodeTemplateId, requirementId, requirementAssignment);
}
-
}
@Override
@@ -73,23 +73,79 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
}
+ @Override
+ public void addNodesGetAttrOut(FunctionTranslator functionTranslator, String nodeTemplateId,
+ String resourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getNestedTemplateConsolidationData(functionTranslator,
+ functionTranslator.getHeatFileName(), resourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ }
+ }
+
+ @Override
+ public void addNodesGetAttrIn(FunctionTranslator functionTranslator,String nodeTemplateId, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getNestedTemplateConsolidationData(functionTranslator, functionTranslator.getHeatFileName(),
+ targetResourceId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrIn(nodeTemplateId, getAttrFuncData);
+ }
+ }
+
+ @Override
+ public void addOutputParamGetAttrIn(FunctionTranslator functionTranslator, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getNestedTemplateConsolidationData(functionTranslator, functionTranslator.getHeatFileName(),
+ targetResourceId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ }
+ }
+
/**
* Add nested consolidation data base on given parameters.
*/
public void addConsolidationData(String serviceTemplateFileName, TranslationContext context,
- String nestedHeatFileName, String nestedNodeTemplateId) {
+ String nestedHeatFileName, String nestedNodeTemplateId) {
getNestedTemplateConsolidationData(serviceTemplateFileName, context,
nestedHeatFileName, nestedNodeTemplateId);
}
+ private GetAttrFuncData createGetAttrFuncData(String propertyName, String attributeName) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(propertyName);
+ getAttrFuncData.setAttributeName(attributeName);
+ return getAttrFuncData;
+ }
+
+ private NestedTemplateConsolidationData getNestedTemplateConsolidationData(FunctionTranslator functionTranslator,
+ String nestedHeatFileName, String nestedNodeTemplateId) {
+ ServiceTemplate serviceTemplate = functionTranslator.getServiceTemplate();
+ TranslationContext context = functionTranslator.getContext();
+ return getNestedTemplateConsolidationData(ToscaUtil
+ .getServiceTemplateFileName(serviceTemplate), context, nestedHeatFileName, nestedNodeTemplateId);
+
+ }
+
private NestedTemplateConsolidationData getNestedTemplateConsolidationData(TranslateTo translateTo,
- String nestedHeatFileName,
- String nestedNodeTemplateId) {
+ String nestedHeatFileName, String nestedNodeTemplateId) {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
TranslationContext context = translateTo.getContext();
return getNestedTemplateConsolidationData(ToscaUtil
- .getServiceTemplateFileName(serviceTemplate), context, nestedHeatFileName, nestedNodeTemplateId);
-
+ .getServiceTemplateFileName(serviceTemplate), context, nestedHeatFileName, nestedNodeTemplateId);
}
private NestedTemplateConsolidationData getNestedTemplateConsolidationData(
@@ -105,8 +161,7 @@ public class NestedConsolidationDataHandler implements ConsolidationDataHandler
return null;
}
return nestedConsolidationData
- .addNestedTemplateConsolidationData(serviceTemplateFileName, nestedNodeTemplateId);
-
+ .addNestedTemplateConsolidationData(serviceTemplateFileName, nestedNodeTemplateId);
}
private boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String nestedNodeTemplateId,
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/PortConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
index ac07daad8f..f2673accf9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationData.java
@@ -69,6 +69,21 @@ public class PortConsolidationData {
resource, subInterfaceNodeTemplateId, parentPortNodeTemplateId);
}
+ /**
+ * Create subInterface template consolidation data base on given parameters - if it doesn't exist yet.
+ *
+ * @return port template consolidation data by given keys
+ */
+ SubInterfaceTemplateConsolidationData addSubInterfaceTemplateConsolidationData(
+ String serviceTemplateFileName, Resource resource,
+ String subInterfaceNodeTemplateId, String parentPortNodeTemplateId,
+ String parentPortResourceId, String parentPortResourceType) {
+ FilePortConsolidationData consolidationData = addFilePortConsolidationData(serviceTemplateFileName);
+ return consolidationData.addSubInterfaceTemplateConsolidationData(
+ resource, subInterfaceNodeTemplateId, parentPortNodeTemplateId,
+ parentPortResourceId, parentPortResourceType);
+ }
+
private FilePortConsolidationData addFilePortConsolidationData(String serviceTemplateFileName) {
FilePortConsolidationData consolidationData = getFilePortConsolidationData(serviceTemplateFileName);
if (consolidationData == null) {
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/PortConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
index 8b9e546280..c28c54c861 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataHandler.java
@@ -16,12 +16,14 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import java.util.Objects;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
public class PortConsolidationDataHandler implements ConsolidationDataHandler {
@@ -79,6 +81,61 @@ public class PortConsolidationDataHandler implements ConsolidationDataHandler {
serviceTemplateFileName, portResourceId, portResourceType, portNodeTemplateId);
}
+ @Override
+ public void addNodesGetAttrOut(FunctionTranslator functionTranslator, String nodeTemplateId,
+ String resourceTranslatedId, String propertyName, String attributeName) {
+
+ String resourceId = functionTranslator.getResourceId();
+ EntityConsolidationData entityConsolidationData =
+ getPortTemplateConsolidationData(functionTranslator, resourceId, resourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ }
+ }
+
+ @Override
+ public void addNodesGetAttrIn(FunctionTranslator functionTranslator,String nodeTemplateId,
+ String targetResourceId, String targetResourceTranslatedId, String propertyName, String attributeName) {
+ EntityConsolidationData entityConsolidationData =
+ getPortTemplateConsolidationData(functionTranslator, targetResourceId, targetResourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addNodesGetAttrIn(nodeTemplateId, getAttrFuncData);
+ }
+ }
+
+ @Override
+ public void addOutputParamGetAttrIn(FunctionTranslator functionTranslator, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ EntityConsolidationData entityConsolidationData =
+ getPortTemplateConsolidationData(functionTranslator, targetResourceId, targetResourceTranslatedId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ }
+ }
+
+ private GetAttrFuncData createGetAttrFuncData(String propertyName, String attributeName) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(propertyName);
+ getAttrFuncData.setAttributeName(attributeName);
+ return getAttrFuncData;
+ }
+
+ private EntityConsolidationData getPortTemplateConsolidationData(FunctionTranslator functionTranslator,
+ String targetResourceId, String targetResourceTranslatedId) {
+ HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
+ Resource resource = heatOrchestrationTemplate.getResources().get(targetResourceId);
+ ServiceTemplate serviceTemplate = functionTranslator.getServiceTemplate();
+ return getPortTemplateConsolidationData(ToscaUtil.getServiceTemplateFileName(serviceTemplate),
+ targetResourceId, resource.getType(), targetResourceTranslatedId);
+ }
+
private PortTemplateConsolidationData getPortTemplateConsolidationData(TranslateTo translateTo,
String portResourceId, String portResourceType, String portNodeTemplateId) {
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
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/SubInterfaceConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
index d5a91f177f..6dc44f9758 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
@@ -1,4 +1,5 @@
/*
+/*
* Copyright © 2016-2018 European Support Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +17,11 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+
+import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
@@ -26,6 +30,7 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHandler {
@@ -44,10 +49,8 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
getSubInterfaceTemplateConsolidationData(translateTo, translateTo.getTranslatedId());
- subInterfaceTemplateConsolidationData.ifPresent(
- consolidationData -> consolidationData.addNodesConnectedOut(nodeTemplateId,
- requirementId, requirementAssignment));
-
+ subInterfaceTemplateConsolidationData.ifPresent(consolidationData ->
+ consolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment));
}
}
@@ -64,24 +67,83 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceId);
- subInterfaceTemplateConsolidationData.ifPresent(
- consolidationData -> consolidationData.addNodesConnectedIn(sourceNodeTemplateId,
- requirementId, requirementAssignment));
+ subInterfaceTemplateConsolidationData.ifPresent(consolidationData ->
+ consolidationData.addNodesConnectedIn(sourceNodeTemplateId, requirementId, requirementAssignment));
}
@Override
public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
HeatOrchestrationTemplate heatOrchestrationTemplate,
- String paramName,
- String contrailSharedResourceId,
+ String paramName, String contrailSharedResourceId,
String sharedTranslatedResourceId) {
- throw new UnsupportedOperationException("API removeParamNameFromAttrFuncList "
- + "not supported for SubInterfaceConsolidationDataHandler");
+ throw new UnsupportedOperationException(
+ "API removeParamNameFromAttrFuncList " + "not supported for SubInterfaceConsolidationDataHandler");
+ }
+
+ @Override
+ public void addNodesGetAttrOut(FunctionTranslator functionTranslator, String nodeTemplateId,
+ String resourceTranslatedId, String propertyName, String attributeName) {
+ TranslateTo subInterfaceTo = createTranslateTo(functionTranslator, functionTranslator.getResourceId(),
+ resourceTranslatedId);
+
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData =
+ getSubInterfaceTemplateConsolidationData(subInterfaceTo, resourceTranslatedId);
+
+ subInterfaceConsolidationData.ifPresent(consolidationData -> {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ consolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ });
+ }
+
+ @Override
+ public void addNodesGetAttrIn(FunctionTranslator functionTranslator,String nodeTemplateId, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+
+ TranslateTo subInterfaceTo = createTranslateTo(functionTranslator, targetResourceId,
+ targetResourceTranslatedId);
+
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData =
+ getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceTranslatedId);
+
+ subInterfaceConsolidationData.ifPresent(consolidationData -> {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ consolidationData.addNodesGetAttrIn(nodeTemplateId, getAttrFuncData);
+ });
+ }
+
+ @Override
+ public void addOutputParamGetAttrIn(FunctionTranslator functionTranslator, String targetResourceId,
+ String targetResourceTranslatedId, String propertyName, String attributeName) {
+ TranslateTo subInterfaceTo = createTranslateTo(functionTranslator, targetResourceId,
+ targetResourceTranslatedId);
+
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceConsolidationData =
+ getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceTranslatedId);
+
+ subInterfaceConsolidationData.ifPresent(consolidationData -> {
+ GetAttrFuncData getAttrFuncData = createGetAttrFuncData(propertyName, attributeName);
+ consolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ });
+ }
+
+ public void setNetworkRole(TranslateTo translateTo, String translatedId, String networkRole) {
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ getSubInterfaceTemplateConsolidationData(translateTo, translatedId);
+
+ subInterfaceTemplateConsolidationData.ifPresent(
+ consolidationData -> consolidationData.setNetworkRole(networkRole));
+ }
+ public void setResourceGroupCount(TranslateTo translateTo, String translatedId,
+ Object resourceGroupCount) {
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ getSubInterfaceTemplateConsolidationData(translateTo, translatedId);
+ subInterfaceTemplateConsolidationData.ifPresent(
+ consolidationData -> consolidationData.setResourceGroupCount(resourceGroupCount));
}
private Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
@@ -92,12 +154,62 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
s, subInterfaceNodeTemplateId));
}
- private SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
- TranslateTo subInterfaceTo, String parentPortNodeTemplateId,String subInterfaceNodeTemplateId) {
+ private SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(TranslateTo subInterfaceTo,
+ String parentPortNodeTemplateId, String subInterfaceNodeTemplateId) {
String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
Resource resource = subInterfaceTo.getResource();
- return portConsolidationData.addSubInterfaceTemplateConsolidationData(
- serviceTemplateFileName, resource, subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ Optional<String> portResourceId = getPortResourceId(subInterfaceTo, parentPortNodeTemplateId);
+
+ if (portResourceId.isPresent()) {
+ String portResourceType = getPortResourceType(subInterfaceTo, portResourceId.get());
+ return portConsolidationData
+ .addSubInterfaceTemplateConsolidationData(serviceTemplateFileName, resource,
+ subInterfaceNodeTemplateId, parentPortNodeTemplateId,
+ portResourceId.get(), portResourceType);
+ } else {
+ return portConsolidationData
+ .addSubInterfaceTemplateConsolidationData(serviceTemplateFileName, resource,
+ subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ }
+ }
+
+ private String getPortResourceType(TranslateTo subInterfaceTo, String portResourceId) {
+ return HeatToToscaUtil.getResourceType(portResourceId, subInterfaceTo
+ .getHeatOrchestrationTemplate(), subInterfaceTo.getHeatFileName());
}
+ private Optional<String> getPortResourceId(TranslateTo subInterfaceTo, String parentPortNodeTemplateId) {
+ Map<String, String> resourceIdTranslatedResourceIdMap =
+ subInterfaceTo.getContext().getTranslatedIds().get(subInterfaceTo.getHeatFileName());
+ return getSubInterfaceParentPortResourceId(parentPortNodeTemplateId,
+ resourceIdTranslatedResourceIdMap);
+ }
+
+ private Optional<String> getSubInterfaceParentPortResourceId(String parentPortNodeTemplateId,
+ Map<String, String> resourceIdTranslatedResourceIdMap) {
+ if (MapUtils.isEmpty(resourceIdTranslatedResourceIdMap)) {
+ return Optional.empty();
+ }
+ for (Map.Entry<String, String> entry : resourceIdTranslatedResourceIdMap.entrySet()) {
+ if (entry.getValue().equals(parentPortNodeTemplateId)) {
+ return Optional.of(entry.getKey());
+ }
+ }
+ return Optional.empty();
+ }
+
+ private TranslateTo createTranslateTo(FunctionTranslator functionTranslator, String resourceId,
+ String resourceTranslatedId) {
+ Resource resource = functionTranslator.getHeatOrchestrationTemplate().getResources().get(resourceId);
+ return new TranslateTo(ToscaUtil.getServiceTemplateFileName(functionTranslator.getServiceTemplate()),
+ functionTranslator.getServiceTemplate(), functionTranslator.getHeatOrchestrationTemplate(),
+ resource, resourceId, resourceTranslatedId, functionTranslator.getContext());
+ }
+
+ private GetAttrFuncData createGetAttrFuncData(String propertyName, String attributeName) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(propertyName);
+ getAttrFuncData.setAttributeName(attributeName);
+ return getAttrFuncData;
+ }
}
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 b766f30388..01e601738b 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
@@ -18,7 +18,6 @@ package org.openecomp.sdc.translator.services.heattotosca;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
import org.apache.commons.collections4.MapUtils;
@@ -26,7 +25,6 @@ import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
@@ -34,29 +32,17 @@ import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationDataHandler;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationDataHandler;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.EntityConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FileComputeConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FileNestedConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.FilePortConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.GetAttrFuncData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.NestedTemplateConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.PortConsolidationData;
-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.datatypes.heattotosca.unifiedmodel.consolidation.TypeComputeConsolidationData;
-import org.openecomp.sdc.translator.services.heattotosca.errors.DuplicateResourceIdsInDifferentFilesErrorBuilder;
+import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator;
+import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR;
/**
* Utility class for consolidation data collection helper methods.
*/
-public class ConsolidationDataUtil {
+ public class ConsolidationDataUtil {
private static final String UNDERSCORE = "_";
private static final String DIGIT_REGEX = "\\d+";
@@ -65,223 +51,13 @@ public class ConsolidationDataUtil {
// prevent instantiation of utility class
}
- /**
- * Gets compute template consolidation data.
- *
- * @param context the translation context
- * @param serviceTemplate the service template
- * @param computeNodeType the compute node type
- * @param computeNodeTemplateId the compute node template id
- * @return the compute template consolidation data
- */
- public static ComputeTemplateConsolidationData getComputeTemplateConsolidationData(TranslationContext context,
- ServiceTemplate serviceTemplate, String computeNodeType, String computeNodeTemplateId) {
-
- ConsolidationData consolidationData = context.getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
-
- ComputeConsolidationData computeConsolidationData = consolidationData.getComputeConsolidationData();
-
- FileComputeConsolidationData fileComputeConsolidationData =
- computeConsolidationData.getFileComputeConsolidationData(serviceTemplateFileName);
-
- if (fileComputeConsolidationData == null) {
- fileComputeConsolidationData = new FileComputeConsolidationData();
- computeConsolidationData.setFileComputeConsolidationData(serviceTemplateFileName,
- fileComputeConsolidationData);
- }
-
- TypeComputeConsolidationData typeComputeConsolidationData =
- fileComputeConsolidationData.getTypeComputeConsolidationData(computeNodeType);
- if (typeComputeConsolidationData == null) {
- typeComputeConsolidationData = new TypeComputeConsolidationData();
- fileComputeConsolidationData.setTypeComputeConsolidationData(computeNodeType,
- typeComputeConsolidationData);
- }
-
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- typeComputeConsolidationData.getComputeTemplateConsolidationData(computeNodeTemplateId);
- if (computeTemplateConsolidationData == null) {
- computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
- computeTemplateConsolidationData.setNodeTemplateId(computeNodeTemplateId);
- typeComputeConsolidationData.setComputeTemplateConsolidationData(computeNodeTemplateId,
- computeTemplateConsolidationData);
- }
-
- return computeTemplateConsolidationData;
- }
-
-
- /**
- * Gets port template consolidation data.
- *
- * @param context the context
- * @param serviceTemplate the service template
- * @param portNodeTemplateId the port node template id
- * @return the port template consolidation data
- */
- public static PortTemplateConsolidationData getPortTemplateConsolidationData(TranslationContext context,
- ServiceTemplate serviceTemplate,
- String portResourceId,
- String portResourceType,
- String portNodeTemplateId) {
-
- ConsolidationData consolidationData = context.getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
-
- PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData();
-
- FilePortConsolidationData filePortConsolidationData =
- portConsolidationData.getFilePortConsolidationData(serviceTemplateFileName);
-
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
- }
-
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = filePortConsolidationData
- .createPortTemplateConsolidationData(portNodeTemplateId, portResourceId, portResourceType);
- filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId,
- portTemplateConsolidationData);
- }
-
- return portTemplateConsolidationData;
- }
-
- public static Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
- TranslateTo subInterfaceTo, String subInterfaceNodeTemplateId) {
-
- Optional<String> parentPortNodeTemplateId =
- HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
-
- return parentPortNodeTemplateId.map(s -> getSubInterfaceTemplateConsolidationData(subInterfaceTo,
- s, subInterfaceNodeTemplateId));
-
- }
-
- private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
- TranslateTo subInterfaceTo, String parentPortNodeTemplateId, String subInterfaceNodeTemplateId) {
-
- ConsolidationData consolidationData = subInterfaceTo.getContext().getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
-
- PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData();
-
- FilePortConsolidationData filePortConsolidationData =
- portConsolidationData.getFilePortConsolidationData(serviceTemplateFileName);
-
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
- }
-
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- Optional<String> portResourceId = getSubInterfaceParentPortResourceId(parentPortNodeTemplateId,
- subInterfaceTo);
- if (portResourceId.isPresent()) {
- portTemplateConsolidationData = filePortConsolidationData.createPortTemplateConsolidationData(
- parentPortNodeTemplateId, portResourceId.get(),
- HeatToToscaUtil.getResourceType(portResourceId.get(), subInterfaceTo
- .getHeatOrchestrationTemplate(), subInterfaceTo.getHeatFileName()));
- } else {
- portTemplateConsolidationData = new PortTemplateConsolidationData();
- portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId);
- }
- filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId,
- portTemplateConsolidationData);
- }
- return portTemplateConsolidationData.addSubInterfaceTemplateConsolidationData(
- subInterfaceTo.getResource(), subInterfaceNodeTemplateId, parentPortNodeTemplateId);
- }
-
- private static Optional<String> getSubInterfaceParentPortResourceId(String parentPortNodeTemplateId,
- TranslateTo subInterfaceTo) {
- Map<String, String> resourceIdTranslatedResourceIdMap =
- subInterfaceTo.getContext().getTranslatedIds().get(subInterfaceTo.getHeatFileName());
- if (MapUtils.isEmpty(resourceIdTranslatedResourceIdMap)) {
- return Optional.empty();
- }
- for (Map.Entry<String, String> entry : resourceIdTranslatedResourceIdMap.entrySet()) {
- if (entry.getValue().equals(parentPortNodeTemplateId)) {
- return Optional.of(entry.getKey());
- }
- }
- return Optional.empty();
- }
-
- /**
- * Gets nested template consolidation data.
- *
- * @param context the context
- * @param serviceTemplate the service template
- * @param nestedNodeTemplateId the nested node template id @return the nested template
- * consolidation data
- */
- public static NestedTemplateConsolidationData getNestedTemplateConsolidationData(TranslationContext context,
- ServiceTemplate serviceTemplate, String nestedHeatFileName, String nestedNodeTemplateId) {
-
- if (isNestedResourceIdOccursInDifferentNestedFiles(context, nestedHeatFileName,
- nestedNodeTemplateId)) {
- throw new CoreException(new DuplicateResourceIdsInDifferentFilesErrorBuilder(nestedNodeTemplateId).build());
- }
-
- if (isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(
- nestedNodeTemplateId, nestedHeatFileName, context)) {
- return null;
- }
-
- ConsolidationData consolidationData = context.getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
-
- NestedConsolidationData nestedConsolidationData = consolidationData
- .getNestedConsolidationData();
-
- FileNestedConsolidationData fileNestedConsolidationData =
- nestedConsolidationData.getFileNestedConsolidationData(serviceTemplateFileName);
-
- if (fileNestedConsolidationData == null) {
- fileNestedConsolidationData = new FileNestedConsolidationData();
- nestedConsolidationData.setFileNestedConsolidationData(serviceTemplateFileName,
- fileNestedConsolidationData);
- }
-
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- fileNestedConsolidationData.getNestedTemplateConsolidationData(nestedNodeTemplateId);
- if (nestedTemplateConsolidationData == null) {
- nestedTemplateConsolidationData = new NestedTemplateConsolidationData();
- nestedTemplateConsolidationData.setNodeTemplateId(nestedNodeTemplateId);
- fileNestedConsolidationData.setNestedTemplateConsolidationData(nestedNodeTemplateId,
- nestedTemplateConsolidationData);
- }
-
- return nestedTemplateConsolidationData;
- }
-
- public static boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String
- nestedNodeTemplateId,
- String nestedHeatFileName,
- TranslationContext context) {
-
+ public static boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(
+ String nestedNodeTemplateId, String nestedHeatFileName, TranslationContext context) {
return context.isServiceTemplateWithoutNodeTemplatesSection(
FileUtils.getFileWithoutExtention(nestedHeatFileName))
|| context.isNodeTemplateIdPointsToStWithoutNodeTemplates(nestedNodeTemplateId);
}
- private static boolean isNestedResourceIdOccursInDifferentNestedFiles(TranslationContext context,
- String nestedHeatFileName,
- String nestedNodeTemplateId) {
- return Objects.nonNull(nestedHeatFileName)
- && context.getAllTranslatedResourceIdsFromDiffNestedFiles(nestedHeatFileName)
- .contains(nestedNodeTemplateId);
- }
-
/**
* Update volume information in consolidation data.
*
@@ -406,7 +182,6 @@ public class ConsolidationDataUtil {
String requirementId,
RequirementAssignment requirementAssignment) {
-
TranslationContext translationContext = translateTo.getContext();
Optional<ConsolidationDataHandler> consolidationDataHandler =
translationContext.getConsolidationDataHandler(consolidationEntityType);
@@ -574,47 +349,75 @@ public class ConsolidationDataUtil {
paramName, contrailSharedResourceId, sharedTranslatedResourceId));
}
+ public static void updateNodeGetAttributeIn(FunctionTranslator functionTranslator, String resourceTranslatedId,
+ String targetResourceId, String targetResourceTranslatedId, String attributeName) {
- private static Optional<ConsolidationDataHandler> getConsolidationDataHandler(
- HeatOrchestrationTemplate heatOrchestrationTemplate, TranslationContext context,
- String contrailSharedResourceId) {
- Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
- ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER;
- consolidationEntityType.setEntityType(resource, resource, context);
- return context.getConsolidationDataHandler(consolidationEntityType.getSourceEntityType());
+ if (functionTranslator == null || functionTranslator.getServiceTemplate() == null) {
+ return;
+ }
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ ConsolidationDataUtil.getConsolidationDataHandler(functionTranslator.getHeatOrchestrationTemplate(),
+ functionTranslator.getContext(), targetResourceId);
+
+ consolidationDataHandler.ifPresent(handler -> handler.addNodesGetAttrIn(functionTranslator,
+ resourceTranslatedId, targetResourceId, targetResourceTranslatedId,
+ getToscaPropertyName(functionTranslator), attributeName));
}
- public static void updateNodeGetAttributeIn(EntityConsolidationData entityConsolidationData,
- String nodeTemplateId, String propertyName,
- String attributeName) {
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
- getAttrFuncData.setFieldName(propertyName);
- getAttrFuncData.setAttributeName(attributeName);
- entityConsolidationData.addNodesGetAttrIn(nodeTemplateId, getAttrFuncData);
+ public static void updateNodeGetAttributeOut(FunctionTranslator functionTranslator,
+ String targetTranslatedResourceId, String resourceTranslatedId, String attrName) {
+
+ if (functionTranslator == null || functionTranslator.getServiceTemplate() == null) {
+ return;
+ }
+
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ ConsolidationDataUtil.getConsolidationDataHandler(functionTranslator.getHeatOrchestrationTemplate(),
+ functionTranslator.getContext(), functionTranslator.getResourceId());
+ consolidationDataHandler.ifPresent(handler -> handler.addNodesGetAttrOut(functionTranslator,
+ targetTranslatedResourceId, resourceTranslatedId, getToscaPropertyName(functionTranslator), attrName));
}
- public static void updateNodeGetAttributeOut(EntityConsolidationData entityConsolidationData,
- String nodeTemplateId, String propertyName,
- String attributeName) {
+ public static void updateOutputParamGetAttrIn(FunctionTranslator functionTranslator,
+ String targetResourceId, String targetResourceTranslatedId, String propertyName, String attrName) {
+ if (functionTranslator == null || functionTranslator.getServiceTemplate() == null) {
+ return;
+ }
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
- getAttrFuncData.setFieldName(propertyName);
- getAttrFuncData.setAttributeName(attributeName);
- entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ ConsolidationDataUtil.getConsolidationDataHandler(functionTranslator.getHeatOrchestrationTemplate(),
+ functionTranslator.getContext(), targetResourceId);
+ consolidationDataHandler.ifPresent(handler -> handler.addOutputParamGetAttrIn(functionTranslator,
+ targetResourceId, targetResourceTranslatedId, propertyName, attrName));
}
- public static void updateOutputGetAttributeInConsolidationData(EntityConsolidationData
- entityConsolidationData,
- String outputParameterName,
- String attributeName) {
-
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
- getAttrFuncData.setFieldName(outputParameterName);
- getAttrFuncData.setAttributeName(attributeName);
- entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ private static Optional<ConsolidationDataHandler> getConsolidationDataHandler(
+ HeatOrchestrationTemplate heatOrchestrationTemplate, TranslationContext context,
+ String contrailSharedResourceId) {
+ Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
+ ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER;
+ consolidationEntityType.setEntityType(resource, resource, context);
+ return context.getConsolidationDataHandler(consolidationEntityType.getSourceEntityType());
+ }
+ private static String getToscaPropertyName(FunctionTranslator functionTranslator) {
+ String toscaPropertyName = functionTranslator.getPropertyName();
+ HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
+ Resource resource = heatOrchestrationTemplate.getResources().get(functionTranslator.getResourceId());
+ boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
+ if (!isNestedResource) {
+ String heatPropertyName = toscaPropertyName;
+ //For handling get_attr in inner levels for complex properties
+ if (toscaPropertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
+ heatPropertyName =
+ toscaPropertyName.substring(0, toscaPropertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
+ }
+ toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(),
+ resource.getType(), heatPropertyName);
+ }
+ return toscaPropertyName;
}
public static boolean isComputeReferenceToPortId(ComputeTemplateConsolidationData compute,
@@ -622,6 +425,7 @@ public class ConsolidationDataUtil {
if (MapUtils.isEmpty(compute.getPorts())) {
return false;
}
+
for (List<String> portIdsPerType : compute.getPorts().values()) {
if (portIdsPerType.contains(portId)) {
return true;
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
index f533353d18..d8f3cebf01 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
@@ -28,22 +28,17 @@ import java.util.Optional;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
import org.openecomp.sdc.heat.services.HeatConstants;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
-import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.EntityConsolidationData;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslation;
import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
-import org.openecomp.sdc.translator.services.heattotosca.NameExtractor;
import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationBase;
public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
@@ -90,7 +85,6 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
String targetResourceId,
String targetResourceTranslatedId,
List<Object> toscaAttList) {
-
Optional<String> resourceTranslatedId;
String resourceId = functionTranslator.getResourceId();
String resourceTranslatedIdValue = null;
@@ -103,8 +97,8 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
resourceTranslatedIdValue, toscaAttList);
}
}
- handleGetAttrInConsolidationData(functionTranslator, resourceTranslatedIdValue, targetResourceId,
- targetResourceTranslatedId, toscaAttList);
+ handleGetAttrInConsolidationData(functionTranslator, resourceTranslatedIdValue,
+ targetResourceId, targetResourceTranslatedId, toscaAttList);
}
private static void handleGetAttrOutConsolidationData(FunctionTranslator functionTranslator,
@@ -114,13 +108,11 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
if (functionTranslator.getServiceTemplate() == null) {
return;
}
- Optional<EntityConsolidationData> entityConsolidationData = getEntityConsolidationData(functionTranslator,
- functionTranslator.getResourceId(), resourceTranslatedId);
- if (entityConsolidationData.isPresent()) {
- String attName = (String) toscaAttList.get(0);
- handleNodeGetAttrOut(targetTranslatedResourceId, functionTranslator, entityConsolidationData.get(),
- attName);
- }
+
+ String attName = (String) toscaAttList.get(0);
+ ConsolidationDataUtil.updateNodeGetAttributeOut(functionTranslator, targetTranslatedResourceId,
+ resourceTranslatedId, attName);
+
}
private static void handleGetAttrInConsolidationData(FunctionTranslator functionTranslator,
@@ -131,91 +123,14 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
if (functionTranslator.getServiceTemplate() == null) {
return;
}
- Optional<EntityConsolidationData> entityConsolidationData = getEntityConsolidationData(functionTranslator,
- targetResourceId, targetResourceTranslatedId);
- if (!entityConsolidationData.isPresent()) {
- return;
- }
String attName = (String) toscaAttList.get(0);
if (Objects.nonNull(resourceTranslatedId)) {
- handleNodeGetAttrIn(resourceTranslatedId, functionTranslator, entityConsolidationData.get(), attName);
+ ConsolidationDataUtil.updateNodeGetAttributeIn(functionTranslator, resourceTranslatedId,
+ targetResourceId, targetResourceTranslatedId, attName);
} else {
- ConsolidationDataUtil.updateOutputGetAttributeInConsolidationData(entityConsolidationData.get(),
- functionTranslator.getPropertyName(), attName);
- }
- }
-
- private static void handleNodeGetAttrOut(String nodeTemplateId, FunctionTranslator functionTranslator,
- EntityConsolidationData entityConsolidationData,
- String attName) {
- Resource resource = functionTranslator.getHeatOrchestrationTemplate().getResources().get(functionTranslator
- .getResourceId());
- boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
- String toscaPropertyName = functionTranslator.getPropertyName();
- if (!isNestedResource) {
- toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), resource
- .getType(), functionTranslator.getPropertyName());
- }
- ConsolidationDataUtil.updateNodeGetAttributeOut(entityConsolidationData, nodeTemplateId, toscaPropertyName,
- attName);
- }
-
- private static void handleNodeGetAttrIn(String nodeTemplateId, FunctionTranslator functionTranslator,
- EntityConsolidationData entityConsolidationData,
- String attName) {
- Resource resource = functionTranslator.getHeatOrchestrationTemplate().getResources().get(functionTranslator
- .getResourceId());
- boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
- String propertyName = functionTranslator.getPropertyName();
- String heatPropertyName = propertyName;
- String toscaPropertyName = propertyName;
- //For handling get_attr in inner levels for complex properties
- if (propertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
- heatPropertyName = propertyName.substring(0, propertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
- }
- if (!isNestedResource) {
- toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), resource
- .getType(), heatPropertyName);
+ ConsolidationDataUtil.updateOutputParamGetAttrIn(functionTranslator, targetResourceId,
+ targetResourceTranslatedId, functionTranslator.getPropertyName(), attName);
}
- ConsolidationDataUtil.updateNodeGetAttributeIn(entityConsolidationData, nodeTemplateId, toscaPropertyName,
- attName);
- }
-
- private static Optional<EntityConsolidationData> getEntityConsolidationData(FunctionTranslator functionTranslator,
- String resourceId,
- String resourceTranslatedId) {
- HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
- TranslationContext context = functionTranslator.getContext();
- ServiceTemplate serviceTemplate = functionTranslator.getServiceTemplate();
- String heatFileName = functionTranslator.getHeatFileName();
-
- Resource resource = heatOrchestrationTemplate.getResources().get(resourceId);
- if (ConsolidationDataUtil.isComputeResource(heatOrchestrationTemplate, resourceId)) {
- String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
- NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(resourceType);
- String computeType = nodeTypeNameExtractor.extractNodeTypeName(resource, resourceId, context
- .getTranslatedIds().get(heatFileName).get(resourceId));
-
- return Optional.of(ConsolidationDataUtil.getComputeTemplateConsolidationData(context, serviceTemplate,
- computeType, resourceTranslatedId));
- } else if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate, resourceId)) {
- return Optional.of(ConsolidationDataUtil
- .getPortTemplateConsolidationData(context, serviceTemplate, resourceId, resource.getType(),
- resourceTranslatedId));
- } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) {
- TranslateTo subInterfaceTo = new TranslateTo(heatFileName, serviceTemplate, heatOrchestrationTemplate,
- resource, resourceId, resourceTranslatedId, context);
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(subInterfaceTo,
- resourceTranslatedId);
- if (subInterfaceTemplateConsolidationData.isPresent()) {
- return Optional.of(subInterfaceTemplateConsolidationData.get());
- }
- } else if (HeatToToscaUtil.isNestedResource(resource)) {
- return Optional.ofNullable(ConsolidationDataUtil
- .getNestedTemplateConsolidationData(context, serviceTemplate, heatFileName, resourceTranslatedId));
- }
- return Optional.empty();
}
private static Optional<List<Object>> handleAttributeIndexOrKey(FunctionTranslator functionTranslator,
@@ -390,6 +305,4 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
}
return returnValue;
}
-
-
}
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 a42e4c3366..2cd4c3a227 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
@@ -40,7 +40,7 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceTemplateConsolidationData;
+import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.SubInterfaceConsolidationDataHandler;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
@@ -115,17 +115,18 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase {
private void populateSubInterfaceTemplateConsolidationData(TranslateTo translateTo,
NodeTemplate nodeTemplate) {
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- ConsolidationDataUtil.getSubInterfaceTemplateConsolidationData(translateTo, translateTo
- .getTranslatedId());
- if (!subInterfaceTemplateConsolidationData.isPresent()) {
- return;
- }
+ SubInterfaceConsolidationDataHandler consolidationDataHandler =
+ translateTo.getContext().getSubInterfaceConsolidationDataHandler();
+
+ String translatedId = translateTo.getTranslatedId();
Optional<String> subInterfaceNetworkRole =
HeatToToscaUtil.getNetworkRoleFromSubInterfaceId(translateTo.getResource(), translateTo.getContext());
- subInterfaceNetworkRole.ifPresent(subInterfaceTemplateConsolidationData.get()::setNetworkRole);
- subInterfaceTemplateConsolidationData.get()
- .setResourceGroupCount(getSubInterfaceCountFromResourceProperties(translateTo));
+ subInterfaceNetworkRole.ifPresent(networkRole -> consolidationDataHandler.setNetworkRole(translateTo,
+ translatedId, networkRole));
+
+ consolidationDataHandler.setResourceGroupCount(translateTo, translatedId,
+ getSubInterfaceCountFromResourceProperties(translateTo));
+
if (CollectionUtils.isEmpty(nodeTemplate.getRequirements())) {
return;
}
@@ -134,8 +135,9 @@ public class ResourceTranslationNestedImpl extends ResourceTranslationBase {
requirementMap.entrySet().stream()
.filter(requirementAssignmentEntry -> ToscaCapabilityType.NATIVE_NETWORK_LINKABLE
.equals(requirementAssignmentEntry.getValue().getCapability()))
- .forEach(requirementAssignmentEntry -> subInterfaceTemplateConsolidationData.get()
- .addNodesConnectedOut(requirementAssignmentEntry.getValue().getNode(),
+ .forEach(requirementAssignmentEntry ->
+ consolidationDataHandler.addNodesConnectedOut(translateTo,
+ requirementAssignmentEntry.getValue().getNode(),
requirementAssignmentEntry.getKey(),
requirementAssignmentEntry.getValue())
)