/*
* ============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.
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 {
@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) {
/*
* ============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.
final Collection<CmHandleTransitionPair> cmHandleTransitionPairs =
prepareCmHandleTransitionBatch(cmHandleStatePerCmHandle);
persistCmHandleBatch(cmHandleTransitionPairs);
- lcmEventsCmHandleStateHandlerAsyncHelper.publishLcmEventBatchAsynchronously(cmHandleTransitionPairs);
+ lcmEventsCmHandleStateHandlerAsyncHelper.sendLcmEventBatchAsynchronously(cmHandleTransitionPairs);
cmHandleStateMonitor.updateCmHandleStateMetrics(cmHandleTransitionPairs);
}
+++ /dev/null
-/*
- * ============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;
- }
-
-}
@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;
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);
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);
}
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));
}
/*
* ============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.
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;
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) {
} 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()
return cmHandleValuesHolder;
}
- private static LcmEventsCreator.CmHandleValuesHolder determineUpdateEventValues(
+ private static CmHandleValuesHolder determineUpdateEventValues(
final NcmpServiceCmHandle targetNcmpServiceCmHandle,
final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
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());
}
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));
}
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()
}
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(),
}
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();
}
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;
}
return oldAndNewPropertiesDifferenceMap;
}
+
+ @NoArgsConstructor
+ @Getter
+ @Setter
+ static class CmHandleValuesHolder {
+
+ private Values oldValues;
+ private Values newValues;
+ }
+
}
}
def mockInventoryPersistence = Mock(InventoryPersistence)
- def mockLcmEventsCreator = Mock(LcmEventsCreator)
+ def mockLcmEventsCreator = Mock(LcmEventsProducerHelper)
def mockLcmEventsProducer = Mock(LcmEventsProducer)
def mockCmHandleStateMonitor = Mock(CmHandleStateMonitor)
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)
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
'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())
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)
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"
}
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' (){
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'
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
}
}
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'
}
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'
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'
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
}
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'() {
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)
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>)
}
}
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
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')]
* @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)) {
.. 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:
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:**
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>`