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.yang.gen.v1.nbi.notifications.rev210628.NbiNotificationsListener;
13 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmService;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationAlarmServiceBuilder;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationService;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.NotificationServiceBuilder;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationAlarmService;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
23 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
24 private final Map<String, Publisher<NotificationService>> publishersServiceMap;
25 private final Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
27 public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationService>> publishersServiceMap,
28 Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
29 this.publishersServiceMap = publishersServiceMap;
30 this.publishersAlarmMap = publishersAlarmMap;
34 public void onPublishNotificationService(PublishNotificationService notification) {
35 LOG.info("Receiving request for publishing notification service");
36 String topic = notification.getTopic();
37 if (!publishersServiceMap.containsKey(topic)) {
38 LOG.error("Unknown topic {}", topic);
41 Publisher<NotificationService> publisher = publishersServiceMap.get(topic);
42 publisher.sendEvent(new NotificationServiceBuilder().setCommonId(notification.getCommonId())
43 .setConnectionType(notification.getConnectionType()).setMessage(notification.getMessage())
44 .setOperationalState(notification.getOperationalState())
45 .setResponseFailed(notification.getResponseFailed())
46 .setServiceAEnd(notification.getServiceAEnd())
47 .setServiceName(notification.getServiceName())
48 .setServiceZEnd(notification.getServiceZEnd()).build(), notification.getConnectionType().getName());
52 public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
53 LOG.info("Receiving request for publishing notification alarm service");
54 String topic = notification.getTopic();
55 if (!publishersAlarmMap.containsKey(topic)) {
56 LOG.error("Unknown topic {}", topic);
59 Publisher<NotificationAlarmService> publisherAlarm = publishersAlarmMap.get(topic);
60 publisherAlarm.sendEvent(new NotificationAlarmServiceBuilder().setConnectionType(notification
62 .setMessage(notification.getMessage())
63 .setOperationalState(notification.getOperationalState())
64 .setServiceName(notification.getServiceName())
65 .build(), "alarm" + notification.getConnectionType().getName());