Refactoring to combine LcmEventsCreator and LcmEventsCreatorHelper 58/140658/2
authoremaclee <lee.anjella.macabuhay@est.tech>
Mon, 7 Apr 2025 12:44:28 +0000 (13:44 +0100)
committeremaclee <lee.anjella.macabuhay@est.tech>
Thu, 10 Apr 2025 10:27:05 +0000 (11:27 +0100)
- 1. Move all in LcmEventsCreatorHelper to LcmEventsCreator
- 2. Rename LcmEventsCreator to LcmEventsProducerHelper
- 3. Rename and update relevant tests
- 4. Refactor words 'publisher' to 'producer' and 'publish' to 'send' where applicable

Issue-ID: CPS-2726
Change-Id: Id0d53f851d25823e0456e95917c2be8856a20c40
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCmHandleStateHandler.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCmHandleStateHandlerAsyncHelper.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCmHandleStateHandlerImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCreator.java [deleted file]
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsProducer.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsProducerHelper.java [moved from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCreatorHelper.java with 59% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsProducerHelperSpec.groovy [moved from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCreatorSpec.groovy with 99% similarity]
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsProducerSpec.groovy
cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsProducer.java
docs/cm-handle-lcm-events.rst

index 69409bb..1395784 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
+ * Copyright (C) 2022-2025 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.
@@ -26,7 +26,7 @@ import org.onap.cps.ncmp.api.inventory.models.CmHandleState;
 import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
 
 /**
- * The implementation of it should handle the persisting of composite state and delegate the request to publish the
+ * The implementation of it should handle the persisting of composite state and delegate the request to send the
  * corresponding lcm event.
  */
 public interface LcmEventsCmHandleStateHandler {
index 9d5bc15..6717f8f 100644 (file)
@@ -35,30 +35,31 @@ import org.springframework.stereotype.Service;
 @RequiredArgsConstructor
 public class LcmEventsCmHandleStateHandlerAsyncHelper {
 
-    private final LcmEventsCreator lcmEventsCreator;
+    private final LcmEventsProducerHelper lcmEventsProducerHelper;
     private final LcmEventsProducer lcmEventsProducer;
 
     /**
-     * Publish LcmEvent in batches and in asynchronous manner.
+     * Send LcmEvent in batches and in asynchronous manner.
      *
      * @param cmHandleTransitionPairs Pair of existing and modified cm handle represented as YangModelCmHandle
      */
     @Async("notificationExecutor")
-    public void publishLcmEventBatchAsynchronously(final Collection<CmHandleTransitionPair> cmHandleTransitionPairs) {
-        cmHandleTransitionPairs.forEach(cmHandleTransitionPair -> publishLcmEvent(
+    public void sendLcmEventBatchAsynchronously(final Collection<CmHandleTransitionPair> cmHandleTransitionPairs) {
+        cmHandleTransitionPairs.forEach(cmHandleTransitionPair -> sendLcmEvent(
                 toNcmpServiceCmHandle(cmHandleTransitionPair.getTargetYangModelCmHandle()),
                 toNcmpServiceCmHandle(cmHandleTransitionPair.getCurrentYangModelCmHandle())));
     }
 
-    private void publishLcmEvent(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-                                 final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+    private void sendLcmEvent(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+                              final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
         final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId();
         final LcmEventHeader lcmEventHeader =
-                lcmEventsCreator.populateLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle,
+                lcmEventsProducerHelper.populateLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle,
                         existingNcmpServiceCmHandle);
         final LcmEvent lcmEvent =
-                lcmEventsCreator.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
-        lcmEventsProducer.publishLcmEvent(cmHandleId, lcmEvent, lcmEventHeader);
+                lcmEventsProducerHelper.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle,
+                        existingNcmpServiceCmHandle);
+        lcmEventsProducer.sendLcmEvent(cmHandleId, lcmEvent, lcmEventHeader);
     }
 
     private static NcmpServiceCmHandle toNcmpServiceCmHandle(final YangModelCmHandle yangModelCmHandle) {
index 5ca1988..5bbc3a0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2025 Nordix Foundation
+ * Copyright (C) 2022-2025 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.
@@ -60,7 +60,7 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState
         final Collection<CmHandleTransitionPair> cmHandleTransitionPairs =
                 prepareCmHandleTransitionBatch(cmHandleStatePerCmHandle);
         persistCmHandleBatch(cmHandleTransitionPairs);
-        lcmEventsCmHandleStateHandlerAsyncHelper.publishLcmEventBatchAsynchronously(cmHandleTransitionPairs);
+        lcmEventsCmHandleStateHandlerAsyncHelper.sendLcmEventBatchAsynchronously(cmHandleTransitionPairs);
         cmHandleStateMonitor.updateCmHandleStateMetrics(cmHandleTransitionPairs);
     }
 
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/sync/lcm/LcmEventsCreator.java
deleted file mode 100644 (file)
index 5137515..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2024 Nordix Foundation
- * ================================================================================
- * 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 java.util.UUID;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-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.v1.LcmEventHeader;
-import org.onap.cps.ncmp.events.lcm.v1.Values;
-import org.onap.cps.ncmp.impl.utils.EventDateTimeFormatter;
-import org.springframework.stereotype.Component;
-
-
-/**
- * LcmEventsCreator to create LcmEvent based on relevant operation.
- */
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class LcmEventsCreator {
-
-    private final LcmEventHeaderMapper lcmEventHeaderMapper;
-
-    /**
-     * Populate Lifecycle Management Event.
-     *
-     * @param cmHandleId                  cm handle identifier
-     * @param targetNcmpServiceCmHandle   target ncmp service cmhandle
-     * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
-     * @return Populated LcmEvent
-     */
-    public LcmEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-        return createLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
-    }
-
-    /**
-     * Populate Lifecycle Management Event Header.
-     *
-     * @param cmHandleId                  cm handle identifier
-     * @param targetNcmpServiceCmHandle   target ncmp service cmhandle
-     * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
-     * @return Populated LcmEventHeader
-     */
-    public LcmEventHeader populateLcmEventHeader(final String cmHandleId,
-            final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-        return createLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
-    }
-
-    private LcmEvent createLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-        final LcmEventType lcmEventType =
-                LcmEventsCreatorHelper.determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
-        final LcmEvent lcmEvent = lcmEventHeader(cmHandleId, lcmEventType);
-        lcmEvent.setEvent(
-                lcmEventPayload(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, lcmEventType));
-        return lcmEvent;
-    }
-
-    private LcmEventHeader createLcmEventHeader(final String cmHandleId,
-            final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-        final LcmEventType lcmEventType =
-                LcmEventsCreatorHelper.determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
-        final LcmEvent lcmEventWithHeaderInformation = lcmEventHeader(cmHandleId, lcmEventType);
-        return lcmEventHeaderMapper.toLcmEventHeader(lcmEventWithHeaderInformation);
-    }
-
-    private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle, final LcmEventType lcmEventType) {
-        final Event event = new Event();
-        event.setCmHandleId(eventCorrelationId);
-        event.setAlternateId(targetNcmpServiceCmHandle.getAlternateId());
-        event.setModuleSetTag(targetNcmpServiceCmHandle.getModuleSetTag());
-        event.setDataProducerIdentifier(targetNcmpServiceCmHandle.getDataProducerIdentifier());
-        final CmHandleValuesHolder cmHandleValuesHolder =
-                LcmEventsCreatorHelper.determineEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle,
-                        lcmEventType);
-        event.setOldValues(cmHandleValuesHolder.getOldValues());
-        event.setNewValues(cmHandleValuesHolder.getNewValues());
-
-        return event;
-    }
-
-    private LcmEvent lcmEventHeader(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;
-    }
-
-    @NoArgsConstructor
-    @Getter
-    @Setter
-    static class CmHandleValuesHolder {
-
-        private Values oldValues;
-        private Values newValues;
-    }
-
-}
index 2ed407f..521da0c 100644 (file)
@@ -46,7 +46,7 @@ import org.springframework.stereotype.Service;
 @RequiredArgsConstructor
 public class LcmEventsProducer {
 
-    private static final Tag TAG_METHOD = Tag.of("method", "publishLcmEvent");
+    private static final Tag TAG_METHOD = Tag.of("method", "sendLcmEvent");
     private static final Tag TAG_CLASS = Tag.of("class", LcmEventsProducer.class.getName());
     private static final String UNAVAILABLE_CM_HANDLE_STATE = "N/A";
     private final EventsProducer<LcmEvent> eventsProducer;
@@ -60,14 +60,14 @@ public class LcmEventsProducer {
     private boolean notificationsEnabled;
 
     /**
-     * Publishes an LCM event to the dedicated topic with optional notification headers.
-     * Capture and log KafkaException If an error occurs while publishing the event to Kafka
+     * Sends an LCM event to the dedicated topic with optional notification headers.
+     * Capture and log KafkaException If an error occurs while sending the event to Kafka
      *
      * @param cmHandleId     Cm Handle Id associated with the LCM event
-     * @param lcmEvent       The LCM event object to be published
+     * @param lcmEvent       The LCM event object to be sent
      * @param lcmEventHeader Optional headers associated with the LCM event
      */
-    public void publishLcmEvent(final String cmHandleId, final LcmEvent lcmEvent, final LcmEventHeader lcmEventHeader) {
+    public void sendLcmEvent(final String cmHandleId, final LcmEvent lcmEvent, final LcmEventHeader lcmEventHeader) {
 
         if (notificationsEnabled) {
             final Timer.Sample timerSample = Timer.start(meterRegistry);
@@ -76,7 +76,7 @@ public class LcmEventsProducer {
                         jsonObjectMapper.convertToValueType(lcmEventHeader, Map.class);
                 eventsProducer.sendEvent(topicName, cmHandleId, lcmEventHeadersMap, lcmEvent);
             } catch (final KafkaException e) {
-                log.error("Unable to publish message to topic : {} and cause : {}", topicName, e.getMessage());
+                log.error("Unable to send message to topic : {} and cause : {}", topicName, e.getMessage());
             } finally {
                 recordMetrics(lcmEvent, timerSample);
             }
@@ -96,8 +96,8 @@ public class LcmEventsProducer {
         final String newCmHandleState = extractCmHandleStateValue(lcmEvent.getEvent().getNewValues());
         tags.add(Tag.of("newCmHandleState", newCmHandleState));
 
-        timerSample.stop(Timer.builder("cps.ncmp.lcm.events.publish")
-                .description("Time taken to publish a LCM event")
+        timerSample.stop(Timer.builder("cps.ncmp.lcm.events.send")
+                .description("Time taken to send a LCM event")
                 .tags(tags)
                 .register(meterRegistry));
     }
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
+ * Copyright (C) 2022-2025 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.
@@ -30,30 +30,78 @@ import com.google.common.collect.Maps;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import lombok.AccessLevel;
+import java.util.UUID;
+import lombok.Getter;
 import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
 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.v1.LcmEventHeader;
 import org.onap.cps.ncmp.events.lcm.v1.Values;
+import org.onap.cps.ncmp.impl.utils.EventDateTimeFormatter;
+import org.springframework.stereotype.Component;
 
 /**
- * LcmEventsCreatorHelper has helper methods to create LcmEvent.
- * Determine the lcm event type i.e create,update and delete.
- * Based on lcm event type create the LcmEvent payload.
+ * LcmEventsProducerHelper to create LcmEvent based on relevant operation.
  */
 @Slf4j
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class LcmEventsCreatorHelper {
+@Component
+@RequiredArgsConstructor
+public class LcmEventsProducerHelper {
+
+    private final LcmEventHeaderMapper lcmEventHeaderMapper;
+
+    /**
+     * Populate Lifecycle Management Event.
+     *
+     * @param cmHandleId                  cm handle identifier
+     * @param targetNcmpServiceCmHandle   target ncmp service cmhandle
+     * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
+     * @return Populated LcmEvent
+     */
+    public LcmEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+        return createLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
+    }
 
     /**
-     * Determining the event type based on the composite state.
+     * Populate Lifecycle Management Event Header.
      *
-     * @param targetNcmpServiceCmHandle   target ncmpServiceCmHandle
-     * @param existingNcmpServiceCmHandle existing ncmpServiceCmHandle
-     * @return Event Type
+     * @param cmHandleId                  cm handle identifier
+     * @param targetNcmpServiceCmHandle   target ncmp service cmhandle
+     * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
+     * @return Populated LcmEventHeader
      */
-    public static LcmEventType determineEventType(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+    public LcmEventHeader populateLcmEventHeader(final String cmHandleId,
+            final NcmpServiceCmHandle targetNcmpServiceCmHandle,
             final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+        return createLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
+    }
+
+    private LcmEvent createLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+        final LcmEventType lcmEventType =
+                determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
+        final LcmEvent lcmEvent = lcmEventHeader(cmHandleId, lcmEventType);
+        lcmEvent.setEvent(
+                lcmEventPayload(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, lcmEventType));
+        return lcmEvent;
+    }
+
+    private LcmEventHeader createLcmEventHeader(final String cmHandleId,
+            final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+        final LcmEventType lcmEventType =
+                determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
+        final LcmEvent lcmEventWithHeaderInformation = lcmEventHeader(cmHandleId, lcmEventType);
+        return lcmEventHeaderMapper.toLcmEventHeader(lcmEventWithHeaderInformation);
+    }
+
+    private static LcmEventType determineEventType(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+                                                   final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
 
         if (existingNcmpServiceCmHandle.getCompositeState() == null) {
             return CREATE;
@@ -63,15 +111,7 @@ public class LcmEventsCreatorHelper {
         return UPDATE;
     }
 
-    /**
-     * Determine the cmhandle value difference pair.Contains the difference in the form of oldValues and newValues.
-     *
-     * @param targetNcmpServiceCmHandle   target ncmpServiceCmHandle
-     * @param existingNcmpServiceCmHandle existing ncmpServiceCmHandle
-     * @param lcmEventType                lcm event type
-     * @return Lcm Event Value difference pair
-     */
-    public static LcmEventsCreator.CmHandleValuesHolder determineEventValues(
+    private static CmHandleValuesHolder determineEventValues(
             final NcmpServiceCmHandle targetNcmpServiceCmHandle, final NcmpServiceCmHandle existingNcmpServiceCmHandle,
             final LcmEventType lcmEventType) {
 
@@ -80,13 +120,42 @@ public class LcmEventsCreatorHelper {
         } else if (UPDATE == lcmEventType) {
             return determineUpdateEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
         }
-        return new LcmEventsCreator.CmHandleValuesHolder();
+        return new CmHandleValuesHolder();
+
+    }
+
+    private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
+            final NcmpServiceCmHandle existingNcmpServiceCmHandle, final LcmEventType lcmEventType) {
+        final Event event = new Event();
+        event.setCmHandleId(eventCorrelationId);
+        event.setAlternateId(targetNcmpServiceCmHandle.getAlternateId());
+        event.setModuleSetTag(targetNcmpServiceCmHandle.getModuleSetTag());
+        event.setDataProducerIdentifier(targetNcmpServiceCmHandle.getDataProducerIdentifier());
+        final CmHandleValuesHolder cmHandleValuesHolder =
+                determineEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle,
+                        lcmEventType);
+        event.setOldValues(cmHandleValuesHolder.getOldValues());
+        event.setNewValues(cmHandleValuesHolder.getNewValues());
+
+        return event;
+    }
 
+    private LcmEvent lcmEventHeader(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 static LcmEventsCreator.CmHandleValuesHolder determineCreateEventValues(
+
+    private static CmHandleValuesHolder determineCreateEventValues(
             final NcmpServiceCmHandle ncmpServiceCmHandle) {
-        final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder = new LcmEventsCreator.CmHandleValuesHolder();
+        final CmHandleValuesHolder cmHandleValuesHolder = new CmHandleValuesHolder();
         cmHandleValuesHolder.setNewValues(new Values());
         cmHandleValuesHolder.getNewValues().setDataSyncEnabled(getDataSyncEnabledFlag(ncmpServiceCmHandle));
         cmHandleValuesHolder.getNewValues()
@@ -95,7 +164,7 @@ public class LcmEventsCreatorHelper {
         return cmHandleValuesHolder;
     }
 
-    private static LcmEventsCreator.CmHandleValuesHolder determineUpdateEventValues(
+    private static CmHandleValuesHolder determineUpdateEventValues(
             final NcmpServiceCmHandle targetNcmpServiceCmHandle,
             final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
 
@@ -107,7 +176,7 @@ public class LcmEventsCreatorHelper {
                 arePublicCmHandlePropertiesEqual(targetNcmpServiceCmHandle.getPublicProperties(),
                         existingNcmpServiceCmHandle.getPublicProperties());
 
-        final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder = new LcmEventsCreator.CmHandleValuesHolder();
+        final CmHandleValuesHolder cmHandleValuesHolder = new CmHandleValuesHolder();
 
         if (hasDataSyncFlagEnabledChanged || hasCmHandleStateChanged || (!arePublicCmHandlePropertiesEqual)) {
             cmHandleValuesHolder.setOldValues(new Values());
@@ -134,8 +203,8 @@ public class LcmEventsCreatorHelper {
     }
 
     private static void setDataSyncEnabledFlag(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle,
-            final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
+                                               final NcmpServiceCmHandle existingNcmpServiceCmHandle,
+                                               final CmHandleValuesHolder cmHandleValuesHolder) {
 
         cmHandleValuesHolder.getOldValues().setDataSyncEnabled(getDataSyncEnabledFlag(existingNcmpServiceCmHandle));
         cmHandleValuesHolder.getNewValues().setDataSyncEnabled(getDataSyncEnabledFlag(targetNcmpServiceCmHandle));
@@ -143,8 +212,8 @@ public class LcmEventsCreatorHelper {
     }
 
     private static void setCmHandleStateChange(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle,
-            final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
+                                               final NcmpServiceCmHandle existingNcmpServiceCmHandle,
+                                               final CmHandleValuesHolder cmHandleValuesHolder) {
         cmHandleValuesHolder.getOldValues()
                 .setCmHandleState(mapCmHandleStateToLcmEventCmHandleState(existingNcmpServiceCmHandle));
         cmHandleValuesHolder.getNewValues()
@@ -152,8 +221,8 @@ public class LcmEventsCreatorHelper {
     }
 
     private static void setPublicCmHandlePropertiesChange(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle,
-            final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
+                                                          final NcmpServiceCmHandle existingNcmpServiceCmHandle,
+                                                          final CmHandleValuesHolder cmHandleValuesHolder) {
 
         final Map<String, Map<String, String>> publicCmHandlePropertiesDifference =
                 getPublicCmHandlePropertiesDifference(targetNcmpServiceCmHandle.getPublicProperties(),
@@ -175,7 +244,7 @@ public class LcmEventsCreatorHelper {
     }
 
     private static boolean hasDataSyncEnabledFlagChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+                                                         final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
 
         final Boolean targetDataSyncFlag = targetNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled();
         final Boolean existingDataSyncFlag = existingNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled();
@@ -188,14 +257,14 @@ public class LcmEventsCreatorHelper {
     }
 
     private static boolean hasCmHandleStateChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
-            final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
+                                                   final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
 
         return targetNcmpServiceCmHandle.getCompositeState().getCmHandleState()
-                       != existingNcmpServiceCmHandle.getCompositeState().getCmHandleState();
+                != existingNcmpServiceCmHandle.getCompositeState().getCmHandleState();
     }
 
     private static boolean arePublicCmHandlePropertiesEqual(final Map<String, String> targetCmHandleProperties,
-            final Map<String, String> existingCmHandleProperties) {
+                                                            final Map<String, String> existingCmHandleProperties) {
         if (targetCmHandleProperties.size() != existingCmHandleProperties.size()) {
             return false;
         }
@@ -224,4 +293,14 @@ public class LcmEventsCreatorHelper {
         return oldAndNewPropertiesDifferenceMap;
     }
 
+
+    @NoArgsConstructor
+    @Getter
+    @Setter
+    static class CmHandleValuesHolder {
+
+        private Values oldValues;
+        private Values newValues;
+    }
+
 }
index 73b5948..ebf2eee 100644 (file)
@@ -54,7 +54,7 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
     }
 
     def mockInventoryPersistence = Mock(InventoryPersistence)
-    def mockLcmEventsCreator = Mock(LcmEventsCreator)
+    def mockLcmEventsCreator = Mock(LcmEventsProducerHelper)
     def mockLcmEventsProducer = Mock(LcmEventsProducer)
     def mockCmHandleStateMonitor = Mock(CmHandleStateMonitor)
 
@@ -65,7 +65,7 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
     def compositeState
     def yangModelCmHandle
 
-    def 'Update and Publish Events on State Change #stateChange'() {
+    def 'Update and Send Events on State Change #stateChange'() {
         given: 'Cm Handle represented as YangModelCmHandle'
             compositeState = new CompositeState(cmHandleState: fromCmHandleState)
             yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState)
@@ -82,8 +82,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             def loggingEvent = (ILoggingEvent) logger.list[0]
             assert loggingEvent.level == Level.INFO
             assert loggingEvent.formattedMessage == "${cmHandleId} is now in ${toCmHandleState} state"
-        and: 'event service is called to publish event'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'event service is called to send event'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
         where: 'state change parameters are provided'
             stateChange           | fromCmHandleState | toCmHandleState
             'ADVISED to READY'    | ADVISED           | READY
@@ -92,20 +92,20 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             'ADVISED to DELETING' | ADVISED           | DELETING
     }
 
-    def 'Update and Publish Events on State Change from non-existing to ADVISED'() {
+    def 'Update and Send Events on State Change from non-existing to ADVISED'() {
         given: 'Cm Handle represented as YangModelCmHandle'
             yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [])
         when: 'update state is invoked'
             objectUnderTest.updateCmHandleStateBatch(Map.of(yangModelCmHandle, ADVISED))
         then: 'CM-handle is saved using inventory persistence'
             1 * mockInventoryPersistence.saveCmHandleBatch(List.of(yangModelCmHandle))
-        and: 'event service is called to publish event'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'event service is called to send event'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
         and: 'a log entry is written'
             assert getLogMessage(0) == "${cmHandleId} is now in ADVISED state"
     }
 
-    def 'Update and Publish Events on State Change from LOCKED to ADVISED'() {
+    def 'Update and Send Events on State Change from LOCKED to ADVISED'() {
         given: 'Cm Handle represented as YangModelCmHandle in LOCKED state'
             compositeState = new CompositeState(cmHandleState: LOCKED,
                 lockReason: CompositeState.LockReason.builder().lockReasonCategory(MODULE_SYNC_FAILED).details('some lock details').build())
@@ -119,13 +119,13 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
                     assert cmHandleStatePerCmHandleId.get(cmHandleId).lockReason.details == 'some lock details'
                 }
             }
-        and: 'event service is called to publish event'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'event service is called to send event'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
         and: 'a log entry is written'
             assert getLogMessage(0) == "${cmHandleId} is now in ADVISED state"
     }
 
-    def 'Update and Publish Events on State Change to from ADVISED to READY'() {
+    def 'Update and Send Events on State Change to from ADVISED to READY'() {
         given: 'Cm Handle represented as YangModelCmHandle'
             compositeState = new CompositeState(cmHandleState: ADVISED)
             yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState)
@@ -141,8 +141,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
                     assert cmHandleStatePerCmHandleId.get(cmHandleId).dataStores.operationalDataStore.dataStoreSyncState == DataStoreSyncState.NONE_REQUESTED
                 }
             }
-        and: 'event service is called to publish event'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'event service is called to send event'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
         and: 'a log entry is written'
             assert getLogMessage(0) == "${cmHandleId} is now in READY state"
     }
@@ -157,8 +157,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             yangModelCmHandle.getCompositeState().getCmHandleState() == DELETING
         and: 'method to persist cm handle state is called once'
             1 * mockInventoryPersistence.saveCmHandleStateBatch(Map.of(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState()))
-        and: 'the method to publish Lcm event is called once'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'the method to send Lcm event is called once'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
     }
 
     def 'Update cmHandle state to DELETING to DELETED' (){
@@ -169,11 +169,11 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             objectUnderTest.updateCmHandleStateBatch(Map.of(yangModelCmHandle, DELETED))
         then: 'the cm handle state is as expected'
             yangModelCmHandle.getCompositeState().getCmHandleState() == DELETED
-        and: 'the method to publish Lcm event is called once'
-            1 * mockLcmEventsProducer.publishLcmEvent(cmHandleId, _, _)
+        and: 'the method to send Lcm event is called once'
+            1 * mockLcmEventsProducer.sendLcmEvent(cmHandleId, _, _)
     }
 
-    def 'No state change and no event to be published'() {
+    def 'No state change and no event to be sent'() {
         given: 'Cm Handle batch with same state transition as before'
             def cmHandleStateMap = setupBatch('NO_CHANGE')
         when: 'updating a batch of changes'
@@ -181,8 +181,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
         then: 'no changes are persisted'
             1 * mockInventoryPersistence.saveCmHandleBatch(EMPTY_LIST)
             1 * mockInventoryPersistence.saveCmHandleStateBatch(EMPTY_MAP)
-        and: 'no event will be published'
-            0 * mockLcmEventsProducer.publishLcmEvent(*_)
+        and: 'no event will be sent'
+            0 * mockLcmEventsProducer.sendLcmEvent(*_)
         and: 'no log entries are written'
             assert logger.list.empty
     }
@@ -200,8 +200,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             }
         and: 'no state updates are persisted'
             1 * mockInventoryPersistence.saveCmHandleStateBatch(EMPTY_MAP)
-        and: 'event service is called to publish events'
-            2 * mockLcmEventsProducer.publishLcmEvent(_, _, _)
+        and: 'event service is called to send events'
+            2 * mockLcmEventsProducer.sendLcmEvent(_, _, _)
         and: 'two log entries are written'
             assert getLogMessage(0) == 'cmhandle1 is now in ADVISED state'
             assert getLogMessage(1) == 'cmhandle2 is now in ADVISED state'
@@ -220,8 +220,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             }
         and: 'no new handles are persisted'
             1 * mockInventoryPersistence.saveCmHandleBatch(EMPTY_LIST)
-        and: 'event service is called to publish events'
-            2 * mockLcmEventsProducer.publishLcmEvent(_, _, _)
+        and: 'event service is called to send events'
+            2 * mockLcmEventsProducer.sendLcmEvent(_, _, _)
         and: 'two log entries are written'
             assert getLogMessage(0) == 'cmhandle1 is now in READY state'
             assert getLogMessage(1) == 'cmhandle2 is now in DELETING state'
@@ -236,8 +236,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             1 * mockInventoryPersistence.saveCmHandleStateBatch(EMPTY_MAP)
         and: 'no new handles are persisted'
             1 * mockInventoryPersistence.saveCmHandleBatch(EMPTY_LIST)
-        and: 'event service is called to publish events'
-            2 * mockLcmEventsProducer.publishLcmEvent(_, _, _)
+        and: 'event service is called to send events'
+            2 * mockLcmEventsProducer.sendLcmEvent(_, _, _)
         and: 'two log entries are written'
             assert getLogMessage(0) == 'cmhandle1 is now in DELETED state'
             assert getLogMessage(1) == 'cmhandle2 is now in DELETED state'
@@ -252,8 +252,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
             objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
         then: 'the exception is not handled'
             thrown(RuntimeException)
-        and: 'no events are published'
-            0 * mockLcmEventsProducer.publishLcmEvent(_, _, _)
+        and: 'no events are sent'
+            0 * mockLcmEventsProducer.sendLcmEvent(_, _, _)
         and: 'no log entries are written'
             assert logger.list.empty
     }
@@ -31,11 +31,11 @@ import static org.onap.cps.ncmp.api.inventory.models.CmHandleState.ADVISED
 import static org.onap.cps.ncmp.api.inventory.models.CmHandleState.DELETING
 import static org.onap.cps.ncmp.api.inventory.models.CmHandleState.READY
 
-class LcmEventsCreatorSpec extends Specification {
+class LcmEventsProducerHelperSpec extends Specification {
 
     LcmEventHeaderMapper lcmEventsHeaderMapper = Mappers.getMapper(LcmEventHeaderMapper)
 
-    def objectUnderTest = new LcmEventsCreator(lcmEventsHeaderMapper)
+    def objectUnderTest = new LcmEventsProducerHelper(lcmEventsHeaderMapper)
     def cmHandleId = 'test-cm-handle'
 
     def 'Map the LcmEvent for #operation'() {
index 8ae13f8..d9944a7 100644 (file)
@@ -43,7 +43,7 @@ class LcmEventsProducerSpec extends Specification {
     def objectUnderTest = new LcmEventsProducer(mockLcmEventsProducer, mockJsonObjectMapper, meterRegistry)
 
     def 'Create and send lcm event where events are #scenario'() {
-        given: 'a cm handle id, Lcm Event, and headers'
+        given: 'a cm handle id and Lcm Event'
             def cmHandleId = 'test-cm-handle-id'
             def eventId = UUID.randomUUID().toString()
             def event = getEventWithCmHandleState(ADVISED, READY)
@@ -55,8 +55,8 @@ class LcmEventsProducerSpec extends Specification {
         and: 'lcm event header is transformed to headers map'
             mockJsonObjectMapper.convertToValueType(lcmEventHeader, Map.class) >> ['eventId': eventId, 'eventCorrelationId': cmHandleId]
         when: 'service is called to send lcm event'
-            objectUnderTest.publishLcmEvent('test-cm-handle-id', lcmEvent, lcmEventHeader)
-        then: 'publisher is called #expectedTimesMethodCalled times'
+            objectUnderTest.sendLcmEvent('test-cm-handle-id', lcmEvent, lcmEventHeader)
+        then: 'producer is called #expectedTimesMethodCalled times'
             expectedTimesMethodCalled * mockLcmEventsProducer.sendEvent(_, cmHandleId, _, lcmEvent) >> {
                 args -> {
                     def eventHeaders = (args[2] as Map<String,Object>)
@@ -67,7 +67,7 @@ class LcmEventsProducerSpec extends Specification {
                 }
             }
         and: 'metrics are recorded with correct tags'
-            def timer = meterRegistry.find('cps.ncmp.lcm.events.publish').timer()
+            def timer = meterRegistry.find('cps.ncmp.lcm.events.send').timer()
             if (notificationsEnabled) {
                 assert timer != null
                 assert timer.count() == expectedTimesMethodCalled
@@ -90,14 +90,14 @@ class LcmEventsProducerSpec extends Specification {
             def lcmEvent = new LcmEvent(event: event, eventId: eventId, eventCorrelationId: cmHandleId)
             def lcmEventHeader = new LcmEventHeader(eventId: eventId, eventCorrelationId: cmHandleId)
             objectUnderTest.notificationsEnabled = true
-        when: 'publisher set to throw an exception'
-            mockLcmEventsProducer.sendEvent(_, _, _, _) >> { throw new KafkaException('publishing failed')}
+        when: 'producer set to throw an exception'
+            mockLcmEventsProducer.sendEvent(_, _, _, _) >> { throw new KafkaException('sending failed')}
         and: 'an event is publised'
-            objectUnderTest.publishLcmEvent(cmHandleId, lcmEvent, lcmEventHeader)
+            objectUnderTest.sendLcmEvent(cmHandleId, lcmEvent, lcmEventHeader)
         then: 'the exception is just logged and not bubbled up'
             noExceptionThrown()
         and: 'metrics are recorded with error tags'
-            def timer = meterRegistry.find('cps.ncmp.lcm.events.publish').timer()
+            def timer = meterRegistry.find('cps.ncmp.lcm.events.send').timer()
             assert timer != null
             assert timer.count() == 1
             def expectedTags = [Tag.of('oldCmHandleState', 'N/A'), Tag.of('newCmHandleState', 'N/A')]
index 2d2a857..6d82245 100644 (file)
@@ -63,7 +63,7 @@ public class CpsDataUpdateEventsProducer {
      * @param operation operation performed on the data
      * @param observedTimestamp timestamp when data was updated.
      */
-    @Timed(value = "cps.dataupdate.events.publish", description = "Time taken to send Data Update event")
+    @Timed(value = "cps.dataupdate.events.send", description = "Time taken to send Data Update event")
     public void sendCpsDataUpdateEvent(final Anchor anchor, final String xpath,
                                        final Operation operation, final OffsetDateTime observedTimestamp) {
         if (notificationsEnabled && cpsChangeEventNotificationsEnabled && isNotificationEnabledForAnchor(anchor)) {
index 3663ffa..a07354d 100644 (file)
@@ -1,6 +1,6 @@
 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
 .. http://creativecommons.org/licenses/by/4.0
-.. Copyright (C) 2023-2025 Nordix Foundation
+.. Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
 
 .. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING
 .. _cmHandleLcmEvents:
@@ -15,7 +15,7 @@ CM Handle Lifecycle Management (LCM) Events
 Introduction
 ============
 
-LCM events for CM Handles are published when a CM Handle is created, deleted or another change in the CM Handle state occurs.
+LCM events for CM Handles are sent when a CM Handle is created, deleted or another change in the CM Handle state occurs.
 
   **3 possible event types:**
 
@@ -25,7 +25,7 @@ LCM events for CM Handles are published when a CM Handle is created, deleted or
 
 CM Handle  LCM Event Schema
 ---------------------------
-The current published LCM event is based on the following schema:
+The current sent LCM events are based on the following schema:
 
 :download:`Life cycle management event header <schemas/lcm/lcm-event-header-v1.json>`
 :download:`Life cycle management event schema <schemas/lcm/lcm-event-schema-v1.json>`