diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2022-07-11 12:15:55 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2022-07-14 09:05:31 +0100 |
commit | a6fa6c368f04c85bf553fce2cf89d25ec366116e (patch) | |
tree | cc69b8995470a7c4af0eaf4ce2a830ffea98b5a2 /cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java | |
parent | 97c875cf3fea520563e1819209ab826f8c03fd5e (diff) |
Code Refactoring Ncmp* to Lcm* as per new scope
- Refactored code to reflect the LcmEvents scope now.
- Test cases updated and dependencies reviewed.
- You can find few occurences of NcmpEvent for now but that will be
cleaned up once we implement CPS-1104 which is for LcmEvent schema
- UPCOMING: LcmEvent schema and then the code to publish the events on
cmHandleStates
- LATER : LcmEvents based on public properties update.
Issue-ID: CPS-1137
Change-Id: I9f395ed733b4028e706205894c36a38412e3452e
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java')
-rw-r--r-- | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java new file mode 100644 index 0000000000..2a946b1008 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsPublisher.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.api.impl.event.lcm; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.onap.ncmp.cmhandle.lcm.event.NcmpEvent; +import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.support.SendResult; +import org.springframework.stereotype.Service; +import org.springframework.util.concurrent.ListenableFuture; +import org.springframework.util.concurrent.ListenableFutureCallback; + +/** + * LcmEventsPublisher to publish the LcmEvents on event of CREATE, UPDATE and DELETE. + */ + +@Slf4j +@Service +@RequiredArgsConstructor +public class LcmEventsPublisher { + + private final KafkaTemplate<String, NcmpEvent> lcmEventKafkaTemplate; + + /** + * LCM Event publisher. + * + * @param topicName valid topic name + * @param eventKey message key + * @param ncmpEvent message payload + */ + public void publishEvent(final String topicName, final String eventKey, final NcmpEvent ncmpEvent) { + final ListenableFuture<SendResult<String, NcmpEvent>> lcmEventFuture = + lcmEventKafkaTemplate.send(topicName, eventKey, ncmpEvent); + + lcmEventFuture.addCallback(new ListenableFutureCallback<>() { + @Override + public void onFailure(final Throwable throwable) { + log.error("Unable to publish event to topic : {} due to {}", topicName, throwable.getMessage()); + } + + @Override + public void onSuccess(final SendResult<String, NcmpEvent> result) { + log.debug("Successfully published event to topic : {} , NcmpEvent : {}", + result.getRecordMetadata().topic(), result.getProducerRecord().value()); + } + }); + } +} |