From 0c046eb5427bbaf12473935cf7168bceb0ba9b78 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Mon, 26 Jan 2026 11:34:54 +0000 Subject: [PATCH] Attempt 2. Introduce V2 for LCM events - Refactored schema for Legacy LCM Event (now V1) - Added schema for CM event V2 - Refactored schemas to re-use common parts - Refactoring Lcm Event production to simplify and support multiple versions - TODO in separate commit: Add feature toggle to activate V2 (not by default) - TODO BEFORE MERGE Compare output of legacy event with refactored V1 version -> should be identical Change-Id: I0ca14e54c87eb8bfd29cfc391c65c9359acebc46 Signed-off-by: ToineSiebelink --- .../main/resources/schemas/lcm/lcm-event-base.json | 48 +++++++++ .../resources/schemas/lcm/lcm-event-schema-v1.json | 119 --------------------- .../main/resources/schemas/lcm/lcm-event-v1.json | 77 +++++++++++++ .../main/resources/schemas/lcm/lcm-event-v2.json | 48 +++++++++ .../sync/lcm/CmHandlePropertyChangeDetector.java | 4 +- .../sync/lcm/CmHandlePropertyUpdates.java | 4 +- .../inventory/sync/lcm/LcmEventObjectCreator.java | 52 ++++----- .../impl/inventory/sync/lcm/LcmEventProducer.java | 39 +++---- .../impl/inventory/sync/lcm/LcmEventVersion.java | 26 +++++ .../inventory/sync/lcm/EventProducerSpec.groovy | 16 +-- .../sync/lcm/LcmEventObjectCreatorSpec.groovy | 18 ++-- .../inventory/sync/lcm/LcmEventProducerSpec.groovy | 2 +- .../inventory/sync/lcm/LcmEventVersionSpec.groovy | 37 +++++++ cps-parent/pom.xml | 2 +- .../java/org/onap/cps/events/EventProducer.java | 3 +- .../ncmp/inventory/CmHandleCreateSpec.groovy | 7 +- .../ncmp/inventory/CmHandleUpdateSpec.groovy | 6 +- 17 files changed, 313 insertions(+), 195 deletions(-) create mode 100644 cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-base.json delete mode 100644 cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-schema-v1.json create mode 100644 cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v1.json create mode 100644 cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v2.json create mode 100644 cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersion.java create mode 100644 cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersionSpec.groovy diff --git a/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-base.json b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-base.json new file mode 100644 index 0000000000..404111288f --- /dev/null +++ b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-base.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:cps:org.onap.ncmp.cmhandle.lcm-event.base", + "description": "The base (header fields) for LCM events", + "type": "object", + "javaType" : "org.onap.cps.ncmp.events.lcm.LcmEventBase", + "javaInterfaces" : ["org.onap.cps.events.LegacyEvent"], + "properties": { + "eventId": { + "description": "The unique id identifying the event", + "type": "string" + }, + "eventCorrelationId": { + "description": "The id identifying the event", + "type": "string" + }, + "eventTime": { + "description": "The timestamp when original event occurred", + "type": "string" + }, + "eventSource": { + "description": "The source of the event", + "type": "string" + }, + "eventType": { + "description": "The type of the event", + "type": "string" + }, + "eventSchema": { + "description": "The schema that this event adheres to", + "type": "string" + }, + "eventSchemaVersion": { + "description": "The version of the schema that this event adheres to", + "type": "string" + } + }, + "required": [ + "eventId", + "eventCorrelationId", + "eventTime", + "eventSource", + "eventType", + "eventSchema", + "eventSchemaVersion" + ], + "additionalProperties": false +} diff --git a/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-schema-v1.json b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-schema-v1.json deleted file mode 100644 index c79af2e49d..0000000000 --- a/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-schema-v1.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "urn:cps:org.onap.ncmp.cmhandle.lcm-event:v1", - - "$ref": "#/definitions/LcmEvent", - - "definitions": { - - "Values": { - "description": "Values that represents the state of a cmHandle", - "type": "object", - "properties": { - "dataSyncEnabled":{ - "description": "Whether data sync enabled", - "type": "boolean" - }, - "cmHandleState": { - "description": "State of cmHandle", - "type": "string", - "enum": ["ADVISED", "READY", "LOCKED", "DELETING", "DELETED"] - }, - "cmHandleProperties": { - "description": "cmHandle properties", - "type": "object", - "default": null, - "existingJavaType": "java.util.List>", - "additionalProperties": false - } - }, - "additionalProperties": false - }, - - "Event": { - "description": "The Payload of an event", - "type": "object", - "properties": { - "cmHandleId": { - "description": "cmHandle id", - "type": "string" - }, - "alternateId": { - "description": "alternative id for cmHandle (e.g. 3GPP FDN)", - "type": "string" - }, - "moduleSetTag": { - "description": "module set tag for cmHandle", - "type": "string" - }, - "dataProducerIdentifier": { - "description": "data producer identifier for cmHandle", - "type": "string" - }, - "oldValues": { - "$ref": "#/definitions/Values" - }, - "newValues": { - "$ref": "#/definitions/Values" - } - }, - "required": [ - "cmHandleId" - ], - "additionalProperties": false - }, - - "LcmEvent": { - "description": "The payload for LCM event", - "type": "object", - "javaType" : "org.onap.cps.ncmp.events.lcm.v1.LcmEvent", - "javaInterfaces" : ["org.onap.cps.events.LegacyEvent"], - "properties": { - "eventId": { - "description": "The unique id identifying the event", - "type": "string" - }, - "eventCorrelationId": { - "description": "The id identifying the event", - "type": "string" - }, - "eventTime": { - "description": "The timestamp when original event occurred", - "type": "string" - }, - "eventSource": { - "description": "The source of the event", - "type": "string" - }, - "eventType": { - "description": "The type of the event", - "type": "string" - }, - "eventSchema": { - "description": "The schema that this event adheres to", - "type": "string" - }, - "eventSchemaVersion": { - "description": "The version of the schema that this event adheres to", - "type": "string" - }, - "event": { - "$ref": "#/definitions/Event" - } - }, - "required": [ - "eventId", - "eventCorrelationId", - "eventTime", - "eventSource", - "eventType", - "eventSchema", - "eventSchemaVersion", - "event" - ], - "additionalProperties": false - } - - } -} diff --git a/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v1.json b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v1.json new file mode 100644 index 0000000000..3404c638b5 --- /dev/null +++ b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v1.json @@ -0,0 +1,77 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:cps:org.onap.ncmp.cmhandle.lcm-event.v1", + "javaType": "org.onap.cps.ncmp.events.lcm.LcmEventV1", + "extends": { + "$ref": "lcm-event-base.json" + }, + "type": "object", + "properties": { + "event": { + "$ref": "#/$defs/PayloadV1" + } + }, + "required": ["event"], + "$defs": { + "PayloadV1": { + "description": "The Payload of an event", + "type": "object", + "properties": { + "cmHandleId": { + "description": "cmHandle id", + "type": "string" + }, + "alternateId": { + "description": "alternative id for cmHandle (e.g. 3GPP FDN)", + "type": "string" + }, + "moduleSetTag": { + "description": "module set tag for cmHandle", + "type": "string" + }, + "dataProducerIdentifier": { + "description": "data producer identifier for cmHandle", + "type": "string" + }, + "oldValues": { + "$ref": "#/$defs/Values" + }, + "newValues": { + "$ref": "#/$defs/Values" + } + }, + "required": ["cmHandleId"], + "additionalProperties": false + }, + "Values": { + "description": "Values that represents the state and properties of a cmHandle", + "javaType": "org.onap.cps.ncmp.events.lcm.Values", + "type": "object", + "properties": { + "dataSyncEnabled": { + "description": "Whether data sync enabled", + "type": "boolean" + }, + "cmHandleState": { + "description": "State of cmHandle", + "type": "string", + "enum": [ + "ADVISED", + "READY", + "LOCKED", + "DELETING", + "DELETED" + ] + }, + "cmHandleProperties": { + "description": "cmHandle properties", + "type": "object", + "default": null, + "existingJavaType": "java.util.List>", + "additionalProperties": false + } + }, + "additionalProperties": false + } + } +} diff --git a/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v2.json b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v2.json new file mode 100644 index 0000000000..9ebf453ac1 --- /dev/null +++ b/cps-ncmp-events/src/main/resources/schemas/lcm/lcm-event-v2.json @@ -0,0 +1,48 @@ +{ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:cps:org.onap.ncmp.cmhandle.lcm-event.v2", + "javaType": "org.onap.cps.ncmp.events.lcm.LcmEventV2", + "extends": { + "$ref": "lcm-event-base.json" + }, + "type": "object", + "properties": { + "event": { + "$ref": "#/$defs/PayloadV2" + } + }, + "required": ["event"], + "$defs": { + "PayloadV2": { + "description": "The Payload of an event V2", + "javaType": "org.onap.cps.ncmp.events.lcm.PayloadV2", + "type": "object", + "properties": { + "cmHandleId": { + "description": "cmHandle id", + "type": "string" + }, + "oldProperties": { + "description": "the old cmHandle properties(values) that have changed or been deleted", + "type": "object", + "default": null, + "existingJavaType": "java.util.Map", + "additionalProperties": false + }, + "newProperties": { + "description": "cmHandle properties(values) that have been changed or been created", + "type": "object", + "default": null, + "existingJavaType": "java.util.Map", + "additionalProperties": false + } + }, + "required": ["cmHandleId"], + "additionalProperties": false + } + } + + + + +} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyChangeDetector.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyChangeDetector.java index e3cf1fb24d..cba35e0ba9 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyChangeDetector.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyChangeDetector.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.events.lcm.v1.Values; +import org.onap.cps.ncmp.events.lcm.Values; /** * Utility class for examining and determining changes in CM handle properties. diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyUpdates.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyUpdates.java index 87c1b8f8e3..7a956d1963 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyUpdates.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/CmHandlePropertyUpdates.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2025-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ package org.onap.cps.ncmp.impl.inventory.sync.lcm; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.onap.cps.ncmp.events.lcm.v1.Values; +import org.onap.cps.ncmp.events.lcm.Values; @NoArgsConstructor @Getter diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java index 5c7b6fdf22..85cc286019 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreator.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,9 @@ import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.events.lcm.v1.Event; -import org.onap.cps.ncmp.events.lcm.v1.LcmEvent; +import org.onap.cps.ncmp.events.lcm.LcmEventBase; +import org.onap.cps.ncmp.events.lcm.LcmEventV1; +import org.onap.cps.ncmp.events.lcm.PayloadV1; import org.onap.cps.ncmp.impl.utils.EventDateTimeFormatter; import org.springframework.stereotype.Service; @@ -50,23 +51,24 @@ public class LcmEventObjectCreator { * @param targetNcmpServiceCmHandle target ncmp service cmhandle * @return Populated LcmEvent */ - public LcmEvent createLcmEvent(final NcmpServiceCmHandle currentNcmpServiceCmHandle, - final NcmpServiceCmHandle targetNcmpServiceCmHandle) { + public LcmEventV1 createLcmEventV1(final NcmpServiceCmHandle currentNcmpServiceCmHandle, + final NcmpServiceCmHandle targetNcmpServiceCmHandle) { final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId(); final LcmEventType lcmEventType = determineEventType(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle); - final LcmEvent lcmEvent = createLcmEventWithHeaderDetails(cmHandleId, lcmEventType); - final Event event = new Event(); - event.setCmHandleId(cmHandleId); - event.setAlternateId(targetNcmpServiceCmHandle.getAlternateId()); - event.setModuleSetTag(targetNcmpServiceCmHandle.getModuleSetTag()); - event.setDataProducerIdentifier(targetNcmpServiceCmHandle.getDataProducerIdentifier()); + final LcmEventV1 lcmEventV1 = new LcmEventV1(); + populateHeaderDetails(lcmEventV1, cmHandleId, lcmEventType); + final PayloadV1 payloadV1 = new PayloadV1(); + payloadV1.setCmHandleId(cmHandleId); + payloadV1.setAlternateId(targetNcmpServiceCmHandle.getAlternateId()); + payloadV1.setModuleSetTag(targetNcmpServiceCmHandle.getModuleSetTag()); + payloadV1.setDataProducerIdentifier(targetNcmpServiceCmHandle.getDataProducerIdentifier()); final CmHandlePropertyUpdates cmHandlePropertyUpdates = determineEventValues(lcmEventType, currentNcmpServiceCmHandle, targetNcmpServiceCmHandle); - event.setOldValues(cmHandlePropertyUpdates.getOldValues()); - event.setNewValues(cmHandlePropertyUpdates.getNewValues()); - lcmEvent.setEvent(event); - return lcmEvent; + payloadV1.setOldValues(cmHandlePropertyUpdates.getOldValues()); + payloadV1.setNewValues(cmHandlePropertyUpdates.getNewValues()); + lcmEventV1.setEvent(payloadV1); + return lcmEventV1; } private static LcmEventType determineEventType(final NcmpServiceCmHandle currentNcmpServiceCmHandle, @@ -93,16 +95,16 @@ public class LcmEventObjectCreator { return new CmHandlePropertyUpdates(); } - private LcmEvent createLcmEventWithHeaderDetails(final String eventCorrelationId, final LcmEventType lcmEventType) { - final LcmEvent lcmEvent = new LcmEvent(); - lcmEvent.setEventId(UUID.randomUUID().toString()); - lcmEvent.setEventCorrelationId(eventCorrelationId); - lcmEvent.setEventTime(EventDateTimeFormatter.getCurrentIsoFormattedDateTime()); - lcmEvent.setEventSource("org.onap.ncmp"); - lcmEvent.setEventType(lcmEventType.getEventType()); - lcmEvent.setEventSchema("org.onap.ncmp:cmhandle-lcm-event"); - lcmEvent.setEventSchemaVersion("1.0"); - return lcmEvent; + private void populateHeaderDetails(final LcmEventBase lcmEventBase, + final String eventCorrelationId, + final LcmEventType lcmEventType) { + lcmEventBase.setEventId(UUID.randomUUID().toString()); + lcmEventBase.setEventCorrelationId(eventCorrelationId); + lcmEventBase.setEventTime(EventDateTimeFormatter.getCurrentIsoFormattedDateTime()); + lcmEventBase.setEventSource("org.onap.ncmp"); + lcmEventBase.setEventType(lcmEventType.getEventType()); + lcmEventBase.setEventSchema("org.onap.ncmp:cmhandle-lcm-event"); + lcmEventBase.setEventSchemaVersion("1.0"); } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducer.java index 37ba176cc2..c0f7370748 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2023-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.events.EventProducer; import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle; -import org.onap.cps.ncmp.events.lcm.v1.LcmEvent; -import org.onap.cps.ncmp.events.lcm.v1.Values; +import org.onap.cps.ncmp.events.lcm.LcmEventBase; +import org.onap.cps.ncmp.events.lcm.LcmEventV1; +import org.onap.cps.ncmp.events.lcm.Values; import org.onap.cps.ncmp.impl.utils.YangDataConverter; import org.springframework.beans.factory.annotation.Value; import org.springframework.kafka.KafkaException; @@ -92,14 +93,14 @@ public class LcmEventProducer { private void sendLcmEvent(final NcmpServiceCmHandle currentNcmpServiceCmHandle, final NcmpServiceCmHandle targetNcmpServiceCmHandle) { if (notificationsEnabled) { - final LcmEvent lcmEvent = lcmEventObjectCreator.createLcmEvent(currentNcmpServiceCmHandle, - targetNcmpServiceCmHandle); + final LcmEventV1 lcmEventV1 = lcmEventObjectCreator.createLcmEventV1(currentNcmpServiceCmHandle, + targetNcmpServiceCmHandle); final Timer.Sample timerSample = Timer.start(meterRegistry); try { - final Map headersAsMap = extractHeadersAsMap(lcmEvent); + final Map headersAsMap = extractHeadersAsMap(lcmEventV1); final String eventKey = currentNcmpServiceCmHandle.getCmHandleId(); - eventProducer.sendLegacyEvent(topicName, eventKey, headersAsMap, lcmEvent); - recordMetrics(lcmEvent, timerSample); + eventProducer.sendLegacyEvent(topicName, eventKey, headersAsMap, lcmEventV1); + recordMetrics(lcmEventV1, timerSample); } catch (final KafkaException e) { log.error("Unable to send message to topic : {} and cause : {}", topicName, e.getMessage()); } @@ -108,24 +109,24 @@ public class LcmEventProducer { } } - private Map extractHeadersAsMap(final LcmEvent lcmEvent) { + private Map extractHeadersAsMap(final LcmEventBase lcmEventBase) { final Map headersAsMap = new HashMap<>(7); - headersAsMap.put("eventId", lcmEvent.getEventId()); - headersAsMap.put("eventCorrelationId", lcmEvent.getEventCorrelationId()); - headersAsMap.put("eventTime", lcmEvent.getEventTime()); - headersAsMap.put("eventSource", lcmEvent.getEventSource()); - headersAsMap.put("eventType", lcmEvent.getEventType()); - headersAsMap.put("eventSchema", lcmEvent.getEventSchema()); - headersAsMap.put("eventSchemaVersion", lcmEvent.getEventSchemaVersion()); + headersAsMap.put("eventId", lcmEventBase.getEventId()); + headersAsMap.put("eventCorrelationId", lcmEventBase.getEventCorrelationId()); + headersAsMap.put("eventTime", lcmEventBase.getEventTime()); + headersAsMap.put("eventSource", lcmEventBase.getEventSource()); + headersAsMap.put("eventType", lcmEventBase.getEventType()); + headersAsMap.put("eventSchema", lcmEventBase.getEventSchema()); + headersAsMap.put("eventSchemaVersion", lcmEventBase.getEventSchemaVersion()); return headersAsMap; } - private void recordMetrics(final LcmEvent lcmEvent, final Timer.Sample timerSample) { + private void recordMetrics(final LcmEventV1 lcmEventV1, final Timer.Sample timerSample) { final List tags = new ArrayList<>(4); tags.add(METRIC_TAG_CLASS); tags.add(METRIC_TAG_METHOD); - tags.add(createCmHandleStateTag("oldCmHandleState", lcmEvent.getEvent().getOldValues())); - tags.add(createCmHandleStateTag("newCmHandleState", lcmEvent.getEvent().getNewValues())); + tags.add(createCmHandleStateTag("oldCmHandleState", lcmEventV1.getEvent().getOldValues())); + tags.add(createCmHandleStateTag("newCmHandleState", lcmEventV1.getEvent().getNewValues())); timerSample.stop(Timer.builder("cps.ncmp.lcm.events.send") .description("Time taken to send a LCM event") .tags(tags) diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersion.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersion.java new file mode 100644 index 0000000000..ab2f22bbe1 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersion.java @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2026 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.impl.inventory.sync.lcm; + +public enum LcmEventVersion { + V1, + V2 +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/EventProducerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/EventProducerSpec.groovy index 3845f69302..0e3db64f69 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/EventProducerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/EventProducerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import org.apache.kafka.clients.consumer.KafkaConsumer import org.apache.kafka.common.serialization.StringDeserializer import org.onap.cps.events.EventProducer import org.onap.cps.events.LegacyEvent -import org.onap.cps.ncmp.events.lcm.v1.Event -import org.onap.cps.ncmp.events.lcm.v1.LcmEvent +import org.onap.cps.ncmp.events.lcm.LcmEventV1 +import org.onap.cps.ncmp.events.lcm.PayloadV1 import org.onap.cps.ncmp.utils.TestUtils import org.onap.cps.ncmp.utils.events.MessagingBaseSpec import org.onap.cps.utils.JsonObjectMapper @@ -64,7 +64,7 @@ class EventProducerSpec extends MessagingBaseSpec { def eventType = 'org.onap.ncmp.cmhandle.lcm.event' def eventSchema = 'org.onap.ncmp.cmhandle.lcm.event' def eventSchemaVersion = 'v1' - def eventData = new LcmEvent( + def lcmEventV1 = new LcmEventV1( eventId: eventId, eventCorrelationId: eventCorrelationId, eventSource: eventSource, @@ -72,7 +72,7 @@ class EventProducerSpec extends MessagingBaseSpec { eventType: eventType, eventSchema: eventSchema, eventSchemaVersion: eventSchemaVersion, - event: new Event(cmHandleId: 'cmhandle-test')) + event: new PayloadV1(cmHandleId: 'cmhandle-test')) and: 'we have a event header' def eventHeader = [ eventId : eventId, @@ -85,7 +85,7 @@ class EventProducerSpec extends MessagingBaseSpec { and: 'consumer has a subscription' legacyEventKafkaConsumer.subscribe([testTopic] as List) when: 'an event is sent' - eventProducer.sendLegacyEvent(testTopic, eventKey, eventHeader, eventData) + eventProducer.sendLegacyEvent(testTopic, eventKey, eventHeader, lcmEventV1) and: 'topic is polled' def records = legacyEventKafkaConsumer.poll(Duration.ofMillis(1500)) then: 'poll returns one record' @@ -94,8 +94,8 @@ class EventProducerSpec extends MessagingBaseSpec { assert eventKey == records[0].key and: 'record matches the expected event' def expectedJsonString = TestUtils.getResourceFileContent('expectedLcmEvent.json') - def expectedLcmEvent = jsonObjectMapper.convertJsonString(expectedJsonString, LcmEvent.class) - assert expectedLcmEvent == jsonObjectMapper.convertJsonString(records[0].value, LcmEvent.class) + def expectedLcmEvent = jsonObjectMapper.convertJsonString(expectedJsonString, LcmEventV1.class) + assert expectedLcmEvent == jsonObjectMapper.convertJsonString(records[0].value, LcmEventV1.class) and: 'record header matches the expected parameters' assert SerializationUtils.deserialize(records[0].headers().lastHeader('eventId').value()) == eventId assert SerializationUtils.deserialize(records[0].headers().lastHeader('eventCorrelationId').value()) == eventCorrelationId diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreatorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreatorSpec.groovy index e3a9edfea6..381b731602 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreatorSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventObjectCreatorSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2024 Nordix Foundation + * Copyright (C) 2022-2026 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ package org.onap.cps.ncmp.impl.inventory.sync.lcm import org.onap.cps.ncmp.api.inventory.models.CmHandleState import org.onap.cps.ncmp.api.inventory.models.CompositeState import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.events.lcm.v1.Values +import org.onap.cps.ncmp.events.lcm.Values import spock.lang.Specification import static org.onap.cps.ncmp.api.inventory.models.CmHandleState.ADVISED @@ -40,7 +40,7 @@ class LcmEventObjectCreatorSpec extends Specification { def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: currentCmHandleState), publicProperties: currentPublicProperties) def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: targetCmHandleState), publicProperties: targetPublicProperties) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId @@ -68,7 +68,7 @@ class LcmEventObjectCreatorSpec extends Specification { def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: READY), publicProperties: publicProperties) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'Properties are just the one which are same' assert result.event.oldValues == null assert result.event.newValues == null @@ -80,7 +80,7 @@ class LcmEventObjectCreatorSpec extends Specification { publicProperties: ['publicProperty1': 'value11', 'publicProperty2': 'value22']) def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value2']) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmhandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmhandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId @@ -101,7 +101,7 @@ class LcmEventObjectCreatorSpec extends Specification { def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: DELETING), publicProperties: ['publicProperty1': 'value1']) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId @@ -117,7 +117,7 @@ class LcmEventObjectCreatorSpec extends Specification { def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: currentDataSyncEnableFlag, cmHandleState: ADVISED)) def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: targetDataSyncEnableFlag, cmHandleState: READY)) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId @@ -145,7 +145,7 @@ class LcmEventObjectCreatorSpec extends Specification { def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: currentDataSyncEnableFlag, cmHandleState: ADVISED)) def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: targetDataSyncEnableFlag, cmHandleState: READY)) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'the data sync flag is not present in the event' assert result.event.oldValues.dataSyncEnabled == null assert result.event.newValues.dataSyncEnabled == null @@ -161,7 +161,7 @@ class LcmEventObjectCreatorSpec extends Specification { def currentNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: currentAlternateId, moduleSetTag: currentModuleSetTag, dataProducerIdentifier: currentDataProducerIdentifier, compositeState: new CompositeState(dataSyncEnabled: false)) def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: targetAlternateId, moduleSetTag: targetModuleSetTag, dataProducerIdentifier: targetDataProducerIdentifier, compositeState: new CompositeState(dataSyncEnabled: false)) when: 'the lcm event is created' - def result = objectUnderTest.createLcmEvent(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) + def result = objectUnderTest.createLcmEventV1(currentNcmpServiceCmHandle, targetNcmpServiceCmHandle) then: 'the alternate ID, module set tag, and data producer identifier are present or are an empty string in the payload' assert result.event.alternateId == targetAlternateId assert result.event.moduleSetTag == targetModuleSetTag diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy index be65e4abfb..8332258b1e 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventProducerSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersionSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersionSpec.groovy new file mode 100644 index 0000000000..d53ed6cfe0 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventVersionSpec.groovy @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2026 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.impl.inventory.sync.lcm + +import spock.lang.Specification + +class LcmEventVersionSpec extends Specification { + + def 'Enum values.'() { + expect: 'enum has expected values' + assert LcmEventVersion.values() == [LcmEventVersion.V1, LcmEventVersion.V2] as LcmEventVersion[] + } + + def 'Enum valueOf.'() { + expect: 'valueOf returns correct enum constant' + assert LcmEventVersion.valueOf('V1') == LcmEventVersion.V1 + assert LcmEventVersion.valueOf('V2') == LcmEventVersion.V2 + } +} diff --git a/cps-parent/pom.xml b/cps-parent/pom.xml index 085712efa1..829d38c756 100644 --- a/cps-parent/pom.xml +++ b/cps-parent/pom.xml @@ -47,7 +47,7 @@ 4.0.1 0.8.14 17 - 1.2.1 + 1.2.2 3.3.1 3.13.0 17 diff --git a/cps-service/src/main/java/org/onap/cps/events/EventProducer.java b/cps-service/src/main/java/org/onap/cps/events/EventProducer.java index 8369d756e4..170488dcdd 100644 --- a/cps-service/src/main/java/org/onap/cps/events/EventProducer.java +++ b/cps-service/src/main/java/org/onap/cps/events/EventProducer.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2022-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,7 +102,6 @@ public class EventProducer { handleLegacyEventCallback(topicName, eventFuture); } - private void handleLegacyEventCallback(final String topicName, final CompletableFuture> eventFuture) { eventFuture.whenComplete((result, e) -> logOutcome(topicName, result, e)); diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy index 3bb87b2a62..15f3a487b4 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleCreateSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2024-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ package org.onap.cps.integration.functional.ncmp.inventory - import org.apache.kafka.clients.consumer.KafkaConsumer import org.onap.cps.events.LegacyEvent import org.onap.cps.integration.KafkaTestContainer @@ -31,7 +30,7 @@ import org.onap.cps.ncmp.api.inventory.models.CmHandleState import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.LockReasonCategory import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.events.lcm.v1.LcmEvent +import org.onap.cps.ncmp.events.lcm.LcmEventV1 import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import spock.util.concurrent.PollingConditions @@ -82,7 +81,7 @@ class CmHandleCreateSpec extends CpsIntegrationSpecBase { def messages = [] def headerMaps = [] consumerRecords.each { consumerRecord -> - messages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEvent)) + messages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEventV1)) headerMaps.add(getHeadersAsMap(consumerRecord)) } and: 'both messages have the correct common attributes (that did not change)' diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy index d497af7470..ae302e8df3 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/inventory/CmHandleUpdateSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved. + * Copyright (C) 2024-2026 OpenInfra Foundation Europe. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.onap.cps.ncmp.api.NcmpResponseStatus import org.onap.cps.ncmp.api.inventory.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle -import org.onap.cps.ncmp.events.lcm.v1.LcmEvent +import org.onap.cps.ncmp.events.lcm.LcmEventV1 import org.onap.cps.ncmp.impl.NetworkCmProxyInventoryFacadeImpl import java.time.Duration @@ -117,7 +117,7 @@ class CmHandleUpdateSpec extends CpsIntegrationSpecBase { and: 'the message has the updated data producer identifier' def notificationMessages = [] for (def consumerRecord : consumerRecords) { - notificationMessages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEvent)) + notificationMessages.add(jsonObjectMapper.convertJsonString(consumerRecord.value().toString(), LcmEventV1)) } assert notificationMessages[0].event.cmHandleId.contains(cmHandleId) assert notificationMessages[0].event.dataProducerIdentifier == 'my-data-producer-id' -- 2.16.6