From eabb6dd6c26f81e1868bae13bb06ffc570c73532 Mon Sep 17 00:00:00 2001 From: talig Date: Wed, 31 Oct 2018 10:26:03 +0200 Subject: Add NFC naming code to the csar of manual vsp In getComponentDisplayName consider the case of manual vsp, in which: the added suffix "_VNF" should be removed in order to get the component display name Change-Id: I4a439b6970ed08bd997fef09ec8360ac1bf2b579 Issue-ID: SDC-1882 Signed-off-by: talig --- .../tosca/AbstractSubstituteToscaEnricher.java | 139 +++++++++++---------- 1 file changed, 70 insertions(+), 69 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main') diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java index 80e469771d..afc5bd2bdc 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricher.java @@ -20,38 +20,38 @@ import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AV import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_FUNCTION; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.NFC_NAMING_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VM_TYPE_TAG; import static org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType.NATIVE_NODE; +import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.MULTIDEPLOYMENTFLAVOR_NODE_TYPE; import static org.openecomp.sdc.tosca.datatypes.ToscaNodeType.VFC_ABSTRACT_SUBSTITUTE; import static org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType.NATIVE_DEPENDS_ON; import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME; import static org.openecomp.sdc.translator.services.heattotosca.Constants.ABSTRACT_NODE_TEMPLATE_ID_PREFIX; +import static org.openecomp.sdc.translator.services.heattotosca.Constants.VNF_NODE_TEMPLATE_ID_SUFFIX; +import java.util.ArrayList; +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.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.datatypes.error.ErrorMessage; -import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.onap.sdc.tosca.datatypes.model.NodeTemplate; import org.onap.sdc.tosca.datatypes.model.NodeType; import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; import org.onap.sdc.tosca.datatypes.model.RequirementDefinition; import org.onap.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.tosca.datatypes.ToscaElementTypes; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.services.DataModelUtil; import org.openecomp.sdc.tosca.services.ToscaAnalyzerService; import org.openecomp.sdc.tosca.services.ToscaConstants; import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - import org.openecomp.sdc.versioning.dao.types.Version; public class AbstractSubstituteToscaEnricher { @@ -80,79 +80,83 @@ public class AbstractSubstituteToscaEnricher { return errors; } - final Map node_templates = serviceTemplate.getTopology_template().getNode_templates(); - if (node_templates == null) { + final Map nodeTemplates = serviceTemplate.getTopology_template().getNode_templates(); + if (nodeTemplates == null) { return errors; } - final Map> componentDisplayNameToNodeTempalteIds = - populateAllNodeTemplateIdForComponent(node_templates, serviceTemplate, toscaModel); + final Map> componentDisplayNameToNodeTemplateIds = + populateAllNodeTemplateIdForComponent(nodeTemplates, serviceTemplate, toscaModel); - node_templates.keySet().stream().forEach(nodeTemplateId -> { - final Optional nodeTemplateById = - toscaAnalyzerService.getNodeTemplateById(serviceTemplate, nodeTemplateId); - final NodeTemplate nodeTemplate = nodeTemplateById.isPresent() ? nodeTemplateById.get() : null; + nodeTemplates.keySet().forEach(nodeTemplateId -> { + final NodeTemplate nodeTemplate = + toscaAnalyzerService.getNodeTemplateById(serviceTemplate, nodeTemplateId).orElse(null); if (toscaAnalyzerService.isTypeOf(nodeTemplate, VFC_ABSTRACT_SUBSTITUTE, serviceTemplate, toscaModel)) { String componentDisplayName = getComponentDisplayName(nodeTemplateId, nodeTemplate); - setProperty(nodeTemplate, VM_TYPE_TAG, componentDisplayName); + enrichProperties(nodeTemplate, componentDisplayName, componentProperties); - if (componentProperties != null && componentProperties.containsKey(componentDisplayName)) { - final String mandatory = - getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, MANDATORY); + enrichRequirements(sourceToTargetDependencies, componentDisplayName, nodeTemplate, + componentDisplayNameToNodeTemplateIds, serviceTemplate, toscaModel); + } + }); + return errors; + } + + private void enrichProperties(NodeTemplate nodeTemplate, String componentDisplayName, + Map> componentProperties) { + setProperty(nodeTemplate, VM_TYPE_TAG, componentDisplayName); - boolean isServiceTemplateFilterNotExists = false; - if (!StringUtils.isEmpty(mandatory)) { - Map innerProps = (Map) nodeTemplate.getProperties() - .get(SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); + if (componentProperties != null && componentProperties.containsKey(componentDisplayName)) { + final String mandatory = + getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, MANDATORY); - if (innerProps == null) { - innerProps = new HashMap(); - isServiceTemplateFilterNotExists = true; - } + boolean isServiceTemplateFilterNotExists = false; + if (!StringUtils.isEmpty(mandatory)) { + Map innerProps = (Map) nodeTemplate.getProperties() + .get(SERVICE_TEMPLATE_FILTER_PROPERTY_NAME); - innerProps.put(MANDATORY, getValue(mandatory)); + if (innerProps == null) { + innerProps = new HashMap(); + isServiceTemplateFilterNotExists = true; + } - if (isServiceTemplateFilterNotExists) { - nodeTemplate.getProperties().put(SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps); - } - } + innerProps.put(MANDATORY, getValue(mandatory)); - setProperty(nodeTemplate, HIGH_AVAIL_MODE, - getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, - HIGH_AVAIL_MODE)); + if (isServiceTemplateFilterNotExists) { + nodeTemplate.getProperties().put(SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, innerProps); + } + } - setProperty(nodeTemplate, NFC_NAMING_CODE, - getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, - NFC_NAMING_CODE)); + setProperty(nodeTemplate, HIGH_AVAIL_MODE, + getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, + HIGH_AVAIL_MODE)); - setProperty(nodeTemplate, VFC_CODE, - getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, VFC_CODE)); + setProperty(nodeTemplate, NFC_NAMING_CODE, + getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, + NFC_NAMING_CODE)); - setProperty(nodeTemplate, NFC_FUNCTION, - getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, NFC_FUNCTION)); + setProperty(nodeTemplate, VFC_CODE, + getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, VFC_CODE)); - if (componentProperties.get(componentDisplayName).get(MIN_INSTANCES) != null) { - nodeTemplate.getProperties().put(MIN_INSTANCES, - componentProperties.get(componentDisplayName).get(MIN_INSTANCES)); - } + setProperty(nodeTemplate, NFC_FUNCTION, + getValueFromQuestionnaireDetails(componentProperties, componentDisplayName, NFC_FUNCTION)); - if (componentProperties.get(componentDisplayName).get(MAX_INSTANCES) != null) { - nodeTemplate.getProperties().put(MAX_INSTANCES, - componentProperties.get(componentDisplayName).get(MAX_INSTANCES)); - } - } + if (componentProperties.get(componentDisplayName).get(MIN_INSTANCES) != null) { + nodeTemplate.getProperties().put(MIN_INSTANCES, + componentProperties.get(componentDisplayName).get(MIN_INSTANCES)); + } - enrichRequirements(sourceToTargetDependencies, componentDisplayName, nodeTemplate, - componentDisplayNameToNodeTempalteIds, serviceTemplate, toscaModel); + if (componentProperties.get(componentDisplayName).get(MAX_INSTANCES) != null) { + nodeTemplate.getProperties().put(MAX_INSTANCES, + componentProperties.get(componentDisplayName).get(MAX_INSTANCES)); } - }); - return errors; + } } - private Map> populateAllNodeTemplateIdForComponent(Map node_templates, + private Map> populateAllNodeTemplateIdForComponent(Map nodeTemplates, ServiceTemplate serviceTemplate, ToscaServiceModel toscaModel) { @@ -160,11 +164,9 @@ public class AbstractSubstituteToscaEnricher { Map> componentDisplayNameToNodeTempalteIds = new HashMap<>(); //set dependency target - node_templates.keySet().stream().forEach(nodeTemplateId -> { - - final Optional nodeTemplateById = - toscaAnalyzerService.getNodeTemplateById(serviceTemplate, nodeTemplateId); - final NodeTemplate nodeTemplate = nodeTemplateById.isPresent() ? nodeTemplateById.get() : null; + nodeTemplates.keySet().forEach(nodeTemplateId -> { + final NodeTemplate nodeTemplate = + toscaAnalyzerService.getNodeTemplateById(serviceTemplate, nodeTemplateId).orElse(null); if (toscaAnalyzerService.isTypeOf(nodeTemplate, VFC_ABSTRACT_SUBSTITUTE, serviceTemplate, toscaModel)) { @@ -242,9 +244,9 @@ public class AbstractSubstituteToscaEnricher { componentDisplayName = removedSuffix[0]; } else { final String type = nodeTemplate.getType(); - final String[] splitted = type.split("\\."); - componentDisplayName = splitted[splitted.length - 1]; - + componentDisplayName = MULTIDEPLOYMENTFLAVOR_NODE_TYPE.equals(type) + ? nodeTemplateId.substring(0, nodeTemplateId.lastIndexOf(VNF_NODE_TEMPLATE_ID_SUFFIX)) + : type.substring(type.lastIndexOf('.') + 1); } return componentDisplayName; } @@ -264,7 +266,6 @@ public class AbstractSubstituteToscaEnricher { } private Boolean getValue(String value) { - String returnValue = null; switch (value) { case "YES": return true; -- cgit 1.2.3-korg