CPS-470 - Getting issue details... STATUS

Overview

The CPS-core notification system only sends data-update events when a root data node is created or the anchor is updated. There is no support for delete change. And, the existing supported operations are also not differentiated in the event. To define the operation type, we need to change the existing event structure and the changes on both the cps-core and cps-temporal sides to support the new event version. 

Decision/Issues



DescriptionDecision
1'operation' field in the event should be mandatory or optional?'optional' because Bell is deploying cps Istanbul in production soon
2

Multiple root data nodes can have an impact on notification services

Will be evaluated as part of the spike

CPS-341 - Getting issue details... STATUS  

Proposal

Operation

OperationScenario
CREATE
  • The root data node is created
UPDATE
  • update action on the root 'data node'
  • create, update and delete action on the non-root data nodes
DELETE
  • The root data node is deleted

Event

Enable Full compatibility

The event V1 schema definition is strict and it is not possible to add any optional fields without breaking the old schema contract. To have the flexibility of adding optional fields in future with full compatibility, we are setting the value of 'additionalProperties' to true in both 'CpsDataUpdatedEvent' and 'Content' definitions. 

Flexible schema definition
{

  "definitions": {
    "CpsDataUpdatedEvent": {
      ...
      "additionalProperties": true
    },
    "Content": {
     ...
      "additionalProperties": true
    },
    ...
  }
}
Add Operation field

The new 'operation' field is added to the event in the content section. The field can be marked as 

  • optional: It makes the event v2 backwards compatible and the user can upgrade cps-temporal before cps-core. As it is a field that should be mandatory, it should be set as mandatory in the v3 which gives the user a release to upgrade cps-core to v2.  
  • mandatory: no compatibility with the older version and both cps-core and cps-temporal have to be updated at the same time.
Added operation property in content
{
  	"definitions": {
		...
    	"Content": {
			"properties": {
				"operation": {
          			"description": "The operation supported by the ",
          			"type": "string",
          			"enum": ["CREATE", "UPDATE", "DELETE"]
        			}
				...
			}
		}
	}
}
Optional Data field

The existing 'data' section in the content should not be provided in the delete event and it should be marked as optional. As we are deleting a mandatory field, the change is still backwards compatible. 

Event V2 JSON Schema
cps-data-updated-event-schema-v2.json
{

  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "urn:cps:org.onap.cps:data-updated-event-schema:v2",

  "$ref": "#/definitions/CpsDataUpdatedEvent",

  "definitions": {

    "CpsDataUpdatedEvent": {
      "description": "The payload for CPS data updated event.",
      "type": "object",
      "properties": {
        "schema": {
          "description": "The schema, including its version, that this event adheres to. E.g. 'urn:cps:org.onap.cps:data-updated-event-schema:v99'.",
          "type": "string",
          "format": "uri"
        },
        "id": {
          "description": "The unique id identifying the event for the specified source. Producer must ensure that source + id is unique for each distinct event.",
          "type": "string"
        },
        "source": {
          "description": "The source of the event. Producer must ensure that source + id is unique for each distinct event.",
          "type": "string",
          "format": "uri"
        },
        "type": {
          "description": "The type of the event.",
          "type": "string"
        },
        "content": {
          "$ref": "#/definitions/Content"
        }
      },
      "required": [
        "schema",
        "id",
        "source",
        "type",
        "content"
      ],
      "additionalProperties": true
    },

    "Content": {
      "description": "The event content.",
      "type": "object",
      "properties": {
        "operation": {
          "description": "The operation supported by the ",
          "type": "string",
          "enum": ["CREATE", "UPDATE", "DELETE"]
        },
        "observedTimestamp": {
          "description": "The timestamp when the data has been observed. The expected format is 'yyyy-MM-dd'T'HH:mm:ss.SSSZ'. Ex: '2020-12-01T00:00:00.000+0000'  ",
          "type": "string"
        },
        "dataspaceName": {
          "description": "The name of CPS Core dataspace the data belongs to.",
          "type": "string"
        },
        "schemaSetName": {
          "description": "The name of CPS Core schema set the data adheres to.",
          "type": "string"
        },
        "anchorName": {
          "description": "The name of CPS Core anchor the data is attached to.",
          "type": "string"
        },
        "data": {
          "$ref": "#/definitions/Data"
        }
      },
      "required": [
        "observedTimestamp",
        "dataspaceName",
        "schemaSetName",
        "anchorName"
      ],
      "additionalProperties": true
    },

    "Data": {
      "description": "Data as json object.",
      "type": "object"
    }

  }

}


example: data updated event v2
{
  "schema": "urn:cps:org.onap.cps:data-updated-event-schema:v2",
  "id": "77b8f114-4562-4069-8234-6d059ff742ac",
  "source": "urn:cps:org.onap.cps",
  "type": "org.onap.cps.data-updated-event",
  "content": {
    "observedTimestamp": "2020-12-01T00:00:00.000+0000",
    "dataspaceName": "my-dataspace",
    "schemaSetName": "bookstore-schemaset",
    "anchorName": "chapters",
    "operation": "CREATE",
    "data": {
      "test:bookstore":{
        "bookstore-name": "Chapters",
        "categories": [
          {
            "code": "01",
            "name": "SciFi",
            "books": [
              {
                "authors": [
                  "Iain M. Banks"
                ],
                "lang": "en",
                "price": 895,
                "pub_year": "1994",
                "title": "Feersum Endjinn"
              }
            ]
          }
        ]
      }
    }
  }
}

Delete Event example
Delete event
{
  "schema": "urn:cps:org.onap.cps:data-updated-event-schema:v2",
  "id": "77b8f114-4562-4069-8234-6d059ff742ac",
  "source": "urn:cps:org.onap.cps",
  "type": "org.onap.cps.data-updated-event",
  "content": {
    "observedTimestamp": "2020-12-01T00:00:00.000+0000",
    "dataspaceName": "my-dataspace",
    "schemaSetName": "bookstore-schemaset",
    "anchorName": "chapters",
    "operation": "DELETE"
  }
}


CPS-Core

There is no specific operation to delete the root node and it gets deleted when Anchor is deleted. In cps-core, a 'DELETE' notification event should be sent

  • when an anchor is deleted or
  • delete Data Node is called with root XPath.

We are adding a new operation field in the event and the values for all the existing scenarios must be provided as per the Operation section of the proposal.

In the 'DELETE' notification, the 'data' field should not be provided as defined in the event.

CPS-Temporal

It will store the new 'operation' field in the newly added column in the network_data table. If this field is optional in the event, the default value of UPDATE will be set on the temporal side.

Database Schema

A new field 'operation' of type varchar(20) is added in the network_data table. 

Migration

The newly added field 'operation' should have a value of 'UPDATE' for the existing data in the network_data table. 




  • No labels