X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nbinotifications%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fnbinotifications%2Fimpl%2FNbiNotificationsImpl.java;h=8ee9e7b5864ec23c66f483ccc4d68a38c280403c;hb=8be42823a12d414dfa491305f4912bb642b6d5e2;hp=77f6f8552c3cf590a60f2d82cb0fb98a30f0de07;hpb=32dca3cd3f1894f783980b982ea4aaf527a274e2;p=transportpce.git 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 77f6f8552..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,39 +7,113 @@ */ 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; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +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.consumer.Subscriber; import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceDeserializer; import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceDeserializer; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceInput; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceOutput; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceOutputBuilder; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceInput; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceOutput; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceOutputBuilder; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.alarm.service.output.NotificationsAlarmService; -import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.process.service.output.NotificationsProcessService; +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; +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.nbi.notifications.rev211013.get.notifications.alarm.service.output.NotificationsAlarmService; +import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notifications.process.service.output.NotificationsProcessService; +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; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.context.NotificationContextBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.output.SubscriptionService; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.output.SubscriptionServiceBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.list.output.Notification; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.list.output.NotificationKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionServiceKey; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscription; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscriptionBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscriptionKey; +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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NbiNotificationsImpl implements NbiNotificationsService { +public class NbiNotificationsImpl implements NbiNotificationsService, TapiNotificationService { private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class); private final JsonStringConverter converterService; private final JsonStringConverter converterAlarmService; + private final JsonStringConverter converterTapiService; private final String server; + private final NetworkTransactionService networkTransactionService; + private final TopicManager topicManager; public NbiNotificationsImpl(JsonStringConverter converterService, - JsonStringConverter converterAlarmService, String server) { + JsonStringConverter converterAlarmService, + JsonStringConverter converterTapiService, String server, + NetworkTransactionService networkTransactionService, TopicManager topicManager) { this.converterService = converterService; this.converterAlarmService = converterAlarmService; + this.converterTapiService = converterTapiService; this.server = server; + this.networkTransactionService = networkTransactionService; + this.topicManager = topicManager; } @Override @@ -75,4 +149,306 @@ public class NbiNotificationsImpl implements NbiNotificationsService { return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder() .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture(); } + + @Override + public ListenableFuture> + getSupportedNotificationTypes(GetSupportedNotificationTypesInput input) { + NotificationContext notificationContext = getNotificationContext(); + if (notificationContext == null) { + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "Couldnt get Notification Context from Datastore") + .buildFuture(); + } + if (notificationContext.getNotifSubscription() == null) { + return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder() + .setSupportedNotificationTypes(new HashSet<>()) + .setSupportedObjectTypes(new HashSet<>()).build()).buildFuture(); + } + Set notificationTypeList = new HashSet<>(); + Set objectTypeList = new HashSet<>(); + for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) { + if (notifSubscription.getSupportedNotificationTypes() != null) { + notificationTypeList.addAll(notifSubscription.getSupportedNotificationTypes()); + } + if (notifSubscription.getSupportedObjectTypes() != null) { + objectTypeList.addAll(notifSubscription.getSupportedObjectTypes()); + } + } + return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder() + .setSupportedNotificationTypes(notificationTypeList) + .setSupportedObjectTypes(objectTypeList).build()).buildFuture(); + } + + @Override + public ListenableFuture> + createNotificationSubscriptionService(CreateNotificationSubscriptionServiceInput input) { + for (Uuid uuid:input.getSubscriptionFilter().getRequestedObjectIdentifier()) { + LOG.info("Adding T-API topic: {} to Kafka server", uuid.getValue()); + this.topicManager.addTapiTopic(uuid.getValue()); + } + SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder() + .setName(input.getSubscriptionFilter().getName()) + .setLocalId(input.getSubscriptionFilter().getLocalId()) + .setIncludeContent(input.getSubscriptionFilter().getIncludeContent()) + .setRequestedNotificationTypes(input.getSubscriptionFilter().getRequestedNotificationTypes()) + .setRequestedLayerProtocols(input.getSubscriptionFilter().getRequestedLayerProtocols()) + .setRequestedObjectIdentifier(input.getSubscriptionFilter().getRequestedObjectIdentifier()) + .setRequestedObjectTypes(input.getSubscriptionFilter().getRequestedObjectTypes()) + .build(); + Uuid notifSubscriptionUuid = new Uuid(UUID.randomUUID().toString()); + SubscriptionService subscriptionService = new SubscriptionServiceBuilder() + .setSubscriptionFilter(subscriptionFilter) + .setSubscriptionState(input.getSubscriptionState()) + .setUuid(notifSubscriptionUuid) + .build(); + + NotifSubscriptionKey notifSubscriptionKey = new NotifSubscriptionKey(notifSubscriptionUuid); + Set notificationTypes = (subscriptionFilter.getRequestedNotificationTypes() != null) + ? subscriptionFilter.getRequestedNotificationTypes() + : new HashSet<>(List.of(NotificationType.ALARMEVENT)); + Set objectTypes = (subscriptionFilter.getRequestedObjectTypes() != null) + ? subscriptionFilter.getRequestedObjectTypes() + : new HashSet<>(List.of(ObjectType.CONNECTIVITYSERVICE)); + NotifSubscription notifSubscription = new NotifSubscriptionBuilder() + .setSubscriptionState(subscriptionService.getSubscriptionState()) + .setSubscriptionFilter(subscriptionService.getSubscriptionFilter()) + .setUuid(notifSubscriptionUuid) + .setSupportedNotificationTypes(notificationTypes) + .setSupportedObjectTypes(objectTypes) + .setName(subscriptionService.getName()) + .build(); + NotificationContext notificationContext = getNotificationContext(); + Map notifSubscriptions = new HashMap<>(); + if (notificationContext != null && notificationContext.getNotifSubscription() != null) { + notifSubscriptions.putAll(notificationContext.getNotifSubscription()); + } + notifSubscriptions.put(notifSubscriptionKey, notifSubscription); + NotificationContext notificationContext1 = new NotificationContextBuilder() + .setNotification(notificationContext == null ? new HashMap<>() : notificationContext.getNotification()) + .setNotifSubscription(notifSubscriptions) + .build(); + if (!updateNotificationContext(notificationContext1)) { + LOG.error("Failed to update Notification context"); + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, "Failed to update notification context").buildFuture(); + } + CreateNotificationSubscriptionServiceOutput serviceOutput = + new CreateNotificationSubscriptionServiceOutputBuilder() + .setSubscriptionService(subscriptionService) + .build(); + return RpcResultBuilder.success(serviceOutput).buildFuture(); + } + + @Override + public ListenableFuture> + updateNotificationSubscriptionService(UpdateNotificationSubscriptionServiceInput input) { + // TODO --> Not yet implemented + return null; + } + + @Override + public ListenableFuture> + deleteNotificationSubscriptionService(DeleteNotificationSubscriptionServiceInput input) { + try { + if (input == null || input.getSubscriptionIdOrName() == null) { + LOG.warn("Missing mandatory params for input {}", input); + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, "Missing input parameters").buildFuture(); + } + Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName()); + 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(); + + if (!optionalNotifSub.isPresent()) { + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, + "Notification subscription doesnt exist").buildFuture(); + } + NotifSubscription notifSubscription = optionalNotifSub.orElseThrow(); + this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID); + this.networkTransactionService.commit().get(); + for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) { + this.topicManager.deleteTapiTopic(objectUuid.getValue()); + } + 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(); + } + + @Override + public ListenableFuture> + getNotificationSubscriptionServiceDetails(GetNotificationSubscriptionServiceDetailsInput input) { + if (input == null || input.getSubscriptionIdOrName() == null) { + LOG.warn("Missing mandatory params for input {}", input); + return RpcResultBuilder.failed() + .withError(ErrorType.RPC, "Missing input parameters").buildFuture(); + } + Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName()); + NotificationContext notificationContext = getNotificationContext(); + if (notificationContext == null) { + return RpcResultBuilder.failed() + .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.rev181210.get.notification.subscription.service + .details.output.SubscriptionServiceBuilder().build()).build()).buildFuture(); + } + if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) { + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, + "Notification subscription service doesnt exist").buildFuture(); + } + return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder() + .setSubscriptionService(new org.opendaylight.yang.gen.v1.urn + .onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service.details.output + .SubscriptionServiceBuilder(notificationContext.getNotifSubscription().get( + new NotifSubscriptionKey(notifSubsUuid))).build()).build()).buildFuture(); + } + + @Override + public ListenableFuture> + getNotificationSubscriptionServiceList(GetNotificationSubscriptionServiceListInput input) { + NotificationContext notificationContext = getNotificationContext(); + if (notificationContext == null) { + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, "Notification context is empty") + .buildFuture(); + } + if (notificationContext.getNotifSubscription() == null) { + return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder() + .setSubscriptionService(new HashMap<>()).build()).buildFuture(); + } + Map + notifSubsMap = new HashMap<>(); + for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) { + org.opendaylight.yang.gen.v1.urn.onf.otcc.yang + .tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionService + subscriptionService = new org.opendaylight.yang.gen.v1 + .urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service + .list.output.SubscriptionServiceBuilder(notifSubscription).build(); + notifSubsMap.put(subscriptionService.key(), subscriptionService); + } + return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder() + .setSubscriptionService(notifSubsMap).build()).buildFuture(); + } + + @Override + public ListenableFuture> getNotificationList(GetNotificationListInput input) { + try { + LOG.info("RPC getNotificationList received"); + if (input == null || input.getSubscriptionIdOrName() == null) { + LOG.warn("Missing mandatory params for input {}", input); + return RpcResultBuilder.failed().withError(ErrorType.RPC, + "Missing input parameters").buildFuture(); + } + Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName()); + 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(); + + if (!optionalNotifSub.isPresent()) { + return RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, + "Notification subscription doesnt exist").buildFuture(); + } + NotifSubscription notifSubscription = optionalNotifSub.orElseThrow(); + List notificationTapiList = new ArrayList<>(); + 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(); + } 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(); + } + + 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 { + InstanceIdentifier notificationcontextIID = + InstanceIdentifier.builder(Context.class).augmentation(Context1.class) + .child(NotificationContext.class).build(); + Optional notificationContextOptional + = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, notificationcontextIID).get(); + if (!notificationContextOptional.isPresent()) { + LOG.error("Could not get TAPI notification context"); + return null; + } + return notificationContextOptional.orElseThrow(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Could not get TAPI notification context"); + } + return null; + } + + private boolean updateNotificationContext(NotificationContext notificationContext1) { + try { + InstanceIdentifier notificationcontextIID = + InstanceIdentifier.builder(Context.class).augmentation(Context1.class) + .child(NotificationContext.class).build(); + this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, notificationcontextIID, + notificationContext1); + this.networkTransactionService.commit().get(); + return true; + } catch (InterruptedException | ExecutionException e) { + LOG.error("Could not update TAPI notification context"); + } + return false; + } + + private Uuid getUuidFromIput(String serviceIdOrName) { + try { + UUID.fromString(serviceIdOrName); + LOG.info("Given attribute {} is a UUID", serviceIdOrName); + return new Uuid(serviceIdOrName); + } catch (IllegalArgumentException e) { + LOG.info("Given attribute {} is not a UUID", serviceIdOrName); + return new Uuid(UUID.nameUUIDFromBytes(serviceIdOrName.getBytes(StandardCharsets.UTF_8)).toString()); + } + } }