diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java | 147 |
1 files changed, 90 insertions, 57 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java index 0e6610d5cd..c03ca56d49 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java @@ -24,12 +24,15 @@ import org.openecomp.config.api.Configuration; import org.openecomp.config.api.ConfigurationManager; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.ManifestFile; import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource; @@ -42,8 +45,6 @@ import org.openecomp.sdc.translator.services.heattotosca.NameExtractor; import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -67,23 +68,23 @@ public class TranslationContext { Configuration config = ConfigurationManager.lookup(); String propertyFileName = SdcCommon.HEAT_TO_TOSCA_MAPPING_CONF; translationMapping = - config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY); + config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY); try { globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate(); } catch (Exception exc) { throw new RuntimeException("Failed to load GlobalTypes", exc); } nameExtractorImplMap = config.populateMap(ConfigConstants.TRANSLATOR_NAMESPACE, - ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class); + ConfigConstants.NAMING_CONVENTION_EXTRACTOR_IMPL_KEY, ImplementationConfiguration.class); supportedConsolidationComputeResources = config.populateMap(ConfigConstants - .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants - .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class); + .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants + .SUPPORTED_CONSOLIDATION_COMPUTE_RESOURCES_KEY, ImplementationConfiguration.class); supportedConsolidationPortResources = config.populateMap(ConfigConstants - .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants - .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class); + .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants + .SUPPORTED_CONSOLIDATION_PORT_RESOURCES_KEY, ImplementationConfiguration.class); enrichPortResourceProperties = config.getAsStringValues(ConfigConstants - .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants - .ENRICH_PORT_RESOURCE_PROP); + .MANDATORY_UNIFIED_MODEL_NAMESPACE, ConfigConstants + .ENRICH_PORT_RESOURCE_PROP); } @@ -118,15 +119,18 @@ public class TranslationContext { private Map<String, UnifiedSubstitutionData> unifiedSubstitutionData = new HashMap<>(); private Set<String> unifiedHandledServiceTemplates = new HashSet<>(); + private Map<String, Map<RequirementAssignment, String>> + mapDependencySubMappingToRequirementAssignment = new HashMap<>(); + public static Map<String, ImplementationConfiguration> getSupportedConsolidationComputeResources() { return supportedConsolidationComputeResources; } public static void setSupportedConsolidationComputeResources( - Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) { + Map<String, ImplementationConfiguration> supportedConsolidationComputeResources) { TranslationContext.supportedConsolidationComputeResources = - supportedConsolidationComputeResources; + supportedConsolidationComputeResources; } public static Map<String, ImplementationConfiguration> getSupportedConsolidationPortResources() { @@ -134,7 +138,7 @@ public class TranslationContext { } public static void setSupportedConsolidationPortResources( - Map<String, ImplementationConfiguration> supportedConsolidationPortResources) { + Map<String, ImplementationConfiguration> supportedConsolidationPortResources) { TranslationContext.supportedConsolidationPortResources = supportedConsolidationPortResources; } @@ -146,7 +150,7 @@ public class TranslationContext { */ public static NameExtractor getNameExtractorImpl(String extractorImplKey) { String nameExtractorImplClassName = - nameExtractorImplMap.get(extractorImplKey).getImplementationClass(); + nameExtractorImplMap.get(extractorImplKey).getImplementationClass(); return CommonMethods.newInstance(nameExtractorImplClassName, NameExtractor.class); } @@ -156,7 +160,7 @@ public class TranslationContext { } public void setUnifiedSubstitutionData( - Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) { + Map<String, UnifiedSubstitutionData> unifiedSubstitutionData) { this.unifiedSubstitutionData = unifiedSubstitutionData; } @@ -166,14 +170,14 @@ public class TranslationContext { NodeTemplate nodeTemplate) { this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData - .get(serviceTemplateName) - .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate); + .get(serviceTemplateName) + .addCleanedNodeTemplate(nodeTemplateId, unifiedCompositionEntity, nodeTemplate); } public NodeTemplate getCleanedNodeTemplate(String serviceTemplateName, String nodeTemplateId) { return this.unifiedSubstitutionData.get(serviceTemplateName) - .getCleanedNodeTemplate(nodeTemplateId); + .getCleanedNodeTemplate(nodeTemplateId); } public void addUnifiedNestedNodeTemplateId(String serviceTemplateName, @@ -181,13 +185,13 @@ public class TranslationContext { String unifiedNestedNodeTemplateId) { this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(serviceTemplateName) - .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId); + .addUnifiedNestedNodeTemplateId(nestedNodeTemplateId, unifiedNestedNodeTemplateId); } public Optional<String> getUnifiedNestedNodeTemplateId(String serviceTemplateName, String nestedNodeTemplateId) { return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() - : this.unifiedSubstitutionData.get(serviceTemplateName) + : this.unifiedSubstitutionData.get(serviceTemplateName) .getUnifiedNestedNodeTemplateId(nestedNodeTemplateId); } @@ -196,13 +200,13 @@ public class TranslationContext { String unifiedNestedNodeTypeId) { this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(serviceTemplateName) - .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId); + .addUnifiedNestedNodeTypeId(nestedNodeTypeId, unifiedNestedNodeTypeId); } public Optional<String> getUnifiedNestedNodeTypeId(String serviceTemplateName, String nestedNodeTemplateId) { return this.unifiedSubstitutionData.get(serviceTemplateName) == null ? Optional.empty() - : this.unifiedSubstitutionData.get(serviceTemplateName) + : this.unifiedSubstitutionData.get(serviceTemplateName) .getUnifiedNestedNodeTypeId(nestedNodeTemplateId); } @@ -259,12 +263,12 @@ public class TranslationContext { } public Set<String> getAllTranslatedResourceIdsFromDiffNestedFiles(String - nestedHeatFileNameToSkip){ + nestedHeatFileNameToSkip){ Set<String> allTranslatedResourceIds = new HashSet<>(); this.translatedIds.entrySet().stream().filter( - heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey() - .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry -> { + heatFileNameToTranslatedIdsEntry -> !heatFileNameToTranslatedIdsEntry.getKey() + .equals(nestedHeatFileNameToSkip)).forEach(heatFileNameToTranslatedIdsEntry -> { allTranslatedResourceIds.addAll(heatFileNameToTranslatedIdsEntry.getValue().keySet()); }); @@ -325,7 +329,7 @@ public class TranslationContext { public void addHeatSharedResourcesByParam(String parameterName, String resourceId, Resource resource) { this.addHeatSharedResourcesByParam(parameterName, - new TranslatedHeatResource(resourceId, resource)); + new TranslatedHeatResource(resourceId, resource)); } private void addHeatSharedResourcesByParam(String parameterName, @@ -351,7 +355,7 @@ public class TranslationContext { } public void addUsedHeatPseudoParams(String heatFileName, String heatPseudoParam, String - translatedToscaParam) { + translatedToscaParam) { if (Objects.isNull(this.usedHeatPseudoParams.get(heatFileName))) { this.usedHeatPseudoParams.put(heatFileName, new HashMap<>()); } @@ -371,15 +375,22 @@ public class TranslationContext { String abstractNodeTemplateId) { Map<String, String> nodeAbstractNodeTemplateIdMap = this.getUnifiedSubstitutionData() - .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData()) - .getNodesRelatedAbstractNode(); + .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData()) + .getNodesRelatedAbstractNode(); if (nodeAbstractNodeTemplateIdMap == null) { nodeAbstractNodeTemplateIdMap = new HashMap<>(); } + + if(nodeAbstractNodeTemplateIdMap.containsKey(originalNodeTemplateId)){ + throw new CoreException((new ErrorCode.ErrorCodeBuilder()) + .withMessage("Resource with id " + + originalNodeTemplateId + " occures more than once in different addOn files") + .build()); + } nodeAbstractNodeTemplateIdMap.put(originalNodeTemplateId, abstractNodeTemplateId); this.getUnifiedSubstitutionData().get(serviceTemplateFileName).setNodesRelatedAbstractNode( - nodeAbstractNodeTemplateIdMap); + nodeAbstractNodeTemplateIdMap); } /** @@ -392,23 +403,23 @@ public class TranslationContext { * service template */ public void addSubstitutionServiceTemplateUnifiedSubstitutionData( - String serviceTemplateFileName, - String originalNodeTemplateId, - String substitutionServiceTemplateNodeTemplateId) { + String serviceTemplateFileName, + String originalNodeTemplateId, + String substitutionServiceTemplateNodeTemplateId) { Map<String, String> nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = this - .getUnifiedSubstitutionData() - .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData()) - .getNodesRelatedSubstitutionServiceTemplateNode(); + .getUnifiedSubstitutionData() + .computeIfAbsent(serviceTemplateFileName, k -> new UnifiedSubstitutionData()) + .getNodesRelatedSubstitutionServiceTemplateNode(); if (nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap == null) { nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap = new HashMap<>(); } nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap.put(originalNodeTemplateId, - substitutionServiceTemplateNodeTemplateId); + substitutionServiceTemplateNodeTemplateId); this.getUnifiedSubstitutionData().get(serviceTemplateFileName) - .setNodesRelatedSubstitutionServiceTemplateNode( - nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap); + .setNodesRelatedSubstitutionServiceTemplateNode( + nodesRelatedSubstitutionServiceTemplateNodeTemplateIdMap); } /** @@ -420,7 +431,7 @@ public class TranslationContext { public String getUnifiedAbstractNodeTemplateId(ServiceTemplate serviceTemplate, String nodeTemplateId) { UnifiedSubstitutionData unifiedSubstitutionData = - this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); return unifiedSubstitutionData.getNodesRelatedAbstractNode().get(nodeTemplateId); } @@ -434,26 +445,26 @@ public class TranslationContext { public String getUnifiedSubstitutionNodeTemplateId(ServiceTemplate serviceTemplate, String nodeTemplateId) { UnifiedSubstitutionData unifiedSubstitutionData = - this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); + this.unifiedSubstitutionData.get(ToscaUtil.getServiceTemplateFileName(serviceTemplate)); return unifiedSubstitutionData.getNodesRelatedSubstitutionServiceTemplateNode() - .get(nodeTemplateId); + .get(nodeTemplateId); } public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName, String computeType) { return this.unifiedSubstitutionData.get(serviceTemplateName) - .getHandledNestedComputeNodeTemplateIndex(computeType); + .getHandledNestedComputeNodeTemplateIndex(computeType); } public void updateHandledComputeType(String serviceTemplateName, String handledComputeType, String nestedServiceTemplateFileName) { String globalSTName = - ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME); + ToscaUtil.getServiceTemplateFileName(Constants.GLOBAL_SUBSTITUTION_TYPES_TEMPLATE_NAME); this.unifiedSubstitutionData.putIfAbsent( - globalSTName, new UnifiedSubstitutionData()); + globalSTName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(globalSTName) - .addHandledComputeType(handledComputeType); + .addHandledComputeType(handledComputeType); this.unifiedSubstitutionData.get(globalSTName).addHandlesNestedServiceTemplate(nestedServiceTemplateFileName); this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); @@ -469,15 +480,15 @@ public class TranslationContext { public boolean isComputeTypeHandledInServiceTemplate(String serviceTemplateName, String computeType) { return !Objects.isNull(this.unifiedSubstitutionData.get(serviceTemplateName)) - && this.unifiedSubstitutionData.get(serviceTemplateName) - .isComputeTypeHandledInServiceTemplate(computeType); + && this.unifiedSubstitutionData.get(serviceTemplateName) + .isComputeTypeHandledInServiceTemplate(computeType); } public int getHandledNestedComputeNodeTemplateIndex(String serviceTemplateName, String nestedServiceTemplateName, String computeType){ return this.unifiedSubstitutionData.get(serviceTemplateName) - .getHandledNestedComputeNodeTemplateIndex(computeType); + .getHandledNestedComputeNodeTemplateIndex(computeType); } public boolean isNestedServiceTemplateWasHandled(String serviceTemplateName, @@ -486,13 +497,13 @@ public class TranslationContext { return false; } return this.unifiedSubstitutionData.get(serviceTemplateName) - .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName); + .isNestedServiceTemplateWasHandled(nestedServiceTemplateFileName); } public Set<String> getAllRelatedNestedNodeTypeIds(){ String globalName = "GlobalSubstitutionTypes"; if(Objects.isNull(this.unifiedSubstitutionData) || - Objects.isNull(this.unifiedSubstitutionData.get(globalName))){ + Objects.isNull(this.unifiedSubstitutionData.get(globalName))){ return new HashSet<>(); } @@ -520,14 +531,14 @@ public class TranslationContext { return false; } return this.unifiedSubstitutionData.get(serviceTemplateName) - .isNestedNodeWasHandled(nestedNodeTemplateId); + .isNestedNodeWasHandled(nestedNodeTemplateId); } public void addNestedNodeAsHandled(String serviceTemplateName, String nestedNodeTemplateId) { this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(serviceTemplateName) - .addHandledNestedNodes(nestedNodeTemplateId); + .addHandledNestedNodes(nestedNodeTemplateId); } public void updateUsedTimesForNestedComputeNodeType(String serviceTemplateName, @@ -535,7 +546,7 @@ public class TranslationContext { this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(serviceTemplateName) - .updateUsedTimesForNestedComputeNodeType(computeType); + .updateUsedTimesForNestedComputeNodeType(computeType); } public int getGlobalNodeTypeIndex(String serviceTemplateName, @@ -544,7 +555,7 @@ public class TranslationContext { return 0; } return this.unifiedSubstitutionData.get(serviceTemplateName).getGlobalNodeTypeIndex - (computeType); + (computeType); } public void addNewPropertyIdToNodeTemplate(String serviceTemplateName, @@ -552,7 +563,7 @@ public class TranslationContext { Object origPropertyValue){ this.unifiedSubstitutionData.putIfAbsent(serviceTemplateName, new UnifiedSubstitutionData()); this.unifiedSubstitutionData.get(serviceTemplateName).addNewPropertyIdToNodeTemplate( - newPropertyId, origPropertyValue); + newPropertyId, origPropertyValue); } public Optional<Object> getNewPropertyInputParamId(String serviceTemplateName, @@ -562,7 +573,7 @@ public class TranslationContext { } return this.unifiedSubstitutionData.get(serviceTemplateName).getNewPropertyInputParam - (newPropertyId); + (newPropertyId); } public Map<String, Object> getAllNewPropertyInputParamIdsPerNodeTenplateId(String serviceTemplateName){ @@ -574,5 +585,27 @@ public class TranslationContext { } + public void addSubMappingReqAssignment(String serviceTemplateName, + RequirementAssignment requirementAssignment, + String newReqId){ + this.mapDependencySubMappingToRequirementAssignment + .putIfAbsent(serviceTemplateName, new HashMap<>()); + this.mapDependencySubMappingToRequirementAssignment.get(serviceTemplateName) + .putIfAbsent(requirementAssignment, newReqId); + } + + public Optional<String> getNewReqAssignmentDependencyId(String serviceTemplateName, + RequirementAssignment requirementAssignment){ + if(!this.mapDependencySubMappingToRequirementAssignment.containsKey(serviceTemplateName)){ + return Optional.empty(); + } + + Map<RequirementAssignment, String> requirementAssignmentMap = + this.mapDependencySubMappingToRequirementAssignment.get(serviceTemplateName); + return requirementAssignmentMap.containsKey + (requirementAssignment) ? Optional.of(requirementAssignmentMap.get(requirementAssignment)) : + Optional.empty(); + } + } |