From 0323aadb6038a630798ad133f8b86a9b9d50feea Mon Sep 17 00:00:00 2001 From: Vasyl Razinkov Date: Tue, 20 Sep 2022 15:18:27 +0000 Subject: Revert "Fix 'Wrong Inputs creation on (Add Service)'" This reverts commit ae24e28cda8247fdce38330356b63db1377be58f. Reason for revert: problem reported with 'default' values Issue-ID: SDC-4097 Change-Id: I8966470070329cc8aafcb45255f2febb9b00ab4e Signed-off-by: Vasyl Razinkov --- .../nsd/generator/NsDescriptorGeneratorImpl.java | 55 ++++++++++------------ 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java') diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java index 18ba2ec21b..9572c44a6b 100644 --- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java +++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java @@ -1,3 +1,4 @@ + /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation @@ -18,7 +19,9 @@ */ package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.generator; +import com.google.common.collect.ImmutableMap; import fj.data.Either; +import groovy.util.MapEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -69,7 +72,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { private static final List PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE = Arrays .asList("cds_model_name", "cds_model_version", "skip_post_instantiation_configuration", "controller_actor"); private static final List ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES = Arrays - .asList("descriptor_id", "designer", "version", "name", "invariant_id", "flavour_id", "ns_profile", "service_availability_level"); + .asList("descriptor_id", "designer", "version", "name", "invariant_id", "flavour_id", "ns_profile", "service_availability_level"); private static final List PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TEMPLATE = Arrays .asList("nf_function", "nf_role", "nf_naming_code", "nf_type", "nf_naming", "availability_zone_max_count", "min_instances", "max_instances", "multi_stage_design", "sdnc_model_name", "sdnc_model_version", "sdnc_artifact_name", "skip_post_instantiation_configuration", @@ -199,7 +202,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { } componentToscaTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping); } - + private Map adjustRequirementNamesToMatchVnfd(final Map requirements) { for (final Map.Entry entry : requirements.entrySet()) { try { @@ -236,7 +239,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { removeCapabilitiesFromNodeTemplate(nodeTemplate); } } - + private void setPropertiesForNodeTemplate(final Entry nodeTemplate) { final Map propertyMap = nodeTemplate.getValue().getProperties(); if (MapUtils.isEmpty(propertyMap)) { @@ -258,13 +261,12 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { } private void setRequirementsForNodeTemplate(final Entry nodeTemplateMap) { - final List> requirementAssignments = nodeTemplateMap.getValue().getRequirements(); - if (requirementAssignments != null) { - final List> requirementAssignmentsMatchingVnfdRequirements = new ArrayList<>(); - for (final Map requirementAssignment : requirementAssignments) { - final Map requirementAssignmentMatchingVnfd = - requirementAssignment.entrySet().stream() - .collect(Collectors.toMap(entry -> entry.getKey().substring(entry.getKey().lastIndexOf('.') + 1), Map.Entry::getValue)); + final List> requirementAssignments = nodeTemplateMap.getValue().getRequirements(); + if (requirementAssignments != null) { + final List> requirementAssignmentsMatchingVnfdRequirements = new ArrayList<>(); + for (final Map requirementAssignment: requirementAssignments) { + final Map requirementAssignmentMatchingVnfd = + requirementAssignment.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().substring(entry.getKey().lastIndexOf('.') + 1), Map.Entry::getValue)); requirementAssignmentsMatchingVnfdRequirements.add(requirementAssignmentMatchingVnfd); } nodeTemplateMap.getValue().setRequirements(requirementAssignmentsMatchingVnfdRequirements); @@ -279,10 +281,10 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { private void removeOnapAndEtsiNsdPropertiesFromInputs(final ToscaTemplate template) { final ToscaTopolgyTemplate topologyTemplate = template.getTopology_template(); final Map inputMap = topologyTemplate.getInputs(); - + + if (MapUtils.isNotEmpty(inputMap)) { - inputMap.entrySet().removeIf(entry -> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE.contains(entry.getKey()) - || ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES.contains(entry.getKey())); + inputMap.entrySet().removeIf(entry -> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE.contains(entry.getKey()) || ETSI_SOL_NSD_NS_NODE_TYPE_PROPERTIES.contains(entry.getKey())); } if (MapUtils.isEmpty(inputMap)) { topologyTemplate.setInputs(null); @@ -317,7 +319,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { } private Map> generateDefaultImportEntry() { - return Map.of("etsi_nfv_sol001_nsd_types", Map.of("file", "etsi_nfv_sol001_nsd_types.yaml")); + return ImmutableMap.of("etsi_nfv_sol001_nsd_types", ImmutableMap.of("file", "etsi_nfv_sol001_nsd_types.yaml")); } private ToscaNodeType createEtsiSolNsNodeType(final ToscaNodeType nsNodeType, final ToscaTemplate componentToscaTemplate) { @@ -334,34 +336,29 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator { } propertiesInNsNodeType.entrySet().removeIf(entry -> PROPERTIES_TO_EXCLUDE_FROM_ETSI_SOL_NSD_NS_NODE_TYPE.contains(entry.getKey())); toscaNodeType.setProperties(propertiesInNsNodeType); - - final List> requirementsInNsNodeType = getRequirementsForNsNodeType(nsNodeType.getRequirements(), - componentToscaTemplate); + + final List> requirementsInNsNodeType = getRequirementsForNsNodeType(nsNodeType.getRequirements(), componentToscaTemplate); if (!requirementsInNsNodeType.isEmpty()) { - toscaNodeType.setRequirements(requirementsInNsNodeType); + toscaNodeType.setRequirements(requirementsInNsNodeType); } return toscaNodeType; } - - private List> getRequirementsForNsNodeType(final List> requirements, - final ToscaTemplate componentToscaTemplate) { - final Map requirementsInSubstitutionMapping = componentToscaTemplate.getTopology_template().getSubstitution_mappings() - .getRequirements(); + + private List> getRequirementsForNsNodeType(final List> requirements, final ToscaTemplate componentToscaTemplate) { + final Map requirementsInSubstitutionMapping = componentToscaTemplate.getTopology_template().getSubstitution_mappings().getRequirements(); if (requirements == null || MapUtils.isEmpty(requirementsInSubstitutionMapping)) { return Collections.emptyList(); } - final List> requirementsToAdd = new ArrayList<>(); - for (final Map requirementMap : requirements) { - final Map neededRequirements = requirementMap.entrySet().stream() - .filter(entry -> requirementsInSubstitutionMapping.containsKey(entry.getKey())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + final List> requirementsToAdd = new ArrayList<>(); + for (final Map requirementMap : requirements) { + final Map neededRequirements = requirementMap.entrySet().stream().filter(entry -> requirementsInSubstitutionMapping.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); if (!neededRequirements.isEmpty()) { requirementsToAdd.add(neededRequirements); } } return requirementsToAdd; - + } private boolean propertyIsDefinedInNodeType(final String propertyName) { -- cgit 1.2.3-korg