X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nbinotifications%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnbinotifications%2Fimpl%2FNbiNotificationsProvider.java;h=6c61bfa25ecf1c4c166d34c426e805ff9443b1fa;hb=refs%2Fchanges%2F47%2F110947%2F2;hp=863d689a3af8db038276ca6435902caf1f8b2c2d;hpb=0a27df8c4c1c62cc0de952d96304ffd09d6bef51;p=transportpce.git diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProvider.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProvider.java index 863d689a3..6c61bfa25 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProvider.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProvider.java @@ -7,91 +7,125 @@ */ package org.opendaylight.transportpce.nbinotifications.impl; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import org.opendaylight.mdsal.binding.api.NotificationService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.converter.JsonStringConverter; import org.opendaylight.transportpce.common.network.NetworkTransactionService; -import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsListenerImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.DeleteNotificationSubscriptionServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceDetailsImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceListImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl; +import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetSupportedNotificationTypesImpl; +import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsHandler; import org.opendaylight.transportpce.nbinotifications.producer.Publisher; import org.opendaylight.transportpce.nbinotifications.utils.TopicManager; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.Context1; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext; +import org.opendaylight.yangtools.concepts.Registration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Component(configurationPid = "org.opendaylight.transportpce.nbinotifications") public class NbiNotificationsProvider { + @ObjectClassDefinition + public @interface Configuration { + @AttributeDefinition + String suscriberServer() default ""; + @AttributeDefinition + String publisherServer() default ""; + } + private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsProvider.class); - private static Map> publishersServiceMap = new HashMap<>(); - private static Map> publishersAlarmMap = new HashMap<>(); - private final RpcProviderService rpcService; - private final NotificationService notificationService; - private final JsonStringConverter converterService; - private final JsonStringConverter converterAlarmService; - private final JsonStringConverter converterTapiService; - private final String subscriberServer; - private ObjectRegistration rpcRegistration; - private ListenerRegistration listenerRegistration; - private TopicManager topicManager = TopicManager.getInstance(); - private final NetworkTransactionService networkTransactionService; + private Map> publishersServiceMap; + private Map> publishersAlarmMap; + private Registration listenerRegistration; + private Registration rpcRegistration; + private NetworkTransactionService networkTransactionService; + @Activate + public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService, + @Reference NotificationService notificationService, + @Reference BindingDOMCodecServices bindingDOMCodecServices, + @Reference NetworkTransactionService networkTransactionService, + final Configuration configuration) { + this(configuration.suscriberServer(), configuration.publisherServer(), rpcProviderService, notificationService, + bindingDOMCodecServices, networkTransactionService); + } - public NbiNotificationsProvider(List publishersService, List publishersAlarm, - String subscriberServer, String publisherServer, - RpcProviderService rpcProviderService, NotificationService notificationService, - BindingDOMCodecServices bindingDOMCodecServices, - NetworkTransactionService networkTransactionService) { - this.rpcService = rpcProviderService; - this.notificationService = notificationService; - this.topicManager.setPublisherServer(publisherServer); - converterService = new JsonStringConverter<>(bindingDOMCodecServices); - this.topicManager.setProcessConverter(converterService); - for (String publisherService: publishersService) { + public NbiNotificationsProvider(String subscriberServer, String publisherServer, + RpcProviderService rpcProviderService, NotificationService notificationService, + BindingDOMCodecServices bindingDOMCodecServices, NetworkTransactionService networkTransactionService) { + this.networkTransactionService = networkTransactionService; + List publishersServiceList = List.of("PceListener", "ServiceHandlerOperations", "ServiceHandler", + "RendererListener"); + TopicManager topicManager = TopicManager.getInstance(); + topicManager.setPublisherServer(publisherServer); + JsonStringConverter converterService = + new JsonStringConverter<>(bindingDOMCodecServices); + topicManager.setProcessConverter(converterService); + for (String publisherService: publishersServiceList) { LOG.info("Creating publisher for the following class {}", publisherService); - this.topicManager.addProcessTopic(publisherService); + topicManager.addProcessTopic(publisherService); } - converterAlarmService = new JsonStringConverter<>(bindingDOMCodecServices); - this.topicManager.setAlarmConverter(converterAlarmService); - for (String publisherAlarm: publishersAlarm) { + JsonStringConverter converterAlarmService = + new JsonStringConverter<>(bindingDOMCodecServices); + topicManager.setAlarmConverter(converterAlarmService); + List publishersAlarmList = List.of("ServiceListener"); + for (String publisherAlarm: publishersAlarmList) { LOG.info("Creating publisher for the following class {}", publisherAlarm); - this.topicManager.addAlarmTopic(publisherAlarm); + topicManager.addAlarmTopic(publisherAlarm); } - this.subscriberServer = subscriberServer; - converterTapiService = new JsonStringConverter<>(bindingDOMCodecServices); - LOG.info("baozhi tapi converter: {}", converterTapiService); - this.topicManager.setTapiConverter(converterTapiService); - this.networkTransactionService = networkTransactionService; - } + JsonStringConverter converterTapiService = + new JsonStringConverter<>(bindingDOMCodecServices); + LOG.info("tapi converter: {}", converterTapiService); + topicManager.setTapiConverter(converterTapiService); - /** - * Method called when the blueprint container is created. - */ - public void init() { + rpcRegistration = rpcProviderService.registerRpcImplementations( + new GetNotificationsProcessServiceImpl(converterService, subscriberServer), + new GetNotificationsAlarmServiceImpl(converterAlarmService, subscriberServer), + new GetSupportedNotificationTypesImpl(this), + new CreateNotificationSubscriptionServiceImpl(this, topicManager), + new DeleteNotificationSubscriptionServiceImpl(networkTransactionService, topicManager), + new GetNotificationSubscriptionServiceDetailsImpl(this), + new GetNotificationSubscriptionServiceListImpl(this), + new GetNotificationListImpl(converterTapiService, subscriberServer, networkTransactionService, + topicManager)); + + NbiNotificationsHandler notificationsListener = new NbiNotificationsHandler( + topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap()); + listenerRegistration = notificationService.registerCompositeListener( + notificationsListener.getCompositeListener()); + topicManager.setNbiNotificationsListener(notificationsListener); + publishersServiceMap = topicManager.getProcessTopicMap(); + publishersAlarmMap = topicManager.getAlarmTopicMap(); LOG.info("NbiNotificationsProvider Session Initiated"); - NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService, - converterTapiService, subscriberServer, this.networkTransactionService, this.topicManager); - rpcRegistration = rpcService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl); - rpcService.registerRpcImplementation(TapiNotificationService.class, nbiImpl); - NbiNotificationsListenerImpl nbiNotificationsListener = - new NbiNotificationsListenerImpl(this.topicManager.getProcessTopicMap(), - this.topicManager.getAlarmTopicMap(), this.topicManager.getTapiTopicMap()); - listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener); - this.topicManager.setNbiNotificationsListener(nbiNotificationsListener); } /** * Method called when the blueprint container is destroyed. */ + @Deactivate public void close() { for (Publisher publisher : publishersServiceMap.values()) { publisher.close(); @@ -104,4 +138,40 @@ public class NbiNotificationsProvider { LOG.info("NbiNotificationsProvider Closed"); } + public NotificationContext getNotificationContext() { + LOG.info("Getting tapi notification context"); + try { + Optional notificationContextOptional = this.networkTransactionService.read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.builder(Context.class) + .augmentation(Context1.class).child(NotificationContext.class) + .build()) + .get(); + if (notificationContextOptional.isPresent()) { + return notificationContextOptional.orElseThrow(); + } + LOG.debug("notification context is empty"); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Caught exception getting Notification Context", e); + } + LOG.error("Could not get TAPI notification context"); + return null; + } + + public boolean updateNotificationContext(NotificationContext notificationContext1) { + try { + this.networkTransactionService.merge( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.builder(Context.class) + .augmentation(Context1.class).child(NotificationContext.class) + .build(), + notificationContext1); + this.networkTransactionService.commit().get(); + return true; + } catch (InterruptedException | ExecutionException e) { + LOG.error("Could not update TAPI notification context"); + } + return false; + } + }