diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2022-02-17 15:48:20 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-03-14 14:38:48 +0000 |
commit | 1ca21c0f673221c3b0eabe9cb8a2fa8b068e9c05 (patch) | |
tree | 25590c865e2d3a1576831ffc90ed46de0d9266ce /catalog-be/src | |
parent | 0d9cc11b4daf60efbe4b7cebbbc6589200cddd53 (diff) |
Support instance count on node template
Issue-ID: SDC-3887
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I45593ee2e0e3eea358ae9344d7432e37e1467915
Diffstat (limited to 'catalog-be/src')
3 files changed, 42 insertions, 3 deletions
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<Object> occur = new ArrayList<Object>(); + List<Object> 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<String, String> 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<String, List<ComponentInstanceInterface>> componentInstanceInterfaces, ComponentInstance componentInstance, Map<String, DataTypeDefinition> 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<Object> occurrences; + private Map<String, String> instance_count; private List<String> directives; private Map<String, String> metadata; private String description; |