From 8be42823a12d414dfa491305f4912bb642b6d5e2 Mon Sep 17 00:00:00 2001 From: Gilles Thouenon Date: Sun, 1 Oct 2023 19:42:14 +0200 Subject: [PATCH] Do not use RpcService in nbinotifications module - Migrate usage of RpcService to the new style yang.binding.Rpc-based implementation for nbinotifications module - Adapt lighty implementation JIRA: TRNSPRTPCE-752 Signed-off-by: Gilles Thouenon Change-Id: I4d52f8849ea6f2b31ef778f1254fc2899828020c --- .../tpce/module/TransportPCEImpl.java | 6 ++--- .../impl/NbiNotificationsImpl.java | 25 +++++++++++++++++++ .../impl/NbiNotificationsProvider.java | 12 +++------ .../impl/NbiNotificationsProviderTest.java | 5 ++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java index b93e5c4b6..e629a152c 100644 --- a/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java +++ b/lighty/src/main/java/io/lighty/controllers/tpce/module/TransportPCEImpl.java @@ -206,9 +206,9 @@ public class TransportPCEImpl extends AbstractLightyModule implements TransportP if (activateNbiNotification) { LOG.info("Creating nbi-notifications beans ..."); nbiNotificationsProvider = new NbiNotificationsProvider( - null, null, lgServRPS, - lgServNS, lightyServices.getAdapterContext().currentSerializer(), - networkTransaction); + lgServRPS, lgServNS, + lightyServices.getAdapterContext().currentSerializer(), + networkTransaction, null); } } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java index c1ea55773..8ee9e7b58 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImpl.java @@ -7,6 +7,7 @@ */ package org.opendaylight.transportpce.nbinotifications.impl; +import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.ListenableFuture; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -27,9 +28,11 @@ import org.opendaylight.transportpce.nbinotifications.serialization.Notification import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceDeserializer; import org.opendaylight.transportpce.nbinotifications.serialization.TapiNotificationDeserializer; import org.opendaylight.transportpce.nbinotifications.utils.TopicManager; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceInput; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutput; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutputBuilder; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessService; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceInput; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutput; import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutputBuilder; @@ -42,27 +45,34 @@ import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notification import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.Context1; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionService; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionService; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationList; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetails; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceList; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypes; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.NotificationType; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.ObjectType; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionService; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionServiceInput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionServiceOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.context.NotificationContext; @@ -78,6 +88,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev18121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.subscription.service.SubscriptionFilter; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.subscription.service.SubscriptionFilterBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Rpc; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -382,6 +393,20 @@ public class NbiNotificationsImpl implements NbiNotificationsService, TapiNotifi "Notifications couldnt be retrieved from Kafka server").buildFuture(); } + public ImmutableClassToInstanceMap> registerRPCs() { + return ImmutableClassToInstanceMap.>builder() + .put(GetNotificationsProcessService.class, this::getNotificationsProcessService) + .put(GetNotificationsAlarmService.class, this::getNotificationsAlarmService) + .put(GetSupportedNotificationTypes.class, this::getSupportedNotificationTypes) + .put(CreateNotificationSubscriptionService.class, this::createNotificationSubscriptionService) + .put(UpdateNotificationSubscriptionService.class, this::updateNotificationSubscriptionService) + .put(DeleteNotificationSubscriptionService.class, this::deleteNotificationSubscriptionService) + .put(GetNotificationSubscriptionServiceDetails.class, this::getNotificationSubscriptionServiceDetails) + .put(GetNotificationSubscriptionServiceList.class, this::getNotificationSubscriptionServiceList) + .put(GetNotificationList.class, this::getNotificationList) + .build(); + } + private NotificationContext getNotificationContext() { LOG.info("Getting tapi notification context"); try { 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 ac4c6ef8e..f1caef3f5 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,7 +7,6 @@ */ package org.opendaylight.transportpce.nbinotifications.impl; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,13 +19,11 @@ import org.opendaylight.transportpce.nbinotifications.listener.NbiNotificationsL 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.yangtools.concepts.Registration; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -51,7 +48,7 @@ public class NbiNotificationsProvider { private static Map> publishersServiceMap = new HashMap<>(); private static Map> publishersAlarmMap = new HashMap<>(); private ListenerRegistration listenerRegistration; - private List> rpcRegistrations = new ArrayList<>(); + private Registration rpcRegistration; @Activate public NbiNotificationsProvider(@Reference RpcProviderService rpcProviderService, @@ -92,8 +89,7 @@ public class NbiNotificationsProvider { NbiNotificationsImpl nbiImpl = new NbiNotificationsImpl(converterService, converterAlarmService, converterTapiService, subscriberServer, networkTransactionService, topicManager); - rpcRegistrations.add(rpcProviderService.registerRpcImplementation(NbiNotificationsService.class, nbiImpl)); - rpcRegistrations.add(rpcProviderService.registerRpcImplementation(TapiNotificationService.class, nbiImpl)); + rpcRegistration = rpcProviderService.registerRpcImplementations(nbiImpl.registerRPCs()); NbiNotificationsListenerImpl nbiNotificationsListener = new NbiNotificationsListenerImpl( topicManager.getProcessTopicMap(), topicManager.getAlarmTopicMap(), topicManager.getTapiTopicMap()); listenerRegistration = notificationService.registerNotificationListener(nbiNotificationsListener); @@ -112,7 +108,7 @@ public class NbiNotificationsProvider { for (Publisher publisherAlarm : publishersAlarmMap.values()) { publisherAlarm.close(); } - rpcRegistrations.forEach(reg -> reg.close()); + rpcRegistration.close(); listenerRegistration.close(); LOG.info("NbiNotificationsProvider Closed"); } diff --git a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProviderTest.java b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProviderTest.java index 68a93c328..2b37bb5a3 100644 --- a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProviderTest.java +++ b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsProviderTest.java @@ -38,11 +38,10 @@ public class NbiNotificationsProviderTest extends AbstractTest { @Test void initTest() { networkTransactionService = new NetworkTransactionImpl(getDataBroker()); - NbiNotificationsProvider provider = new NbiNotificationsProvider("localhost:8080", "localhost:8080", + new NbiNotificationsProvider("localhost:8080", "localhost:8080", rpcProviderRegistry, notificationService, getDataStoreContextUtil().getBindingDOMCodecServices(), networkTransactionService); - verify(rpcProviderRegistry, times(2)) - .registerRpcImplementation(any(), any(NbiNotificationsImpl.class)); + verify(rpcProviderRegistry, times(1)).registerRpcImplementations(any()); verify(notificationService, times(1)) .registerNotificationListener(any(NbiNotificationsListenerImpl.class)); } -- 2.36.6