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.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
14 import org.opendaylight.mdsal.binding.api.NotificationService;
15 import org.opendaylight.mdsal.binding.api.RpcProviderService;
16 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
17 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
18 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
19 import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl;
20 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
21 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsService;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
27 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.concepts.ObjectRegistration;
30 import org.osgi.service.component.annotations.Activate;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Deactivate;
33 import org.osgi.service.component.annotations.Reference;
34 import org.osgi.service.metatype.annotations.AttributeDefinition;
35 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 @Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
40 public class NbiNotificationsProvider {
42 @ObjectClassDefinition
43 public @interface Configuration {
45 String suscriberServer() default "";
47 String publisherServer() default "";
50 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
51 private static Map<String, Publisher<NotificationProcessService>> publishersServiceMap = new HashMap<>();
52 private static Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap = new HashMap<>();
53 private ListenerRegistration<NbiNotificationsListener> listenerRegistration;
54 private List<ObjectRegistration<NbiNotificationsImpl>> rpcRegistrations = new ArrayList<>();
57 public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
58 @Reference NotificationService notificationService,
59 @Reference BindingDOMCodecServices bindingDOMCodecServices,
60 @Reference NetworkTransactionService networkTransactionService,
61 final Configuration configuration) {
62 this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
63 bindingDOMCodecServices, networkTransactionService);
66 public NbiNotificationsProvider(String subscriberServer, String publisherServer,
67 RpcProviderService rpcProviderService, NotificationService notificationService,
68 BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
69 List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
71 TopicManager topicManager = TopicManager.getInstance();
72 topicManager.setPublisherServer(publisherServer);
73 JsonStringConverter<NotificationProcessService> converterService =
74 new JsonStringConverter<>(bindingDOMCodecServices);
75 topicManager.setProcessConverter(converterService);
76 for (String publisherService: publishersServiceList) {
77 LOG.info("Creating publisher for the following class {}", publisherService);
78 topicManager.addProcessTopic(publisherService);
80 JsonStringConverter<NotificationAlarmService> converterAlarmService =
81 new JsonStringConverter<>(bindingDOMCodecServices);
82 topicManager.setAlarmConverter(converterAlarmService);
83 List<String> publishersAlarmList = List.of("ServiceListener");
84 for (String publisherAlarm: publishersAlarmList) {
85 LOG.info("Creating publisher for the following class {}", publisherAlarm);
86 topicManager.addAlarmTopic(publisherAlarm);
88 JsonStringConverter<NotificationTapiService> converterTapiService =
89 new JsonStringConverter<>(bindingDOMCodecServices);
90 LOG.info("baozhi tapi converter: {}", converterTapiService);
91 topicManager.setTapiConverter(converterTapiService);
93 NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService,
94 converterTapiService, subscriberServer, networkTransactionService, topicManager);
95 rpcRegistrations.add(rpcProviderService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl));
96 rpcRegistrations.add(rpcProviderService.registerRpcImplementation(TapiNotificationService.class, nbiImpl));
97 NbiNotificationsListenerImpl nbiNotificationsListener = new NbiNotificationsListenerImpl(
98 topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
99 listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener);
100 topicManager.setNbiNotificationsListener(nbiNotificationsListener);
101 LOG.info("NbiNotificationsProvider Session Initiated");
105 * Method called when the blueprint container is destroyed.
108 public void close() {
109 for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
112 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
113 publisherAlarm.close();
115 rpcRegistrations.forEach(reg -> reg.close());
116 listenerRegistration.close();
117 LOG.info("NbiNotificationsProvider Closed");