From 6791c53443a13a6c3d37b9351480365ee80b4c31 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Wed, 12 Jul 2023 09:10:40 +0100 Subject: Support occurrences and instance count in import Signed-off-by: MichaelMorris Issue-ID: SDC-4566 Change-Id: I884082253e3b3a9c20da68ab064f4ae6528f6fe0 --- .../csar/YamlTemplateParsingHandler.java | 22 +++++++++++++++++++--- .../impl/ServiceImportBusinessLogic.java | 3 +++ .../sdc/be/model/UploadComponentInstanceInfo.java | 3 +++ .../java/org/openecomp/sdc/be/utils/TypeUtils.java | 3 ++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index b90e3bb0b8..7c031a29e7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -107,13 +107,10 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefin import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction; import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; -import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.enums.FilterValueType; import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType; -import org.openecomp.sdc.be.datatypes.enums.PropertySource; -import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstanceProperty; @@ -825,6 +822,7 @@ public class YamlTemplateParsingHandler { setDirectives(nodeTemplateInfo, nodeTemplateJsonMap); setNodeFilter(nodeTemplateInfo, nodeTemplateJsonMap); setSubstitutions(substitutionMappings, nodeTemplateInfo); + setOccurrencesAndInstanceCount(nodeTemplateInfo, nodeTemplateJsonMap); } else { rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); } @@ -932,6 +930,24 @@ public class YamlTemplateParsingHandler { .createNodeFilterData(nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE_FILTER.getElementName()))); } } + + @SuppressWarnings("unchecked") + private void setOccurrencesAndInstanceCount(UploadComponentInstanceInfo nodeTemplateInfo, Map nodeTemplateJsonMap) { + if (nodeTemplateJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) { + List occurrences = (List) nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName()); + nodeTemplateInfo.setMinOccurrences(occurrences.get(0).toString()); + nodeTemplateInfo.setMaxOccurrences(occurrences.get(1).toString()); + } + if (nodeTemplateJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.INSTANCE_COUNT.getElementName())) { + Object instanceCount = nodeTemplateJsonMap.get(TypeUtils.ToscaTagNamesEnum.INSTANCE_COUNT.getElementName()); + if (instanceCount instanceof Map) { + String instanceCountAsString = "{get_input:" + (String)((Map)instanceCount).get("get_input") + "}"; + nodeTemplateInfo.setInstanceCount(instanceCountAsString); + } else { + nodeTemplateInfo.setInstanceCount(instanceCount.toString()); + } + } + } @SuppressWarnings("unchecked") private Map> createReqModuleFromYaml(Map nodeTemplateJsonMap, String nodeName) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index b6a7fccff4..a31e9234c1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -2721,6 +2721,9 @@ public class ServiceImportBusinessLogic { Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType()); componentInstance.setName(uploadComponentInstanceInfo.getName()); componentInstance.setIcon(origResource.getIcon()); + componentInstance.setMinOccurrences(uploadComponentInstanceInfo.getMinOccurrences()); + componentInstance.setMaxOccurrences(uploadComponentInstanceInfo.getMaxOccurrences()); + componentInstance.setInstanceCount(uploadComponentInstanceInfo.getInstanceCount()); resourcesInstancesMap.put(componentInstance, origResource); } catch (final ComponentException e) { throw e; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java index 5aad2fb91d..f950827d77 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadComponentInstanceInfo.java @@ -44,4 +44,7 @@ public class UploadComponentInstanceInfo { private Map interfaces; private UploadNodeFilterInfo uploadNodeFilterInfo; private Map> operations; + private String maxOccurrences; + private String minOccurrences; + private String instanceCount; } diff --git a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java index ff5677208a..a7e6975347 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java @@ -79,7 +79,8 @@ public class TypeUtils { IMPLEMENTATION("implementation"), SUBSTITUTION_FILTERS("substitution_filter"), DERIVED_FROM_NAME("derivedFromName"), - INTERFACE_TYPES("interface_types"); + INTERFACE_TYPES("interface_types"), + INSTANCE_COUNT("instance_count"); // @formatter:om private final String elementName; -- cgit 1.2.3-korg