Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Issues & Decisions

#

Issue

Notes 

Decision

1Add or Delete leaves handle as UPDATE or ADD/DELETE?

The delta report proposed follows the Json Patch format of representing the differences between 2 JSON data. Apart from this the delta is dependent on individual data nodes of the JSON data, this is because the delta report will contain the action, xpath and the source/target data. And since the xpaths are unique to data nodes and not leaf data, every delta entity in delta report will be between 2 data nodes. Going by the general convention and referring RFC-6902:

  • Add: If a data node exists only in the target location (target anchor or JSON payload) then it will be considered an ADD action and all the leaf data under this data node and the child data nodes of the aforementioned data node will be considered as newly added data.
    • The child data nodes will be reported separately in the delta report because these data nodes can be individually identified with their unique xpaths.
  • Remove: If a data node exists only in the source location (source anchor) but is not in the target location (target anchor or JSON payload) then this will be considered as a REMOVE operation. All the leaf data under this data node and the child data nodes of the aforementioned data node will be considered as removed.
    • The child data nodes will be reported separately in the delta report because these data nodes can be individually identified with their unique xpaths.
  • Update: If a data node exists both, in the source and target location then the individual leaf nodes of this data node are compared to find any changes in the data. If the data is changed then it is reported as an UPDATE action because leaf data of an already existing data node are updated here.
    • only the leaves which are added, deleted or modified are reported in delta report. Any unmodified leaf is not reported.
    • Child data nodes are evaluated individually, if a child node is added it's an ADD action, if a child node is removed its REMOVE action and if a child node exists in both locations, then the leaves are evaluated for any changes which are reported as UPDATE action.
Updated as per notes.
2How to handle multiple changes at different levels?
Since the delta report will contain the xpaths of data nodes changed, so for changes at multiple levels i.e., parent and child data nodes, the approach will be to handle each data node individually and report them in the delta report. 

3More scenarios need to be explored and documented in detail. Such as handling arrays within a json, handling child/grandchild changes.
scenarios such as data nodes at multiple levels, arrays and lists are covered.

CPS Delta feature Exceptions

Wherever possible the Delta Feature will throw the same exceptions as defined in CPS core. If any new exception for the delta feature is required, the following will be updated here.

HTTP response codes for Delta between 2 Anchors API

The proposed API will be part of the CPS Data Interface. The following response codes will be returned by the API:

#Sub InterfaceMethodScenario

HTTP Response codes

to be implemented

Notes
1Data

Proposed API:

GET-/v2/dataspaces/{dataspace-name}/anchors/{anchor-name}/delta?anchor2={anchor-name}?xpath={xpath}&descendants={descendants}

Proposed method name:  getDeltaByDataspaceAndAnchors()

Generate a delta report between 2 anchors in a given dataspace.

  • 200 (OK)
    • success
  • 400
    • dataspace not found
      DataspaceNotFoundException
    • anchor not found
      AnchorNotFoundException
    • Data node not found
      DataNodeNotFoundException
    • invalid xpath
      CpsPathException
  • 500
    • unexpected error
AnchorNotFoundException should provide the name of missing anchor from the given two anchor names.

Request parameters:

Parameter nameInRequiredDescription
dataspace-namePathYesDataspace name
anchor-namePathYesFirst Anchor Name/Reference Anchor
target-anchor-nameQueryYesSecond Anchor Name/Comparand Anchor
xpathQueryYesxpath of the node
descendantsQueryNoLevel of descendants for delta comparison. 

Response Body/Delta Report Format

Code Block
titleResponse body should contain anchors delta report (added/deleted/modified configuration) as below.
collapsetrue
[
  {
    "action": "ADD",
    "xpath": "/bookstore/categories/[@code=3]",
    "target-data": {
      "code": 3,
      "name": "kidz"
    }
  },
  {
    "action": "REMOVE",
    "xpath": "/bookstore/categories/[@code=1]",
    "source-data": {
      "code": 1,
      "name": "Fiction"
    }
  },
  {
    "action": "UPDATE",
    "xpath": "/bookstore/categories/[@code=2]",
    "source-data": {
      "name": "Funny"
    },
    "target-data": {
      "name": "Comic"
    }
  }
]

Mechanism for Delta generation between Anchors

Gliffy Diagram
size600
displayNameCPS Delta Flowchart
nameCPS Delta Flowchart
pagePin2

Additional Details

Format/Conventions to be used for Delta Report

The delta report format is based on two RFCs namely RFC 6902 and RFC 9144 . A detailed comparison of the RFCs can be found here.

RFC 6902 JSON Patch

JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation(JSON) document; it is suitable for use with the HTTP PATCH method.

...

