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 com.google.common.collect.ImmutableClassToInstanceMap;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.nio.charset.StandardCharsets;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.NoSuchElementException;
19 import java.util.Optional;
21 import java.util.UUID;
22 import java.util.concurrent.ExecutionException;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
25 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
26 import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber;
27 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceDeserializer;
28 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceDeserializer;
29 import org.opendaylight.transportpce.nbinotifications.serialization.TapiNotificationDeserializer;
30 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmService;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceInput;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutput;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsAlarmServiceOutputBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessService;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceInput;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutput;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.GetNotificationsProcessServiceOutputBuilder;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsService;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationAlarmService;
41 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationProcessService;
42 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NotificationTapiService;
43 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notifications.alarm.service.output.NotificationsAlarmService;
44 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.get.notifications.process.service.output.NotificationsProcessService;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.Context1;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionService;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceInput;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutput;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.CreateNotificationSubscriptionServiceOutputBuilder;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionService;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceInput;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceOutput;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.DeleteNotificationSubscriptionServiceOutputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationList;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListInput;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutput;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationListOutputBuilder;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetails;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsInput;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsOutput;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceDetailsOutputBuilder;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceList;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListInput;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListOutput;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetNotificationSubscriptionServiceListOutputBuilder;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypes;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesInput;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesOutput;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.GetSupportedNotificationTypesOutputBuilder;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.NotificationType;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.ObjectType;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.TapiNotificationService;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionService;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionServiceInput;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.UpdateNotificationSubscriptionServiceOutput;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.context.NotificationContext;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.context.NotificationContextBuilder;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.output.SubscriptionService;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.create.notification.subscription.service.output.SubscriptionServiceBuilder;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.list.output.Notification;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.list.output.NotificationKey;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionServiceKey;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscription;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscriptionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.context.NotifSubscriptionKey;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.subscription.service.SubscriptionFilter;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev181210.notification.subscription.service.SubscriptionFilterBuilder;
90 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
91 import org.opendaylight.yangtools.yang.binding.Rpc;
92 import org.opendaylight.yangtools.yang.common.ErrorType;
93 import org.opendaylight.yangtools.yang.common.RpcResult;
94 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
95 import org.slf4j.Logger;
96 import org.slf4j.LoggerFactory;
98 public class NbiNotificationsImpl implements NbiNotificationsService, TapiNotificationService {
99 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class);
100 private final JsonStringConverter<NotificationProcessService> converterService;
101 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
102 private final JsonStringConverter<NotificationTapiService> converterTapiService;
103 private final String server;
104 private final NetworkTransactionService networkTransactionService;
105 private final TopicManager topicManager;
107 public NbiNotificationsImpl(JsonStringConverter<NotificationProcessService> converterService,
108 JsonStringConverter<NotificationAlarmService> converterAlarmService,
109 JsonStringConverter<NotificationTapiService> converterTapiService, String server,
110 NetworkTransactionService networkTransactionService, TopicManager topicManager) {
111 this.converterService = converterService;
112 this.converterAlarmService = converterAlarmService;
113 this.converterTapiService = converterTapiService;
114 this.server = server;
115 this.networkTransactionService = networkTransactionService;
116 this.topicManager = topicManager;
120 public ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> getNotificationsProcessService(
121 GetNotificationsProcessServiceInput input) {
122 LOG.info("RPC getNotificationsService received");
123 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
124 LOG.warn("Missing mandatory params for input {}", input);
125 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder().build()).buildFuture();
127 Subscriber<NotificationProcessService, NotificationsProcessService> subscriber = new Subscriber<>(
128 input.getIdConsumer(), input.getGroupId(), server, converterService,
129 NotificationServiceDeserializer.class);
130 List<NotificationsProcessService> notificationServiceList = subscriber
131 .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME);
132 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder()
133 .setNotificationsProcessService(notificationServiceList).build()).buildFuture();
137 public ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> getNotificationsAlarmService(
138 GetNotificationsAlarmServiceInput input) {
139 LOG.info("RPC getNotificationsAlarmService received");
140 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
141 LOG.warn("Missing mandatory params for input {}", input);
142 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder().build()).buildFuture();
144 Subscriber<NotificationAlarmService, NotificationsAlarmService> subscriber = new Subscriber<>(
145 input.getIdConsumer(), input.getGroupId(), server, converterAlarmService,
146 NotificationAlarmServiceDeserializer.class);
147 List<NotificationsAlarmService> notificationAlarmServiceList = subscriber
148 .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME);
149 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder()
150 .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture();
154 public ListenableFuture<RpcResult<GetSupportedNotificationTypesOutput>>
155 getSupportedNotificationTypes(GetSupportedNotificationTypesInput input) {
156 NotificationContext notificationContext = getNotificationContext();
157 if (notificationContext == null) {
158 return RpcResultBuilder.<GetSupportedNotificationTypesOutput>failed()
159 .withError(ErrorType.APPLICATION, "Couldnt get Notification Context from Datastore")
162 if (notificationContext.getNotifSubscription() == null) {
163 return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder()
164 .setSupportedNotificationTypes(new HashSet<>())
165 .setSupportedObjectTypes(new HashSet<>()).build()).buildFuture();
167 Set<NotificationType> notificationTypeList = new HashSet<>();
168 Set<ObjectType> objectTypeList = new HashSet<>();
169 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
170 if (notifSubscription.getSupportedNotificationTypes() != null) {
171 notificationTypeList.addAll(notifSubscription.getSupportedNotificationTypes());
173 if (notifSubscription.getSupportedObjectTypes() != null) {
174 objectTypeList.addAll(notifSubscription.getSupportedObjectTypes());
177 return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder()
178 .setSupportedNotificationTypes(notificationTypeList)
179 .setSupportedObjectTypes(objectTypeList).build()).buildFuture();
183 public ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>>
184 createNotificationSubscriptionService(CreateNotificationSubscriptionServiceInput input) {
185 for (Uuid uuid:input.getSubscriptionFilter().getRequestedObjectIdentifier()) {
186 LOG.info("Adding T-API topic: {} to Kafka server", uuid.getValue());
187 this.topicManager.addTapiTopic(uuid.getValue());
189 SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder()
190 .setName(input.getSubscriptionFilter().getName())
191 .setLocalId(input.getSubscriptionFilter().getLocalId())
192 .setIncludeContent(input.getSubscriptionFilter().getIncludeContent())
193 .setRequestedNotificationTypes(input.getSubscriptionFilter().getRequestedNotificationTypes())
194 .setRequestedLayerProtocols(input.getSubscriptionFilter().getRequestedLayerProtocols())
195 .setRequestedObjectIdentifier(input.getSubscriptionFilter().getRequestedObjectIdentifier())
196 .setRequestedObjectTypes(input.getSubscriptionFilter().getRequestedObjectTypes())
198 Uuid notifSubscriptionUuid = new Uuid(UUID.randomUUID().toString());
199 SubscriptionService subscriptionService = new SubscriptionServiceBuilder()
200 .setSubscriptionFilter(subscriptionFilter)
201 .setSubscriptionState(input.getSubscriptionState())
202 .setUuid(notifSubscriptionUuid)
205 NotifSubscriptionKey notifSubscriptionKey = new NotifSubscriptionKey(notifSubscriptionUuid);
206 Set<NotificationType> notificationTypes = (subscriptionFilter.getRequestedNotificationTypes() != null)
207 ? subscriptionFilter.getRequestedNotificationTypes()
208 : new HashSet<>(List.of(NotificationType.ALARMEVENT));
209 Set<ObjectType> objectTypes = (subscriptionFilter.getRequestedObjectTypes() != null)
210 ? subscriptionFilter.getRequestedObjectTypes()
211 : new HashSet<>(List.of(ObjectType.CONNECTIVITYSERVICE));
212 NotifSubscription notifSubscription = new NotifSubscriptionBuilder()
213 .setSubscriptionState(subscriptionService.getSubscriptionState())
214 .setSubscriptionFilter(subscriptionService.getSubscriptionFilter())
215 .setUuid(notifSubscriptionUuid)
216 .setSupportedNotificationTypes(notificationTypes)
217 .setSupportedObjectTypes(objectTypes)
218 .setName(subscriptionService.getName())
220 NotificationContext notificationContext = getNotificationContext();
221 Map<NotifSubscriptionKey, NotifSubscription> notifSubscriptions = new HashMap<>();
222 if (notificationContext != null && notificationContext.getNotifSubscription() != null) {
223 notifSubscriptions.putAll(notificationContext.getNotifSubscription());
225 notifSubscriptions.put(notifSubscriptionKey, notifSubscription);
226 NotificationContext notificationContext1 = new NotificationContextBuilder()
227 .setNotification(notificationContext == null ? new HashMap<>() : notificationContext.getNotification())
228 .setNotifSubscription(notifSubscriptions)
230 if (!updateNotificationContext(notificationContext1)) {
231 LOG.error("Failed to update Notification context");
232 return RpcResultBuilder.<CreateNotificationSubscriptionServiceOutput>failed()
233 .withError(ErrorType.RPC, "Failed to update notification context").buildFuture();
235 CreateNotificationSubscriptionServiceOutput serviceOutput =
236 new CreateNotificationSubscriptionServiceOutputBuilder()
237 .setSubscriptionService(subscriptionService)
239 return RpcResultBuilder.success(serviceOutput).buildFuture();
243 public ListenableFuture<RpcResult<UpdateNotificationSubscriptionServiceOutput>>
244 updateNotificationSubscriptionService(UpdateNotificationSubscriptionServiceInput input) {
245 // TODO --> Not yet implemented
250 public ListenableFuture<RpcResult<DeleteNotificationSubscriptionServiceOutput>>
251 deleteNotificationSubscriptionService(DeleteNotificationSubscriptionServiceInput input) {
253 if (input == null || input.getSubscriptionIdOrName() == null) {
254 LOG.warn("Missing mandatory params for input {}", input);
255 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
256 .withError(ErrorType.RPC, "Missing input parameters").buildFuture();
258 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
259 InstanceIdentifier<NotifSubscription> notifSubscriptionIID = InstanceIdentifier.builder(Context.class)
260 .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class,
261 new NotifSubscriptionKey(notifSubsUuid)).build();
262 Optional<NotifSubscription> optionalNotifSub = this.networkTransactionService.read(
263 LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get();
265 if (!optionalNotifSub.isPresent()) {
266 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
267 .withError(ErrorType.APPLICATION,
268 "Notification subscription doesnt exist").buildFuture();
270 NotifSubscription notifSubscription = optionalNotifSub.orElseThrow();
271 this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID);
272 this.networkTransactionService.commit().get();
273 for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) {
274 this.topicManager.deleteTapiTopic(objectUuid.getValue());
276 return RpcResultBuilder.success(new DeleteNotificationSubscriptionServiceOutputBuilder().build())
278 } catch (InterruptedException | ExecutionException | NoSuchElementException e) {
279 LOG.error("Failed to delete Notification subscription service", e);
281 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
282 .withError(ErrorType.APPLICATION,
283 "Failed to delete notification subscription service").buildFuture();
287 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceDetailsOutput>>
288 getNotificationSubscriptionServiceDetails(GetNotificationSubscriptionServiceDetailsInput input) {
289 if (input == null || input.getSubscriptionIdOrName() == null) {
290 LOG.warn("Missing mandatory params for input {}", input);
291 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
292 .withError(ErrorType.RPC, "Missing input parameters").buildFuture();
294 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
295 NotificationContext notificationContext = getNotificationContext();
296 if (notificationContext == null) {
297 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
298 .withError(ErrorType.APPLICATION, "Notification context is empty")
301 if (notificationContext.getNotifSubscription() == null) {
302 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
303 .setSubscriptionService(new org.opendaylight.yang.gen.v1
304 .urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service
305 .details.output.SubscriptionServiceBuilder().build()).build()).buildFuture();
307 if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) {
308 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
309 .withError(ErrorType.APPLICATION,
310 "Notification subscription service doesnt exist").buildFuture();
312 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
313 .setSubscriptionService(new org.opendaylight.yang.gen.v1.urn
314 .onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service.details.output
315 .SubscriptionServiceBuilder(notificationContext.getNotifSubscription().get(
316 new NotifSubscriptionKey(notifSubsUuid))).build()).build()).buildFuture();
320 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceListOutput>>
321 getNotificationSubscriptionServiceList(GetNotificationSubscriptionServiceListInput input) {
322 NotificationContext notificationContext = getNotificationContext();
323 if (notificationContext == null) {
324 return RpcResultBuilder.<GetNotificationSubscriptionServiceListOutput>failed()
325 .withError(ErrorType.APPLICATION, "Notification context is empty")
328 if (notificationContext.getNotifSubscription() == null) {
329 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
330 .setSubscriptionService(new HashMap<>()).build()).buildFuture();
332 Map<SubscriptionServiceKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
333 .tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionService>
334 notifSubsMap = new HashMap<>();
335 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
336 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
337 .tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionService
338 subscriptionService = new org.opendaylight.yang.gen.v1
339 .urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service
340 .list.output.SubscriptionServiceBuilder(notifSubscription).build();
341 notifSubsMap.put(subscriptionService.key(), subscriptionService);
343 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
344 .setSubscriptionService(notifSubsMap).build()).buildFuture();
348 public ListenableFuture<RpcResult<GetNotificationListOutput>> getNotificationList(GetNotificationListInput input) {
350 LOG.info("RPC getNotificationList received");
351 if (input == null || input.getSubscriptionIdOrName() == null) {
352 LOG.warn("Missing mandatory params for input {}", input);
353 return RpcResultBuilder.<GetNotificationListOutput>failed().withError(ErrorType.RPC,
354 "Missing input parameters").buildFuture();
356 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
357 InstanceIdentifier<NotifSubscription> notifSubscriptionIID = InstanceIdentifier.builder(Context.class)
358 .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class,
359 new NotifSubscriptionKey(notifSubsUuid)).build();
360 Optional<NotifSubscription> optionalNotifSub = this.networkTransactionService.read(
361 LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get();
363 if (!optionalNotifSub.isPresent()) {
364 return RpcResultBuilder.<GetNotificationListOutput>failed()
365 .withError(ErrorType.APPLICATION,
366 "Notification subscription doesnt exist").buildFuture();
368 NotifSubscription notifSubscription = optionalNotifSub.orElseThrow();
369 List<Notification> notificationTapiList = new ArrayList<>();
370 for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) {
371 if (!this.topicManager.getTapiTopicMap().containsKey(objectUuid.getValue())) {
372 LOG.warn("Topic doesnt exist for {}", objectUuid.getValue());
375 LOG.info("Going to get notifications for topic {}", objectUuid.getValue());
376 Subscriber<NotificationTapiService, Notification> subscriber = new Subscriber<>(
377 objectUuid.getValue(), objectUuid.getValue(), server, converterTapiService,
378 TapiNotificationDeserializer.class);
379 notificationTapiList.addAll(subscriber.subscribe(objectUuid.getValue(), Notification.QNAME));
381 LOG.info("TAPI notifications = {}", notificationTapiList);
382 Map<NotificationKey, Notification> notificationMap = new HashMap<>();
383 for (Notification notif:notificationTapiList) {
384 notificationMap.put(notif.key(), notif);
386 return RpcResultBuilder.success(new GetNotificationListOutputBuilder()
387 .setNotification(notificationMap).build()).buildFuture();
388 } catch (InterruptedException | ExecutionException | NoSuchElementException e) {
389 LOG.error("Failed to get Notifications from Kafka", e);
391 return RpcResultBuilder.<GetNotificationListOutput>failed()
392 .withError(ErrorType.APPLICATION,
393 "Notifications couldnt be retrieved from Kafka server").buildFuture();
396 public ImmutableClassToInstanceMap<Rpc<?, ?>> registerRPCs() {
397 return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
398 .put(GetNotificationsProcessService.class, this::getNotificationsProcessService)
399 .put(GetNotificationsAlarmService.class, this::getNotificationsAlarmService)
400 .put(GetSupportedNotificationTypes.class, this::getSupportedNotificationTypes)
401 .put(CreateNotificationSubscriptionService.class, this::createNotificationSubscriptionService)
402 .put(UpdateNotificationSubscriptionService.class, this::updateNotificationSubscriptionService)
403 .put(DeleteNotificationSubscriptionService.class, this::deleteNotificationSubscriptionService)
404 .put(GetNotificationSubscriptionServiceDetails.class, this::getNotificationSubscriptionServiceDetails)
405 .put(GetNotificationSubscriptionServiceList.class, this::getNotificationSubscriptionServiceList)
406 .put(GetNotificationList.class, this::getNotificationList)
410 private NotificationContext getNotificationContext() {
411 LOG.info("Getting tapi notification context");
413 InstanceIdentifier<NotificationContext> notificationcontextIID =
414 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
415 .child(NotificationContext.class).build();
416 Optional<NotificationContext> notificationContextOptional
417 = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, notificationcontextIID).get();
418 if (!notificationContextOptional.isPresent()) {
419 LOG.error("Could not get TAPI notification context");
422 return notificationContextOptional.orElseThrow();
423 } catch (InterruptedException | ExecutionException e) {
424 LOG.error("Could not get TAPI notification context");
429 private boolean updateNotificationContext(NotificationContext notificationContext1) {
431 InstanceIdentifier<NotificationContext> notificationcontextIID =
432 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
433 .child(NotificationContext.class).build();
434 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, notificationcontextIID,
435 notificationContext1);
436 this.networkTransactionService.commit().get();
438 } catch (InterruptedException | ExecutionException e) {
439 LOG.error("Could not update TAPI notification context");
444 private Uuid getUuidFromIput(String serviceIdOrName) {
446 UUID.fromString(serviceIdOrName);
447 LOG.info("Given attribute {} is a UUID", serviceIdOrName);
448 return new Uuid(serviceIdOrName);
449 } catch (IllegalArgumentException e) {
450 LOG.info("Given attribute {} is not a UUID", serviceIdOrName);
451 return new Uuid(UUID.nameUUIDFromBytes(serviceIdOrName.getBytes(StandardCharsets.UTF_8)).toString());