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.rev210813.NbiNotificationsListener;
13 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
14 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmServiceBuilder;
15 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessServiceBuilder;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationAlarmService;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.PublishNotificationProcessService;
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<NotificationProcessService>> publishersServiceMap;
25 private final Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
27 public NbiNotificationsListenerImpl(Map<String, Publisher<NotificationProcessService>> publishersServiceMap,
28 Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap) {
29 this.publishersServiceMap = publishersServiceMap;
30 this.publishersAlarmMap = publishersAlarmMap;
34 public void onPublishNotificationProcessService(PublishNotificationProcessService notification) {
35 LOG.info("Receiving request for publishing notification service");
36 String publisherName = notification.getPublisherName();
37 if (!publishersServiceMap.containsKey(publisherName)) {
38 LOG.error("Unknown publisher {}", publisherName);
41 Publisher<NotificationProcessService> publisher = publishersServiceMap.get(publisherName);
42 publisher.sendEvent(new NotificationProcessServiceBuilder()
43 .setCommonId(notification.getCommonId())
44 .setConnectionType(notification.getConnectionType())
45 .setMessage(notification.getMessage())
46 .setOperationalState(notification.getOperationalState())
47 .setResponseFailed(notification.getResponseFailed())
48 .setServiceAEnd(notification.getServiceAEnd())
49 .setServiceName(notification.getServiceName())
50 .setServiceZEnd(notification.getServiceZEnd())
51 .build(), notification.getConnectionType().getName());
55 public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
56 LOG.info("Receiving request for publishing notification alarm service");
57 String publisherName = notification.getPublisherName();
58 if (!publishersAlarmMap.containsKey(publisherName)) {
59 LOG.error("Unknown topic {}", publisherName);
62 Publisher<NotificationAlarmService> publisherAlarm = publishersAlarmMap.get(publisherName);
63 publisherAlarm.sendEvent(new NotificationAlarmServiceBuilder()
64 .setConnectionType(notification.getConnectionType())
65 .setMessage(notification.getMessage())
66 .setOperationalState(notification.getOperationalState())
67 .setServiceName(notification.getServiceName())
68 .build(), "alarm" + notification.getConnectionType().getName());