Code Block
titleSample JSON Patch
collapsetrue
[
     { "op": "test", "path": "/a/b/c", "value": "foo" },
     { "op": "remove", "path": "/a/b/c" },
     { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
     { "op": "replace", "path": "/a/b/c", "value": 42 },
     { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
     { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
   ]

RFC 9144 Data Model

RFC 9144 YANG data model that defines RPCs intended to be used in conjunction with NETCONF [RFC6241] or RESTCONF [RFC8040]. These RFCs allow a client to request a server to compare two NMDA datastores and report any differences.

Comparison of RFC 9144 Data Model and RFC6902 JSON Patch format

  • The core of the RFC 9144 solution is a new operator, <compare>, that compares the data tree contents of two datastores. The operation checks whether there are any differences in values or in data nodes that are contained in either datastore and then returns any differences as output. The output is returned in the format specified below.
  • The RFC6902 approach to Delta report generation follows the JSON patch format. A JSON Patch document represents an array of objects, where each object contains exactly one operation, path and associated values. The operation can have following values: add, remove, replace, move, copy and test. The path represents the JSON patch format and the values contain the difference in source and target values.


Code Block
titleSample delta as per RFC9144
collapsetrue
{ "ietf-nmda-compare:output" : {
    "differences" : {
      "ietf-yang-patch:yang-patch" : {
        "patch-id" : "interface status",
        "comment" : "diff between intended (source) and operational",
        "edit" : [
          {
            "edit-id" : "1",
            "operation" : "replace",
            "target" : "/ietf-interfaces:interface=eth0/enabled",
            "value" : {
               "ietf-interfaces:interface/enabled" : "false"
            },
            "source-value" : {
               "ietf-interfaces:interface/enabled" : "true",
               "@ietf-interfaces:interface/enabled" : {
                 "ietf-origin:origin" : "ietf-origin:learned"
               }
             }
          },
          {
            "edit-id" : "2",
            "operation" : "create",
            "target" : "/ietf-interfaces:interface=eth0/description",
            "value" : {
              "ietf-interface:interface/description" : "ip interface"
            }
          }
        ]
      }
    }
  }
}

 


Code Block
titleSample JSON Patch document as per RFC 6902 
collapsetrue
PATCH /my/data HTTP/1.1
   Host: example.org
   Content-Length: 326
   Content-Type: application/json-patch+json
   If-Match: "abc123"
 
   [
     { "op": "test", "path": "/a/b/c", "value": "foo" },
     { "op": "remove", "path": "/a/b/c" },
     { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
     { "op": "replace", "path": "/a/b/c", "value": 42 },
     { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
     { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
   ]


CPS Delta Report Format

Based on the RFC documentations mentioned above, CPS Delta Report is designed in the format specified in the following code block. This Delta Report takes the features from both RFCs that are best suited for CPS and fulfill its requirements.

...

Code Block
titleDelta Report Format for CPS
collapsetrue
[
  {
    "action": "ADD",
    "xpath": "/bookstore/categories/[@code=3]",
    "target-data": {
      "code": "3,",
      "name": "kidz"
    }
  },
  {
    "action": "REMOVE",
    "xpath": "/bookstore/categories/[@code=1]",
    "source-data": {
      "code": "1,",
      "name": "Fiction"
    }
  },
  {
    "action": "UPDATE",
    "xpath": "/bookstore/categories/[@code=2]",
    "source-data": {
      "name": "Funny"
    },
    "target-data": {
      "name": "Comic"
    }
  }
]

Proposed Algorithm

The JSON data stored in CPS can be retrieved as Maps, And using this we can find the delta between two anchors retrieved as two separate Maps. The result can be stored in an JSON array with appropriate notations for action, xpath and payload. The following algorithm can be used to find the difference between the two maps and also recursively finds the difference between the child data nodes. The response is in form of a JSON Array which closely represents the JSON Patch format as described above.

Algorithm:

  1. Create an empty JSON Array, to store the result
    • The JSON array will contain the following: action, xpath, payload as individual JSON objects each object representing a singular operation.
  2. Fetch the data from two anchors and store in two separate Maps
  3. Iterate over the entries of first map
  4. For each entry of first map, check if the key is present in second map.
  5. If the key is not found in second map, it means that the key-value pair has been removed from the second map. Create a JSON Object with DELETE action, the xpath to deleted node and payload. Add the Object to the JSON Array.
  6. If the key is present in the second map, compare the values associated with the keys in both maps.
  7. If the values are instance of Map, recursively call the comparision algorithm to compare all nested maps. Add all the necessary fields into a JSON object and put the object into the JSON Array
  8. If the values are not equal, it means the key-value pair was updated. Create a JSON Object with UPDATE action, the xpath to updated nodes and payload. Add the Object to the JSON Array.
  9. Iterate over the keys of second map and find the keys not present in first map. These keys were added as new entries. Create a JSON Object with ADD action, the xpath to added node and payload. Add the Object to the JSON Array.
  10. Return the JSON Array and the updates to Kafka events