2 * Copyright © 2020 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.nbinotifications.listener;
11 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
12 import org.opendaylight.transportpce.nbinotifications.utils.NbiNotificationsUtils;
13 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmServiceBuilder;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessServiceBuilder;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiServiceBuilder;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
27 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
28 private Map<String, Publisher<NotificationProcessService>> publishersServiceMap;
29 private Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
30 private Map<String, Publisher<NotificationTapiService>> tapiPublisherMap;
32 public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationProcessService>> publishersServiceMap,
33 Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap,
34 Map<String, Publisher<NotificationTapiService>> tapiPublisherMap) {
35 this.publishersServiceMap = publishersServiceMap;
36 this.publishersAlarmMap = publishersAlarmMap;
37 this.tapiPublisherMap = tapiPublisherMap;
41 public void onPublishNotificationProcessService(PublishNotificationProcessService notification) {
42 LOG.info("Receiving request for publishing notification service");
43 String publisherName = notification.getPublisherName();
44 if (!publishersServiceMap.containsKey(publisherName)) {
45 LOG.error("Unknown publisher {}", publisherName);
48 Publisher<NotificationProcessService> publisher = publishersServiceMap.get(publisherName);
49 publisher.sendEvent(new NotificationProcessServiceBuilder()
50 .setCommonId(notification.getCommonId())
51 .setConnectionType(notification.getConnectionType())
52 .setMessage(notification.getMessage())
53 .setOperationalState(notification.getOperationalState())
54 .setResponseFailed(notification.getResponseFailed())
55 .setServiceAEnd(notification.getServiceAEnd())
56 .setServiceName(notification.getServiceName())
57 .setServiceZEnd(notification.getServiceZEnd())
58 .build(), notification.getConnectionType().getName());
62 public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
63 LOG.info("Receiving request for publishing notification alarm service");
64 String publisherName = notification.getPublisherName();
65 if (!publishersAlarmMap.containsKey(publisherName)) {
66 LOG.error("Unknown topic {}", publisherName);
69 Publisher<NotificationAlarmService> publisherAlarm = publishersAlarmMap.get(publisherName);
70 publisherAlarm.sendEvent(new NotificationAlarmServiceBuilder()
71 .setConnectionType(notification.getConnectionType())
72 .setMessage(notification.getMessage())
73 .setOperationalState(notification.getOperationalState())
74 .setServiceName(notification.getServiceName())
75 .build(), "alarm" + notification.getConnectionType().getName());
79 public void onPublishTapiNotificationService(PublishTapiNotificationService notification) {
80 LOG.info("Receiving request for publishing TAPI notification");
81 String topic = notification.getTopic();
82 if (!tapiPublisherMap.containsKey(topic)) {
83 LOG.error("Unknown topic {}", topic);
86 Publisher<NotificationTapiService> publisher = tapiPublisherMap.get(topic);
87 publisher.sendEvent(new NotificationTapiServiceBuilder(
88 NbiNotificationsUtils.transformTapiNotification(notification)).build(), topic);
91 public void setPublishersServiceMap(Map<String, Publisher<NotificationProcessService>> publishersServiceMap) {
92 this.publishersServiceMap = publishersServiceMap;
95 public void setPublishersAlarmMap(Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
96 this.publishersAlarmMap = publishersAlarmMap;
99 public void setTapiPublishersMap(Map<String, Publisher<NotificationTapiService>> tapiPublishersMap) {
100 this.tapiPublisherMap = tapiPublishersMap;
103 public Publisher<NotificationTapiService> getTapiPublisherFromTopic(String topic) {
104 return this.tapiPublisherMap.get(topic);