From cb23b1771e3fc552090f80791b852ce8ad05f150 Mon Sep 17 00:00:00 2001 From: "puthuparambil.aditya" Date: Mon, 10 Jan 2022 12:58:37 +0000 Subject: Support operation field for CPS Temporal Query Output API - Update in openapi.yaml to support operation field - Repository test updated to test the operation field - Rest api test updated - Updates in documentation to include the operation field Issue-ID: CPS-844 Signed-off-by: puthuparambil.aditya Change-Id: If424c273b84b1f415ba706d0956f0841ce9c4196 --- .../cps-data-updated-event-schema-v1.json | 87 --------------------- .../cps-data-updated-event-schema.json | 91 ++++++++++++++++++++++ docs/_static/openapi/swagger/openapi.yml | 19 ++++- docs/content/deployment.rst | 13 +++- docs/content/modeling.rst | 28 ++++++- openapi/swagger/openapi.yml | 8 +- .../controller/rest/QueryControllerSpec.groovy | 6 +- .../NetworkDataRepositoryImplSpec.groovy | 5 +- 8 files changed, 161 insertions(+), 96 deletions(-) delete mode 100644 docs/_static/event-schema/cps-data-updated-event-schema-v1.json create mode 100644 docs/_static/event-schema/cps-data-updated-event-schema.json diff --git a/docs/_static/event-schema/cps-data-updated-event-schema-v1.json b/docs/_static/event-schema/cps-data-updated-event-schema-v1.json deleted file mode 100644 index 2057955..0000000 --- a/docs/_static/event-schema/cps-data-updated-event-schema-v1.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "urn:cps:org.onap.cps:data-updated-event-schema:v1", - - "$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": false - }, - - "Content": { - "description": "The event content.", - "type": "object", - "properties": { - "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", - "data" - ], - "additionalProperties": false - }, - - "Data": { - "description": "Data as json object.", - "type": "object" - } - - } - -} \ No newline at end of file diff --git a/docs/_static/event-schema/cps-data-updated-event-schema.json b/docs/_static/event-schema/cps-data-updated-event-schema.json new file mode 100644 index 0000000..94d8db8 --- /dev/null +++ b/docs/_static/event-schema/cps-data-updated-event-schema.json @@ -0,0 +1,91 @@ +{ + + "$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": { + "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" + }, + "operation": { + "description": "The operation on the data", + "type": "string", + "enum": ["CREATE", "UPDATE", "DELETE"] + }, + "data": { + "$ref": "#/definitions/Data" + } + }, + "required": [ + "observedTimestamp", + "dataspaceName", + "schemaSetName", + "anchorName" + ], + "additionalProperties": true + }, + + "Data": { + "description": "Data as json object.", + "type": "object" + } + + } + +} \ No newline at end of file diff --git a/docs/_static/openapi/swagger/openapi.yml b/docs/_static/openapi/swagger/openapi.yml index 991d807..a96947b 100644 --- a/docs/_static/openapi/swagger/openapi.yml +++ b/docs/_static/openapi/swagger/openapi.yml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2021 Bell Canada. +# Copyright (c) 2021-2022 Bell Canada. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -51,6 +51,7 @@ paths: required: true schema: type: string + example: my-anchor - $ref: '#/components/parameters/observedTimestampAfter' - $ref: '#/components/parameters/simplePayloadFilter' - $ref: '#/components/parameters/pointInTime' @@ -192,18 +193,30 @@ components: application/json: schema: $ref: '#/components/schemas/ErrorMessage' + example: + status: 400 + message: Bad request error message + details: Bad request error details Unauthorized: description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/ErrorMessage' + example: + status: 401 + message: Unauthorized error message + details: Unauthorized error details Forbidden: description: Forbidden content: application/json: schema: $ref: '#/components/schemas/ErrorMessage' + example: + status: 403 + message: Forbidden error message + details: Forbidden error details schemas: AnchorDetails: type: object @@ -212,6 +225,10 @@ components: observedTimestamp: type: string example: '2021-03-21T00:00:00.000-0000' + operation: + type: string + enum: [CREATE, UPDATE, DELETE] + example: UPDATE dataspace: type: string example: 'my-dataspace' diff --git a/docs/content/deployment.rst b/docs/content/deployment.rst index fd6fd59..0013466 100644 --- a/docs/content/deployment.rst +++ b/docs/content/deployment.rst @@ -2,7 +2,7 @@ .. Creative Commons Attribution 4.0 International License. .. http://creativecommons.org/licenses/by/4.0 .. -.. Copyright (C) 2021 Bell Canada +.. Copyright (C) 2021-2022 Bell Canada .. Modifications Copyright (C) 2021 Nordix Foundation ======================= @@ -127,3 +127,14 @@ For development purposes, CPS Temporal can be ran on any environment using Docker. Refer to `README.md `_ and `docker-compose.yml `_ files for more details. + +Upgrade +======= + +**Cps data-updated-event schema v2** + +Cps data-updated-event schema v2 used in Jakarta is backward compatible with data-updated-event schema v1 used in Istanbul. + +It means that consumers using the schema v2 can process events generated by producers using the schema v2 or v1. + +This implies that cps temporal (consumer) must be upgraded from Istanbul to Jakarta at the same time or before cps core (producer) is upgraded from Istanbul to Jakarta. \ No newline at end of file diff --git a/docs/content/modeling.rst b/docs/content/modeling.rst index 8871a81..e8c5345 100644 --- a/docs/content/modeling.rst +++ b/docs/content/modeling.rst @@ -2,7 +2,7 @@ .. Creative Commons Attribution 4.0 International License. .. http://creativecommons.org/licenses/by/4.0 .. -.. Copyright (C) 2021 Bell Canada +.. Copyright (C) 2021-2022 Bell Canada ===================== CPS Temporal Modeling @@ -14,19 +14,20 @@ Event Structure Data manipulated by both CPS Core and CPS Temporal to represent a Data Updated Event is a JSON structure that is defined by following Json Schema: -* :download:`cps-data-updated-event-schema.json <../_static/event-schema/cps-data-updated-event-schema-v1.json>` +* :download:`cps-data-updated-event-schema.json <../_static/event-schema/cps-data-updated-event-schema.json>` And following is an example of an event compliant with this schema: .. code:: json { - "schema": "urn:cps:org.onap.cps:data-updated-event-schema:v1", + "schema": "urn:cps:org.onap.cps:data-updated-event-schema:v2", "id": "38aa6cc6-264d-4ede-b534-18f5c1f403ea", "source": "urn:cps:org.onap.cps", "type": "org.onap.cps.data-updated-event", "content": { "observedTimestamp": "2021-06-09T13:00:00.123-0400", + "operation": "UPDATE", "dataspaceName": "my-dataspace", "schemaSetName": "my-schema-set", "anchorName": "my-anchor", @@ -39,3 +40,24 @@ And following is an example of an event compliant with this schema: } } +Event versions +============== + +The following table lists the data-updated-event schema evolution over releases : + + +-----------+------------+-------------------------+---------------------+ + | Version | Release | Compatibility Type | Upgrade First | + | | | (with previous version) | | + +===========+============+=========================+=====================+ + | v1 | Istanbul | n/a | Any order | + +-----------+------------+-------------------------+---------------------+ + | v2 | Jakarta | Backward | Consumer (Temporal) | + +-----------+------------+-------------------------+---------------------+ + +**Compatibility Types** + +Several compatibility types exist when an event schema definition is evolving from one release to the next one: + +- Backward compatibility means that consumers using the new schema can read data produced with the previous schema. +- Forward compatibility means that data produced with a new schema can be read by consumers using the previous schema. +- Full compatibility means that schemas are both backward and forward compatible: old data can be read with the new schema, and new data can also be read with the previous schema. \ No newline at end of file diff --git a/openapi/swagger/openapi.yml b/openapi/swagger/openapi.yml index 5b3578a..a96947b 100644 --- a/openapi/swagger/openapi.yml +++ b/openapi/swagger/openapi.yml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2021 Bell Canada. +# Copyright (c) 2021-2022 Bell Canada. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -194,7 +194,7 @@ components: schema: $ref: '#/components/schemas/ErrorMessage' example: - status: 400 BAD_REQUEST + status: 400 message: Bad request error message details: Bad request error details Unauthorized: @@ -225,6 +225,10 @@ components: observedTimestamp: type: string example: '2021-03-21T00:00:00.000-0000' + operation: + type: string + enum: [CREATE, UPDATE, DELETE] + example: UPDATE dataspace: type: string example: 'my-dataspace' diff --git a/src/test/groovy/org/onap/cps/temporal/controller/rest/QueryControllerSpec.groovy b/src/test/groovy/org/onap/cps/temporal/controller/rest/QueryControllerSpec.groovy index 7847b34..305a55b 100644 --- a/src/test/groovy/org/onap/cps/temporal/controller/rest/QueryControllerSpec.groovy +++ b/src/test/groovy/org/onap/cps/temporal/controller/rest/QueryControllerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (c) 2021 Bell Canada. + * Copyright (c) 2021-2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ package org.onap.cps.temporal.controller.rest import org.onap.cps.temporal.controller.utils.DateTimeUtility import com.fasterxml.jackson.databind.ObjectMapper +import org.onap.cps.temporal.domain.Operation + import java.time.OffsetDateTime import org.onap.cps.temporal.controller.rest.model.AnchorDetails import org.onap.cps.temporal.controller.rest.model.AnchorDetailsMapperImpl @@ -239,6 +241,7 @@ class QueryControllerSpec extends Specification { return NetworkData.builder().dataspace(myDataspace) .schemaSet(mySchemaset).anchor(myAnchor).payload('{"message" : "Hello World"}') .observedTimestamp(OffsetDateTime.now()) + .operation(Operation.CREATE) .createdTimestamp(OffsetDateTime.now()).build() } @@ -248,6 +251,7 @@ class QueryControllerSpec extends Specification { anchorDetails.setAnchor(networkData.getAnchor()) anchorDetails.setSchemaSet(networkData.getSchemaSet()) anchorDetails.setObservedTimestamp(DateTimeUtility.toString(networkData.getObservedTimestamp())) + anchorDetails.setOperation(AnchorDetails.OperationEnum.valueOf(networkData.getOperation().toString())) anchorDetails.setData(networkData.getPayload()) return anchorDetails } diff --git a/src/test/groovy/org/onap/cps/temporal/repository/NetworkDataRepositoryImplSpec.groovy b/src/test/groovy/org/onap/cps/temporal/repository/NetworkDataRepositoryImplSpec.groovy index d33df75..ad7ea75 100644 --- a/src/test/groovy/org/onap/cps/temporal/repository/NetworkDataRepositoryImplSpec.groovy +++ b/src/test/groovy/org/onap/cps/temporal/repository/NetworkDataRepositoryImplSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (c) 2021 Bell Canada. + * Copyright (c) 2021-2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.cps.temporal.repository import org.onap.cps.temporal.domain.NetworkData +import org.onap.cps.temporal.domain.Operation import org.onap.cps.temporal.domain.SearchCriteria import org.onap.cps.temporal.repository.containers.TimescaleContainer import org.springframework.beans.factory.annotation.Autowired @@ -118,6 +119,7 @@ class NetworkDataRepositoryImplSpec extends Specification { assert data.getObservedTimestamp().isAfter(observedAfter) || data.getObservedTimestamp().isEqual(observedAfter) assert data.getAnchor() == queryAnchorName assert data.getDataspace() == queryDataspaceName + assert data.getOperation() != null } } @@ -141,6 +143,7 @@ class NetworkDataRepositoryImplSpec extends Specification { assert data.getCreatedTimestamp().isBefore(createdBefore) || data.getCreatedTimestamp().isEqual(createdBefore) assert data.getAnchor() == queryAnchorName assert data.getDataspace() == queryDataspaceName + assert data.getOperation() != null } } -- cgit 1.2.3-korg