Prepare for next event schema version 51/123451/3 mr/584/123451/3
authorBruno Sakoto <bruno.sakoto@bell.ca>
Fri, 20 Aug 2021 22:59:14 +0000 (18:59 -0400)
committerBruno Sakoto <bruno.sakoto@bell.ca>
Tue, 24 Aug 2021 16:17:42 +0000 (12:17 -0400)
Issue-ID: CPS-584, CPS-459
Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
Change-Id: Iaf605492783f8c06f40522a427ce63bd2d1b34d0

cps-application/src/main/resources/application.yml
cps-events/src/main/resources/schemas/cps-data-updated-event-schema.json
cps-events/src/test/groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy
cps-events/src/test/resources/bookstore-chapters.json
cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy

index e185bf2..bafe7f4 100644 (file)
@@ -71,7 +71,7 @@ spring:
 notification:\r
     data-updated:\r
         enabled: false\r
-        topic: ${CPS_CHANGE_EVENT_TOPIC:cps.cfg-state-events}\r
+        topic: ${CPS_CHANGE_EVENT_TOPIC:cps.data-updated-events}\r
         filters:\r
             enabled-dataspaces: ${DATASPACE_FILTER_PATTERNS:""}\r
 \r
index de445ec..c2fa5f2 100644 (file)
@@ -1,7 +1,7 @@
 {
 
   "$schema": "https://json-schema.org/draft/2019-09/schema",
-  "$id": "urn:cps:org.onap.cps:data-updated-event-schema:1.1.0-SNAPSHOT",
+  "$id": "urn:cps:org.onap.cps:data-updated-event-schema:v1",
 
   "$ref": "#/definitions/CpsDataUpdatedEvent",
 
       "type": "object",
       "properties": {
         "schema": {
-          "description": "The schema, including its version, that this event adheres to.",
+          "description": "The schema, including its version, that this event adheres to. Ex: 'urn:cps:org.onap.cps:data-updated-event-schema:v1'.",
           "type": "string",
-          "default": "urn:cps:org.onap.cps:data-updated-event-schema:1.1.0-SNAPSHOT",
-          "enum": ["urn:cps:org.onap.cps:data-updated-event-schema:1.1.0-SNAPSHOT"]
+          "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.",
@@ -69,7 +68,7 @@
         }
       },
       "required": [
-        "timestamp",
+        "observedTimestamp",
         "dataspaceName",
         "schemaSetName",
         "anchorName",
@@ -85,4 +84,4 @@
 
   }
 
-}
\ No newline at end of file
+}
index f72ecee..545b183 100644 (file)
@@ -33,13 +33,13 @@ class CpsDataUpdatedEventSpec extends Specification {
     def objectMapper = new ObjectMapper()
 
     final DATASPACE_NAME = 'my-dataspace'
-    final BOOKSTORE_SCHEMA_SET = 'bootstore-schemaset'
+    final BOOKSTORE_SCHEMA_SET = 'bookstore-schemaset'
     final ANCHOR_NAME = 'chapters'
     final EVENT_TIMESTAMP = '2020-12-01T00:00:00.000+0000'
     final EVENT_ID = '77b8f114-4562-4069-8234-6d059ff742ac'
     final EVENT_SOURCE = new URI('urn:cps:org.onap.cps')
     final EVENT_TYPE = 'org.onap.cps.data-updated-event'
-    final EVENT_SCHEMA = 'urn:cps:org.onap.cps:data-updated-event-schema:1.1.0-SNAPSHOT'
+    final EVENT_SCHEMA = new URI('urn:cps:org.onap.cps:data-updated-event-schema:v1')
 
     final DATA = [
             'test:bookstore': [
@@ -67,7 +67,7 @@ class CpsDataUpdatedEventSpec extends Specification {
         then: 'CpsDataUpdatedEvent POJO has the excepted values'
             cpsDataUpdatedEvent.id == EVENT_ID
             cpsDataUpdatedEvent.source == EVENT_SOURCE
-            cpsDataUpdatedEvent.schema.value() == EVENT_SCHEMA
+            cpsDataUpdatedEvent.schema == EVENT_SCHEMA
             cpsDataUpdatedEvent.type == EVENT_TYPE
             def content = cpsDataUpdatedEvent.content
             content.observedTimestamp == EVENT_TIMESTAMP
@@ -90,8 +90,7 @@ class CpsDataUpdatedEventSpec extends Specification {
         and: 'CpsDataUpdatedEvent with the content'
             def cpsDataUpdateEvent = new CpsDataUpdatedEvent()
             cpsDataUpdateEvent
-                    .withSchema(
-                            CpsDataUpdatedEvent.Schema.fromValue(EVENT_SCHEMA))
+                    .withSchema(EVENT_SCHEMA)
                     .withId(EVENT_ID)
                     .withSource(EVENT_SOURCE)
                     .withType(EVENT_TYPE)
@@ -111,4 +110,4 @@ class CpsDataUpdatedEventSpec extends Specification {
         )
     }
 
-}
\ No newline at end of file
+}
index de46b71..753426a 100644 (file)
@@ -1,12 +1,12 @@
 {
-  "schema": "urn:cps:org.onap.cps:data-updated-event-schema:1.1.0-SNAPSHOT",
+  "schema": "urn:cps:org.onap.cps:data-updated-event-schema:v1",
   "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": "bootstore-schemaset",
+    "schemaSetName": "bookstore-schemaset",
     "anchorName": "chapters",
     "data": {
       "test:bookstore":{
@@ -31,4 +31,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}
index e1473d3..26b89fc 100644 (file)
@@ -27,7 +27,6 @@ import org.onap.cps.api.CpsAdminService;
 import org.onap.cps.api.CpsDataService;
 import org.onap.cps.event.model.Content;
 import org.onap.cps.event.model.CpsDataUpdatedEvent;
-import org.onap.cps.event.model.CpsDataUpdatedEvent.Schema;
 import org.onap.cps.event.model.Data;
 import org.onap.cps.spi.FetchDescendantsOption;
 import org.onap.cps.spi.model.Anchor;
@@ -38,6 +37,7 @@ import org.springframework.stereotype.Component;
 @Component
 class CpsDataUpdatedEventFactory {
 
+    private static final URI EVENT_SCHEMA;
     private static final URI EVENT_SOURCE;
     private static final String EVENT_TYPE = "org.onap.cps.data-updated-event";
     private static final DateTimeFormatter dateTimeFormatter =
@@ -45,6 +45,7 @@ class CpsDataUpdatedEventFactory {
 
     static  {
         try {
+            EVENT_SCHEMA = new URI("urn:cps:org.onap.cps:data-updated-event-schema:v1");
             EVENT_SOURCE = new URI("urn:cps:org.onap.cps");
         } catch (final URISyntaxException e) {
             // As it is fixed string, I don't expect to see this error
@@ -52,8 +53,8 @@ class CpsDataUpdatedEventFactory {
         }
     }
 
-    private CpsDataService cpsDataService;
-    private CpsAdminService cpsAdminService;
+    private final CpsDataService cpsDataService;
+    private final CpsAdminService cpsAdminService;
 
     public CpsDataUpdatedEventFactory(final CpsDataService cpsDataService, final CpsAdminService cpsAdminService) {
         this.cpsDataService = cpsDataService;
@@ -71,7 +72,7 @@ class CpsDataUpdatedEventFactory {
         final var cpsDataUpdatedEvent = new CpsDataUpdatedEvent();
         cpsDataUpdatedEvent.withContent(createContent(anchor, dataNode));
         cpsDataUpdatedEvent.withId(UUID.randomUUID().toString());
-        cpsDataUpdatedEvent.withSchema(Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT);
+        cpsDataUpdatedEvent.withSchema(EVENT_SCHEMA);
         cpsDataUpdatedEvent.withSource(EVENT_SOURCE);
         cpsDataUpdatedEvent.withType(EVENT_TYPE);
         return cpsDataUpdatedEvent;
index aecc3f7..2ce77bd 100644 (file)
@@ -21,7 +21,6 @@ package org.onap.cps.notification
 
 import org.onap.cps.api.CpsAdminService
 import org.onap.cps.api.CpsDataService
-import org.onap.cps.event.model.CpsDataUpdatedEvent
 import org.onap.cps.event.model.Data
 import org.onap.cps.spi.FetchDescendantsOption
 import org.onap.cps.spi.model.Anchor
@@ -61,7 +60,7 @@ class CpsDataUpdateEventFactorySpec extends Specification {
             with(cpsDataUpdatedEvent) {
                 type == 'org.onap.cps.data-updated-event'
                 source == new URI('urn:cps:org.onap.cps')
-                schema == CpsDataUpdatedEvent.Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT
+                schema == new URI('urn:cps:org.onap.cps:data-updated-event-schema:v1')
                 StringUtils.hasText(id)
                 content != null
             }