summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.java138
-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/ConsolidationData.java210
-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.java54
-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/EntityConsolidationData.java492
-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.java138
-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.java98
-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.java122
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java1134
8 files changed, 1463 insertions, 923 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/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
new file mode 100644
index 0000000000..cc27dd9806
--- /dev/null
+++ 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
@@ -0,0 +1,138 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Objects;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+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.DataModelUtil;
+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;
+
+public class ComputeConsolidationDataHandler implements ConsolidationDataHandler {
+
+ private final ComputeConsolidationData computeConsolidationData;
+
+ ComputeConsolidationDataHandler(ComputeConsolidationData computeConsolidationData) {
+ this.computeConsolidationData = computeConsolidationData;
+ }
+
+ @Override
+ public void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+ String translatedSourceNodeId = translateTo.getTranslatedId();
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ NodeTemplate computeNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, translatedSourceNodeId);
+ String nodeType = computeNodeTemplate.getType();
+
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(translateTo, nodeType, translatedSourceNodeId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ entityConsolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment);
+ }
+ }
+
+ @Override
+ public void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
+ String dependentNodeTemplateId, String targetResourceId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, dependentNodeTemplateId);
+ String nodeType = getNodeType(nodeTemplate, translateTo, targetResourceId, dependentNodeTemplateId);
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(translateTo, nodeType, dependentNodeTemplateId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ entityConsolidationData.addNodesConnectedIn(sourceNodeTemplateId, requirementId, requirementAssignment);
+ }
+ }
+
+ @Override
+ public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate, String paramName, String contrailSharedResourceId,
+ String sharedTranslatedResourceId) {
+
+ NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, sharedTranslatedResourceId);
+ EntityConsolidationData entityConsolidationData =
+ getComputeTemplateConsolidationData(serviceTemplate, nodeTemplate.getType(),
+ sharedTranslatedResourceId);
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ entityConsolidationData.removeParamNameFromAttrFuncList(paramName);
+ }
+ }
+
+ private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
+ TranslateTo translateTo, String computeNodeType, String computeNodeTemplateId) {
+
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ return getComputeTemplateConsolidationData(serviceTemplate, computeNodeType, computeNodeTemplateId);
+ }
+
+ private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(ServiceTemplate serviceTemplate,
+ String computeNodeType, String computeNodeTemplateId) {
+
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+
+ 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;
+ }
+
+ private String getNodeType(NodeTemplate computeNodeTemplate, TranslateTo translateTo, String targetResourceId,
+ String nodeTemplateId) {
+
+ if (Objects.isNull(computeNodeTemplate)) {
+ Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
+ NameExtractor nodeTypeNameExtractor = TranslationContext.getNameExtractorImpl(targetResource.getType());
+ return nodeTypeNameExtractor.extractNodeTypeName(translateTo.getHeatOrchestrationTemplate()
+ .getResources().get(nodeTemplateId), nodeTemplateId, nodeTemplateId);
+ }
+
+ return computeNodeTemplate.getType();
+ }
+} \ 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/ConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
index 20cc3be3cd..c46e7450e5 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationData.java
@@ -1,81 +1,139 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
-/**
- * The type Consolidation data.
- */
+import java.util.Optional;
+import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType;
+
public class ConsolidationData {
- //Compute consolidation data
- private ComputeConsolidationData computeConsolidationData;
-
- //Port Consolidation data
- private PortConsolidationData portConsolidationData;
-
- //Nested Consolidation data
- private NestedConsolidationData nestedConsolidationData;
-
-
- /**
- * Instantiates a new Consolidation data.
- */
- public ConsolidationData() {
- computeConsolidationData = new ComputeConsolidationData();
- portConsolidationData = new PortConsolidationData();
- nestedConsolidationData = new NestedConsolidationData();
- }
-
- /**
- * Gets compute consolidation data.
- *
- * @return the compute consolidation data
- */
- public ComputeConsolidationData getComputeConsolidationData() {
- return computeConsolidationData;
- }
-
- /**
- * Sets compute consolidation data.
- *
- * @param computeConsolidationData the compute consolidation data
- */
- public void setComputeConsolidationData(ComputeConsolidationData computeConsolidationData) {
- this.computeConsolidationData = computeConsolidationData;
- }
-
- /**
- * Gets port consolidation data.
- *
- * @return the port consolidation data
- */
- public PortConsolidationData getPortConsolidationData() {
- return portConsolidationData;
- }
-
- /**
- * Sets port consolidation data.
- *
- * @param portConsolidationData the port consolidation data
- */
- public void setPortConsolidationData(
- PortConsolidationData portConsolidationData) {
- this.portConsolidationData = portConsolidationData;
- }
-
- /**
- * Gets nested consolidation data.
- *
- * @return the nested consolidation data
- */
- public NestedConsolidationData getNestedConsolidationData() {
- return nestedConsolidationData;
- }
-
- /**
- * Sets nested consolidation data.
- *
- * @param nestedConsolidationData the nested consolidation data
- */
- public void setNestedConsolidationData(NestedConsolidationData nestedConsolidationData) {
- this.nestedConsolidationData = nestedConsolidationData;
- }
+ private ComputeConsolidationData computeConsolidationData;
+ private final ComputeConsolidationDataHandler computeConsolidationDataHandler;
+
+ private PortConsolidationData portConsolidationData;
+ private final PortConsolidationDataHandler portConsolidationDataHandler;
+ private final SubInterfaceConsolidationDataHandler subInterfaceConsolidationDataHandler;
+
+ private NestedConsolidationData nestedConsolidationData;
+ private final NestedConsolidationDataHandler nestedConsolidationDataHandler;
+
+ public ConsolidationData() {
+
+ computeConsolidationData = new ComputeConsolidationData();
+ computeConsolidationDataHandler = new ComputeConsolidationDataHandler(computeConsolidationData);
+
+ portConsolidationData = new PortConsolidationData();
+ portConsolidationDataHandler = new PortConsolidationDataHandler(portConsolidationData);
+ subInterfaceConsolidationDataHandler = new SubInterfaceConsolidationDataHandler(portConsolidationData);
+
+ nestedConsolidationData = new NestedConsolidationData();
+ nestedConsolidationDataHandler = new NestedConsolidationDataHandler(nestedConsolidationData);
+
+ }
+
+ /**
+ * Get Consolidation data handler by entity type.
+ *
+ * @return If there is no consolidation handler for a type, return an empty {@link Optional}.
+ */
+ public Optional<ConsolidationDataHandler> getConsolidationDataHandler(ConsolidationEntityType type) {
+
+ switch (type) {
+ case COMPUTE:
+ return Optional.of(getComputeConsolidationDataHelper());
+ case PORT:
+ return Optional.of(getPortConsolidationDataHandler());
+ case SUB_INTERFACE:
+ return Optional.of(getSubInterfaceConsolidationDataHandler());
+ case NESTED:
+ case VFC_NESTED:
+ return Optional.of(getNestedConsolidationDataHandler());
+ default:
+ return Optional.empty();
+ }
+ }
+
+ public ComputeConsolidationDataHandler getComputeConsolidationDataHelper() {
+ return computeConsolidationDataHandler;
+ }
+
+ public PortConsolidationDataHandler getPortConsolidationDataHandler() {
+ return portConsolidationDataHandler;
+ }
+
+ public NestedConsolidationDataHandler getNestedConsolidationDataHandler() {
+ return nestedConsolidationDataHandler;
+ }
+
+ public SubInterfaceConsolidationDataHandler getSubInterfaceConsolidationDataHandler() {
+ return subInterfaceConsolidationDataHandler;
+ }
+
+ /**
+ * Gets compute consolidation data.
+ *
+ * @return the compute consolidation data
+ */
+ public ComputeConsolidationData getComputeConsolidationData() {
+ return computeConsolidationData;
+ }
+
+ /**
+ * Sets compute consolidation data.
+ *
+ * @param computeConsolidationData the compute consolidation data
+ */
+ public void setComputeConsolidationData(ComputeConsolidationData computeConsolidationData) {
+ this.computeConsolidationData = computeConsolidationData;
+ }
+
+ /**
+ * Gets port consolidation data.
+ *
+ * @return the port consolidation data
+ */
+ public PortConsolidationData getPortConsolidationData() {
+ return portConsolidationData;
+ }
+
+ /**
+ * Sets port consolidation data.
+ *
+ * @param portConsolidationData the port consolidation data
+ */
+ public void setPortConsolidationData(PortConsolidationData portConsolidationData) {
+ this.portConsolidationData = portConsolidationData;
+ }
+
+ /**
+ * Gets nested consolidation data.
+ *
+ * @return the nested consolidation data
+ */
+ public NestedConsolidationData getNestedConsolidationData() {
+ return nestedConsolidationData;
+ }
+
+ /**
+ * Sets nested consolidation data.
+ *
+ * @param nestedConsolidationData the nested consolidation data
+ */
+ public void setNestedConsolidationData(NestedConsolidationData nestedConsolidationData) {
+ this.nestedConsolidationData = nestedConsolidationData;
+ }
}
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
new file mode 100644
index 0000000000..bbd26342b1
--- /dev/null
+++ 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
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+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;
+
+public interface ConsolidationDataHandler {
+
+ /**
+ * Add node connected out from current consolidation entity.
+ *
+ * @param nodeTemplateId the node template id of target node - node connected out from current node
+ * @param requirementId the requirement id of requirement assignment
+ * @param requirementAssignment the requirement assignment data connected to target node
+ */
+ void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId,
+ String requirementId, RequirementAssignment requirementAssignment);
+
+ /**
+ * Add source node connected in to target node consolidation entity.
+ *
+ * @param sourceNodeTemplateId the node template id of source node connected to consolidation entity
+ * @param targetNodeTemplateId the node template id of consolidation entity node
+ * @param targetResourceId the resource id of consolidation entity node
+ * @param requirementId the requirement id of source node
+ * @param requirementAssignment the requirement assignment data of source node
+ */
+ void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
+ String targetNodeTemplateId,
+ String targetResourceId, String requirementId,
+ RequirementAssignment requirementAssignment);
+
+ void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String paramName, String contrailSharedResourceId,
+ String sharedTranslatedResourceId);
+}
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/EntityConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
index 0b4b454adf..06b1a58718 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
@@ -1,245 +1,275 @@
-package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
/**
* The type Entity consolidation data.
*/
public class EntityConsolidationData {
- private String nodeTemplateId;
-
- //groups that point to this entity node template
- private List<String> groupIds;
-
- // key - node template id which has connection to this entity
- // value - List of Requirement assignment data which connect to this entity
- private Map<String, List<RequirementAssignmentData>> nodesConnectedIn;
-
- // key - node template id which connected from this entity
- // List of Requirement assignment data which connect to the key node template id
- private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
-
- //key - node template id which include get attribute function from this entity
- //key - node template id which include get attribute function from this entity
- //value - List of getAttr data
- private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
-
- //key - node template id which is pointed by this entity using get attribute function
- //value - List of getAttr data
- private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
-
- //List of getAttr data
- private List<GetAttrFuncData> outputParametersGetAttrIn;
-
- /**
- * Gets node template id.
- *
- * @return the node template id
- */
- public String getNodeTemplateId() {
- return nodeTemplateId;
- }
-
- /**
- * Sets node template id.
- *
- * @param nodeTemplateId the node template id
- */
- public void setNodeTemplateId(String nodeTemplateId) {
- this.nodeTemplateId = nodeTemplateId;
- }
-
- /**
- * Gets group ids point to me.
- *
- * @return the group ids point to me
- */
- public List<String> getGroupIds() {
- return groupIds;
- }
-
- /**
- * Sets group ids point to me.
- *
- * @param groupIds the group ids point to me
- */
- public void setGroupIds(List<String> groupIds) {
- this.groupIds = groupIds;
- }
-
-
- /**
- * Sets node connected to me.
- *
- * @param nodesConnectedIn the node connected to me
- */
- public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
- this.nodesConnectedIn = nodesConnectedIn;
- }
-
- /**
- * Add nodeConnectedIn.
- *
- * @param nodeTemplateId the node template id which has connection to me
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
- public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
+ private String nodeTemplateId;
+
+ //groups that point to this entity node template
+ private List<String> groupIds;
+
+ // key - node template id which has connection to this entity
+ // value - List of Requirement assignment data which connect to this entity
+ private Map<String, List<RequirementAssignmentData>> nodesConnectedIn;
+
+ // key - node template id which connected from this entity
+ // List of Requirement assignment data which connect to the key node template id
+ private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
+
+ //key - node template id which include get attribute function from this entity
+ //key - node template id which include get attribute function from this entity
+ //value - List of getAttr data
+ private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
+
+ //key - node template id which is pointed by this entity using get attribute function
+ //value - List of getAttr data
+ private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
+
+ //List of getAttr data
+ private List<GetAttrFuncData> outputParametersGetAttrIn;
+
+ /**
+ * Gets node template id.
+ *
+ * @return the node template id
+ */
+ public String getNodeTemplateId() {
+ return nodeTemplateId;
+ }
+
+ /**
+ * Sets node template id.
+ *
+ * @param nodeTemplateId the node template id
+ */
+ public void setNodeTemplateId(String nodeTemplateId) {
+ this.nodeTemplateId = nodeTemplateId;
+ }
+
+ /**
+ * Gets group ids point to me.
+ *
+ * @return the group ids point to me
+ */
+ public List<String> getGroupIds() {
+ return groupIds;
+ }
+
+ /**
+ * Sets group ids point to me.
+ *
+ * @param groupIds the group ids point to me
+ */
+ public void setGroupIds(List<String> groupIds) {
+ this.groupIds = groupIds;
+ }
+
+
+ /**
+ * Sets node connected to me.
+ *
+ * @param nodesConnectedIn the node connected to me
+ */
+ public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
+ this.nodesConnectedIn = nodesConnectedIn;
+ }
+
+ /**
+ * Add nodeConnectedIn.
+ *
+ * @param nodeTemplateId the node template id which has connection to me
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
+ public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
RequirementAssignment requirementAssignment) {
- if (this.nodesConnectedIn == null) {
- this.nodesConnectedIn = new HashMap<>();
- }
- this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
- this.nodesConnectedIn.get(nodeTemplateId).add(new RequirementAssignmentData(requirementId,
- requirementAssignment));
- }
-
- /**
- * Gets node connected to me.
- *
- * @return the node connected to me
- */
- public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
- return nodesConnectedIn;
- }
-
-
- /**
- * Gets node connected from me.
- *
- * @return the node connected from me
- */
- public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
- return nodesConnectedOut;
- }
-
- /**
- * Sets node connected from me.
- *
- * @param nodesConnectedOut the node connected from me
- */
- public void setNodesConnectedOut(
- Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
- this.nodesConnectedOut = nodesConnectedOut;
- }
-
- /**
- * Add nodeConnectedOut.
- *
- * @param nodeTemplateId the node template id which is connected from me
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
- public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
- RequirementAssignment
- requirementAssignment) {
- if (this.nodesConnectedOut == null) {
- this.nodesConnectedOut = new HashMap<>();
- }
- this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
- this.nodesConnectedOut.get(nodeTemplateId).add(new RequirementAssignmentData(requirementId,
- requirementAssignment));
- }
-
- /**
- * Gets nodes get attr in.
- *
- * @return the get attr in
- */
- public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
- return nodesGetAttrIn;
- }
-
- /**
- * Sets nodes get attr in.
- *
- * @param nodesGetAttrIn the get attr in
- */
- public void setNodesGetAttrIn(
- Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
- this.nodesGetAttrIn = nodesGetAttrIn;
- }
-
- /**
- * Add nodes get attr in data.
- *
- * @param nodeTemplateId the node template id
- * @param getAttrFuncData get attr data
- */
- public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
- if (nodesGetAttrIn == null) {
- nodesGetAttrIn = new HashMap<>();
- }
- this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
- this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
- }
-
- /**
- * Gets output parameters get attr from me.
- *
- * @return the get attr from me
- */
- public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
- return outputParametersGetAttrIn;
- }
-
- /**
- * Sets output parameters get attr from me.
- *
- * @param outputParametersGetAttrIn the output parameters get attr from me
- */
- public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
- this.outputParametersGetAttrIn = outputParametersGetAttrIn;
- }
-
- /**
- * Add output parameters get attr data.
- *
- * @param getAttrFuncData get attr data
- */
- public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
- if (outputParametersGetAttrIn == null) {
- outputParametersGetAttrIn = new ArrayList<>();
- }
- this.outputParametersGetAttrIn.add(getAttrFuncData);
- }
-
- /**
- * Gets nodes get attr out.
- *
- * @return the get attr out
- */
- public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
- return nodesGetAttrOut;
- }
-
- /**
- * Sets nodes get attr out.
- *
- * @param nodesGetAttrOut the get attr out
- */
- public void setNodesGetAttrOut(
- Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
- this.nodesGetAttrOut = nodesGetAttrOut;
- }
-
- /**
- * Add nodes get attr out data.
- *
- * @param nodeTemplateId the node template id
- * @param getAttrFuncData get attr data
- */
- public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
- if (nodesGetAttrOut == null) {
- nodesGetAttrOut = new HashMap<>();
- }
- this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
- this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
- }
+
+ if (this.nodesConnectedIn == null) {
+ this.nodesConnectedIn = new HashMap<>();
+ }
+
+ this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
+ this.nodesConnectedIn.get(nodeTemplateId).add(
+ new RequirementAssignmentData(requirementId, requirementAssignment));
+ }
+
+ /**
+ * Gets node connected to me.
+ *
+ * @return the node connected to me
+ */
+ public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
+ return nodesConnectedIn;
+ }
+
+
+ /**
+ * Gets node connected from me.
+ *
+ * @return the node connected from me
+ */
+ public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
+ return nodesConnectedOut;
+ }
+
+ /**
+ * Sets node connected from me.
+ *
+ * @param nodesConnectedOut the node connected from me
+ */
+ public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
+ this.nodesConnectedOut = nodesConnectedOut;
+ }
+
+ /**
+ * Add nodeConnectedOut.
+ *
+ * @param nodeTemplateId the node template id which is connected from me
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
+ public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+ if (this.nodesConnectedOut == null) {
+ this.nodesConnectedOut = new HashMap<>();
+ }
+
+ this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
+ this.nodesConnectedOut.get(nodeTemplateId).add(
+ new RequirementAssignmentData(requirementId, requirementAssignment));
+ }
+
+ /**
+ * Gets nodes get attr in.
+ *
+ * @return the get attr in
+ */
+ public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
+ return nodesGetAttrIn;
+ }
+
+ /**
+ * Sets nodes get attr in.
+ *
+ * @param nodesGetAttrIn the get attr in
+ */
+ public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
+ this.nodesGetAttrIn = nodesGetAttrIn;
+ }
+
+ /**
+ * Add nodes get attr in data.
+ *
+ * @param nodeTemplateId the node template id
+ * @param getAttrFuncData get attr data
+ */
+ public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
+
+ if (nodesGetAttrIn == null) {
+ nodesGetAttrIn = new HashMap<>();
+ }
+
+ this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
+ this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
+ }
+
+ /**
+ * Gets output parameters get attr from me.
+ *
+ * @return the get attr from me
+ */
+ public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
+ return outputParametersGetAttrIn;
+ }
+
+ /**
+ * Sets output parameters get attr from me.
+ *
+ * @param outputParametersGetAttrIn the output parameters get attr from me
+ */
+ public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
+ this.outputParametersGetAttrIn = outputParametersGetAttrIn;
+ }
+
+ /**
+ * Add output parameters get attr data.
+ *
+ * @param getAttrFuncData get attr data
+ */
+ public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
+
+ if (outputParametersGetAttrIn == null) {
+ outputParametersGetAttrIn = new ArrayList<>();
+ }
+
+ this.outputParametersGetAttrIn.add(getAttrFuncData);
+ }
+
+ /**
+ * Gets nodes get attr out.
+ *
+ * @return the get attr out
+ */
+ public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
+ return nodesGetAttrOut;
+ }
+
+ /**
+ * Sets nodes get attr out.
+ *
+ * @param nodesGetAttrOut the get attr out
+ */
+ public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
+ this.nodesGetAttrOut = nodesGetAttrOut;
+ }
+
+ /**
+ * Add nodes get attr out data.
+ *
+ * @param nodeTemplateId the node template id
+ * @param getAttrFuncData get attr data
+ */
+ public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
+
+ if (nodesGetAttrOut == null) {
+ nodesGetAttrOut = new HashMap<>();
+ }
+
+ this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
+ this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
+ }
+
+ public void removeParamNameFromAttrFuncList(String paramName) {
+
+ if (outputParametersGetAttrIn == null) {
+ return;
+ }
+
+ outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName()));
+ }
}
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
new file mode 100644
index 0000000000..f7c877074d
--- /dev/null
+++ 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
@@ -0,0 +1,138 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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.core.utilities.file.FileUtils;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+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;
+
+public class NestedConsolidationDataHandler implements ConsolidationDataHandler {
+
+ private final NestedConsolidationData nestedConsolidationData;
+
+ public NestedConsolidationDataHandler(NestedConsolidationData nestedConsolidationData) {
+ this.nestedConsolidationData = nestedConsolidationData;
+ }
+
+ @Override
+ public void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+ EntityConsolidationData entityConsolidationData =
+ getNestedTemplateConsolidationData(translateTo, translateTo.getHeatFileName(),
+ translateTo.getTranslatedId());
+
+ if (Objects.nonNull(entityConsolidationData)) {
+ entityConsolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment);
+ }
+ }
+
+ @Override
+ 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
+ public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String paramName,
+ String contrailSharedResourceId,
+ String sharedTranslatedResourceId) {
+
+ throw new UnsupportedOperationException(
+ "API removeParamNameFromAttrFuncList not supported for NestedConsolidationDataHandler");
+
+ }
+
+ private NestedTemplateConsolidationData getNestedTemplateConsolidationData(TranslateTo translateTo,
+ String nestedHeatFileName,
+ String nestedNodeTemplateId) {
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ TranslationContext context = translateTo.getContext();
+ return getNestedTemplateConsolidationData(serviceTemplate, context, nestedHeatFileName, nestedNodeTemplateId);
+ }
+
+ private NestedTemplateConsolidationData getNestedTemplateConsolidationData(
+ ServiceTemplate serviceTemplate, TranslationContext context,
+ String nestedHeatFileName, String nestedNodeTemplateId) {
+
+
+ if (isNestedResourceIdOccursInDifferentNestedFiles(context, nestedHeatFileName,
+ nestedNodeTemplateId)) {
+ throw new CoreException(new
+ DuplicateResourceIdsInDifferentFilesErrorBuilder(
+ nestedNodeTemplateId).build());
+ }
+
+ if (isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(
+ nestedNodeTemplateId, nestedHeatFileName, context)) {
+ return null;
+ }
+
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ 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;
+ }
+
+ private boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String nestedNodeTemplateId,
+ String nestedHeatFileName,
+ TranslationContext context) {
+
+ return context.isServiceTemplateWithoutNodeTemplatesSection(
+ FileUtils.getFileWithoutExtention(nestedHeatFileName))
+ || context.isNodeTemplateIdPointsToStWithoutNodeTemplates(nestedNodeTemplateId);
+ }
+
+ private boolean isNestedResourceIdOccursInDifferentNestedFiles(TranslationContext context,
+ String nestedHeatFileName,
+ String nestedNodeTemplateId) {
+ return Objects.nonNull(nestedHeatFileName) && context.getAllTranslatedResourceIdsFromDiffNestedFiles(
+ nestedHeatFileName).contains(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/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
new file mode 100644
index 0000000000..2da1f7e0fa
--- /dev/null
+++ 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
@@ -0,0 +1,98 @@
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Optional;
+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.HeatToToscaUtil;
+
+public class PortConsolidationDataHandler implements ConsolidationDataHandler {
+
+ private final PortConsolidationData portConsolidationData;
+
+ public PortConsolidationDataHandler(PortConsolidationData portConsolidationData) {
+ this.portConsolidationData = portConsolidationData;
+ }
+
+ @Override
+ public void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+ EntityConsolidationData entityConsolidationData =
+ getPortTemplateConsolidationData(translateTo, translateTo.getResourceId(),
+ translateTo.getResource().getType(), translateTo.getTranslatedId());
+
+ entityConsolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment);
+
+ }
+
+ @Override
+ public void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
+ String dependentNodeTemplateId, String targetResourceId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+ EntityConsolidationData entityConsolidationData =
+ getPortTemplateConsolidationData(translateTo, translateTo.getResourceId(),
+ translateTo.getResource().getType(), dependentNodeTemplateId);
+
+ entityConsolidationData.addNodesConnectedIn(sourceNodeTemplateId, requirementId, requirementAssignment);
+
+ }
+
+ @Override
+ public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate, String paramName, String contrailSharedResourceId,
+ String sharedTranslatedResourceId) {
+
+ Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
+ EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(serviceTemplate,
+ contrailSharedResourceId, resource.getType(), sharedTranslatedResourceId);
+ entityConsolidationData.removeParamNameFromAttrFuncList(paramName);
+
+ }
+
+ private PortTemplateConsolidationData getPortTemplateConsolidationData(TranslateTo translateTo,
+ String portResourceId, String portResourceType, String portNodeTemplateId) {
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ return getPortTemplateConsolidationData(serviceTemplate, portResourceId, portResourceType, portNodeTemplateId);
+ }
+
+ private PortTemplateConsolidationData getPortTemplateConsolidationData(ServiceTemplate serviceTemplate,
+ String portResourceId, String portResourceType, String portNodeTemplateId) {
+
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ FilePortConsolidationData filePortConsolidationData = portConsolidationData
+ .getFilePortConsolidationData(serviceTemplateFileName);
+
+ if (filePortConsolidationData == null) {
+ filePortConsolidationData = new FilePortConsolidationData();
+ portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
+ filePortConsolidationData);
+ }
+
+ PortTemplateConsolidationData portTemplateConsolidationData =
+ filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId);
+ if (portTemplateConsolidationData == null) {
+ portTemplateConsolidationData = getInitPortTemplateConsolidationData(portNodeTemplateId,
+ portResourceId, portResourceType);
+ filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId,
+ portTemplateConsolidationData);
+ }
+
+ 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;
+ }
+}
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
new file mode 100644
index 0000000000..ddc770bac7
--- /dev/null
+++ 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
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+import java.util.Objects;
+import java.util.Optional;
+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.TranslationContext;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
+
+public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHandler {
+
+ private final PortConsolidationData portConsolidationData;
+
+ SubInterfaceConsolidationDataHandler(PortConsolidationData portConsolidationData) {
+ this.portConsolidationData = portConsolidationData;
+ }
+
+ @Override
+ public void addNodesConnectedOut(TranslateTo translateTo, String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ if (Objects.nonNull(
+ serviceTemplate.getTopology_template().getNode_templates().get(translateTo.getTranslatedId()))) {
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ getSubInterfaceTemplateConsolidationData(translateTo, translateTo.getTranslatedId());
+
+ subInterfaceTemplateConsolidationData.ifPresent(
+ consolidationData -> consolidationData.addNodesConnectedOut(nodeTemplateId,
+ requirementId, requirementAssignment));
+
+ }
+ }
+
+ @Override
+ public void addNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
+ String dependentNodeTemplateId, String targetResourceId,
+ String requirementId, RequirementAssignment requirementAssignment) {
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ TranslationContext translationContext = translateTo.getContext();
+ Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
+ TranslateTo subInterfaceTo = new TranslateTo(translateTo.getHeatFileName(), serviceTemplate,
+ translateTo.getHeatOrchestrationTemplate(), targetResource,
+ targetResourceId, null, translationContext);
+ Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
+ getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceId);
+
+ subInterfaceTemplateConsolidationData.ifPresent(
+ consolidationData -> consolidationData.addNodesConnectedIn(sourceNodeTemplateId,
+ requirementId, requirementAssignment));
+
+ }
+
+ @Override
+ public void removeParamNameFromAttrFuncList(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String paramName,
+ String contrailSharedResourceId,
+ String sharedTranslatedResourceId) {
+
+
+ throw new UnsupportedOperationException(
+ "API removeParamNameFromAttrFuncList not supported for SubInterfaceConsolidationDataHandler");
+
+ }
+
+ private Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
+ TranslateTo subInterfaceTo, String subInterfaceNodeTemplateId) {
+
+ Optional<String> parentPortNodeTemplateId =
+ HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
+ return parentPortNodeTemplateId.map(s -> getSubInterfaceTemplateConsolidationData(subInterfaceTo, s,
+ subInterfaceNodeTemplateId));
+
+ }
+
+ private SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(TranslateTo subInterfaceTo,
+ String parentPortNodeTemplateId, String subInterfaceNodeTemplateId) {
+
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
+ FilePortConsolidationData filePortConsolidationData =
+ portConsolidationData.getFilePortConsolidationData(serviceTemplateFileName);
+
+ if (filePortConsolidationData == null) {
+ filePortConsolidationData = new FilePortConsolidationData();
+ portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
+ filePortConsolidationData);
+ }
+
+ PortTemplateConsolidationData portTemplateConsolidationData =
+ filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId);
+ if (portTemplateConsolidationData == null) {
+ portTemplateConsolidationData = new PortTemplateConsolidationData();
+ portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId);
+ filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId,
+ portTemplateConsolidationData);
+ }
+
+ return portTemplateConsolidationData.getSubInterfaceResourceTemplateConsolidationData(
+ subInterfaceTo.getResource(), subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+ }
+
+}
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 34fccc05fe..be282082ff 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
@@ -16,24 +16,28 @@
package org.openecomp.sdc.translator.services.heattotosca;
+import java.util.ArrayList;
+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;
+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;
import org.openecomp.sdc.heat.datatypes.model.Resource;
-import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
-import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.sdc.tosca.services.DataModelUtil;
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.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;
@@ -43,694 +47,592 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolida
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.RequirementAssignmentData;
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 java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-
/**
* Utility class for consolidation data collection helper methods.
*/
public class ConsolidationDataUtil {
- private static final String UNDERSCORE = "_";
- private static final String DIGIT_REGEX = "\\d+";
-
- private ConsolidationDataUtil() {
- }
-
- /**
- * 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);
- }
+ private static final String UNDERSCORE = "_";
+ private static final String DIGIT_REGEX = "\\d+";
- TypeComputeConsolidationData typeComputeConsolidationData = fileComputeConsolidationData
- .getTypeComputeConsolidationData(computeNodeType);
- if (typeComputeConsolidationData == null) {
- typeComputeConsolidationData = new TypeComputeConsolidationData();
- fileComputeConsolidationData.setTypeComputeConsolidationData(computeNodeType,
- typeComputeConsolidationData);
+ private ConsolidationDataUtil() {
+ // prevent instantiation of utility class
}
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- typeComputeConsolidationData.getComputeTemplateConsolidationData(computeNodeTemplateId);
- if (computeTemplateConsolidationData == null) {
- computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
- computeTemplateConsolidationData.setNodeTemplateId(computeNodeTemplateId);
- typeComputeConsolidationData.setComputeTemplateConsolidationData(computeNodeTemplateId,
- computeTemplateConsolidationData);
+ /**
+ * 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;
}
- 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) {
+ /**
+ * 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 = getInitPortTemplateConsolidationData(portNodeTemplateId,
+ portResourceId, portResourceType);
+ filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId,
+ portTemplateConsolidationData);
+ }
+
+ return portTemplateConsolidationData;
+ }
- ConsolidationData consolidationData = context.getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
+ 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;
+ }
- PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData();
- FilePortConsolidationData filePortConsolidationData = portConsolidationData
- .getFilePortConsolidationData(serviceTemplateFileName);
+ public static Optional<SubInterfaceTemplateConsolidationData> getSubInterfaceTemplateConsolidationData(
+ TranslateTo subInterfaceTo, String subInterfaceNodeTemplateId) {
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
+ Optional<String> parentPortNodeTemplateId =
+ HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
+ if (parentPortNodeTemplateId.isPresent()) {
+ return Optional.ofNullable(getSubInterfaceTemplateConsolidationData(subInterfaceTo,
+ parentPortNodeTemplateId.get(), subInterfaceNodeTemplateId));
+ }
+ return Optional.empty();
}
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(portNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = getInitPortTemplateConsolidationData(portNodeTemplateId,
- portResourceId, portResourceType);
- filePortConsolidationData.setPortTemplateConsolidationData(portNodeTemplateId, portTemplateConsolidationData);
- }
+ private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
+ TranslateTo subInterfaceTo, String parentPortNodeTemplateId, String subInterfaceNodeTemplateId) {
- 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) {
- Optional<String> parentPortNodeTemplateId =
- HeatToToscaUtil.getSubInterfaceParentPortNodeTemplateId(subInterfaceTo);
- if (parentPortNodeTemplateId.isPresent()) {
- return Optional.ofNullable(getSubInterfaceTemplateConsolidationData(subInterfaceTo,
- parentPortNodeTemplateId.get(), subInterfaceNodeTemplateId));
- }
- return Optional.empty();
- }
+ ConsolidationData consolidationData = subInterfaceTo.getContext().getConsolidationData();
+ String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
- private static SubInterfaceTemplateConsolidationData getSubInterfaceTemplateConsolidationData(
- TranslateTo subInterfaceTo,
- String parentPortNodeTemplateId,
- String subInterfaceNodeTemplateId) {
+ PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData();
- ConsolidationData consolidationData = subInterfaceTo.getContext().getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(subInterfaceTo.getServiceTemplate());
+ FilePortConsolidationData filePortConsolidationData =
+ portConsolidationData.getFilePortConsolidationData(serviceTemplateFileName);
- PortConsolidationData portConsolidationData = consolidationData.getPortConsolidationData();
+ if (filePortConsolidationData == null) {
+ filePortConsolidationData = new FilePortConsolidationData();
+ portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
+ filePortConsolidationData);
+ }
- FilePortConsolidationData filePortConsolidationData = portConsolidationData
- .getFilePortConsolidationData(serviceTemplateFileName);
+ PortTemplateConsolidationData portTemplateConsolidationData =
+ filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId);
+ if (portTemplateConsolidationData == null) {
+ portTemplateConsolidationData = new PortTemplateConsolidationData();
+ portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId);
+ filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId,
+ portTemplateConsolidationData);
+ }
- if (filePortConsolidationData == null) {
- filePortConsolidationData = new FilePortConsolidationData();
- portConsolidationData.setFilePortConsolidationData(serviceTemplateFileName,
- filePortConsolidationData);
+ return portTemplateConsolidationData.getSubInterfaceResourceTemplateConsolidationData(
+ subInterfaceTo.getResource(), subInterfaceNodeTemplateId, parentPortNodeTemplateId);
}
- PortTemplateConsolidationData portTemplateConsolidationData =
- filePortConsolidationData.getPortTemplateConsolidationData(parentPortNodeTemplateId);
- if (portTemplateConsolidationData == null) {
- portTemplateConsolidationData = new PortTemplateConsolidationData();
- portTemplateConsolidationData.setNodeTemplateId(parentPortNodeTemplateId);
- filePortConsolidationData.setPortTemplateConsolidationData(parentPortNodeTemplateId,
- portTemplateConsolidationData);
+ /**
+ * 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;
}
- return portTemplateConsolidationData.getSubInterfaceResourceTemplateConsolidationData(subInterfaceTo.getResource(),
- subInterfaceNodeTemplateId, parentPortNodeTemplateId);
- }
-
- /**
- * 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 (isNestedResourceIdOccuresInDifferentNestedFiles(context, nestedHeatFileName,
- nestedNodeTemplateId)) {
- throw new CoreException(
- new DuplicateResourceIdsInDifferentFilesErrorBuilder(nestedNodeTemplateId).build());
- }
+ public static boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String
+ nestedNodeTemplateId,
+ String nestedHeatFileName,
+ TranslationContext context) {
- if (isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(
- nestedNodeTemplateId, nestedHeatFileName, context)) {
- return null;
+ return context.isServiceTemplateWithoutNodeTemplatesSection(
+ FileUtils.getFileWithoutExtention(nestedHeatFileName))
+ || context.isNodeTemplateIdPointsToStWithoutNodeTemplates(nestedNodeTemplateId);
}
- ConsolidationData consolidationData = context.getConsolidationData();
- String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
-
- NestedConsolidationData nestedConsolidationData = consolidationData
- .getNestedConsolidationData();
-
- FileNestedConsolidationData fileNestedConsolidationData = nestedConsolidationData
- .getFileNestedConsolidationData(serviceTemplateFileName);
+ private static boolean isNestedResourceIdOccursInDifferentNestedFiles(TranslationContext context,
+ String nestedHeatFileName,
+ String nestedNodeTemplateId) {
+ return Objects.nonNull(nestedHeatFileName)
+ && context.getAllTranslatedResourceIdsFromDiffNestedFiles(nestedHeatFileName)
+ .contains(nestedNodeTemplateId);
+ }
- if (fileNestedConsolidationData == null) {
- fileNestedConsolidationData = new FileNestedConsolidationData();
- nestedConsolidationData.setFileNestedConsolidationData(serviceTemplateFileName,
- fileNestedConsolidationData);
+ /**
+ * Update group id information in consolidation data.
+ *
+ * @param entityConsolidationData Entity consolidation data (Port/Compute)
+ * @param translatedGroupId Group id of which compute node is a part
+ */
+ public static void updateGroupIdInConsolidationData(EntityConsolidationData
+ entityConsolidationData,
+ String translatedGroupId) {
+ if (entityConsolidationData.getGroupIds() == null) {
+ entityConsolidationData.setGroupIds(new ArrayList<>());
+ }
+ entityConsolidationData.getGroupIds().add(translatedGroupId);
}
- NestedTemplateConsolidationData nestedTemplateConsolidationData =
- fileNestedConsolidationData.getNestedTemplateConsolidationData(nestedNodeTemplateId);
- if (nestedTemplateConsolidationData == null) {
- nestedTemplateConsolidationData = new NestedTemplateConsolidationData();
- nestedTemplateConsolidationData.setNodeTemplateId(nestedNodeTemplateId);
- fileNestedConsolidationData.setNestedTemplateConsolidationData(nestedNodeTemplateId,
- nestedTemplateConsolidationData);
+ /**
+ * Update volume information in consolidation data.
+ *
+ * @param translateTo {@link TranslateTo} object
+ * @param computeType Local type of the compute node
+ * @param computeNodeTemplateId Node template id of the compute node
+ * @param requirementAssignment RequirementAssignment object
+ */
+ public static void updateComputeConsolidationDataVolumes(TranslateTo translateTo,
+ String computeType,
+ String computeNodeTemplateId,
+ String requirementId,
+ RequirementAssignment
+ requirementAssignment) {
+ TranslationContext translationContext = translateTo.getContext();
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ ComputeTemplateConsolidationData computeTemplateConsolidationData =
+ getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeType,
+ computeNodeTemplateId);
+ computeTemplateConsolidationData.addVolume(requirementId, requirementAssignment);
}
- return nestedTemplateConsolidationData;
- }
- public static boolean isNodeTemplatePointsToServiceTemplateWithoutNodeTemplates(String
- nestedNodeTemplateId,
- String nestedHeatFileName,
- TranslationContext context) {
-
- return context.isServiceTemplateWithoutNodeTemplatesSection(
- FileUtils.getFileWithoutExtention(nestedHeatFileName))
- || context.isNodeTemplateIdPointsToStWithoutNodeTemplates(nestedNodeTemplateId);
- }
-
- private static boolean isNestedResourceIdOccuresInDifferentNestedFiles(TranslationContext context,
- String nestedHeatFileName,
- String nestedNodeTemplateId) {
- return Objects.nonNull(nestedHeatFileName)
- && context.getAllTranslatedResourceIdsFromDiffNestedFiles(nestedHeatFileName)
- .contains(nestedNodeTemplateId);
- }
-
- /**
- * Update group id information in consolidation data.
- *
- * @param entityConsolidationData Entity consolidation data (Port/Compute)
- * @param translatedGroupId Group id of which compute node is a part
- */
- public static void updateGroupIdInConsolidationData(EntityConsolidationData
- entityConsolidationData,
- String translatedGroupId) {
- if (entityConsolidationData.getGroupIds() == null) {
- entityConsolidationData.setGroupIds(new ArrayList<>());
+ /**
+ * Update port in consolidation data.
+ *
+ * @param translateTo the translate to
+ * @param computeNodeType the compute node type
+ * @param portResourceId the port resource id
+ * @param portNodeTemplateId the port node template id
+ */
+ public static void updatePortInConsolidationData(TranslateTo translateTo,
+ String computeNodeType,
+ String portResourceId,
+ String portResourceType,
+ String portNodeTemplateId) {
+ TranslationContext translationContext = translateTo.getContext();
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ ComputeTemplateConsolidationData computeTemplateConsolidationData =
+ getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeNodeType,
+ translateTo.getTranslatedId());
+ computeTemplateConsolidationData.addPort(getPortType(portNodeTemplateId), portNodeTemplateId);
+ // create port in consolidation data
+ getPortTemplateConsolidationData(translationContext, serviceTemplate, portResourceId,
+ portResourceType, portNodeTemplateId);
}
- entityConsolidationData.getGroupIds().add(translatedGroupId);
- }
-
- /**
- * Update volume information in consolidation data.
- *
- * @param translateTo {@link TranslateTo} object
- * @param computeType Local type of the compute node
- * @param computeNodeTemplateId Node template id of the compute node
- * @param requirementAssignment RequirementAssignment object
- */
- public static void updateComputeConsolidationDataVolumes(TranslateTo translateTo,
- String computeType,
- String computeNodeTemplateId,
- String requirementId,
- RequirementAssignment
- requirementAssignment) {
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeType,
- computeNodeTemplateId);
- computeTemplateConsolidationData.addVolume(requirementId, requirementAssignment);
- }
-
-
- /**
- * Update port in consolidation data.
- *
- * @param translateTo the translate to
- * @param computeNodeType the compute node type
- * @param portResourceId the port resource id
- * @param portNodeTemplateId the port node template id
- */
- public static void updatePortInConsolidationData(TranslateTo translateTo,
- String computeNodeType,
- String portResourceId,
- String portResourceType,
- String portNodeTemplateId) {
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeNodeType,
- translateTo.getTranslatedId());
- computeTemplateConsolidationData.addPort(getPortType(portNodeTemplateId), portNodeTemplateId);
- // create port in consolidation data
- getPortTemplateConsolidationData(translationContext, serviceTemplate, portResourceId,
- portResourceType, portNodeTemplateId);
- }
-
- /**
- * Update nodes connected in and out for Depends on and connectivity in consolidation data.
- *
- * @param translateTo the translate to
- * @param targetResourceId the target resource id
- * @param nodeTemplateId the source node template id
- * @param requirementAssignment the requirement assignment
- */
- public static void updateNodesConnectedData(TranslateTo translateTo, String targetResourceId,
- Resource targetResource, Resource sourceResource,
- String nodeTemplateId, String requirementId,
- RequirementAssignment requirementAssignment) {
- ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER;
- consolidationEntityType.setEntityType(sourceResource, targetResource, translateTo.getContext());
- // Add resource dependency information in nodesConnectedIn if the target node
- // is a consolidation entity
- if (isConsolidationEntity(consolidationEntityType.getTargetEntityType())) {
- ConsolidationDataUtil.updateNodesConnectedIn(translateTo,
- nodeTemplateId, consolidationEntityType.getTargetEntityType(), targetResourceId,
- requirementId, requirementAssignment);
+
+ /**
+ * Update nodes connected in and out for Depends on and connectivity in consolidation data.
+ *
+ * @param translateTo the translate to
+ * @param targetResourceId the target resource id
+ * @param nodeTemplateId the source node template id
+ * @param requirementAssignment the requirement assignment
+ */
+ public static void updateNodesConnectedData(TranslateTo translateTo, String targetResourceId,
+ Resource targetResource, Resource sourceResource,
+ String nodeTemplateId, String requirementId,
+ RequirementAssignment requirementAssignment) {
+ ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER;
+ consolidationEntityType.setEntityType(sourceResource, targetResource, translateTo.getContext());
+ // Add resource dependency information in nodesConnectedIn if the target node
+ // is a consolidation entity
+ if (isConsolidationEntity(consolidationEntityType.getTargetEntityType())) {
+ ConsolidationDataUtil.updateNodesConnectedIn(translateTo,
+ nodeTemplateId, consolidationEntityType.getTargetEntityType(), targetResourceId,
+ requirementId, requirementAssignment);
+ }
+
+ //Add resource dependency information in nodesConnectedOut if the source node
+ //is a consolidation entity
+ if (isConsolidationEntity(consolidationEntityType.getSourceEntityType())) {
+ ConsolidationDataUtil.updateNodesConnectedOut(translateTo,
+ requirementAssignment.getNode(), consolidationEntityType.getSourceEntityType(),
+ requirementId, requirementAssignment);
+
+ }
}
- //Add resource dependency information in nodesConnectedOut if the source node
- //is a consolidation entity
- if (isConsolidationEntity(consolidationEntityType.getSourceEntityType())) {
- ConsolidationDataUtil.updateNodesConnectedOut(translateTo,
- requirementAssignment.getNode(), consolidationEntityType.getSourceEntityType(),
- requirementId, requirementAssignment);
- }
- }
-
-
- private static boolean isConsolidationEntity(ConsolidationEntityType consolidationEntityType) {
- return ConsolidationEntityType.getSupportedConsolidationEntities().contains(consolidationEntityType);
- }
-
- /**
- * Update nodes connected from this node in consolidation data.
- *
- * @param translateTo the translate to
- * @param nodeTemplateId the node template id of the target node
- * @param consolidationEntityType the entity type (compute or port)
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
- public static void updateNodesConnectedOut(TranslateTo translateTo,
- String nodeTemplateId,
- ConsolidationEntityType consolidationEntityType,
- String requirementId,
- RequirementAssignment requirementAssignment) {
- EntityConsolidationData entityConsolidationData = null;
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
-
- translationContext.updateRequirementAssignmentIdIndex(ToscaUtil.getServiceTemplateFileName
- (translateTo.getServiceTemplate()), translateTo.getResourceId(), requirementId);
-
- RequirementAssignmentData requirementAssignmentData = new RequirementAssignmentData(
- requirementId, requirementAssignment);
-
- if (consolidationEntityType == ConsolidationEntityType.COMPUTE) {
- String nodeType = DataModelUtil.getNodeTemplate(serviceTemplate, translateTo
- .getTranslatedId()).getType();
- entityConsolidationData = getComputeTemplateConsolidationData(translationContext,
- serviceTemplate, nodeType, translateTo.getTranslatedId());
- } else if (consolidationEntityType == ConsolidationEntityType.PORT) {
- entityConsolidationData = getPortTemplateConsolidationData(translationContext, serviceTemplate,
- translateTo.getResourceId(), translateTo.getResource().getType(), translateTo
- .getTranslatedId());
- } else if (consolidationEntityType == ConsolidationEntityType.SUB_INTERFACE
- && Objects.nonNull(serviceTemplate.getTopology_template().getNode_templates()
- .get(translateTo.getTranslatedId()))) {
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- getSubInterfaceTemplateConsolidationData(translateTo, translateTo.getTranslatedId());
- if (subInterfaceTemplateConsolidationData.isPresent()) {
- entityConsolidationData = subInterfaceTemplateConsolidationData.get();
- }
- } else if (consolidationEntityType == ConsolidationEntityType.VFC_NESTED
- || consolidationEntityType == ConsolidationEntityType.NESTED) {
- entityConsolidationData =
- getNestedTemplateConsolidationData(translationContext, serviceTemplate,
- translateTo.getHeatFileName(),
- translateTo.getTranslatedId());
+ private static boolean isConsolidationEntity(ConsolidationEntityType consolidationEntityType) {
+ return ConsolidationEntityType.getSupportedConsolidationEntities().contains(consolidationEntityType);
}
- if (Objects.nonNull(entityConsolidationData)) {
- if (Objects.isNull(entityConsolidationData.getNodesConnectedOut())) {
- entityConsolidationData.setNodesConnectedOut(new HashMap<>());
- }
+ /**
+ * Update nodes connected from this node in consolidation data.
+ *
+ * @param translateTo the translate to
+ * @param nodeTemplateId the node template id of the target node
+ * @param consolidationEntityType the entity type (compute or port)
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
+ public static void updateNodesConnectedOut(TranslateTo translateTo,
+ String nodeTemplateId,
+ ConsolidationEntityType consolidationEntityType,
+ String requirementId,
+ RequirementAssignment requirementAssignment) {
+ TranslationContext translationContext = translateTo.getContext();
+ translationContext.updateRequirementAssignmentIdIndex(
+ ToscaUtil.getServiceTemplateFileName(translateTo.getServiceTemplate()), translateTo.getResourceId(),
+ requirementId);
+
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ translationContext.getConsolidationData().getConsolidationDataHandler(consolidationEntityType);
+ consolidationDataHandler.ifPresent(handler -> handler.addNodesConnectedOut(
+ translateTo, nodeTemplateId, requirementId, requirementAssignment));
- entityConsolidationData.getNodesConnectedOut()
- .computeIfAbsent(nodeTemplateId, k -> new ArrayList<>())
- .add(requirementAssignmentData);
- }
- }
-
- /**
- * Update nodes connected from this node in consolidation data.
- *
- * @param translateTo the translate to
- * @param sourceNodeTemplateId the node template id of the source node
- * @param consolidationEntityType Entity type (compute or port)
- * @param requirementId Requirement Id
- * @param requirementAssignment the requirement assignment
- */
- public static void updateNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
- ConsolidationEntityType consolidationEntityType,
- String targetResourceId,
- String requirementId,
- RequirementAssignment requirementAssignment) {
- EntityConsolidationData entityConsolidationData = null;
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- RequirementAssignmentData requirementAssignmentData = new RequirementAssignmentData(
- requirementId, requirementAssignment);
- String dependentNodeTemplateId = requirementAssignment.getNode();
- if (consolidationEntityType == ConsolidationEntityType.COMPUTE) {
- NodeTemplate computeNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
- dependentNodeTemplateId);
- String nodeType;
- if (Objects.isNull(computeNodeTemplate)) {
- Resource targetResource =
- translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
- NameExtractor nodeTypeNameExtractor =
- TranslationContext.getNameExtractorImpl(targetResource.getType());
- nodeType =
- nodeTypeNameExtractor.extractNodeTypeName(translateTo.getHeatOrchestrationTemplate()
- .getResources().get(dependentNodeTemplateId),
- dependentNodeTemplateId, dependentNodeTemplateId);
- } else {
- nodeType = computeNodeTemplate.getType();
- }
-
- entityConsolidationData = getComputeTemplateConsolidationData(translationContext,
- serviceTemplate, nodeType, dependentNodeTemplateId);
- } else if (consolidationEntityType == ConsolidationEntityType.PORT) {
- entityConsolidationData = getPortTemplateConsolidationData(translationContext, serviceTemplate,
- translateTo.getResourceId(), translateTo.getResource().getType(), dependentNodeTemplateId);
- } else if (consolidationEntityType == ConsolidationEntityType.SUB_INTERFACE) {
- Resource targetResource =
- translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId);
- TranslateTo subInterfaceTo = new TranslateTo(translateTo.getHeatFileName(), serviceTemplate, translateTo
- .getHeatOrchestrationTemplate(), targetResource, targetResourceId, null, translationContext);
- Optional<SubInterfaceTemplateConsolidationData> subInterfaceTemplateConsolidationData =
- getSubInterfaceTemplateConsolidationData(subInterfaceTo, targetResourceId);
- if (subInterfaceTemplateConsolidationData.isPresent()) {
- entityConsolidationData = subInterfaceTemplateConsolidationData.get();
- }
- } else if (consolidationEntityType == ConsolidationEntityType.NESTED
- || consolidationEntityType == ConsolidationEntityType.VFC_NESTED) {
- entityConsolidationData = getNestedTemplateConsolidationData(translationContext,
- serviceTemplate, translateTo.getHeatFileName(), dependentNodeTemplateId);
}
- if (entityConsolidationData != null) {
- if (entityConsolidationData.getNodesConnectedIn() == null) {
- entityConsolidationData.setNodesConnectedIn(new HashMap<>());
- }
+ /**
+ * Update nodes connected from this node in consolidation data.
+ *
+ * @param translateTo the translate to
+ * @param sourceNodeTemplateId the node template id of the source node
+ * @param consolidationEntityType Entity type (compute or port)
+ * @param targetResourceId Target Resource Id
+ * @param requirementId Requirement Id
+ * @param requirementAssignment the requirement assignment
+ */
+ public static void updateNodesConnectedIn(TranslateTo translateTo, String sourceNodeTemplateId,
+ ConsolidationEntityType consolidationEntityType,
+ String targetResourceId,
+ String requirementId,
+ RequirementAssignment requirementAssignment) {
+
+
+ TranslationContext translationContext = translateTo.getContext();
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ translationContext.getConsolidationData().getConsolidationDataHandler(consolidationEntityType);
+ String dependentNodeTemplateId = requirementAssignment.getNode();
+ consolidationDataHandler.ifPresent(
+ handler -> handler.addNodesConnectedIn(translateTo, sourceNodeTemplateId, dependentNodeTemplateId,
+ targetResourceId, requirementId, requirementAssignment));
- entityConsolidationData.getNodesConnectedIn()
- .computeIfAbsent(sourceNodeTemplateId, k -> new ArrayList<>())
- .add(requirementAssignmentData);
+ }
+ /**
+ * Checks if the current HEAT resource if of type compute.
+ *
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceId the resource id
+ * @return true if the resource is of compute type and false otherwise
+ */
+ public static boolean isComputeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId) {
+ String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
+ Map<String, ImplementationConfiguration> supportedComputeResources =
+ TranslationContext.getSupportedConsolidationComputeResources();
+ if (supportedComputeResources.containsKey(resourceType)) {
+ return supportedComputeResources.get(resourceType).isEnable();
+ }
+ return false;
}
- }
-
- /**
- * Checks if the current HEAT resource if of type compute.
- *
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resourceId the resource id
- * @return true if the resource is of compute type and false otherwise
- */
- public static boolean isComputeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
- String resourceId) {
- String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
- Map<String, ImplementationConfiguration> supportedComputeResources = TranslationContext
- .getSupportedConsolidationComputeResources();
- if (supportedComputeResources.containsKey(resourceType)) {
- return supportedComputeResources.get(resourceType).isEnable();
+
+ /**
+ * Checks if the current HEAT resource if of type compute.
+ *
+ * @param resource the resource
+ * @return true if the resource is of compute type and false otherwise
+ */
+ public static boolean isComputeResource(Resource resource) {
+ String resourceType = resource.getType();
+ Map<String, ImplementationConfiguration> supportedComputeResources =
+ TranslationContext.getSupportedConsolidationComputeResources();
+ if (supportedComputeResources.containsKey(resourceType)) {
+ return supportedComputeResources.get(resourceType).isEnable();
+ }
+ return false;
}
- return false;
- }
-
- /**
- * Checks if the current HEAT resource if of type compute.
- *
- * @param resource the resource
- * @return true if the resource is of compute type and false otherwise
- */
- public static boolean isComputeResource(Resource resource) {
- String resourceType = resource.getType();
- Map<String, ImplementationConfiguration> supportedComputeResources = TranslationContext
- .getSupportedConsolidationComputeResources();
- if (supportedComputeResources.containsKey(resourceType)) {
- return supportedComputeResources.get(resourceType).isEnable();
+
+ /**
+ * Checks if the current HEAT resource if of type port.
+ *
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceId the resource id
+ * @return true if the resource is of port type and false otherwise
+ */
+ public static boolean isPortResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId) {
+ String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
+ Map<String, ImplementationConfiguration> supportedPortResources =
+ TranslationContext.getSupportedConsolidationPortResources();
+ if (supportedPortResources.containsKey(resourceType)) {
+ return supportedPortResources.get(resourceType).isEnable();
+ }
+ return false;
}
- return false;
- }
-
- /**
- * Checks if the current HEAT resource if of type port.
- *
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resourceId the resource id
- * @return true if the resource is of port type and false otherwise
- */
- public static boolean isPortResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
- String resourceId) {
- String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
- Map<String, ImplementationConfiguration> supportedPortResources = TranslationContext
- .getSupportedConsolidationPortResources();
- if (supportedPortResources.containsKey(resourceType)) {
- return supportedPortResources.get(resourceType).isEnable();
+
+ /**
+ * Checks if the current HEAT resource if of type port.
+ *
+ * @param resource the resource
+ * @return true if the resource is of port type and false otherwise
+ */
+ public static boolean isPortResource(Resource resource) {
+ String resourceType = resource.getType();
+ Map<String, ImplementationConfiguration> supportedPortResources =
+ TranslationContext.getSupportedConsolidationPortResources();
+ if (supportedPortResources.containsKey(resourceType)) {
+ return supportedPortResources.get(resourceType).isEnable();
+ }
+ return false;
}
- return false;
- }
-
- /**
- * Checks if the current HEAT resource if of type port.
- *
- * @param resource the resource
- * @return true if the resource is of port type and false otherwise
- */
- public static boolean isPortResource(Resource resource) {
- String resourceType = resource.getType();
- Map<String, ImplementationConfiguration> supportedPortResources = TranslationContext
- .getSupportedConsolidationPortResources();
- if (supportedPortResources.containsKey(resourceType)) {
- return supportedPortResources.get(resourceType).isEnable();
+
+ /**
+ * Checks if the current HEAT resource if of type volume.
+ *
+ * @param heatOrchestrationTemplate the heat orchestration template
+ * @param resourceId the resource id
+ * @return true if the resource is of volume type and false otherwise
+ */
+ public static boolean isVolumeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
+ String resourceId) {
+ String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
+ return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
+ || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE
+ .getHeatResource());
}
- return false;
- }
-
- /**
- * Checks if the current HEAT resource if of type volume.
- *
- * @param heatOrchestrationTemplate the heat orchestration template
- * @param resourceId the resource id
- * @return true if the resource is of volume type and false otherwise
- */
- public static boolean isVolumeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
- String resourceId) {
- String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
- return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
- || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE
- .getHeatResource());
- }
-
- /**
- * Checks if the current HEAT resource if of type volume.
- *
- * @param resource the resource
- * @return true if the resource is of volume type and false otherwise
- */
- public static boolean isVolumeResource(Resource resource) {
- String resourceType = resource.getType();
- return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
- || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE
- .getHeatResource());
- }
-
- /**
- * Gets port type.
- *
- * @param portNodeTemplateId the port node template id
- * @return the port type
- */
- public static String getPortType(String portNodeTemplateId) {
-
- if (StringUtils.isBlank(portNodeTemplateId)) {
- return portNodeTemplateId;
+
+ /**
+ * Checks if the current HEAT resource if of type volume.
+ *
+ * @param resource the resource
+ * @return true if the resource is of volume type and false otherwise
+ */
+ public static boolean isVolumeResource(Resource resource) {
+ String resourceType = resource.getType();
+ return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
+ || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE
+ .getHeatResource());
}
- String formattedName = portNodeTemplateId.replaceAll(UNDERSCORE + DIGIT_REGEX + "$", "");
+ /**
+ * Gets port type.
+ *
+ * @param portNodeTemplateId the port node template id
+ * @return the port type
+ */
+ public static String getPortType(String portNodeTemplateId) {
- StringBuilder sb = new StringBuilder();
- int count = 0;
- for (String token : formattedName.split(UNDERSCORE)) {
+ if (StringUtils.isBlank(portNodeTemplateId)) {
+ return portNodeTemplateId;
+ }
- if (StringUtils.isNotBlank(token)) {
- count++;
- }
+ String formattedName = portNodeTemplateId.replaceAll(UNDERSCORE + DIGIT_REGEX + "$", "");
- if (count != 2 || !token.matches(DIGIT_REGEX)) {
- sb.append(token).append(UNDERSCORE);
- }
- }
+ StringBuilder sb = new StringBuilder();
+ int count = 0;
+ for (String token : formattedName.split(UNDERSCORE)) {
+
+ if (StringUtils.isNotBlank(token)) {
+ count++;
+ }
+
+ if (count != 2 || (!StringUtils.isBlank(token) && !token.matches(DIGIT_REGEX))) {
+ sb.append(token).append(UNDERSCORE);
+ }
+ }
- return portNodeTemplateId.endsWith(UNDERSCORE) ? sb.toString() : sb.substring(0, sb.length() - 1);
- }
-
- /**
- * Update node template id for the nested node templates in the consolidation data.
- *
- * @param translateTo the translate to
- */
- public static void updateNestedNodeTemplateId(TranslateTo translateTo) {
- TranslationContext context = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- getNestedTemplateConsolidationData(
- context, serviceTemplate, translateTo.getHeatFileName(), translateTo.getTranslatedId());
- }
-
- public static void removeSharedResource(ServiceTemplate serviceTemplate,
- HeatOrchestrationTemplate heatOrchestrationTemplate,
- TranslationContext context,
- String paramName,
- String contrailSharedResourceId,
- String sharedTranslatedResourceId) {
- if (ConsolidationDataUtil.isComputeResource(heatOrchestrationTemplate,
- contrailSharedResourceId)) {
- NodeTemplate nodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate,
- sharedTranslatedResourceId);
- EntityConsolidationData entityConsolidationData = getComputeTemplateConsolidationData(
- context, serviceTemplate, nodeTemplate.getType(), sharedTranslatedResourceId);
- List<GetAttrFuncData> getAttrFuncDataList = entityConsolidationData
- .getOutputParametersGetAttrIn();
- removeParamNameFromAttrFuncList(paramName, getAttrFuncDataList);
+ return portNodeTemplateId.endsWith(UNDERSCORE) ? sb.toString() : sb.substring(0, sb.length() - 1);
}
- if (ConsolidationDataUtil.isPortResource(heatOrchestrationTemplate,
- contrailSharedResourceId)) {
- Resource resource = heatOrchestrationTemplate.getResources().get(contrailSharedResourceId);
- EntityConsolidationData entityConsolidationData = getPortTemplateConsolidationData(context, serviceTemplate,
- contrailSharedResourceId, resource.getType(), sharedTranslatedResourceId);
- List<GetAttrFuncData> getAttrFuncDataList = entityConsolidationData
- .getOutputParametersGetAttrIn();
- removeParamNameFromAttrFuncList(paramName, getAttrFuncDataList);
+
+ /**
+ * Update node template id for the nested node templates in the consolidation data.
+ *
+ * @param translateTo the translate to
+ */
+ public static void updateNestedNodeTemplateId(TranslateTo translateTo) {
+ TranslationContext context = translateTo.getContext();
+ ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
+ getNestedTemplateConsolidationData(
+ context, serviceTemplate, translateTo.getHeatFileName(), translateTo.getTranslatedId());
}
- }
-
- private static void removeParamNameFromAttrFuncList(String paramName,
- List<GetAttrFuncData> getAttrFuncDataList) {
- Iterator<GetAttrFuncData> itr = getAttrFuncDataList.iterator();
- while (itr.hasNext()) {
- GetAttrFuncData getAttrFuncData = itr.next();
- if (paramName.equals(getAttrFuncData.getFieldName())) {
- itr.remove();
- }
+
+ public static void removeSharedResource(ServiceTemplate serviceTemplate,
+ HeatOrchestrationTemplate heatOrchestrationTemplate,
+ TranslationContext context,
+ String paramName,
+ String contrailSharedResourceId,
+ String sharedTranslatedResourceId) {
+ Optional<ConsolidationDataHandler> consolidationDataHandler =
+ ConsolidationDataUtil.getConsolidationDataHandler(heatOrchestrationTemplate, context,
+ contrailSharedResourceId);
+
+ consolidationDataHandler.ifPresent(
+ handler -> handler.removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate,
+ paramName, contrailSharedResourceId, sharedTranslatedResourceId));
}
- }
- 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 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.getConsolidationData().getConsolidationDataHandler(
+ consolidationEntityType.getSourceEntityType());
- public static void updateNodeGetAttributeOut(EntityConsolidationData entityConsolidationData,
- String nodeTemplateId, String propertyName,
- String attributeName) {
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
- getAttrFuncData.setFieldName(propertyName);
- getAttrFuncData.setAttributeName(attributeName);
- entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ }
+
+ 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(EntityConsolidationData entityConsolidationData,
+ String nodeTemplateId, String propertyName,
+ String attributeName) {
- public static void updateOutputGetAttributeInConsolidationData(EntityConsolidationData
- entityConsolidationData,
- String outputParameterName,
- String attributeName) {
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(propertyName);
+ getAttrFuncData.setAttributeName(attributeName);
+ entityConsolidationData.addNodesGetAttrOut(nodeTemplateId, getAttrFuncData);
+ }
- GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
- getAttrFuncData.setFieldName(outputParameterName);
- getAttrFuncData.setAttributeName(attributeName);
- entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
+ public static void updateOutputGetAttributeInConsolidationData(EntityConsolidationData
+ entityConsolidationData,
+ String outputParameterName,
+ String attributeName) {
- }
+ GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
+ getAttrFuncData.setFieldName(outputParameterName);
+ getAttrFuncData.setAttributeName(attributeName);
+ entityConsolidationData.addOutputParamGetAttrIn(getAttrFuncData);
- public static boolean isComputeReferenceToPortId(ComputeTemplateConsolidationData compute,
- String portId) {
- if (MapUtils.isEmpty(compute.getPorts())) {
- return false;
}
- for (List<String> portIdsPerType : compute.getPorts().values()) {
- if (portIdsPerType.contains(portId)) {
- return true;
- }
+
+ public static boolean isComputeReferenceToPortId(ComputeTemplateConsolidationData compute,
+ String portId) {
+ if (MapUtils.isEmpty(compute.getPorts())) {
+ return false;
+ }
+ for (List<String> portIdsPerType : compute.getPorts().values()) {
+ if (portIdsPerType.contains(portId)) {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
}