diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java')
1 files changed, 33 insertions, 62 deletions
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/ResourceTranslationResourceGroupImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java index 779550e99d..d976434e06 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationResourceGroupImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation; import static org.openecomp.sdc.heat.services.HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME; @@ -25,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; - import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; @@ -48,61 +46,51 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas @Override protected void translate(TranslateTo translateTo) { final String heatFileName = translateTo.getHeatFileName(); - Object resourceDef = - translateTo.getResource().getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); + Object resourceDef = translateTo.getResource().getProperties().get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME); Resource nestedResource = new Resource(); Object typeDefinition = ((Map) resourceDef).get(RESOURCE_DEF_TYPE_PROPERTY_NAME); if (!(typeDefinition instanceof String)) { logger.warn("Resource '{}' of type '{}' with resourceDef which is not pointing to nested heat file is not" - + " supported and will be ignored in the translation ", translateTo.getResourceId(), - HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()); + + " supported and will be ignored in the translation ", translateTo.getResourceId(), + HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()); return; } String type = (String) typeDefinition; if (!HeatToToscaUtil.isYmlFileType(type)) { logger.warn("Resource '{}' of type '{}' with resourceDef which is not pointing to nested heat file is not" - + " supported and will be ignored in the translation ", translateTo.getResourceId(), - HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()); + + " supported and will be ignored in the translation ", translateTo.getResourceId(), + HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource()); return; } - nestedResource.setType(type); - nestedResource.setProperties((Map<String, Object>) ((Map) resourceDef).get(HeatConstants - .RESOURCE_DEF_PROPERTIES)); + nestedResource.setProperties((Map<String, Object>) ((Map) resourceDef).get(HeatConstants.RESOURCE_DEF_PROPERTIES)); nestedResource.setMetadata(((Map) resourceDef).get(NESTED_RESOURCE_METADATA)); - - Optional<String> substitutionNodeTemplateId = - ResourceTranslationFactory.getInstance(nestedResource) - .translateResource(heatFileName, translateTo.getServiceTemplate(), - translateTo.getHeatOrchestrationTemplate(), nestedResource, - translateTo.getResourceId(), translateTo.getContext()); - - substitutionNodeTemplateId.ifPresent(nodeTemplateId -> addSubstitutionNodeTemplate(translateTo, - nodeTemplateId)); + Optional<String> substitutionNodeTemplateId = ResourceTranslationFactory.getInstance(nestedResource) + .translateResource(heatFileName, translateTo.getServiceTemplate(), translateTo.getHeatOrchestrationTemplate(), nestedResource, + translateTo.getResourceId(), translateTo.getContext()); + substitutionNodeTemplateId.ifPresent(nodeTemplateId -> addSubstitutionNodeTemplate(translateTo, nodeTemplateId)); } private void addSubstitutionNodeTemplate(TranslateTo translateTo, String substitutionNodeTemplateId) { - NodeTemplate substitutionNodeTemplate = - DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId); + NodeTemplate substitutionNodeTemplate = DataModelUtil.getNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId); if (Objects.isNull(substitutionNodeTemplate)) { return; } - Map<String, Object> serviceTemplateFilter = (Map<String, Object>) substitutionNodeTemplate - .getProperties().get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + Map<String, Object> serviceTemplateFilter = (Map<String, Object>) substitutionNodeTemplate.getProperties() + .get(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); populateServiceTemplateFilterProperties(translateTo, substitutionNodeTemplate, serviceTemplateFilter); handlingIndexVar(translateTo, substitutionNodeTemplate); - DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId, - substitutionNodeTemplate); + DataModelUtil.addNodeTemplate(translateTo.getServiceTemplate(), substitutionNodeTemplateId, substitutionNodeTemplate); } private void handlingIndexVar(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate) { List<String> indexVarProperties = new ArrayList<>(); String indexVarValue = getIndexVarValue(translateTo); - replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties(), indexVarProperties, - translateTo); + replacePropertiesIndexVarValue(indexVarValue, substitutionNodeTemplate.getProperties(), indexVarProperties, translateTo); //Add index var properties to context for unified model later - translateTo.getContext().addIndexVarProperties(ToscaUtil.getServiceTemplateFileName(translateTo - .getServiceTemplate()), translateTo.getTranslatedId(), indexVarProperties); + translateTo.getContext() + .addIndexVarProperties(ToscaUtil.getServiceTemplateFileName(translateTo.getServiceTemplate()), translateTo.getTranslatedId(), + indexVarProperties); } private Map<String, List<String>> getNewIndexVarValue() { @@ -115,55 +103,47 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas return newIndexVarValue; } - private void replacePropertiesIndexVarValue(String indexVarValue, - Map<String, Object> properties, - List<String> indexVarProperties, + private void replacePropertiesIndexVarValue(String indexVarValue, Map<String, Object> properties, List<String> indexVarProperties, TranslateTo translateTo) { if (properties == null || properties.isEmpty()) { return; } - for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) { Object propertyValue = propertyEntry.getValue(); if (propertyValue != null && propertyValue.equals(RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE)) { indexVarProperties.add(propertyEntry.getKey()); } - Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue, - indexVarProperties, translateTo); + Object newPropertyValue = getUpdatedPropertyValueWithIndex(indexVarValue, propertyValue, indexVarProperties, translateTo); if (newPropertyValue != null) { properties.put(propertyEntry.getKey(), newPropertyValue); } } } - private Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue, - List<String> indexVarProperties, + private Object getUpdatedPropertyValueWithIndex(String indexVarValue, Object propertyValue, List<String> indexVarProperties, TranslateTo translateTo) { if (propertyValue instanceof String) { return handleStringPropertyValueWithIndex(indexVarValue, propertyValue); } else if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { return handleMapPropertyValueWithIndex(indexVarValue, propertyValue, indexVarProperties, translateTo); } else if (propertyValue instanceof List && !((List) propertyValue).isEmpty()) { - return handleListPropertyValueWithIndex(indexVarValue, (List) propertyValue, indexVarProperties, - translateTo); + return handleListPropertyValueWithIndex(indexVarValue, (List) propertyValue, indexVarProperties, translateTo); } return propertyValue; } - private Object handleListPropertyValueWithIndex(String indexVarValue, List propertyValue, - List<String> indexVarProperties, TranslateTo translateTo) { + private Object handleListPropertyValueWithIndex(String indexVarValue, List propertyValue, List<String> indexVarProperties, + TranslateTo translateTo) { List<Object> newPropertyValueList = new ArrayList<>(); for (Object entry : propertyValue) { - newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry, - indexVarProperties, translateTo)); + newPropertyValueList.add(getUpdatedPropertyValueWithIndex(indexVarValue, entry, indexVarProperties, translateTo)); } return newPropertyValueList; } - private Object handleMapPropertyValueWithIndex(String indexVarValue, Object propertyValue, - List<String> indexVarProperties, TranslateTo translateTo) { - replacePropertiesIndexVarValue(indexVarValue, (Map<String, Object>) propertyValue, indexVarProperties, - translateTo); + private Object handleMapPropertyValueWithIndex(String indexVarValue, Object propertyValue, List<String> indexVarProperties, + TranslateTo translateTo) { + replacePropertiesIndexVarValue(indexVarValue, (Map<String, Object>) propertyValue, indexVarProperties, translateTo); return propertyValue; } @@ -175,7 +155,6 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas Map<String, List<Object>> concatMap = new HashMap<>(); List<Object> concatList = new ArrayList<>(); String value = (String) propertyValue; - while (value.contains(indexVarValue)) { if (value.indexOf(indexVarValue) == 0) { concatList.add(getNewIndexVarValue()); @@ -189,7 +168,6 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas if (!value.isEmpty()) { concatList.add(value); } - concatMap.put(ToscaFunctions.CONCAT.getFunctionName(), concatList); return concatMap; } @@ -201,26 +179,19 @@ public class ResourceTranslationResourceGroupImpl extends ResourceTranslationBas if (indexVar == null) { return HeatConstants.RESOURCE_GROUP_INDEX_VAR_DEFAULT_VALUE; } - if (indexVar instanceof String) { return (String) indexVar; } - throw new CoreException( - new InvalidPropertyValueErrorBuilder(HeatConstants.INDEX_PROPERTY_NAME, - indexVar.toString(), "String").build()); + throw new CoreException(new InvalidPropertyValueErrorBuilder(HeatConstants.INDEX_PROPERTY_NAME, indexVar.toString(), "String").build()); } - private void populateServiceTemplateFilterProperties(TranslateTo translateTo, - NodeTemplate substitutionNodeTemplate, + private void populateServiceTemplateFilterProperties(TranslateTo translateTo, NodeTemplate substitutionNodeTemplate, Map<String, Object> serviceTemplateFilter) { boolean mandatory = false; Object countValue = TranslatorHeatToToscaPropertyConverter - .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getResourceId(), - ToscaConstants.COUNT_PROPERTY_NAME, translateTo.getResource().getProperties() - .get(ToscaConstants.COUNT_PROPERTY_NAME), null, - translateTo.getHeatFileName(), translateTo.getHeatOrchestrationTemplate(), - substitutionNodeTemplate, translateTo.getContext()); - + .getToscaPropertyValue(translateTo.getServiceTemplate(), translateTo.getResourceId(), ToscaConstants.COUNT_PROPERTY_NAME, + translateTo.getResource().getProperties().get(ToscaConstants.COUNT_PROPERTY_NAME), null, translateTo.getHeatFileName(), + translateTo.getHeatOrchestrationTemplate(), substitutionNodeTemplate, translateTo.getContext()); if (countValue != null) { serviceTemplateFilter.put(ToscaConstants.COUNT_PROPERTY_NAME, countValue); } else { |