From 1ca21c0f673221c3b0eabe9cb8a2fa8b068e9c05 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Thu, 17 Feb 2022 15:48:20 +0000 Subject: Support instance count on node template Issue-ID: SDC-3887 Signed-off-by: JvD_Ericsson Change-Id: I45593ee2e0e3eea358ae9344d7432e37e1467915 --- .../impl/ComponentInstanceBusinessLogic.java | 1 + .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 43 ++++++++++++++++++++-- .../sdc/be/tosca/model/ToscaNodeTemplate.java | 1 + 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 2f712e1e7b..60e2501f11 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -1265,6 +1265,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { oldComponentInstance.setDirectives(newComponentInstance.getDirectives()); oldComponentInstance.setMaxOccurrences(newComponentInstance.getMaxOccurrences()); oldComponentInstance.setMinOccurrences(newComponentInstance.getMinOccurrences()); + oldComponentInstance.setInstanceCount(newComponentInstance.getInstanceCount()); if (oldComponentInstance.getGroupInstances() != null) { oldComponentInstance.getGroupInstances().forEach(group -> group.setName(getNewGroupName(oldComponentInstance.getNormalizedName(), ValidationUtils.normalizeComponentInstanceName(newComponentInstance.getName()), group.getName()))); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 5c30d0977c..586b9f66b9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -27,7 +27,13 @@ import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_ATTRIBUTE; import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_INPUT; import static org.openecomp.sdc.tosca.datatypes.ToscaFunctions.GET_PROPERTY; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonParser; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonReader; import fj.data.Either; +import java.io.StringReader; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -104,6 +110,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.impl.ModelOperation; +import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter; import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType; import org.openecomp.sdc.be.tosca.builder.ToscaRelationshipBuilder; import org.openecomp.sdc.be.tosca.exception.ToscaConversionException; @@ -130,6 +137,7 @@ import org.openecomp.sdc.be.tosca.utils.InputConverter; import org.openecomp.sdc.be.tosca.utils.OutputConverter; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; +import org.openecomp.sdc.tosca.datatypes.ToscaFunctions; import org.springframework.beans.factory.annotation.Autowired; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions.FlowStyle; @@ -914,11 +922,19 @@ public class ToscaExportHandler { nodeTemplate.setArtifacts(convertToNodeTemplateArtifacts(componentInstance.getToscaArtifacts())); } if (componentInstance.getMinOccurrences() != null && componentInstance.getMaxOccurrences()!= null){ - List occur = new ArrayList(); + List occur = new ArrayList<>(); occur.add(parseToIntIfPossible(componentInstance.getMinOccurrences())); occur.add(parseToIntIfPossible(componentInstance.getMaxOccurrences())); nodeTemplate.setOccurrences(occur); } + if (componentInstance.getInstanceCount() != null){ + ObjectMapper objectMapper = new ObjectMapper(); + Object obj = convertToToscaObject(componentInstance.getInstanceCount()); + if(obj != null) { + Map map = objectMapper.convertValue(obj, Map.class); + nodeTemplate.setInstance_count(map); + } + } nodeTemplate.setType(componentInstance.getToscaComponentName()); nodeTemplate.setDirectives(componentInstance.getDirectives()); nodeTemplate.setNode_filter(convertToNodeTemplateNodeFilterComponent(componentInstance.getNodeFilter())); @@ -1022,12 +1038,33 @@ public class ToscaExportHandler { log.debug("finish convert topology template for {} for type {}", component.getUniqueId(), component.getComponentType()); return convertNodeTemplatesRes; } - + + public Object convertToToscaObject(String value) { + try { + ToscaMapValueConverter mapConverterInst = ToscaMapValueConverter.getInstance(); + JsonParser jsonParser = new JsonParser(); + StringReader reader = new StringReader(value); + JsonReader jsonReader = new JsonReader(reader); + jsonReader.setLenient(true); + JsonElement jsonElement = jsonParser.parse(jsonReader); + if (jsonElement.isJsonObject()) { + JsonObject jsonObj = jsonElement.getAsJsonObject(); + if (jsonObj.entrySet().size() == 1 && jsonObj.has(ToscaFunctions.GET_INPUT.getFunctionName())) { + return mapConverterInst.handleComplexJsonValue(jsonElement); + } + } + return null; + } catch (Exception e) { + log.debug("convertToToscaValue failed to parse json value :", e); + return null; + } + } + private Object parseToIntIfPossible(final String value) { final Integer intValue = Ints.tryParse(value); return intValue == null ? value : intValue; } - + private void handleInstanceInterfaces( Map> componentInstanceInterfaces, ComponentInstance componentInstance, Map dataTypes, ToscaNodeTemplate nodeTemplate, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java index 0a75870502..6fd660e2aa 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java @@ -35,6 +35,7 @@ public class ToscaNodeTemplate { private String type; private List occurrences; + private Map instance_count; private List directives; private Map metadata; private String description; -- cgit 1.2.3-korg