diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2017-11-05 17:14:25 +0200 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-11-05 15:39:16 +0000 |
commit | 7b492b5f191cd5c22e3c4254f5f3ef7476122e9d (patch) | |
tree | 883406afe9451ee6389ab9033021e528f2c9813a /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org | |
parent | d059aeab877b4217e05dff07fdbaf61bf6c1a73e (diff) |
Port scaling not working properly
Made changes in evaluating port naming pattern.
Change-Id: If9a3fc9c3d50fa5c4da319d2ff7d5f8ce6ca8ffe
Issue-ID: SDC-573
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java | 65 |
1 files changed, 26 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/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 c5a6735ee7..a09d56672d 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 @@ -1,16 +1,13 @@ package org.openecomp.sdc.translator.services.heattotosca; import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.math.NumberUtils; +import org.apache.commons.lang3.StringUtils; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes; import org.openecomp.sdc.heat.datatypes.model.Resource; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; @@ -47,7 +44,8 @@ import java.util.Objects; */ public class ConsolidationDataUtil { - protected static Logger logger = (Logger) LoggerFactory.getLogger(ConsolidationDataUtil.class); + private static final String UNDERSCORE = "_"; + private static final String DIGIT_REGEX = "\\d+"; /** * Gets compute template consolidation data. @@ -393,7 +391,7 @@ public class ConsolidationDataUtil { Resource targetResource = translateTo.getHeatOrchestrationTemplate().getResources().get(targetResourceId); NameExtractor nodeTypeNameExtractor = - translateTo.getContext().getNameExtractorImpl(targetResource.getType()); + TranslationContext.getNameExtractorImpl(targetResource.getType()); nodeType = nodeTypeNameExtractor.extractNodeTypeName(translateTo.getHeatOrchestrationTemplate() .getResources().get(dependentNodeTemplateId), @@ -438,10 +436,7 @@ public class ConsolidationDataUtil { Map<String, ImplementationConfiguration> supportedComputeResources = TranslationContext .getSupportedConsolidationComputeResources(); if (supportedComputeResources.containsKey(resourceType)) { - if (supportedComputeResources.get(resourceType).isEnable()) { - return true; - } - return false; + return supportedComputeResources.get(resourceType).isEnable(); } return false; } @@ -457,10 +452,7 @@ public class ConsolidationDataUtil { Map<String, ImplementationConfiguration> supportedComputeResources = TranslationContext .getSupportedConsolidationComputeResources(); if (supportedComputeResources.containsKey(resourceType)) { - if (supportedComputeResources.get(resourceType).isEnable()) { - return true; - } - return false; + return supportedComputeResources.get(resourceType).isEnable(); } return false; } @@ -478,10 +470,7 @@ public class ConsolidationDataUtil { Map<String, ImplementationConfiguration> supportedPortResources = TranslationContext .getSupportedConsolidationPortResources(); if (supportedPortResources.containsKey(resourceType)) { - if (supportedPortResources.get(resourceType).isEnable()) { - return true; - } - return false; + return supportedPortResources.get(resourceType).isEnable(); } return false; } @@ -497,10 +486,7 @@ public class ConsolidationDataUtil { Map<String, ImplementationConfiguration> supportedPortResources = TranslationContext .getSupportedConsolidationPortResources(); if (supportedPortResources.containsKey(resourceType)) { - if (supportedPortResources.get(resourceType).isEnable()) { - return true; - } - return false; + return supportedPortResources.get(resourceType).isEnable(); } return false; } @@ -540,26 +526,27 @@ public class ConsolidationDataUtil { * @return the port type */ public static String getPortType(String portNodeTemplateId) { - String[] portSplitArr = portNodeTemplateId.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)"); - String finalValue = ""; - if (NumberUtils.isNumber(portSplitArr[portSplitArr.length - 1])) { - for (String id : portSplitArr) { - finalValue = finalValue + id; - } - while (finalValue.length() > 0) { - if (Character.isLetter(finalValue.charAt(finalValue.length() - 1))) { - break; - } - finalValue = finalValue.substring(0, finalValue.length() - 1); + + if (!StringUtils.isNotBlank(portNodeTemplateId)) { + return portNodeTemplateId; + } + + String formattedName = portNodeTemplateId.replaceAll(DIGIT_REGEX + "$", ""); + + StringBuilder sb = new StringBuilder(); + int count = 0; + for (String token : formattedName.split(UNDERSCORE)) { + + if (StringUtils.isNotBlank(token)) { + count++; } - } else { - for (String id : portSplitArr) { - if (!NumberUtils.isNumber(id)) { - finalValue = finalValue + id; - } + + if (count != 2 || !token.matches(DIGIT_REGEX)) { + sb.append(token).append(UNDERSCORE); } } - return finalValue; + + return portNodeTemplateId.endsWith(UNDERSCORE) ? sb.toString() : sb.substring(0, sb.length() - 1); } /** |