Initial Findings
It is found that the current Patch operation in CPS core can only update value of one leaf node under a container node at a time.
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:
|
|
JSON Data Stored in CPS DB using POST operation.
The following JSON data was first stored in CPS DB:
Analysis of Patch operation (Update node leaves)
Currently after multiple data trees are stored in CPS DB. On performing the Patch operation, with root node xpath "/", 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 "/"
Response: 500 Server Error
On performing Get operation we get the following JSON data, here none of the leaves are updatedUpdating the first data tree
CURL request to update first data treecurl --location --request PATCH 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/sample/nodes?xpath=%2Finterface-A' \ --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node0iyclt1syzfqj28jzo5qc5gks1.node0' \ --data '{ "int:interface": { "name": "Interface-A", "address": "10.10.10.200", //value to be updated "enabled": true, //value to be updated "subnet-mask": "255.255.255.0" } }'
Response 200 OK
Updated data after making get request[ { "int:interface-A": { "domain": "false", "host-name": "host", "interface": [ { "name": "Interface-A", "address": "10.10.10.200", //updated "enabled": true, //updated "subnet-mask": "255.255.255.0" } ] } } ]
Updating the second data tree
CURL request to update second data treecurl --location --request PATCH 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/sample/nodes?xpath=%2Finterface-B' \ --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node0iyclt1syzfqj28jzo5qc5gks1.node0' \ --data '{ "int:interface": { "name": "Interface-B", "address": "10.10.10.200", "subnet-mask": "255.255.255.10" } }'
Response 200 OK
Updated data after making get request[ { "int:interface-B": { "interface": [ { "name": "Interface-B", "address": "10.10.10.200", "subnet-mask": "255.255.255.10" } ] } } ]
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 node in each data tree
{ "first-container": { "a-leaf": "a-value" }, "last-container": { "x-leaf": "x-value" } }
An update operation is performed on both data trees as follows:
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
[ { "multiple-data-tree:last-container": { "x-leaf": "x-new-value" } }, { "multiple-data-tree:first-container": { "a-leaf": "a-value" } } ]
The same behavior is seen in the first scenario above, where if the leaves are updated and the list is left as it is. Then only the leaf node of second data tree gets updated.
When updating list node and leaf node under one container node, returns Status 200 but list data is not updated
(Note: This following finding was identified as an issue with list-nodes and not multiple data nodes. It is documented separately CPS-1383: Investigate CPS-Path for modifications of multiple fragments under an anchor.)
Assuming the following data is in the databse
{ "int:interface-A": { "domain": "false", "host-name": "host", "interface": [ { "name": "Interface-A", "address": "10.10.10.200", "enabled": true, "subnet-mask": "255.255.255.0" } ] } }
When performing update operation with xPath set as root
curl --location --request PATCH 'http://localhost:8080/cps/api/v1/dataspaces/testDataspace/anchors/sample/nodes?xpath=%2F' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --header 'Cookie: JSESSIONID=node01ejoiyh1brii5zx8z9mk2r39l1.node0' \ --data '{ "int:interface-A": { "domain": "false", "host-name": "New-Host", //value to be updated "interface": [ { "name": "Interface-A", "address": "10.10.10.0", //value to be updated "enabled": false, //value to be updated "subnet-mask": "255.255.255.0" } ] } }'
Status 200 OK is returned, but on performing the Get operation it is noticed only the leaf nodes get updated and list node remains as it is.
{ "int:interface-A": { "domain": "false", "host-name": "New-Host", //Updated "interface": [ { "name": "Interface-A", "address": "10.10.10.200", //list remains unchanged "enabled": true, //list remains unchanged "subnet-mask": "255.255.255.0" } ] } }