You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Overview

Ideally one anchor could support more then one data tree instance using different independent models provided in the schema-set for that anchor. Refer CPS-341 - Getting issue details... STATUS

The Problem statement

The YANG specification allows multiple containers (lists etc) to be defined on a module's top level, however in CPS currently the eligible JSON data (having corresponding data sets) is not accepted. When data is parsed using YangUtils.parseJsonData(...) the exception like below occurs

org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException: Normalized Node result was already set.
 at org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult.setResult(NormalizedNodeResult.java:39) at org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResultBuilder.addChild(NormalizedNodeResultBuilder.java:57) at org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter.writeChild(ImmutableNormalizedNodeStreamWriter.java:305) at org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter.endNode(ImmutableNormalizedNodeStreamWriter.java:283) at org.opendaylight.yangtools.yang.data.util.ContainerNodeDataWithSchema.write(ContainerNodeDataWithSchema.java:37) at org.opendaylight.yangtools.yang.data.util.CompositeNodeDataWithSchema.write(CompositeNodeDataWithSchema.java:273) at org.opendaylight.yangtools.yang.data.util.AbstractNodeDataWithSchema.write(AbstractNodeDataWithSchema.java:74) at org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream.parse(JsonParserStream.java:170) at org.onap.cps.utils.YangUtils.parseJsonData(YangUtils.java:73)
...

Goal of this spike

The current limitation of only one data tree(single top level data node) being supported by CPS does not seems to be justifiable. The goal of this study is to find out what is the cause of the above error and bring in support for JSON data with multiple top level nodes.

Problem Statement

Possible SolutionsSub-TasksNotes/CommentsPros/Cons

Add support for JSON data with multiple top level nodes. Refer: CPS-341 - Getting issue details... STATUS

Identify the top-level data nodes in the existing JSON payload and then iterate over them and store them individually one by one in using Create node endpoint
  • Make a separate PoC where we parse JSON data individually
  • Get operation needs to be updated accordingly, currently it returns only the first data tree even if multiple data trees exist under same anchor. New Get Data node API is needed
  • gson might have support for this, Need more research on it
  • CPS team preferred Jackson over gson

Pros: 

  • No changes to current payload
  • No need to write new API, existing API will serve the purpose
  • Backwards compatible

Cons:

  • The approach is complex compared to using JSON array as payload, Need to write logic to parse over multiple data tree without losing top key element and this might require additional libraries as well.
Use JSON array and store the JSON array in CPS DB using Create node endpoint 
  • need to define new payload

Sample:

[{...},{...},{...}]
  • New test cases need to be added
  • Need to update get operation as well to retrieve multiple data trees, so new endpoint is needed
  • Need to test existing GET nodes API in depth.
  • The payload needs to be changed. Will add the payload format soon.
  • Need to identify which endpoints might get effected with this change
  • Can convert the JSON object payload to an Array internally when single object is passed

Pros:

  • Minimal code change (approach will require us to iterate over multiple data trees passed as JSON array)

Cons:

  • New endpoint need to be added. Need to decide on endpoint because current Post API uses "nodes".

Findings for the above mentioned Possible Solutions

Possible SolutionsPayloadDescription/FindingsComments
Identify the top-level keys in the existing JSON payload (which is JSON object) and then iterate over them and store them individually one by one in using Create node endpoint

The JSON object with multiple data trees would be structured as follows:

{
  "container-1": { values },   //data tree 1
  "container-2": { values }    //data tree 2
}

Refer the following files for Yang and Json data (from spike CPS-341):

JSON-object-multiple-top.jsonJSON-object-multiple-top.yang

  • Generally to iterate over a JSON object the top level key (here top_key_of_data_tree_1 and top_key_of_data_tree_2) is used to identify the number of data trees in the JSON object.
  • The problem with this approach is, that the libraries tested for the usecase only return the values stored under the top key and in order to retain the whole JSON we need to perform some data manipulation (concatenating key with value within CPS) which is not feasible.

Use new payload in form of JSON array and store the JSON array in CPS DB using Create node endpoint 

The JSON object with multiple data trees would be structured as follows:

[
	{   //data tree 1
    	"container-1": { values }
	},
	{   //data tree 2
    	"container-2": { values }
	}
]

Refer the following files for Yang and Json data (from spike CPS-341):

JSON-array-multiple-data-tree.jsonJSON-array-multiple-data-tree.yang

  • In this approach the data is received as JSON array and by performing simple iteration over the array we should be able to store the data with multiple trees in CPS
  • A PoC is WIP for the same.

  • No labels