diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-03 20:04:37 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-03 20:06:51 +0300 |
commit | 33e00cd1d7d580a2fdafad771d54e29bb455cb5d (patch) | |
tree | 15f2f1c08313eac8633aaf3935e0df1dcae9a74c /openecomp-be/lib/openecomp-sdc-translator-lib | |
parent | 2e4d90a7a3c76deb582df234a1b474daeb37ae30 (diff) |
Update group members ids
Issue-Id: SDC-427
Change-Id: If7a476adfac7c56c97e14330e4fddcc6d9f2d293
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib')
2 files changed, 51 insertions, 7 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java index 81ef3e01ce..c1f69cf3bf 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java @@ -86,6 +86,7 @@ import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypes import org.openecomp.sdc.translator.services.heattotosca.helper.FunctionTranslationHelper; import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; @@ -135,11 +136,15 @@ public class HeatToToscaUtil { return translatorOutput; } - InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap); - heatToToscaTranslator.addExternalArtifacts(SdcCommon.HEAT_META, structureFile); + try (InputStream structureFile = getHeatStructureTreeFile(fileNameContentMap)) { + heatToToscaTranslator.addExternalArtifacts(SdcCommon.HEAT_META, structureFile); - mdcDataDebugMessage.debugExitMessage(null, null); - return heatToToscaTranslator.translate(); + mdcDataDebugMessage.debugExitMessage(null, null); + return heatToToscaTranslator.translate(); + } catch (IOException e) { + // rethrow as a RuntimeException to keep the signature backward compatible + throw new RuntimeException(e); + } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java index 43079f9025..012be05257 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.translator.services.heattotosca; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.translator.datatypes.TranslatorOutput; import org.openecomp.core.utilities.file.FileUtils; @@ -48,6 +49,7 @@ import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.ToscaFileOutputService; +import org.openecomp.sdc.tosca.services.ToscaUtil; import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl; import org.openecomp.sdc.translator.datatypes.heattotosca.AttachedResourceId; @@ -213,17 +215,54 @@ public class TranslationService { groupDefinition.getProperties().put(Constants.DESCRIPTION_PROPERTY_NAME, hotDescription); } groupDefinition.setMembers(new ArrayList<>()); - Map<String, Set<String>> heatStackGroupMembers = context.getHeatStackGroupMembers(); - if (heatStackGroupMembers.get(fileName) == null) { + Set<String> heatStackGroupMembersIds = getHeatStackGroupMembers(fileName, + serviceTemplate, context); + if (CollectionUtils.isEmpty(heatStackGroupMembersIds)) { return; //not creating a group when no resources are present in the heat input } - groupDefinition.getMembers().addAll(heatStackGroupMembers.get(fileName)); + groupDefinition.getMembers().addAll(heatStackGroupMembersIds); DataModelUtil .addGroupDefinitionToTopologyTemplate(serviceTemplate, heatStackGroupId, groupDefinition); mdcDataDebugMessage.debugExitMessage(null, null); } + private Set<String> getHeatStackGroupMembers(String heatFileName, + ServiceTemplate serviceTemplate, + TranslationContext context){ + + Map<String, Set<String>> heatStackGroupMembers = context.getHeatStackGroupMembers(); + Set<String> groupMembers = MapUtils.isEmpty(heatStackGroupMembers) ? new HashSet<>() + : heatStackGroupMembers.get(heatFileName); + + if(CollectionUtils.isEmpty(groupMembers)){ + return new HashSet<>(); + } + + Set<String> updatedMembersIds = new HashSet<>(); + + groupMembers.forEach(member -> { + if (Objects.nonNull(DataModelUtil.getNodeTemplate(serviceTemplate, member))) { + updatedMembersIds.add(member); + } else { + updateSubstitutableGroupMemberId(heatFileName, serviceTemplate, updatedMembersIds); + } + }); + + return updatedMembersIds; + } + + private void updateSubstitutableGroupMemberId(String heatFileName, + ServiceTemplate serviceTemplate, + Set<String> updatedMembersIds) { + Optional<String> substitutableGroupMemberId = + ToscaUtil.getSubstitutableGroupMemberId(heatFileName, serviceTemplate); + + if (substitutableGroupMemberId.isPresent()) { + updatedMembersIds.add(substitutableGroupMemberId.get()); + } + } + private void translateInputParameters(ServiceTemplate serviceTemplate, HeatOrchestrationTemplate heatOrchestrationTemplate, FileData heatFileData, TranslationContext context, |