aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be-plugins
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-09-01 14:31:28 +0100
committerMichael Morris <michael.morris@est.tech>2023-09-07 13:16:33 +0000
commit28e1a54e6074f50dcc06f7ea4eb3943ad873b448 (patch)
treeedc59848dedfda9cf5d68e08b6744516d0e761a4 /catalog-be-plugins
parentc469756a1092194adedd590d35f0f1f8feac3a36 (diff)
Create plugin point for csar generation
Issue-ID: SDC-4578 Signed-off-by: franciscovila <javier.paradela.vila@est.tech> Change-Id: I3bb280ce4e442780598464216145abc130765539 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Diffstat (limited to 'catalog-be-plugins')
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImpl.java58
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java2
2 files changed, 32 insertions, 28 deletions
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 eb601d836d..5398c36f72 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,4 +1,3 @@
-
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation
@@ -21,7 +20,6 @@ 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;
@@ -36,8 +34,8 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.exception.NsdException;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.Nsd;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.model.VnfDescriptor;
@@ -72,7 +70,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
private static final List<String> 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<String> 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<String> 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",
@@ -202,7 +200,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
}
componentToscaTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
}
-
+
private Map<String, String[]> adjustRequirementNamesToMatchVnfd(final Map<String, String[]> requirements) {
for (final Map.Entry<String, String[]> entry : requirements.entrySet()) {
try {
@@ -239,7 +237,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
removeCapabilitiesFromNodeTemplate(nodeTemplate);
}
}
-
+
private void setPropertiesForNodeTemplate(final Entry<String, ToscaNodeTemplate> nodeTemplate) {
final Map<String, Object> propertyMap = nodeTemplate.getValue().getProperties();
if (MapUtils.isEmpty(propertyMap)) {
@@ -261,12 +259,13 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
}
private void setRequirementsForNodeTemplate(final Entry<String, ToscaNodeTemplate> nodeTemplateMap) {
- final List<Map<String,ToscaTemplateRequirement>> requirementAssignments = nodeTemplateMap.getValue().getRequirements();
- if (requirementAssignments != null) {
- final List<Map<String,ToscaTemplateRequirement>> requirementAssignmentsMatchingVnfdRequirements = new ArrayList<>();
- for (final Map<String, ToscaTemplateRequirement> requirementAssignment: requirementAssignments) {
- final Map<String, ToscaTemplateRequirement> requirementAssignmentMatchingVnfd =
- requirementAssignment.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().substring(entry.getKey().lastIndexOf('.') + 1), Map.Entry::getValue));
+ final List<Map<String, ToscaTemplateRequirement>> requirementAssignments = nodeTemplateMap.getValue().getRequirements();
+ if (requirementAssignments != null) {
+ final List<Map<String, ToscaTemplateRequirement>> requirementAssignmentsMatchingVnfdRequirements = new ArrayList<>();
+ for (final Map<String, ToscaTemplateRequirement> requirementAssignment : requirementAssignments) {
+ final Map<String, ToscaTemplateRequirement> 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);
@@ -281,10 +280,10 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
private void removeOnapAndEtsiNsdPropertiesFromInputs(final ToscaTemplate template) {
final ToscaTopolgyTemplate topologyTemplate = template.getTopology_template();
final Map<String, ToscaProperty> 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);
@@ -319,7 +318,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
}
private Map<String, Map<String, String>> generateDefaultImportEntry() {
- return ImmutableMap.of("etsi_nfv_sol001_nsd_types", ImmutableMap.of("file", "etsi_nfv_sol001_nsd_types.yaml"));
+ return Map.of("etsi_nfv_sol001_nsd_types", Map.of("file", "etsi_nfv_sol001_nsd_types.yaml"));
}
private ToscaNodeType createEtsiSolNsNodeType(final ToscaNodeType nsNodeType, final ToscaTemplate componentToscaTemplate) {
@@ -336,29 +335,34 @@ 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<Map<String, ToscaRequirement>> requirementsInNsNodeType = getRequirementsForNsNodeType(nsNodeType.getRequirements(), componentToscaTemplate);
+
+ final List<Map<String, ToscaRequirement>> requirementsInNsNodeType = getRequirementsForNsNodeType(nsNodeType.getRequirements(),
+ componentToscaTemplate);
if (!requirementsInNsNodeType.isEmpty()) {
- toscaNodeType.setRequirements(requirementsInNsNodeType);
+ toscaNodeType.setRequirements(requirementsInNsNodeType);
}
return toscaNodeType;
}
-
- private List<Map<String,ToscaRequirement>> getRequirementsForNsNodeType(final List<Map<String,ToscaRequirement>> requirements, final ToscaTemplate componentToscaTemplate) {
- final Map<String, String[]> requirementsInSubstitutionMapping = componentToscaTemplate.getTopology_template().getSubstitution_mappings().getRequirements();
+
+ private List<Map<String, ToscaRequirement>> getRequirementsForNsNodeType(final List<Map<String, ToscaRequirement>> requirements,
+ final ToscaTemplate componentToscaTemplate) {
+ final Map<String, String[]> requirementsInSubstitutionMapping = componentToscaTemplate.getTopology_template().getSubstitution_mappings()
+ .getRequirements();
if (requirements == null || MapUtils.isEmpty(requirementsInSubstitutionMapping)) {
return Collections.emptyList();
}
- final List<Map<String,ToscaRequirement>> requirementsToAdd = new ArrayList<>();
- for (final Map<String,ToscaRequirement> requirementMap : requirements) {
- final Map<String,ToscaRequirement> neededRequirements = requirementMap.entrySet().stream().filter(entry -> requirementsInSubstitutionMapping.containsKey(entry.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+ final List<Map<String, ToscaRequirement>> requirementsToAdd = new ArrayList<>();
+ for (final Map<String, ToscaRequirement> requirementMap : requirements) {
+ final Map<String, ToscaRequirement> 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) {
@@ -394,7 +398,7 @@ public class NsDescriptorGeneratorImpl implements NsDescriptorGenerator {
}
private ToscaTemplate parseToToscaTemplate(final Component component) throws NsdException {
- final Either<ToscaTemplate, ToscaError> toscaTemplateRes = toscaExportHandler.convertToToscaTemplate(component);
+ final Either<ToscaTemplate, ToscaError> toscaTemplateRes = toscaExportHandler.convertToToscaTemplate(component, false);
if (toscaTemplateRes.isRight()) {
String errorMsg = String
.format("Could not parse component '%s' to tosca template. Error '%s'", component.getName(), toscaTemplateRes.right().value().name());
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java
index 4c2c0a9a51..7ad43db45b 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/test/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/NsDescriptorGeneratorImplTest.java
@@ -181,7 +181,7 @@ class NsDescriptorGeneratorImplTest {
interfaceToscaNodeType.setRequirements(interfaceNodeTypeRequirements);
final String nsNodeTypeName = "nsNodeTypeName";
componentInterfaceToscaTemplate.setNode_types(ImmutableMap.of(nsNodeTypeName, interfaceToscaNodeType));
- when(toscaExportHandler.convertToToscaTemplate(component)).thenReturn(Either.left(componentToscaTemplate));
+ when(toscaExportHandler.convertToToscaTemplate(component, false)).thenReturn(Either.left(componentToscaTemplate));
when(toscaExportHandler.convertInterfaceNodeType(any(), any(), any(), any(), anyBoolean()))
.thenReturn(Either.left(componentInterfaceToscaTemplate));
final List<VnfDescriptor> vnfDescriptorList = new ArrayList<>();