Initial Findings
It is found that the current Patch operation in CPS core can only update value of one data tree leaf nodes under a container node at a time. So if there are multiple data trees under an anchor and a Patch is performed on all the data trees using root node xPath "/" then only the first data tree gets updated and the remaining data trees remain as it is,
Based on the above outcome, another test to update individual data trees was preformed, and it was found that when a specific data tree is being updated using its specific xPath none of the data trees get updated and a 400 BAD REQUEST is received.
Decisions
To be added
Issues & Decisions:
Notes | Decisions |
---|---|
As per discussion with stakeholder (DT), the following decisions were made:
|
After discussion in the CPS-sub team, following conclusions were made:
|
| After the investigation it was found that the reason behind the inconsistencies discovered was lack of support for Patch operation for multiple data nodes. As per discussion in CPS sub team daily call it was decided to bring in support for Patch operation for multiple data nodes. As it would address all the inconsistencies discovered. |
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:
Code Block | ||
---|---|---|
| ||
{ "multiple-data-tree:interface-A": { "first-container":host-name": "host", "interface": [ { "a-leaf": "a-Valuename": "Interface-A", "address": "10.10.10.1", "subnet-mask": "255.255.255.0", "enabled": false } ], "domain": "false" }, "last-containermultiple-data-tree:interface-B": { "x-leaf": "x-valueinterface": [ { "name": "Interface-B", "address": "10.10.10.1", "subnet-mask": "255.255.255.0" } ] } } |
Analysis of Patch operation (Update node leaves)
Currently after multiple data trees are stored in CPS DB. On performing the Patch operation on the same data, with root node xpath set as root "/", the first data tree is only updated by the Patch operation. To test this following scenarios were performed:
Updating all data trees under an anchor with root node xPath "/"
allCode Block title CURL request to update
Response: 200 OK codemultiple leaves across multiple data trees collapse true curl --location --request PATCH 'http://localhost:8080/cps/api/v2v1/dataspaces/testDataspace/anchors/multipleDataTreesample/nodes?xpath=%2F&observed-timestamp=2021-03-21T00%3A10%3A34.030-0100' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node056putyccbmdr1ij6x17mynl312node0iyclt1syzfqj28jzo5qc5gks1.node0' \ --data '{ "first-containermultiple-data-tree:interface-A": { "ahost-leafname": "a-updated-valuehost-A", //value to be updated "interface": [ { "name": "Interface-A", "address": "10.10.10.100", "subnet-mask": "255.255.255.25", "enabled": false } ], "domain": "true" }, "last-containermultiple-data-tree:interface-B": { "x-leaf": "x-updated-value"interface": [ { "name": "Interface-B", "address": "10.10.10.100", //value to be updated "subnet-mask": "255.255.255.0" //value to be updated } ] } }'
Code Block title Response: 500 Server Error collapse true { "status": "500 INTERNAL_SERVER_ERROR", "message": "could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement", "details": "Check logs for details." }
Reason: The following scenario would fail because CPS Patch operation only supports updating multiple leaves under one container node at a time. And here when we try to update multiple leaves present in two different containers the operations fails.
Code Block title On performing Get operation we get the following JSON data
Updating the first data tree code, here none of the leaves are updated collapse true [ { "multiple-data-tree:last-container": { "int:interface-A": { "domain": "false", "host-name": "host", "interface": [ { "name": "x-leaf": "x-value" Interface-A", "address": "10.10.10.1", "enabled": false, "subnet-mask": "255.255.255.0" } ] } }, { "multiple-data-tree:first-container": "int:interface-B": { "interface": [ { "name": "a-leaf": "a-updated-value" } } ]
CURL request to update first data treeInterface-B", "address": "10.10.10.1", "subnet-mask": "255.255.255.0" } ] } } ]
Updating the data trees individually, leads to successful updation
When updating multiple leaves present under individual data nodes the operation successfully executes.Code Block title CURL request to update leaves under container data node collapse true code
curl --location --request PATCH 'http://localhost:8080/cps/api/v2v1/dataspaces/testDataspace/anchors/multipleDataTreesample/nodes?xpath=%2Ffirst-container&observed-timestamp=2021-03-21T00%3A10%3A34.030-0100%2F' \ --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node02yp851tkv9yvzexd1irvkyqc0node0iyclt1syzfqj28jzo5qc5gks1.node0' \ --data '{ "firstint:interface-containerA": { "a-leaf "domain": "true", //value to be updated "host-name": "a-updated-value"Host-A" //value to be updated } }'
Response 200 OK
Code Block title Updated data after making get request collapse true [ { "statusint:interface-A": "400 BAD_REQUEST", { "domain": "true", //updated "messagehost-name": "Failed to parse json data. Unsupported xpath or json data:{\"first-container\":{\"a-leaf\":\"a-updated-value\"}}", "details": "Schema node with name first-container was not found under (org:onap:ccsdk:multiDataTree?revision=2020-09-15)first-container." }
Updating the second data tree
CURL request to update second data treeHost-A", //updated "interface": [ { "name": "Interface-A", "address": "10.10.10.200", "enabled": true, "subnet-mask": "255.255.255.0" } ] } } ]
Code Block codetitle CURL request to update leaves of one list item in a list data node collapse true curl --location --request PATCH 'http://localhost:8080/cps/api/v2v1/dataspaces/testDataspace/anchors/multipleDataTreesample/nodes?xpath=%2Flast-container&observed-timestamp=2021-03-21T00%3A10%3A34.030-0100' %2Finterface-B' \ --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node02yp851tkv9yvzexd1irvkyqc0node0iyclt1syzfqj28jzo5qc5gks1.node0' \ --data '{ "last-container "int:interface": { "x-leaf": "x-updated-value" } }'
Response
{ "status": "400 BAD_REQUEST", "message": "Failed to parse json data. Unsupported xpath or json data:{\"last-container\":{\"x-leaf\":\"x-updated-value\"}}", "details": "Schema node with name last-container was not found under (org:onap:ccsdk:multiDataTree?revision=2020-09-15)last-container." }Code Block "name": "Interface-B", "address": "10.10.10.200", //value to be updated "subnet-mask": "255.255.255.10" //value to be updated } }'
Response 200 OK
Code Block title Updated data after making get request collapse true [ { "int:interface-B": { "interface": [ { "name": "Interface-B", "address": "10.10.10.200", //updated "subnet-mask": "255.255.255.10" //updated } ] } } ]
Inconsistencies with Patch Operation
When updating multiple data trees with only leaf nodes
Assuming the following data is in the data base, having one leaf in each data tree
Code Block |
---|
{
"first-container": {
"a-leaf": "a-value"
},
"last-container": {
"x-leaf": "x-value"
}
} |
An update operation is performed on both data trees as follows:
Code Block | ||
---|---|---|
| ||
curl --location --request PATCH 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/multipleDataTree/nodes?xpath=%2F' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node0kglnliqz1tzc1g0x6opgrphei0.node0' \
--data '{
"first-container": {
"a-leaf": "a-new-value"
},
"last-container": {
"x-leaf": "x-new-value"
}
}' |
On performing a get operation, it is noticed that only first data tree gets updated
Code Block | ||
---|---|---|
| ||
[
{
"multiple-data-tree:last-container": {
"x-leaf": "x-new-value"
}
},
{
"multiple-data-tree:first-container": {
"a-leaf": "a-value"
}
}
] |