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

Compare with Current View Page History

« Previous Version 13 Current »

Issues and Decisions 

#IssuesNotesDecision
1do we need separate operation for list or can we support all variations using same solution without interface changes

Toine Siebelink Prefer single solution that address all scenarios (multiple containers or list entries) correctly without interface changes. 

2Should all patch operations be part of singel transactionfor now treat individual
3what to do with failures
  1. stop and rollback (depends on issue #2)
  2. silently ignore
  3. stop processing with rollback 

Initial findings

When trying to perform Patch operation on a list data node, wherein multiple list items are updated in one request. It is seen that only the top most item in the list gets updated where as the remaining list items remain as it is.

And the response sent back is 200 OK. This might lead to the user assuming that the Patch operation was executed successfully over multiple list items but in reality it would have only updated the fist item in the list.

Example

Assuming the following data is in the database


Data Example
{
  "int:interface-A": {
    "interface": [
      {
        "name": "Interface-A",
        "address": "10.10.10.200",
        "enabled": true,
        "subnet-mask": "255.255.255.0"
      },

      {
        "name": "Interface-B",
        "address": "10.10.10.200",
        "enabled": true,
        "subnet-mask": "255.255.255.0"
      }
    ]
  }
}

When performing update operation on the list data node

Patch operation
curl --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=node01ejoiyh1brii5zx8z9mk2r39l1.node0' \
--data '{
  "int:interface-A": {
    "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"
      },              

      {
        "name": "Interface-B",
        "address": "1.1.1.1",          //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 first item in the list node gets updated and second one remains as it is.

Data After Update
{
  "int:interface-A": {
    "interface": [
      {
        "name": "Interface-A",
        "address": "10.10.10.0",        //changed value
        "enabled": false,                  //changed value
        "subnet-mask": "255.255.255.0"
      },              

      {
        "name": "Interface-B",
        "address": "10.10.10.200",       //unchanged value
        "enabled": true,                //unchanged value
        "subnet-mask": "255.255.255.0"
      }

    ]
  }
}

Impact of CPS-1526 on this issue

The problem that CPS-1526 resolves is that when trying to update multiple data nodes in one request then a 400 Bad Request is sent back as response, earlier it would send a 500 response with a message not clear enough to identify the problem.

So, assuming that there is an anchor with multiple data nodes in the DB and when a user tries to update more than one data node at once the system responds and gives a message that the operation is unsupported. But when a user tries to update the data nodes directly under the root node individually then the operation executes successfully.

Now this behavior is not limited to the data nodes directly under the root node xpath, but is applicable to all the data nodes under a specific xpath as well.

So, if there is a list data node with multiple list items, and the user tries to update multiple list items at once as in the example above, the system now returns a 400 Bad Request, with the error message that the operation is unsupported because the user is basically updating multiple data nodes under a list, earlier this response was a 200 OK with a partial Patch operation taking place in the background.

Response received after CPS 1526

Response
{
    "status": "400 BAD_REQUEST",
    "message": "Operation is not supported for multiple data nodes",
    "details": "Number of data nodes present: 2"
}


Possible Solutions to Updating multiple items.

  • Iterate over top-level element in patch.
  • match each top element element to target data 
  • execute each patch
  • Transactional ?!
  • test & demo for each scenario
    • top level containers
    • top level list elements
    • list elements under same continaer
  • No labels