CPS-1401: Implement V2 of GET Data Node API
Initial Findings
It was found that the V1 of Get Data Node API would always return the first data node under an anchor. So if there are multiple data nodes stored under an anchor, when the Get operation was performed to retrieve all data nodes(by setting the xPath as root node xPath"/"), then only the first data node in the stack would be returned.
Also when the get operation is performed to retrieve individual parent data nodes under an anchor, the data nodes are retrieved successfully. Hence proving that even when multiple data nodes exist under an anchor, only one of them can be retrieved at a time and when trying to retrieve all of them by using root node xPath the operation only returns the first data node.
Decisions
After team discussion based on the findings mentioned below, it was decided to release V2 of Get Data Node API, where in the response body was to be updated to be a JSON array. And within this array individual data trees would be returned.
JSON Data Stored in CPS DB using POST operation
The following JSON data was first stored in CPS DB, then to test the GET operation:
{
"first-container": {
"a-leaf": "a-Value"
},
"last-container": {
"x-leaf": "x-value"
}
}
Analysis of Get a Node API
Currently after multiple data trees are stored in CPS DB. On performing the GET operation on the same data, with xpath set as root "/", the first data tree is returned by the Get Data Node API. This data tree is returned in form of a JSON Object as follows:
CURL Request to get all data nodes under an anchor:
curl --location 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/sample/node?xpath=%2F' \
--header 'Accept: application/json' \
--header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE='
Response:
Current JSON response body
{
"multiple-data-tree:first-container": {
"a-leaf": "a-Value"
}
}
CURL Request to get individual data tree(with xPath= /first-container) under an anchor:
Response:
Current JSON response body
CURL Request to get individual data tree(with xPath= /last-container) under an anchor:
Response:
Current JSON response body
Expected Outcome
After the GET API is updated, we want all the data trees to be returned when the xpath is set to root "/" and when a specific xpath is provided we want the functionality to remain as is.
Based on the existing GET request there are two possible responses we can get here:
Data returned as a JSON array, with the array containing individual data trees (This approach was finalized to be implemented in V2 of get API)
Get all the data trees in a JSON Array
Data Returned as a JSON object, with all data trees in a single object
Get all the data trees as JSON Objects
Impact on CPS-NCMP_DMI plugin
The CPS NCMP DMI plugin internally calls the getDataNode method in order to fetch the configuration data for NCMP-DMI plugin, As of now it expects only a single DataNode to be returned by the getDataNode method and with the updated GET API we are now getting a collection of one or more data nodes from the getDtaNode method.
A couple of things to be checked here are:
Will there be any Impact of multiple data nodes on the functionality of NCMP plugin
Appropriate approach to bring in support for multiple data nodes into NCMP