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.impl;
10 import java.util.HashMap;
11 import java.util.List;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
16 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
17 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
18 import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
19 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
20 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
26 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService;
27 import org.opendaylight.yangtools.concepts.ListenerRegistration;
28 import org.opendaylight.yangtools.concepts.ObjectRegistration;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class NbiNotificationsProvider {
34 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
35 private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
36 private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
37 private final RpcProviderService rpcService;
38 private final NotificationService notificationService;
39 private final JsonStringConverter<NotificationProcessService> converterService;
40 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
41 private final JsonStringConverter<NotificationTapiService> converterTapiService;
42 private final String subscriberServer;
43 private ObjectRegistration<NbiNotificationsService> rpcRegistration;
44 private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
45 private TopicManager topicManager = TopicManager.getInstance();
46 private final NetworkTransactionService networkTransactionService;
49 public NbiNotificationsProvider(List<String> publishersService, List<String> publishersAlarm,
50 String subscriberServer, String publisherServer,
51 RpcProviderService rpcProviderService, NotificationService notificationService,
52 BindingDOMCodecServices bindingDOMCodecServices,
53 NetworkTransactionService networkTransactionService) {
54 this.rpcService = rpcProviderService;
55 this.notificationService = notificationService;
56 this.topicManager.setPublisherServer(publisherServer);
57 converterService = new JsonStringConverter<>(bindingDOMCodecServices);
58 this.topicManager.setProcessConverter(converterService);
59 for (String publisherService: publishersService) {
60 LOG.info("Creating publisher for the following class {}", publisherService);
61 this.topicManager.addProcessTopic(publisherService);
63 converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices);
64 this.topicManager.setAlarmConverter(converterAlarmService);
65 for (String publisherAlarm: publishersAlarm) {
66 LOG.info("Creating publisher for the following class {}", publisherAlarm);
67 this.topicManager.addAlarmTopic(publisherAlarm);
69 this.subscriberServer = subscriberServer;
70 converterTapiService = new JsonStringConverter<>(bindingDOMCodecServices);
71 LOG.info("baozhi tapi converter: {}", converterTapiService);
72 this.topicManager.setTapiConverter(converterTapiService);
73 this.networkTransactionService = networkTransactionService;
77 * Method called when the blueprint container is created.
80 LOG.info("NbiNotificationsProvider Session Initiated");
81 NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
82 subscriberServer, this.networkTransactionService, this.topicManager);
83 rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl);
84 rpcService.registerRpcImplementation(TapiNotificationService.class, nbiImpl);
85 NbiNotificationsListenerImpl nbiNotificationsListener =
86 new NbiNotificationsListenerImpl(this.topicManager.getProcessTopicMap(),
87 this.topicManager.getAlarmTopicMap(), this.topicManager.getTapiTopicMap());
88 listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener);
89 this.topicManager.setNbiNotificationsListener(nbiNotificationsListener);
93 * Method called when the blueprint container is destroyed.
96 for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
99 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
100 publisherAlarm.close();
102 rpcRegistration.close();
103 listenerRegistration.close();
104 LOG.info("NbiNotificationsProvider Closed");