From 8db6414556299a32343805942fc0233efd6dc6e6 Mon Sep 17 00:00:00 2001 From: Bruno Sakoto Date: Fri, 20 Aug 2021 18:59:14 -0400 Subject: Prepare for next event schema version Issue-ID: CPS-584, CPS-459 Signed-off-by: Bruno Sakoto Change-Id: Iaf605492783f8c06f40522a427ce63bd2d1b34d0 --- cps-application/src/main/resources/application.yml | 2 +- .../main/resources/schemas/cps-data-updated-event-schema.json | 11 +++++------ .../groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy | 11 +++++------ cps-events/src/test/resources/bookstore-chapters.json | 6 +++--- .../org/onap/cps/notification/CpsDataUpdatedEventFactory.java | 9 +++++---- .../cps/notification/CpsDataUpdateEventFactorySpec.groovy | 3 +-- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cps-application/src/main/resources/application.yml b/cps-application/src/main/resources/application.yml index e185bf23f..bafe7f4f3 100644 --- a/cps-application/src/main/resources/application.yml +++ b/cps-application/src/main/resources/application.yml @@ -71,7 +71,7 @@ spring: notification: data-updated: enabled: false - topic: ${CPS_CHANGE_EVENT_TOPIC:cps.cfg-state-events} + topic: ${CPS_CHANGE_EVENT_TOPIC:cps.data-updated-events} filters: enabled-dataspaces: ${DATASPACE_FILTER_PATTERNS:""} diff --git a/cps-events/src/main/resources/schemas/cps-data-updated-event-schema.json b/cps-events/src/main/resources/schemas/cps-data-updated-event-schema.json index de445ec72..c2fa5f287 100644 --- a/cps-events/src/main/resources/schemas/cps-data-updated-event-schema.json +++ b/cps-events/src/main/resources/schemas/cps-data-updated-event-schema.json @@ -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", @@ -12,10 +12,9 @@ "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 +} diff --git a/cps-events/src/test/groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy b/cps-events/src/test/groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy index f72eceed1..545b18337 100644 --- a/cps-events/src/test/groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy +++ b/cps-events/src/test/groovy/org/onap/cps/event/CpsDataUpdatedEventSpec.groovy @@ -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 +} diff --git a/cps-events/src/test/resources/bookstore-chapters.json b/cps-events/src/test/resources/bookstore-chapters.json index de46b7184..753426a60 100644 --- a/cps-events/src/test/resources/bookstore-chapters.json +++ b/cps-events/src/test/resources/bookstore-chapters.json @@ -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 +} diff --git a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java index e1473d3ff..26b89fcd5 100644 --- a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java +++ b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java @@ -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; diff --git a/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy b/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy index aecc3f7ee..2ce77bd1a 100644 --- a/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy @@ -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 } -- cgit 1.2.3-korg