diff options
author | 2018-07-11 20:15:47 +0300 | |
---|---|---|
committer | 2018-07-15 14:02:15 +0000 | |
commit | dece2c1d9149fce088669baa9621e7e4a6ce093a (patch) | |
tree | d93c6cc54ac115495cc9397cb347b8aa5a1af5f0 /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp | |
parent | 874bd9ed420ce8c281450e730d6d1ed3e3dc688e (diff) |
Nested input params appears in MainServiceTemplate
When Nested heat belongs to Volume HEAT and Volume Heat was associated to main HEAT (parent)
input parameters came from such nested were appear in MainServiceTemplate.yaml (TOSCA)
Also these parameters had annotation in nestedServiceTemplate.yaml
Change-Id: I46fff53de502c7ec48b6e4c26087121be89dd0a1
Issue-ID: SDC-1498
Signed-off-by: eleonorali <eleonoral@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp')
2 files changed, 65 insertions, 51 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 f2773ae01f..bd8b558f11 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 @@ -213,7 +213,7 @@ public class HeatToToscaUtil { List<FileData> fileDataList = context.getManifest().getContent().getData(); for (FileData fileData : fileDataList) { if (TranslationService.getTypesToProcessByTranslator().contains(fileData.getType()) && fileData.getFile() - .equals(heatFileName)) { + .equals(heatFileName)) { return fileData; } } @@ -225,7 +225,6 @@ public class HeatToToscaUtil { FileDataCollection fileDataCollection = new FileDataCollection(); Map<String, FileData> filteredFiles = filterFileDataListByType(fileDataList, typeFilter); Set<String> referenced = new HashSet<>(); - for (FileData fileData : filteredFiles.values()) { String fileName = fileData.getFile(); @@ -236,8 +235,8 @@ public class HeatToToscaUtil { HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil().yamlToObject( translationContext.getFileContent(fileName), HeatOrchestrationTemplate.class); if (MapUtils.isNotEmpty(heatOrchestrationTemplate.getResources())) { - applyFilterOnFileCollection(heatOrchestrationTemplate, translationContext, fileDataCollection, - filteredFiles, referenced); + referenced.addAll(applyFilterOnFileCollection(heatOrchestrationTemplate, translationContext, + fileDataCollection, filteredFiles)); } } else { @@ -246,7 +245,9 @@ public class HeatToToscaUtil { } } + referenced.addAll(getAssociatedFiles(filteredFiles.values())); referenced.forEach(filteredFiles::remove); + if (!CollectionUtils.isEmpty(fileDataCollection.getBaseFile())) { for (FileData fileData : fileDataCollection.getBaseFile()) { filteredFiles.remove(fileData.getFile()); @@ -256,54 +257,80 @@ public class HeatToToscaUtil { return fileDataCollection; } - private static void applyFilterOnFileCollection(HeatOrchestrationTemplate heatOrchestrationTemplate, + private static Set<String> getAssociatedFiles(Collection<FileData> filteredFiles) { + Set<String> associatedFiles = new HashSet<>(); + filteredFiles.stream().filter(file -> file.getParentFile() != null + && FileData.Type.canBeAssociated(file.getType())) + .forEach(file -> associatedFiles.add(file.getFile())); + return associatedFiles; + } + + private static Set<String> applyFilterOnFileCollection(HeatOrchestrationTemplate heatOrchestrationTemplate, TranslationContext translationContext, FileDataCollection fileDataCollection, - Map<String, FileData> filteredFiles, - Set<String> referenced) { + Map<String, FileData> filteredFiles) { + Set<String> nestedFiles = new HashSet<>(); List<String> filenames = extractFilenamesFromFileDataList(filteredFiles.values()); - for (Resource resource : heatOrchestrationTemplate.getResources().values()) { - if (filenames.contains(resource.getType())) { - handleNestedFile(translationContext, fileDataCollection, filteredFiles, referenced, resource.getType()); - } else if (resource.getType().equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) { - handleResourceGrpNestedFile(resource, translationContext, fileDataCollection, filteredFiles, filenames, - referenced); + String resourceType = resource.getType(); + if (filenames.contains(resourceType)) { + handleNestedFile(translationContext, fileDataCollection, filteredFiles, resourceType); + nestedFiles.add(resourceType); + } else if (resourceType.equals(HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource())) { + Optional<String> nestedFile = handleResourceGrpNestedFile(resource, translationContext, + fileDataCollection, filteredFiles, filenames); + nestedFile.ifPresent(nestedFiles::add); } } + return nestedFiles; } - private static void handleResourceGrpNestedFile(Resource resource, TranslationContext translationContext, - FileDataCollection fileDataCollection, - Map<String, FileData> filteredFiles, List<String> filenames, - Set<String> referenced) { + private static Optional<String> handleResourceGrpNestedFile(Resource resource, TranslationContext + translationContext, FileDataCollection fileDataCollection, + Map<String, FileData> filteredFiles, List<String> filenames) { Object resourceDef = resource.getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); Object innerTypeDef = ((Map) resourceDef).get(HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME); if (innerTypeDef instanceof String) { String internalResourceType = (String) innerTypeDef; if (filenames.contains(internalResourceType)) { - handleNestedFile(translationContext, fileDataCollection, filteredFiles, referenced, + handleNestedFile(translationContext, fileDataCollection, filteredFiles, internalResourceType); + return Optional.of(internalResourceType); } } + return Optional.empty(); } private static void handleNestedFile(TranslationContext translationContext, FileDataCollection fileDataCollection, - Map<String, FileData> filteredFiles, Set<String> referenced, + Map<String, FileData> filteredFiles, String nestedFileName) { - referenced.add(nestedFileName); fileDataCollection.addNestedFiles(filteredFiles.get(nestedFileName)); translationContext.getNestedHeatsFiles().add(nestedFileName); } - private static Map<String, FileData> filterFileDataListByType(List<FileData> fileDataList, - Set<FileData.Type> typesToGet) { + private static Map<String, FileData> filterFileDataListByType(List<FileData> fileDataList, + Set<FileData.Type> typesToGet) { Map<String, FileData> filtered = new HashMap<>(); - fileDataList.stream().filter(file -> typesToGet.contains(file.getType())) - .forEach(file -> filtered.put(file.getFile(), file)); + filterFileDataListByType(fileDataList, filtered, typesToGet, null); return filtered; } + private static void filterFileDataListByType(List<FileData> fileDataList, Map<String, FileData> filtered, + Set<FileData.Type> typesToGet, String parentFileName) { + fileDataList.stream().filter(file -> typesToGet.contains(file.getType())) + .forEach(file -> { + filtered.put(file.getFile(), file); + file.setParentFile(parentFileName); + }); + + Set<FileData.Type> canBeAssociatedTypes = typesToGet.stream() + .filter(FileData.Type::canBeAssociated).collect(Collectors.toSet()); + + fileDataList.stream().filter(file -> Objects.nonNull(file.getData())) + .forEach(file -> filterFileDataListByType(file.getData(), filtered, + canBeAssociatedTypes, file.getFile())); + } + private static List<String> extractFilenamesFromFileDataList(Collection<FileData> fileDataList) { return fileDataList.stream().map(FileData::getFile).collect(Collectors.toList()); } 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 ee0cee6bab..2a845fb06a 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 @@ -131,34 +131,21 @@ public class TranslationService { */ public void translateHeatFile(ServiceTemplate serviceTemplate, FileData heatFileData, TranslationContext context) { - translateHeatFile(serviceTemplate, heatFileData, null, context); - } - - /** - * Translate heat file. - * - * @param serviceTemplate the service template - * @param heatFileData the current heat file data - * @param parentHeatFileName the main heat to which associated current heat file (e.g. volume heat) - * @param context the context - */ - public void translateHeatFile(ServiceTemplate serviceTemplate, FileData heatFileData, String parentHeatFileName, - TranslationContext context) { String heatFileName = heatFileData.getFile(); HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil() .yamlToObject(context.getFileContent(heatFileName), HeatOrchestrationTemplate.class); translateInputParameters(serviceTemplate, heatOrchestrationTemplate, heatFileData, context, - heatFileName, parentHeatFileName); + heatFileName); + translateResources(heatFileName, serviceTemplate, heatOrchestrationTemplate, context); translateOutputParameters(serviceTemplate, heatOrchestrationTemplate, heatFileData, heatFileName, context); createHeatStackGroup(serviceTemplate, heatFileData, heatOrchestrationTemplate, context); handleHeatPseudoParam(heatFileName, serviceTemplate, context); - if (Objects.nonNull(heatFileData.getData())) { - heatFileData.getData().stream().filter(data -> data.getType() == FileData.Type.HEAT_VOL) - .forEach(data -> translateHeatFile(serviceTemplate, data, heatFileData.getFile(), context)); + heatFileData.getData().stream().filter(data -> FileData.Type.canBeAssociated(data.getType())) + .forEach(data -> translateHeatFile(serviceTemplate, data, context)); } } @@ -244,7 +231,7 @@ public class TranslationService { private void translateInputParameters(ServiceTemplate serviceTemplate, HeatOrchestrationTemplate heatOrchestrationTemplate, FileData heatFileData, TranslationContext context, - String heatFileName, String parentHeatFileName) { + String heatFileName) { if (heatOrchestrationTemplate.getParameters() == null) { return; } @@ -252,7 +239,7 @@ public class TranslationService { Map<String, ParameterDefinition> parameterDefinitionMap = TranslatorHeatToToscaParameterConverter .parameterConverter(serviceTemplate, heatOrchestrationTemplate.getParameters(), - heatOrchestrationTemplate, heatFileName, parentHeatFileName, context); + heatOrchestrationTemplate, heatFileName, heatFileData.getParentFile(), context); Environment heatEnvFile = getHeatEnvFile(heatFileData, context); Map<String, Object> parameters = heatEnvFile.getParameters(); Object parameterValue; @@ -286,19 +273,19 @@ public class TranslationService { } - private void updateAnnotations(Map<String, ParameterDefinition> inputParameters, Map<String, ParameterDefinition> newParameters) { - + private void updateAnnotations(Map<String, ParameterDefinition> inputParameters, Map<String, + ParameterDefinition> newParameters) { newParameters.entrySet().stream().filter(stringParameterDefinitionEntry -> - inputParameters.containsKey(stringParameterDefinitionEntry.getKey()) && - isHasAnnotation(inputParameters, stringParameterDefinitionEntry)). - forEach(stringParameterDefinitionEntry -> { - List inputParamVFModuleList = getVFModulesList(inputParameters.get(stringParameterDefinitionEntry.getKey())); + inputParameters.containsKey(stringParameterDefinitionEntry.getKey()) + && isHasAnnotation(inputParameters, stringParameterDefinitionEntry)) + .forEach(stringParameterDefinitionEntry -> { + List inputParamVFModuleList = getVFModulesList( + inputParameters.get(stringParameterDefinitionEntry.getKey())); List newParamVFModuleList = getVFModulesList(stringParameterDefinitionEntry.getValue()); - if(inputParamVFModuleList.contains(newParamVFModuleList.get(0))){ + if (inputParamVFModuleList.contains(newParamVFModuleList.get(0))) { newParamVFModuleList.remove(0); } newParamVFModuleList.addAll(inputParamVFModuleList); - }); } |