From 81c51aba1e8ba0a801a1d3d0430bf00a88680a9e Mon Sep 17 00:00:00 2001 From: eleonorali Date: Wed, 1 Aug 2018 16:28:50 +0300 Subject: TOSCA Consolidation Data - Refactoring Part 4 Some additional minor changes Change-Id: Ia0a89b8cfba9ed5b4ead06ab42b93421d79a4beb Issue-ID: SDC-1330 Signed-off-by: eleonorali --- .../SubInterfaceConsolidationDataHandler.java | 12 ++-- .../heattotosca/ConsolidationDataUtil.java | 79 ++++------------------ .../services/heattotosca/HeatToToscaUtil.java | 7 +- 3 files changed, 22 insertions(+), 76 deletions(-) (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java index 6dc44f9758..d1b4148672 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java @@ -1,4 +1,3 @@ -/* /* * Copyright © 2016-2018 European Support Limited * @@ -80,7 +79,7 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa throw new UnsupportedOperationException( - "API removeParamNameFromAttrFuncList " + "not supported for SubInterfaceConsolidationDataHandler"); + "API removeParamNameFromAttrFuncList doesn't supported for SubInterfaceConsolidationDataHandler"); } @Override @@ -190,12 +189,9 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa if (MapUtils.isEmpty(resourceIdTranslatedResourceIdMap)) { return Optional.empty(); } - for (Map.Entry entry : resourceIdTranslatedResourceIdMap.entrySet()) { - if (entry.getValue().equals(parentPortNodeTemplateId)) { - return Optional.of(entry.getKey()); - } - } - return Optional.empty(); + return resourceIdTranslatedResourceIdMap.entrySet().stream() + .filter(entry -> entry.getValue().equals(parentPortNodeTemplateId)) + .findFirst().map(Map.Entry::getKey); } private TranslateTo createTranslateTo(FunctionTranslator functionTranslator, String resourceId, 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 01e601738b..e7c32e195b 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 @@ -39,9 +39,9 @@ import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslatio import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR; -/** - * Utility class for consolidation data collection helper methods. - */ + /** + * Utility class for consolidation data collection helper methods. + */ public class ConsolidationDataUtil { private static final String UNDERSCORE = "_"; @@ -192,24 +192,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants. } - /** - * 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 supportedComputeResources = - TranslationContext.getSupportedConsolidationComputeResources(); - if (supportedComputeResources.containsKey(resourceType)) { - return supportedComputeResources.get(resourceType).isEnable(); - } - return false; - } - /** * Checks if the current HEAT resource if of type compute. * @@ -226,24 +208,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants. 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 supportedPortResources = - TranslationContext.getSupportedConsolidationPortResources(); - if (supportedPortResources.containsKey(resourceType)) { - return supportedPortResources.get(resourceType).isEnable(); - } - return false; - } - /** * Checks if the current HEAT resource if of type port. * @@ -260,21 +224,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants. 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. * @@ -403,19 +352,19 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants. } private static String getToscaPropertyName(FunctionTranslator functionTranslator) { - String toscaPropertyName = functionTranslator.getPropertyName(); HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate(); Resource resource = heatOrchestrationTemplate.getResources().get(functionTranslator.getResourceId()); - boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource); - if (!isNestedResource) { - String heatPropertyName = toscaPropertyName; - //For handling get_attr in inner levels for complex properties - if (toscaPropertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) { - heatPropertyName = - toscaPropertyName.substring(0, toscaPropertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR)); - } - toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), - resource.getType(), heatPropertyName); + String toscaPropertyName = functionTranslator.getPropertyName(); + if (!HeatToToscaUtil.isNestedResource(resource)) { + return HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(), + resource.getType(), getHeatPropertyName(toscaPropertyName)); + } + return toscaPropertyName; + } + + private static String getHeatPropertyName(String toscaPropertyName) { + if (toscaPropertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) { + return toscaPropertyName.substring(0, toscaPropertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR)); } return toscaPropertyName; } 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 bd8b558f11..2d283d301a 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 @@ -652,9 +652,10 @@ public class HeatToToscaUtil { Optional nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource); HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject( context.getFileContent(nestedHeatFileName.get()), HeatOrchestrationTemplate.class); - if (Objects.nonNull(nestedHeatOrchestrationTemplate.getResources())) { - for (String innerResourceId : nestedHeatOrchestrationTemplate.getResources().keySet()) { - if (ConsolidationDataUtil.isComputeResource(nestedHeatOrchestrationTemplate, innerResourceId)) { + Map resources = nestedHeatOrchestrationTemplate.getResources(); + if (Objects.nonNull(resources)) { + for (Resource innerResource : resources.values()) { + if (ConsolidationDataUtil.isComputeResource(innerResource)) { return true; } } -- cgit 1.2.3-korg