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.List;
12 import java.util.Optional;
13 import java.util.concurrent.ExecutionException;
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.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
19 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
20 import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl;
21 import org.opendaylight.transportpce.nbinotifications.impl.rpc.DeleteNotificationSubscriptionServiceImpl;
22 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl;
23 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceDetailsImpl;
24 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceListImpl;
25 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl;
26 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl;
27 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetSupportedNotificationTypesImpl;
28 import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler;
29 import org.opendaylight.transportpce.nbinotifications.producer.Publisher;
30 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.Context1;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext;
37 import org.opendaylight.yangtools.concepts.Registration;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.osgi.service.component.annotations.Activate;
40 import org.osgi.service.component.annotations.Component;
41 import org.osgi.service.component.annotations.Deactivate;
42 import org.osgi.service.component.annotations.Reference;
43 import org.osgi.service.metatype.annotations.AttributeDefinition;
44 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 @Component(configurationPid = "org.opendaylight.transportpce.nbinotifications")
49 public class NbiNotificationsProvider {
51 @ObjectClassDefinition
52 public @interface Configuration {
54 String suscriberServer() default "";
56 String publisherServer() default "";
59 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class);
60 private Map<String, Publisher<NotificationProcessService>> publishersServiceMap;
61 private Map<String, Publisher<NotificationAlarmService>> publishersAlarmMap;
62 private Registration listenerRegistration;
63 private Registration rpcRegistration;
64 private NetworkTransactionService networkTransactionService;
67 public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService,
68 @Reference NotificationService notificationService,
69 @Reference BindingDOMCodecServices bindingDOMCodecServices,
70 @Reference NetworkTransactionService networkTransactionService,
71 final Configuration configuration) {
72 this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService,
73 bindingDOMCodecServices, networkTransactionService);
76 public NbiNotificationsProvider(String subscriberServer, String publisherServer,
77 RpcProviderService rpcProviderService, NotificationService notificationService,
78 BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) {
79 this.networkTransactionService = networkTransactionService;
80 List<String> publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler",
82 TopicManager topicManager = TopicManager.getInstance();
83 topicManager.setPublisherServer(publisherServer);
84 JsonStringConverter<NotificationProcessService> converterService =
85 new JsonStringConverter<>(bindingDOMCodecServices);
86 topicManager.setProcessConverter(converterService);
87 for (String publisherService: publishersServiceList) {
88 LOG.info("Creating publisher for the following class {}", publisherService);
89 topicManager.addProcessTopic(publisherService);
91 JsonStringConverter<NotificationAlarmService> converterAlarmService =
92 new JsonStringConverter<>(bindingDOMCodecServices);
93 topicManager.setAlarmConverter(converterAlarmService);
94 List<String> publishersAlarmList = List.of("ServiceListener");
95 for (String publisherAlarm: publishersAlarmList) {
96 LOG.info("Creating publisher for the following class {}", publisherAlarm);
97 topicManager.addAlarmTopic(publisherAlarm);
99 JsonStringConverter<NotificationTapiService> converterTapiService =
100 new JsonStringConverter<>(bindingDOMCodecServices);
101 LOG.info("tapi converter: {}", converterTapiService);
102 topicManager.setTapiConverter(converterTapiService);
104 rpcRegistration = rpcProviderService.registerRpcImplementations(
105 new GetNotificationsProcessServiceImpl(converterService, subscriberServer),
106 new GetNotificationsAlarmServiceImpl(converterAlarmService, subscriberServer),
107 new GetSupportedNotificationTypesImpl(this),
108 new CreateNotificationSubscriptionServiceImpl(this, topicManager),
109 new DeleteNotificationSubscriptionServiceImpl(networkTransactionService, topicManager),
110 new GetNotificationSubscriptionServiceDetailsImpl(this),
111 new GetNotificationSubscriptionServiceListImpl(this),
112 new GetNotificationListImpl(converterTapiService, subscriberServer, networkTransactionService,
115 NbiNotificationsHandler notificationsListener = new NbiNotificationsHandler(
116 topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap());
117 listenerRegistration = notificationService.registerCompositeListener(
118 notificationsListener.getCompositeListener());
119 topicManager.setNbiNotificationsListener(notificationsListener);
120 publishersServiceMap = topicManager.getProcessTopicMap();
121 publishersAlarmMap = topicManager.getAlarmTopicMap();
122 LOG.info("NbiNotificationsProvider Session Initiated");
126 * Method called when the blueprint container is destroyed.
129 public void close() {
130 for (Publisher<NotificationProcessService> publisher : publishersServiceMap.values()) {
133 for (Publisher<NotificationAlarmService> publisherAlarm : publishersAlarmMap.values()) {
134 publisherAlarm.close();
136 rpcRegistration.close();
137 listenerRegistration.close();
138 LOG.info("NbiNotificationsProvider Closed");
141 public NotificationContext getNotificationContext() {
142 LOG.info("Getting tapi notification context");
144 Optional<NotificationContext> notificationContextOptional = this.networkTransactionService.read(
145 LogicalDatastoreType.OPERATIONAL,
146 InstanceIdentifier.builder(Context.class)
147 .augmentation(Context1.class).child(NotificationContext.class)
150 if (notificationContextOptional.isPresent()) {
151 return notificationContextOptional.orElseThrow();
153 LOG.debug("notification context is empty");
154 } catch (InterruptedException | ExecutionException e) {
155 LOG.error("Caught exception getting Notification Context", e);
157 LOG.error("Could not get TAPI notification context");
161 public boolean updateNotificationContext(NotificationContext notificationContext1) {
163 this.networkTransactionService.merge(
164 LogicalDatastoreType.OPERATIONAL,
165 InstanceIdentifier.builder(Context.class)
166 .augmentation(Context1.class).child(NotificationContext.class)
168 notificationContext1);
169 this.networkTransactionService.commit().get();
171 } catch (InterruptedException | ExecutionException e) {
172 LOG.error("Could not update TAPI notification context");