From 2ad2790ecabcb389c87e7e7003a833e73431d41f Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Wed, 13 Mar 2024 17:47:09 +0100 Subject: [PATCH] Refactor nbinotifications Signed-off-by: guillaume.lambert Change-Id: I2c1e78e2712b26825cd7fe56060779a0622f5d11 --- ...teNotificationSubscriptionServiceImpl.java | 75 ++++++++++--------- ...teNotificationSubscriptionServiceImpl.java | 38 +++++----- .../impl/rpc/GetNotificationListImpl.java | 47 +++++------- ...icationSubscriptionServiceDetailsImpl.java | 38 ++++++---- ...tificationSubscriptionServiceListImpl.java | 25 ++++--- .../rpc/GetNotificationsAlarmServiceImpl.java | 17 +++-- .../GetNotificationsProcessServiceImpl.java | 19 ++--- .../impl/NbiNotificationsImplTest.java | 20 ++--- 8 files changed, 144 insertions(+), 135 deletions(-) diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/CreateNotificationSubscriptionServiceImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/CreateNotificationSubscriptionServiceImpl.java index 772fb20ae..b6b79f7ee 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/CreateNotificationSubscriptionServiceImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/CreateNotificationSubscriptionServiceImpl.java @@ -25,9 +25,10 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev22112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscription; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscriptionBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscriptionKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.Notification; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotificationKey; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.subscription.service.SubscriptionFilter; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.subscription.service.SubscriptionFilterBuilder; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.subscription.service.SubscriptionFilterKey; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -50,10 +51,11 @@ public class CreateNotificationSubscriptionServiceImpl implements CreateNotifica @Override public ListenableFuture> invoke( CreateNotificationSubscriptionServiceInput input) { - for (Uuid uuid:input.getSubscriptionFilter().getRequestedObjectIdentifier()) { + for (Uuid uuid : input.getSubscriptionFilter().getRequestedObjectIdentifier()) { LOG.info("Adding T-API topic: {} to Kafka server", uuid.getValue()); this.topicManager.addTapiTopic(uuid.getValue()); } + Uuid notifSubscriptionUuid = new Uuid(UUID.randomUUID().toString()); SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder() .setName(input.getSubscriptionFilter().getName()) .setLocalId(input.getSubscriptionFilter().getLocalId()) @@ -63,45 +65,48 @@ public class CreateNotificationSubscriptionServiceImpl implements CreateNotifica .setRequestedObjectIdentifier(input.getSubscriptionFilter().getRequestedObjectIdentifier()) .setRequestedObjectTypes(input.getSubscriptionFilter().getRequestedObjectTypes()) .build(); - Uuid notifSubscriptionUuid = new Uuid(UUID.randomUUID().toString()); - Map sfmap = new HashMap<>(); - sfmap.put(subscriptionFilter.key(), subscriptionFilter); SubscriptionService subscriptionService = new SubscriptionServiceBuilder() - .setSubscriptionFilter(sfmap) - .setSubscriptionState(input.getSubscriptionState()) .setUuid(notifSubscriptionUuid) + .setSubscriptionFilter(new HashMap<>(Map.of(subscriptionFilter.key(), subscriptionFilter))) + .setSubscriptionState(input.getSubscriptionState()) .build(); - - NotifSubscriptionKey notifSubscriptionKey = new NotifSubscriptionKey(notifSubscriptionUuid); - NotifSubscription notifSubscription = new NotifSubscriptionBuilder() - .setSubscriptionState(subscriptionService.getSubscriptionState()) - .setSubscriptionFilter(subscriptionService.getSubscriptionFilter()) - .setUuid(notifSubscriptionUuid) + Map notifSubscriptions = new HashMap<>(Map.of( + new NotifSubscriptionKey(notifSubscriptionUuid), + new NotifSubscriptionBuilder() + .setSubscriptionState(subscriptionService.getSubscriptionState()) + .setSubscriptionFilter(subscriptionService.getSubscriptionFilter()) + .setUuid(notifSubscriptionUuid) // Following 2 items are no more in notification-context with T-API 2.4 -// .setSupportedNotificationTypes(notificationTypes) -// .setSupportedObjectTypes(objectTypes) - .setName(subscriptionService.getName()) - .build(); +// .setSupportedNotificationTypes(notificationTypes) +// .setSupportedObjectTypes(objectTypes) + .setName(subscriptionService.getName()) + .build())); + Map notifications; NotificationContext notificationContext = nbiNotifications.getNotificationContext(); - Map notifSubscriptions = new HashMap<>(); - if (notificationContext != null && notificationContext.getNotifSubscription() != null) { - notifSubscriptions.putAll(notificationContext.getNotifSubscription()); + if (notificationContext == null) { + notifications = new HashMap<>(); + } else { + notifications = notificationContext.getNotification(); + var subsc = notificationContext.getNotifSubscription(); + if (subsc != null) { + notifSubscriptions.putAll(subsc); + } } - notifSubscriptions.put(notifSubscriptionKey, notifSubscription); - NotificationContext notificationContext1 = new NotificationContextBuilder() - .setNotification(notificationContext == null ? new HashMap<>() : notificationContext.getNotification()) - .setNotifSubscription(notifSubscriptions) - .build(); - if (!nbiNotifications.updateNotificationContext(notificationContext1)) { - LOG.error("Failed to update Notification context"); - return RpcResultBuilder.failed() - .withError(ErrorType.RPC, "Failed to update notification context").buildFuture(); + if (nbiNotifications.updateNotificationContext( + new NotificationContextBuilder() + .setNotification(notifications) + .setNotifSubscription(notifSubscriptions) + .build())) { + return RpcResultBuilder + .success( + new CreateNotificationSubscriptionServiceOutputBuilder() + .setSubscriptionService(subscriptionService) + .build()) + .buildFuture(); } - CreateNotificationSubscriptionServiceOutput serviceOutput = - new CreateNotificationSubscriptionServiceOutputBuilder() - .setSubscriptionService(subscriptionService) - .build(); - return RpcResultBuilder.success(serviceOutput).buildFuture(); + LOG.error("Failed to update Notification context"); + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, "Failed to update notification context") + .buildFuture(); } - } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/DeleteNotificationSubscriptionServiceImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/DeleteNotificationSubscriptionServiceImpl.java index 68e13fde2..726d9c67a 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/DeleteNotificationSubscriptionServiceImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/DeleteNotificationSubscriptionServiceImpl.java @@ -41,8 +41,8 @@ public class DeleteNotificationSubscriptionServiceImpl implements DeleteNotifica private final NetworkTransactionService networkTransactionService; private final TopicManager topicManager; - public DeleteNotificationSubscriptionServiceImpl(NetworkTransactionService networkTransactionService, - TopicManager topicManager) { + public DeleteNotificationSubscriptionServiceImpl( + NetworkTransactionService networkTransactionService, TopicManager topicManager) { this.networkTransactionService = networkTransactionService; this.topicManager = topicManager; } @@ -54,40 +54,40 @@ public class DeleteNotificationSubscriptionServiceImpl implements DeleteNotifica if (input == null || input.getUuid() == null) { LOG.warn("Missing mandatory params for input {}", input); return RpcResultBuilder.failed() - .withError(ErrorType.RPC, "Missing input parameters").buildFuture(); + .withError(ErrorType.RPC, "Missing input parameters") + .buildFuture(); } Uuid notifSubsUuid = input.getUuid(); InstanceIdentifier notifSubscriptionIID = InstanceIdentifier.builder(Context.class) - .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class, - new NotifSubscriptionKey(notifSubsUuid)).build(); - Optional optionalNotifSub = this.networkTransactionService.read( - LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get(); - + .augmentation(Context1.class) + .child(NotificationContext.class) + .child(NotifSubscription.class, new NotifSubscriptionKey(notifSubsUuid)) + .build(); + Optional optionalNotifSub = this.networkTransactionService + .read(LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID) + .get(); if (optionalNotifSub.isEmpty()) { return RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Notification subscription doesnt exist").buildFuture(); + .withError(ErrorType.APPLICATION, "Notification subscription doesnt exist") + .buildFuture(); } NotifSubscription notifSubscription = optionalNotifSub.orElseThrow(); this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID); this.networkTransactionService.commit().get(); - for (Map.Entry sfEntry : notifSubscription - .getSubscriptionFilter().entrySet()) { + for (Map.Entry sfEntry : + notifSubscription.getSubscriptionFilter().entrySet()) { for (Uuid objectUuid:sfEntry.getValue().getRequestedObjectIdentifier()) { this.topicManager.deleteTapiTopic(objectUuid.getValue()); } } -// for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) { -// this.topicManager.deleteTapiTopic(objectUuid.getValue()); -// } - return RpcResultBuilder.success(new DeleteNotificationSubscriptionServiceOutputBuilder().build()) + return RpcResultBuilder + .success(new DeleteNotificationSubscriptionServiceOutputBuilder().build()) .buildFuture(); } catch (InterruptedException | ExecutionException | NoSuchElementException e) { LOG.error("Failed to delete Notification subscription service", e); } return RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Failed to delete notification subscription service").buildFuture(); + .withError(ErrorType.APPLICATION, "Failed to delete notification subscription service") + .buildFuture(); } - } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationListImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationListImpl.java index 72a145a72..acfc4bf5f 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationListImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationListImpl.java @@ -67,25 +67,28 @@ public class GetNotificationListImpl implements GetNotificationList { LOG.info("RPC getNotificationList received"); if (input == null || input.getSubscriptionId() == null) { LOG.warn("Missing mandatory params for input {}", input); - return RpcResultBuilder.failed().withError(ErrorType.RPC, - "Missing input parameters").buildFuture(); + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, "Missing input parameters") + .buildFuture(); } Uuid notifSubsUuid = input.getSubscriptionId(); - InstanceIdentifier notifSubscriptionIID = InstanceIdentifier.builder(Context.class) - .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class, - new NotifSubscriptionKey(notifSubsUuid)).build(); - Optional optionalNotifSub = this.networkTransactionService.read( - LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get(); - + Optional optionalNotifSub = this.networkTransactionService + .read( + LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.builder(Context.class).augmentation(Context1.class) + .child(NotificationContext.class) + .child(NotifSubscription.class, new NotifSubscriptionKey(notifSubsUuid)) + .build()) + .get(); if (optionalNotifSub.isEmpty()) { return RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Notification subscription doesnt exist").buildFuture(); + .withError(ErrorType.APPLICATION, "Notification subscription doesnt exist") + .buildFuture(); } NotifSubscription notifSubscription = optionalNotifSub.orElseThrow(); List notificationTapiList = new ArrayList<>(); - for (Map.Entry sfEntry : notifSubscription - .getSubscriptionFilter().entrySet()) { + for (Map.Entry sfEntry : + notifSubscription.getSubscriptionFilter().entrySet()) { for (Uuid objectUuid:sfEntry.getValue().getRequestedObjectIdentifier()) { if (!this.topicManager.getTapiTopicMap().containsKey(objectUuid.getValue())) { LOG.warn("Topic doesnt exist for {}", objectUuid.getValue()); @@ -98,30 +101,20 @@ public class GetNotificationListImpl implements GetNotificationList { notificationTapiList.addAll(subscriber.subscribe(objectUuid.getValue(), Notification.QNAME)); } } -// for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) { -// if (!this.topicManager.getTapiTopicMap().containsKey(objectUuid.getValue())) { -// LOG.warn("Topic doesnt exist for {}", objectUuid.getValue()); -// continue; -// } -// LOG.info("Going to get notifications for topic {}", objectUuid.getValue()); -// Subscriber subscriber = new Subscriber<>( -// objectUuid.getValue(), objectUuid.getValue(), server, converterTapiService, -// TapiNotificationDeserializer.class); -// notificationTapiList.addAll(subscriber.subscribe(objectUuid.getValue(), Notification.QNAME)); -// } LOG.info("TAPI notifications = {}", notificationTapiList); Map notificationMap = new HashMap<>(); for (Notification notif:notificationTapiList) { notificationMap.put(notif.key(), notif); } - return RpcResultBuilder.success(new GetNotificationListOutputBuilder() - .setNotification(notificationMap).build()).buildFuture(); + return RpcResultBuilder + .success(new GetNotificationListOutputBuilder().setNotification(notificationMap).build()) + .buildFuture(); } catch (InterruptedException | ExecutionException | NoSuchElementException e) { LOG.error("Failed to get Notifications from Kafka", e); } return RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Notifications couldnt be retrieved from Kafka server").buildFuture(); + .withError(ErrorType.APPLICATION, "Notifications couldnt be retrieved from Kafka server") + .buildFuture(); } } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceDetailsImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceDetailsImpl.java index 150616b17..e054bf4b7 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceDetailsImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceDetailsImpl.java @@ -15,6 +15,7 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev22112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetailsOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetailsOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.details.output.SubscriptionServiceBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscriptionKey; import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -38,7 +39,8 @@ public class GetNotificationSubscriptionServiceDetailsImpl implements GetNotific if (input == null || input.getUuid() == null) { LOG.warn("Missing mandatory params for input {}", input); return RpcResultBuilder.failed() - .withError(ErrorType.RPC, "Missing input parameters").buildFuture(); + .withError(ErrorType.RPC, "Missing input parameters") + .buildFuture(); } Uuid notifSubsUuid = input.getUuid(); NotificationContext notificationContext = nbiNotifications.getNotificationContext(); @@ -47,22 +49,28 @@ public class GetNotificationSubscriptionServiceDetailsImpl implements GetNotific .withError(ErrorType.APPLICATION, "Notification context is empty") .buildFuture(); } - if (notificationContext.getNotifSubscription() == null) { - return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder() - .setSubscriptionService(new org.opendaylight.yang.gen.v1 - .urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service - .details.output.SubscriptionServiceBuilder().build()).build()).buildFuture(); + var subsc = notificationContext.getNotifSubscription(); + if (subsc == null) { + return RpcResultBuilder + .success( + new GetNotificationSubscriptionServiceDetailsOutputBuilder() + .setSubscriptionService(new SubscriptionServiceBuilder().build()) + .build()) + .buildFuture(); } - if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) { - return RpcResultBuilder.failed() - .withError(ErrorType.APPLICATION, - "Notification subscription service doesnt exist").buildFuture(); + if (subsc.containsKey(new NotifSubscriptionKey(notifSubsUuid))) { + return RpcResultBuilder + .success( + new GetNotificationSubscriptionServiceDetailsOutputBuilder() + .setSubscriptionService( + new SubscriptionServiceBuilder(subsc.get(new NotifSubscriptionKey(notifSubsUuid))).build()) + .build()) + .buildFuture(); } - return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder() - .setSubscriptionService(new org.opendaylight.yang.gen.v1.urn - .onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.details.output - .SubscriptionServiceBuilder(notificationContext.getNotifSubscription().get( - new NotifSubscriptionKey(notifSubsUuid))).build()).build()).buildFuture(); + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "Notification subscription service doesnt exist") + .buildFuture(); + } } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceListImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceListImpl.java index 6eb004a84..b533ac95c 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceListImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationSubscriptionServiceListImpl.java @@ -16,6 +16,8 @@ import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev22112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceListOutput; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionServiceBuilder; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionServiceKey; import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.context.NotifSubscription; import org.opendaylight.yangtools.yang.common.ErrorType; @@ -41,22 +43,21 @@ public class GetNotificationSubscriptionServiceListImpl implements GetNotificati .buildFuture(); } if (notificationContext.getNotifSubscription() == null) { - return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder() - .setSubscriptionService(new HashMap<>()).build()).buildFuture(); + return RpcResultBuilder + .success(new GetNotificationSubscriptionServiceListOutputBuilder() + .setSubscriptionService(new HashMap<>()) + .build()) + .buildFuture(); } - Map - notifSubsMap = new HashMap<>(); + Map notifSubsMap = new HashMap<>(); for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) { - org.opendaylight.yang.gen.v1.urn.onf.otcc.yang - .tapi.notification.rev221121.get.notification.subscription.service.list.output.SubscriptionService - subscriptionService = new org.opendaylight.yang.gen.v1 - .urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.subscription.service - .list.output.SubscriptionServiceBuilder(notifSubscription).build(); + SubscriptionService subscriptionService = new SubscriptionServiceBuilder(notifSubscription).build(); notifSubsMap.put(subscriptionService.key(), subscriptionService); } - return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder() - .setSubscriptionService(notifSubsMap).build()).buildFuture(); + return RpcResultBuilder + .success( + new GetNotificationSubscriptionServiceListOutputBuilder().setSubscriptionService(notifSubsMap).build()) + .buildFuture(); } } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsAlarmServiceImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsAlarmServiceImpl.java index bf3b680d8..6dd12564c 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsAlarmServiceImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsAlarmServiceImpl.java @@ -8,7 +8,6 @@ package org.opendaylight.transportpce.nbinotifications.impl.rpc; import com.google.common.util.concurrent.ListenableFuture; -import java.util.List; import org.opendaylight.transportpce.common.converter.JsonStringConverter; import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber; import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceDeserializer; @@ -44,13 +43,15 @@ public class GetNotificationsAlarmServiceImpl implements GetNotificationsAlarmSe LOG.warn("Missing mandatory params for input {}", input); return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder().build()).buildFuture(); } - Subscriber subscriber = new Subscriber<>( - input.getIdConsumer(), input.getGroupId(), server, converterAlarmService, - NotificationAlarmServiceDeserializer.class); - List notificationAlarmServiceList = subscriber - .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME); - return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder() - .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture(); + return RpcResultBuilder + .success(new GetNotificationsAlarmServiceOutputBuilder() + .setNotificationsAlarmService( + new Subscriber( + input.getIdConsumer(), input.getGroupId(), server, converterAlarmService, + NotificationAlarmServiceDeserializer.class) + .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME)) + .build()) + .buildFuture(); } } diff --git a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsProcessServiceImpl.java b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsProcessServiceImpl.java index 3a2700f22..67e092b67 100644 --- a/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsProcessServiceImpl.java +++ b/nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/impl/rpc/GetNotificationsProcessServiceImpl.java @@ -8,7 +8,6 @@ package org.opendaylight.transportpce.nbinotifications.impl.rpc; import com.google.common.util.concurrent.ListenableFuture; -import java.util.List; import org.opendaylight.transportpce.common.converter.JsonStringConverter; import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber; import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceDeserializer; @@ -44,13 +43,15 @@ public class GetNotificationsProcessServiceImpl implements GetNotificationsProce LOG.warn("Missing mandatory params for input {}", input); return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder().build()).buildFuture(); } - Subscriber subscriber = new Subscriber<>( - input.getIdConsumer(), input.getGroupId(), server, converterService, - NotificationServiceDeserializer.class); - List notificationServiceList = subscriber - .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME); - return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder() - .setNotificationsProcessService(notificationServiceList).build()).buildFuture(); + return RpcResultBuilder + .success( + new GetNotificationsProcessServiceOutputBuilder() + .setNotificationsProcessService( + new Subscriber( + input.getIdConsumer(), input.getGroupId(), server, converterService, + NotificationServiceDeserializer.class) + .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME)) + .build()) + .buildFuture(); } - } diff --git a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java index 91b109b73..4bb418e84 100644 --- a/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java +++ b/nbinotifications/src/test/java/org/opendaylight/transportpce/nbinotifications/impl/NbiNotificationsImplTest.java @@ -76,16 +76,16 @@ public class NbiNotificationsImplTest extends AbstractTest { @Test void getNotificationsServiceEmptyDataTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080").invoke( - new GetNotificationsProcessServiceInputBuilder().build()); + new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080") + .invoke(new GetNotificationsProcessServiceInputBuilder().build()); assertNull(result.get().getResult().getNotificationsProcessService(), "Should be null"); } @Test void getNotificationsServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080") - .invoke(new GetNotificationsProcessServiceInputBuilder() + new GetNotificationsProcessServiceImpl(converterProcess, "localhost:8080") + .invoke(new GetNotificationsProcessServiceInputBuilder() .setGroupId("groupId") .setIdConsumer("consumerId") .setConnectionType(ConnectionType.Service) @@ -96,8 +96,8 @@ public class NbiNotificationsImplTest extends AbstractTest { @Test void getNotificationsAlarmServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - new GetNotificationsAlarmServiceImpl(converterAlarm, "localhost:8080") - .invoke(new GetNotificationsAlarmServiceInputBuilder() + new GetNotificationsAlarmServiceImpl(converterAlarm, "localhost:8080") + .invoke(new GetNotificationsAlarmServiceInputBuilder() .setGroupId("groupId") .setIdConsumer("consumerId") .setConnectionType(ConnectionType.Service) @@ -108,8 +108,8 @@ public class NbiNotificationsImplTest extends AbstractTest { @Test void createTapiNotificationSubscriptionServiceTest() throws InterruptedException, ExecutionException { ListenableFuture> result = - new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager) - .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build()); + new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager) + .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build()); assertNotNull(result.get().getResult().getSubscriptionService().getUuid().toString(), "Should receive UUID for subscription service"); } @@ -120,8 +120,8 @@ public class NbiNotificationsImplTest extends AbstractTest { new CreateNotificationSubscriptionServiceImpl(nbiNotifications, topicManager) .invoke(NotificationServiceDataUtils.buildNotificationSubscriptionServiceInputBuilder().build()); ListenableFuture> result2 = - new GetNotificationListImpl(converterTapi, "localhost:8080", networkTransactionService, topicManager) - .invoke(new GetNotificationListInputBuilder() + new GetNotificationListImpl(converterTapi, "localhost:8080", networkTransactionService, topicManager) + .invoke(new GetNotificationListInputBuilder() .setTimeRange(null) .setSubscriptionId(result.get().getResult().getSubscriptionService().getUuid()) .build()); -- 2.36.6