diff options
author | aribeiro <anderson.ribeiro@est.tech> | 2019-10-01 16:47:26 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-11-19 07:48:02 +0000 |
commit | 35b5687d60558bac72c1e53ddd9044584964a3d8 (patch) | |
tree | dc2e184f2cef02c6d1aee0b5baf1585d2b7b3ffe /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main | |
parent | 0f9257b8265404c82ccdfae6aafce940f20a2947 (diff) |
Fix for scalar-unit type value.
Issue-ID: SDC-323
Change-Id: I7f19a7356e1cd34deca0a168b3cb707ef657b9cb
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main')
3 files changed, 67 insertions, 39 deletions
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 866f78c1b5..339d6ff023 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 @@ -232,12 +232,12 @@ public class TranslationService { return; } + final Environment heatEnvFile = getHeatEnvFile(heatFileData, context); + final Map<String, Object> parameters = heatEnvFile.getParameters(); Map<String, ParameterDefinition> parameterDefinitionMap = TranslatorHeatToToscaParameterConverter .parameterConverter(serviceTemplate, heatOrchestrationTemplate.getParameters(), - heatOrchestrationTemplate, heatFileName, heatFileData.getParentFile(), context); - Environment heatEnvFile = getHeatEnvFile(heatFileData, context); - Map<String, Object> parameters = heatEnvFile.getParameters(); + heatOrchestrationTemplate, heatFileName, heatFileData.getParentFile(), context, parameters); Object parameterValue; if (parameters != null) { for (Map.Entry<String, ParameterDefinition> entry : parameterDefinitionMap.entrySet()) { diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java index 84d36f7bb3..a69c26c04f 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationCinderVolumeImpl.java @@ -16,6 +16,7 @@ package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation; +import java.util.Map; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.heat.datatypes.HeatBoolean; import org.openecomp.sdc.heat.services.HeatConstants; @@ -25,16 +26,14 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo; import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatToToscaPropertyConverter; -import java.util.Map; - public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase { private static final String VOLUME_SIZE_PROPERTY_NAME = "size"; @Override - public void translate(TranslateTo translateTo) { - NodeTemplate nodeTemplate = new NodeTemplate(); + public void translate(final TranslateTo translateTo) { + final NodeTemplate nodeTemplate = new NodeTemplate(); nodeTemplate.setType(ToscaNodeType.CINDER_VOLUME); nodeTemplate.setProperties(TranslatorHeatToToscaPropertyConverter .getToscaPropertiesSimpleConversion(translateTo.getServiceTemplate(), @@ -43,9 +42,9 @@ public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase translateTo.getHeatOrchestrationTemplate(), translateTo.getResource().getType(), nodeTemplate, translateTo.getContext())); handleSizeProperty(nodeTemplate.getProperties()); - String toscaReadOnlyPropName = + final String toscaReadOnlyPropName = HeatToToscaUtil.getToscaPropertyName(translateTo, HeatConstants.READ_ONLY_PROPERTY_NAME); - Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName); + final Object readOnlyPropVal = nodeTemplate.getProperties().get(toscaReadOnlyPropName); if (readOnlyPropVal != null && !(readOnlyPropVal instanceof Map)) { nodeTemplate.getProperties().put(toscaReadOnlyPropName, HeatBoolean.eval(readOnlyPropVal)); } @@ -54,18 +53,11 @@ public class ResourceTranslationCinderVolumeImpl extends ResourceTranslationBase } - private void handleSizeProperty(Map<String, Object> nodeTemplateProperties) { - Object size = nodeTemplateProperties.get(VOLUME_SIZE_PROPERTY_NAME); + private void handleSizeProperty(final Map<String, Object> nodeTemplateProperties) { + final Object size = nodeTemplateProperties.get(VOLUME_SIZE_PROPERTY_NAME); if (size == null) { return; } - if (size instanceof Map) { - Map<String, Object> propMap = (Map) size; - Map.Entry<String, Object> entry = propMap.entrySet().iterator().next(); - String val = "(" + entry.getKey() + " : " + entry.getValue() + ") * 1024"; - nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, val); - } else { - nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, size + "*1024"); - } + nodeTemplateProperties.put(VOLUME_SIZE_PROPERTY_NAME, size); } } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java index d4dc1ac80f..386b2e1ea9 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/mapping/TranslatorHeatToToscaParameterConverter.java @@ -23,14 +23,23 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; - import org.apache.commons.collections4.MapUtils; -import org.onap.sdc.tosca.datatypes.model.*; +import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.tosca.datatypes.model.Constraint; +import org.onap.sdc.tosca.datatypes.model.EntrySchema; +import org.onap.sdc.tosca.datatypes.model.ParameterDefinition; +import org.onap.sdc.tosca.datatypes.model.ScalarUnitValidator; +import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; import org.onap.sdc.tosca.datatypes.model.heatextend.AnnotationDefinition; import org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt; import org.openecomp.core.utilities.file.FileUtils; - +import org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes; +import org.openecomp.sdc.heat.datatypes.ToscaScalarUnitFrequency; +import org.openecomp.sdc.heat.datatypes.ToscaScalarUnitSize; +import org.openecomp.sdc.heat.datatypes.ToscaScalarUnitTime; +import org.openecomp.sdc.heat.datatypes.ToscaScalarUnitTypes; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.model.Output; import org.openecomp.sdc.heat.datatypes.model.Parameter; @@ -78,15 +87,17 @@ public class TranslatorHeatToToscaParameterConverter { * @return the map */ public static Map<String, ParameterDefinition> parameterConverter(ServiceTemplate serviceTemplate, - Map<String, Parameter> parameters, HeatOrchestrationTemplate heatOrchestrationTemplate, - String heatFileName, String parentHeatFileName, TranslationContext context) { + Map<String, Parameter> parameters, + HeatOrchestrationTemplate heatOrchestrationTemplate, + String heatFileName, String parentHeatFileName, + TranslationContext context, + Map<String, Object> heatEnvParameters) { Map<String, ParameterDefinition> parameterDefinitionMap = new HashMap<>(); for (Map.Entry<String, Parameter> entry : parameters.entrySet()) { String heatParamName = entry.getKey(); parameterDefinitionMap.put(heatParamName, - getToscaParameter(serviceTemplate,heatParamName, entry.getValue(), - heatOrchestrationTemplate, - heatFileName, parentHeatFileName, context)); + getToscaParameter(serviceTemplate,heatParamName, entry.getValue(), heatOrchestrationTemplate, heatFileName, + parentHeatFileName, context, heatEnvParameters)); } return parameterDefinitionMap; } @@ -100,9 +111,9 @@ public class TranslatorHeatToToscaParameterConverter { * @param context the context * @return the map */ - public static Map<String, ParameterDefinition> parameterOutputConverter(ServiceTemplate - serviceTemplate, - Map<String, Output> parameters, HeatOrchestrationTemplate heatOrchestrationTemplate, + public static Map<String, ParameterDefinition> parameterOutputConverter(ServiceTemplate serviceTemplate, + Map<String, Output> parameters, + HeatOrchestrationTemplate heatOrchestrationTemplate, String heatFileName, TranslationContext context) { Map<String, ParameterDefinition> parameterDefinitionMap = new HashMap<>(); for (Map.Entry<String, Output> entry : parameters.entrySet()) { @@ -125,16 +136,16 @@ public class TranslatorHeatToToscaParameterConverter { * @return the tosca parameter */ private static ParameterDefinitionExt getToscaParameter(ServiceTemplate serviceTemplate, - String heatParameterName, - Parameter heatParameter, - HeatOrchestrationTemplate - heatOrchestrationTemplate, - String heatFileName, - String parentHeatFileName, - TranslationContext context) { + String heatParameterName, + Parameter heatParameter, + HeatOrchestrationTemplate heatOrchestrationTemplate, + String heatFileName, + String parentHeatFileName, + TranslationContext context, + Map<String, Object> heatEnvParameters) { ParameterDefinitionExt toscaParameter = new ParameterDefinitionExt(); - toscaParameter.setType(getToscaParameterType(heatParameter.getType())); + toscaParameter.setType(getToscaParameterType(heatParameter.getType(), heatEnvParameters)); toscaParameter.setEntry_schema(getToscaParameterEntrySchema(toscaParameter.getType())); toscaParameter.setLabel(heatParameter.getLabel()); toscaParameter.setDescription(heatParameter.getDescription()); @@ -330,7 +341,32 @@ public class TranslatorHeatToToscaParameterConverter { return entrySchema; } - protected static String getToscaParameterType(String heatParameterType) { + protected static String getToscaParameterType(final String heatParameterType, + final Map<String, Object> heatEnvParameters) { + if (heatEnvParameters != null && DefinedHeatParameterTypes.NUMBER.getType().equals(heatParameterType)) { + if (getScalarUnitType(heatEnvParameters, ToscaScalarUnitSize.class) != null) { + return ToscaScalarUnitTypes.SCALAR_UNIT_SIZE.getType(); + } else if (getScalarUnitType(heatEnvParameters, ToscaScalarUnitTime.class) != null) { + return ToscaScalarUnitTypes.SCALAR_UNIT_TIME.getType(); + } else if (getScalarUnitType(heatEnvParameters, ToscaScalarUnitFrequency.class) != null) { + return ToscaScalarUnitTypes.SCALAR_UNIT_FREQUENCY.getType(); + } + } + return parameterTypeMapping.get(heatParameterType); } + + private static <E extends Enum<E>> String getScalarUnitType(final Map<String, Object> heatEnvParameters, + final Class<E> enumClass) { + final ScalarUnitValidator scalarUnitValidator = ScalarUnitValidator.getInstance(); + if (Arrays.stream(enumClass.getEnumConstants()).anyMatch(unitType -> + heatEnvParameters.values().stream().filter(Objects::nonNull) + .anyMatch(parameterValue -> scalarUnitValidator.isScalarUnit(parameterValue.toString()) && + Arrays.stream(StringUtils.split(parameterValue.toString())) + .anyMatch(strParamValue -> strParamValue.equalsIgnoreCase(unitType.name()))))) { + return enumClass.getTypeName(); + } + return null; + } + } |