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.NbiNotificationsHandler;
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.rev230728.NotificationAlarmService;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
24 import org.opendaylight.yangtools.concepts.Registration;
25 import org.osgi.service.component.annotations.Activate;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
29 import org.osgi.service.metatype.annotations.AttributeDefinition;
30 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 @Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
35 public class NbiNotificationsProvider {
37 @ObjectClassDefinition
38 public @interface Configuration {
40 String suscriberServer() default "";
42 String publisherServer() default "";
45 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
46 private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
47 private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
48 private Registration listenerRegistration;
49 private Registration rpcRegistration;
52 public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
53 @Reference NotificationService notificationService,
54 @Reference BindingDOMCodecServices bindingDOMCodecServices,
55 @Reference NetworkTransactionService networkTransactionService,
56 final Configuration configuration) {
57 this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
58 bindingDOMCodecServices, networkTransactionService);
61 public NbiNotificationsProvider(String subscriberServer, String publisherServer,
62 RpcProviderService rpcProviderService, NotificationService notificationService,
63 BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
64 List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
66 TopicManager topicManager = TopicManager.getInstance();
67 topicManager.setPublisherServer(publisherServer);
68 JsonStringConverter<NotificationProcessService> converterService =
69 new JsonStringConverter<>(bindingDOMCodecServices);
70 topicManager.setProcessConverter(converterService);
71 for (String publisherService: publishersServiceList) {
72 LOG.info("Creating publisher for the following class {}", publisherService);
73 topicManager.addProcessTopic(publisherService);
75 JsonStringConverter<NotificationAlarmService> converterAlarmService =
76 new JsonStringConverter<>(bindingDOMCodecServices);
77 topicManager.setAlarmConverter(converterAlarmService);
78 List<String> publishersAlarmList = List.of("ServiceListener");
79 for (String publisherAlarm: publishersAlarmList) {
80 LOG.info("Creating publisher for the following class {}", publisherAlarm);
81 topicManager.addAlarmTopic(publisherAlarm);
83 JsonStringConverter<NotificationTapiService> converterTapiService =
84 new JsonStringConverter<>(bindingDOMCodecServices);
85 LOG.info("baozhi tapi converter: {}", converterTapiService);
86 topicManager.setTapiConverter(converterTapiService);
88 NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
89 converterTapiService, subscriberServer, networkTransactionService, topicManager);
90 rpcRegistration = rpcProviderService.registerRpcImplementations(nbiImpl.registerRPCs());
91 NbiNotificationsHandler notificationsListener = new NbiNotificationsHandler(
92 topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
93 listenerRegistration = notificationService.registerCompositeListener(
94 notificationsListener.getCompositeListener());
95 topicManager.setNbiNotificationsListener(notificationsListener);
96 LOG.info("NbiNotificationsProvider Session Initiated");
100 * Method called when the blueprint container is destroyed.
103 public void close() {
104 for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
107 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
108 publisherAlarm.close();
110 rpcRegistration.close();
111 listenerRegistration.close();
112 LOG.info("NbiNotificationsProvider Closed");