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/helper/ContrailTranslationHelper.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java | 179 |
1 files changed, 79 insertions, 100 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java index cabb92c254..c36d8c66fa 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/ContrailTranslationHelper.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.translator.services.heattotosca.helper; import java.util.ArrayList; @@ -26,7 +25,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; - import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.heat.datatypes.HeatBoolean; import org.openecomp.sdc.heat.datatypes.model.Resource; @@ -37,108 +35,89 @@ import org.openecomp.sdc.translator.services.heattotosca.ConfigConstants; import org.openecomp.sdc.translator.services.heattotosca.NameExtractor; public class ContrailTranslationHelper { - /** - * Gets compute node type id. - * - * @param contrailServiceTemplateResource contrail service teamplte resource - * @param contrailServiceTemplateResourceId contrailservice template resource id - * @param contrailServiceTemplateTranslatedId contrail service tempalte resource translated id - * @return the compute node type id - */ - public String getComputeNodeTypeId(Resource contrailServiceTemplateResource, - String contrailServiceTemplateResourceId, - String contrailServiceTemplateTranslatedId, - TranslationContext context) { - NameExtractor nodeTypeNameExtractor = - context.getNameExtractorImpl(ConfigConstants.CONTRAIL_COMPUTE_NODE_TYPE_IMPL_KEY); - return nodeTypeNameExtractor - .extractNodeTypeName(contrailServiceTemplateResource, contrailServiceTemplateResourceId, - contrailServiceTemplateTranslatedId); - } - - /** - * Get property Regx matcher list. - * - * @return Regex exprission per contrail service template resource property, while contail compute - * type name is consider when setting the name value - */ - public List<PropertyRegexMatcher> getPropertyRegexMatchersForComputeNodeType() { - List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>(); - propertyRegexMatchers - .add(new PropertyRegexMatcher("image_name", Collections.singletonList(".+_image_name$"), - "_image_name")); - propertyRegexMatchers - .add(new PropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"), - "_flavor_name")); - return propertyRegexMatchers; - } - public String getSubstitutionContrailServiceTemplateMetadata(String heatFileName, - String serviceInstanceTranslatedId) { - return FileUtils.getFileWithoutExtention(heatFileName) + "_" + serviceInstanceTranslatedId; - } - - /** - * Translate fn split function optional. - * - * @param propertyValue the property value - * @param listSize the list size - * @param includeBooleanValue the include boolean value - * @return the optional - */ - public Optional<List<Map<String, List>>> translateFnSplitFunction(Object propertyValue, - int listSize, - boolean - includeBooleanValue) { - List<Map<String, List>> tokenPropertyValueList = new ArrayList<>(); - - if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { - Map<String, Object> propMap = (Map) propertyValue; - Map.Entry<String, Object> entry = propMap.entrySet().iterator().next(); - Object entity = entry.getValue(); - String key = entry.getKey(); - String tokenChar; + /** + * Gets compute node type id. + * + * @param contrailServiceTemplateResource contrail service teamplte resource + * @param contrailServiceTemplateResourceId contrailservice template resource id + * @param contrailServiceTemplateTranslatedId contrail service tempalte resource translated id + * @return the compute node type id + */ + public String getComputeNodeTypeId(Resource contrailServiceTemplateResource, String contrailServiceTemplateResourceId, + String contrailServiceTemplateTranslatedId, TranslationContext context) { + NameExtractor nodeTypeNameExtractor = context.getNameExtractorImpl(ConfigConstants.CONTRAIL_COMPUTE_NODE_TYPE_IMPL_KEY); + return nodeTypeNameExtractor + .extractNodeTypeName(contrailServiceTemplateResource, contrailServiceTemplateResourceId, contrailServiceTemplateTranslatedId); + } - if (key.equals("Fn::Split") && entity instanceof List) { - tokenChar = (String) ((List) entity).get(0); - Object refParameter = ((List) entity).get(1); + /** + * Get property Regx matcher list. + * + * @return Regex exprission per contrail service template resource property, while contail compute type name is consider when setting the name + * value + */ + public List<PropertyRegexMatcher> getPropertyRegexMatchersForComputeNodeType() { + List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>(); + propertyRegexMatchers.add(new PropertyRegexMatcher("image_name", Collections.singletonList(".+_image_name$"), "_image_name")); + propertyRegexMatchers.add(new PropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"), "_flavor_name")); + return propertyRegexMatchers; + } - for (int substringIndex = 0; substringIndex < listSize; substringIndex++) { - Map<String, List> tokenPropertyValue = new HashMap<>(); - tokenPropertyValue.put("token", new ArrayList<>()); + public String getSubstitutionContrailServiceTemplateMetadata(String heatFileName, String serviceInstanceTranslatedId) { + return FileUtils.getFileWithoutExtention(heatFileName) + "_" + serviceInstanceTranslatedId; + } - if (refParameter instanceof Map && ((Map) refParameter).get("Ref") != null) { - Map<String, String> stringWithToken = new HashMap<>(); - ((Map) stringWithToken) - .put(ToscaFunctions.GET_INPUT.getFunctionName(), ((Map) refParameter).get("Ref")); - tokenPropertyValue.get("token").add(stringWithToken); - } else if (refParameter instanceof String) { - if (includeBooleanValue) { - StringBuilder booleanBuilder = new StringBuilder(); - String[] booleanValueList = ((String) refParameter).split(tokenChar); - for (int i = 0; i < booleanValueList.length; i++) { - if (i == 0) { - booleanBuilder.append(HeatBoolean.eval(booleanValueList[i])); - } else { - booleanBuilder.append(tokenChar); - booleanBuilder.append(HeatBoolean.eval(booleanValueList[i])); + /** + * Translate fn split function optional. + * + * @param propertyValue the property value + * @param listSize the list size + * @param includeBooleanValue the include boolean value + * @return the optional + */ + public Optional<List<Map<String, List>>> translateFnSplitFunction(Object propertyValue, int listSize, boolean includeBooleanValue) { + List<Map<String, List>> tokenPropertyValueList = new ArrayList<>(); + if (propertyValue instanceof Map && !((Map) propertyValue).isEmpty()) { + Map<String, Object> propMap = (Map) propertyValue; + Map.Entry<String, Object> entry = propMap.entrySet().iterator().next(); + Object entity = entry.getValue(); + String key = entry.getKey(); + String tokenChar; + if (key.equals("Fn::Split") && entity instanceof List) { + tokenChar = (String) ((List) entity).get(0); + Object refParameter = ((List) entity).get(1); + for (int substringIndex = 0; substringIndex < listSize; substringIndex++) { + Map<String, List> tokenPropertyValue = new HashMap<>(); + tokenPropertyValue.put("token", new ArrayList<>()); + if (refParameter instanceof Map && ((Map) refParameter).get("Ref") != null) { + Map<String, String> stringWithToken = new HashMap<>(); + ((Map) stringWithToken).put(ToscaFunctions.GET_INPUT.getFunctionName(), ((Map) refParameter).get("Ref")); + tokenPropertyValue.get("token").add(stringWithToken); + } else if (refParameter instanceof String) { + if (includeBooleanValue) { + StringBuilder booleanBuilder = new StringBuilder(); + String[] booleanValueList = ((String) refParameter).split(tokenChar); + for (int i = 0; i < booleanValueList.length; i++) { + if (i == 0) { + booleanBuilder.append(HeatBoolean.eval(booleanValueList[i])); + } else { + booleanBuilder.append(tokenChar); + booleanBuilder.append(HeatBoolean.eval(booleanValueList[i])); + } + } + tokenPropertyValue.get("token").add(booleanBuilder.toString()); + } else { + tokenPropertyValue.get("token").add(refParameter); + } + } + tokenPropertyValue.get("token").add(tokenChar); + tokenPropertyValue.get("token").add(substringIndex); + tokenPropertyValueList.add(tokenPropertyValue); } - } - tokenPropertyValue.get("token").add(booleanBuilder.toString()); - } else { - tokenPropertyValue.get("token").add(refParameter); + return Optional.of(tokenPropertyValueList); } - } - tokenPropertyValue.get("token").add(tokenChar); - tokenPropertyValue.get("token").add(substringIndex); - tokenPropertyValueList.add(tokenPropertyValue); } - - return Optional.of(tokenPropertyValueList); - - } + return Optional.empty(); } - - return Optional.empty(); - } } |