diff options
author | avigaffa <avi.gaffa@amdocs.com> | 2018-03-11 12:23:20 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-03-11 16:05:10 +0000 |
commit | 3107efd8aa9721a195580fc283205bed26104875 (patch) | |
tree | 1a5b6992dd71f12b9521514de41acd340fe68abb /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main | |
parent | a6d224838995e21205152bbea8ed2c719ea4ee59 (diff) |
Validation of VSP fails with error null
Change-Id: I98bbff6b567932d06d4764ac24bc25984741834c
Issue-ID: SDC-1093
Signed-off-by: avigaffa <avi.gaffa@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main')
2 files changed, 61 insertions, 32 deletions
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 370f48915a..487dd19458 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 @@ -86,7 +86,6 @@ import org.openecomp.sdc.translator.services.heattotosca.mapping.TranslatorHeatT import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -95,6 +94,8 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -130,9 +131,9 @@ public class HeatToToscaUtil { fileNameContentMap.getFileList().stream() .filter(fileName -> !(fileName.equals(SdcCommon.MANIFEST_NAME))).forEach( - fileName -> heatToToscaTranslator - .addFile(fileName, FileUtils.toByteArray - (fileNameContentMap.getFileContent(fileName)))); + fileName -> heatToToscaTranslator + .addFile(fileName, FileUtils.toByteArray + (fileNameContentMap.getFileContent(fileName)))); Map<String, List<ErrorMessage>> errors = heatToToscaTranslator.validate(); if (MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors))) { @@ -564,7 +565,7 @@ public class HeatToToscaUtil { } private static boolean isNestedVlanResource(String nestedHeatFileName, - TranslationContext translationContext) { + TranslationContext translationContext) { HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil() .yamlToObject(translationContext.getFileContent(nestedHeatFileName), HeatOrchestrationTemplate.class); @@ -606,7 +607,7 @@ public class HeatToToscaUtil { public static String getSubInterfaceResourceType(Resource resource) { if (!HeatToToscaUtil.isYamlFile(resource.getType())) { - return ((Map) resource.getProperties() + return ((Map) resource.getProperties() .get(HeatConstants.RESOURCE_DEF_PROPERTY_NAME)) .get(HeatConstants.RESOURCE_DEF_TYPE_PROPERTY_NAME) .toString(); @@ -635,10 +636,10 @@ public class HeatToToscaUtil { Map<String, String> parentPortPropertyValue = (Map) parentPortObj; if (parentPortPropertyValue.keySet().contains(ResourceReferenceFunctions .GET_RESOURCE.getFunction())) { - return ResourceTranslationBase.getResourceTranslatedId(subInterfaceTo.getHeatFileName(), - subInterfaceTo.getHeatOrchestrationTemplate(), - parentPortPropertyValue.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()), - subInterfaceTo.getContext()); + return ResourceTranslationBase.getResourceTranslatedId(subInterfaceTo.getHeatFileName(), + subInterfaceTo.getHeatOrchestrationTemplate(), + parentPortPropertyValue.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()), + subInterfaceTo.getContext()); } } } @@ -1267,10 +1268,10 @@ public class HeatToToscaUtil { //set substitution node type requirements exposedRequirementsDefinition = toscaAnalyzerService.calculateExposedRequirements(nodeTypeRequirementsDefinition, - nodeTemplateRequirementsAssignment); + nodeTemplateRequirementsAssignment); DataModelUtil .addSubstitutionNodeTypeRequirements(substitutionNodeType, exposedRequirementsDefinition, - nodeTemplateId); + nodeTemplateId); //get capabilities addNodeTypeCapabilitiesToSubMapping(nodeTypeCapabilitiesDefinition, @@ -1280,7 +1281,7 @@ public class HeatToToscaUtil { exposedCapabilitiesDefinition = toscaAnalyzerService.calculateExposedCapabilities(nodeTypeCapabilitiesDefinition, - fullFilledRequirementsDefinition); + fullFilledRequirementsDefinition); DataModelUtil.addNodeTypeCapabilitiesDef(substitutionNodeType, exposedCapabilitiesDefinition); return substitutionMapping; } @@ -1298,7 +1299,7 @@ public class HeatToToscaUtil { .stream() .forEach(capabilityNodeEntry -> addCapabilityToSubMapping( - templateName, capabilityNodeEntry, nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping)); + templateName, capabilityNodeEntry, nodeTypeCapabilitiesDefinition, capabilitySubstitutionMapping)); } } @@ -1478,7 +1479,7 @@ public class HeatToToscaUtil { //Method evaluate the network role from sub interface node template id, designed considering // only single sub interface present in nested file else it will return null public static Optional<String> getNetworkRoleFromResource(Resource resource, - TranslationContext translationContext) { + TranslationContext translationContext) { Optional<String> networkRole = Optional.empty(); Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource); @@ -1493,35 +1494,63 @@ public class HeatToToscaUtil { if (MapUtils.isNotEmpty(nestedHeatOrchestrationTemplate.getResources())) { ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper = new ContrailV2VirtualMachineInterfaceHelper(); - Optional<Map.Entry<String, Resource>> vlanSubinterfaceResource = nestedHeatOrchestrationTemplate + Optional<Map.Entry<String, Resource>> vlanSubInterfaceResource = nestedHeatOrchestrationTemplate .getResources().entrySet().stream() .filter(resourceEntry -> contrailV2VirtualMachineInterfaceHelper .isVlanSubInterfaceResource(resourceEntry.getValue())) .findFirst(); - if (vlanSubinterfaceResource.isPresent()) { - Map.Entry<String, Resource> vlanSubinterfaceResourceEntry = vlanSubinterfaceResource.get(); - networkRole = evaluateNetworkRoleFromResourceId(vlanSubinterfaceResourceEntry.getKey(), - vlanSubinterfaceResourceEntry.getValue().getType()); + if (vlanSubInterfaceResource.isPresent()) { + Map.Entry<String, Resource> vlanSubInterfaceResourceEntry = vlanSubInterfaceResource.get(); + networkRole = evaluateNetworkRoleFromResourceId(vlanSubInterfaceResourceEntry.getKey(), + vlanSubInterfaceResourceEntry.getValue().getType()); } } return networkRole; } public static Optional<String> evaluateNetworkRoleFromResourceId(String resourceId, String resourceType) { - String[] splitStr = resourceId.toLowerCase().split(UNDERSCORE); - List<String> splitList = Arrays.asList(splitStr); - if (resourceType.equals(HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource())) { - if (splitList.contains(VMI)) { - return Optional.of(splitList.get(splitList.indexOf(VMI) - 1)); - } + return Optional.ofNullable(extractNetworkRoleFromContrailPortId(resourceId)); } if (resourceType.equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) { - if (splitList.contains(NEUTRON_PORT_IDENTIFIER)) { - return Optional.of(splitList.get(splitList.indexOf(NEUTRON_PORT_IDENTIFIER) - 1)); - } + return Optional.ofNullable(extractNetworkRoleFromNeutronPortId(resourceId)); } return Optional.empty(); } + + private static String extractNetworkRoleFromContrailPortId(String portResourceId) { + String vmiResourceIdRegex = "(\\w+)(_\\d+){0,1}_(\\w+)_vmi(_\\d+){0,1}"; + String vmiIntResourceIdRegex = "(\\w+)(_\\d+){0,1}_int_(\\w+)_vmi(_\\d+){0,1}"; + + String portNetworkRole = getPortNetworkRole(portResourceId, vmiResourceIdRegex); + String portIntNetworkRole = getPortNetworkRole(portResourceId, vmiIntResourceIdRegex); + + return Objects.nonNull(portNetworkRole) ? portNetworkRole : portIntNetworkRole; + } + + + private static String extractNetworkRoleFromNeutronPortId(String portResourceId) { + String portResourceIdRegex = "(\\w+)(_\\d+){0,1}_(\\w+)_port(_\\d+){0,1}"; + String portIntResourceIdRegex = "(\\w+)(_\\d+){0,1}_int_(\\w+)_port(_\\d+){0,1}"; + + String portNetworkRole = getPortNetworkRole(portResourceId, portResourceIdRegex); + String portIntNetworkRole = getPortNetworkRole(portResourceId, portIntResourceIdRegex); + + return Objects.nonNull(portNetworkRole) ? portNetworkRole : portIntNetworkRole; + } + + private static String getPortNetworkRole(String portResourceId, String portIdRegex) { + Pattern pattern = Pattern.compile(portIdRegex); + Matcher matcher = pattern.matcher(portResourceId); + if (matcher.matches()) { + String networkRole = matcher.group(3); + //Assuming network role will not contain ONLY digits + if (!networkRole.matches("\\d+")) { + return matcher.group(3); + } + } + return null; + } + } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionManager.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionManager.java index 86761b7339..b335e0005c 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionManager.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/UnifiedCompositionManager.java @@ -67,12 +67,12 @@ public class UnifiedCompositionManager { ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl(); for (String substitutedNodeTemplateId : fileNestedConsolidationData .getAllNestedNodeTemplateIds()) { - if (translationContext + NodeTemplate nestedNodeTemplate = + DataModelUtil.getNodeTemplate(serviceTemplate, substitutedNodeTemplateId); + if (Objects.isNull(nestedNodeTemplate) || translationContext .isNestedNodeWasHandled(serviceTemplateFileName, substitutedNodeTemplateId)) { continue; } - NodeTemplate nestedNodeTemplate = - DataModelUtil.getNodeTemplate(serviceTemplate, substitutedNodeTemplateId); Optional<String> substituteServiceTemplateName = toscaAnalyzerService.getSubstituteServiceTemplateName(substitutedNodeTemplateId, nestedNodeTemplate); |