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.rev230726.GetNotificationsAlarmService;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsAlarmServiceInput;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsAlarmServiceOutput;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsAlarmServiceOutputBuilder;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessService;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessServiceInput;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessServiceOutput;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.GetNotificationsProcessServiceOutputBuilder;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NbiNotificationsService;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationAlarmService;
41 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationProcessService;
42 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.NotificationTapiService;
43 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.get.notifications.alarm.service.output.NotificationsAlarmService;
44 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.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.ErrorTag;
93 import org.opendaylight.yangtools.yang.common.ErrorType;
94 import org.opendaylight.yangtools.yang.common.RpcResult;
95 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
96 import org.slf4j.Logger;
97 import org.slf4j.LoggerFactory;
99 public class NbiNotificationsImpl implements NbiNotificationsService, TapiNotificationService {
100 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class);
101 private final JsonStringConverter<NotificationProcessService> converterService;
102 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
103 private final JsonStringConverter<NotificationTapiService> converterTapiService;
104 private final String server;
105 private final NetworkTransactionService networkTransactionService;
106 private final TopicManager topicManager;
108 public NbiNotificationsImpl(JsonStringConverter<NotificationProcessService> converterService,
109 JsonStringConverter<NotificationAlarmService> converterAlarmService,
110 JsonStringConverter<NotificationTapiService> converterTapiService, String server,
111 NetworkTransactionService networkTransactionService, TopicManager topicManager) {
112 this.converterService = converterService;
113 this.converterAlarmService = converterAlarmService;
114 this.converterTapiService = converterTapiService;
115 this.server = server;
116 this.networkTransactionService = networkTransactionService;
117 this.topicManager = topicManager;
121 public ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> getNotificationsProcessService(
122 GetNotificationsProcessServiceInput input) {
123 LOG.info("RPC getNotificationsService received");
124 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
125 LOG.warn("Missing mandatory params for input {}", input);
126 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder().build()).buildFuture();
128 Subscriber<NotificationProcessService, NotificationsProcessService> subscriber = new Subscriber<>(
129 input.getIdConsumer(), input.getGroupId(), server, converterService,
130 NotificationServiceDeserializer.class);
131 List<NotificationsProcessService> notificationServiceList = subscriber
132 .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME);
133 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder()
134 .setNotificationsProcessService(notificationServiceList).build()).buildFuture();
138 public ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> getNotificationsAlarmService(
139 GetNotificationsAlarmServiceInput input) {
140 LOG.info("RPC getNotificationsAlarmService received");
141 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
142 LOG.warn("Missing mandatory params for input {}", input);
143 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder().build()).buildFuture();
145 Subscriber<NotificationAlarmService, NotificationsAlarmService> subscriber = new Subscriber<>(
146 input.getIdConsumer(), input.getGroupId(), server, converterAlarmService,
147 NotificationAlarmServiceDeserializer.class);
148 List<NotificationsAlarmService> notificationAlarmServiceList = subscriber
149 .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME);
150 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder()
151 .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture();
155 public ListenableFuture<RpcResult<GetSupportedNotificationTypesOutput>>
156 getSupportedNotificationTypes(GetSupportedNotificationTypesInput input) {
157 NotificationContext notificationContext = getNotificationContext();
158 if (notificationContext == null) {
159 return RpcResultBuilder.<GetSupportedNotificationTypesOutput>failed()
160 .withError(ErrorType.APPLICATION, "Couldnt get Notification Context from Datastore")
163 if (notificationContext.getNotifSubscription() == null) {
164 return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder()
165 .setSupportedNotificationTypes(new HashSet<>())
166 .setSupportedObjectTypes(new HashSet<>()).build()).buildFuture();
168 Set<NotificationType> notificationTypeList = new HashSet<>();
169 Set<ObjectType> objectTypeList = new HashSet<>();
170 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
171 if (notifSubscription.getSupportedNotificationTypes() != null) {
172 notificationTypeList.addAll(notifSubscription.getSupportedNotificationTypes());
174 if (notifSubscription.getSupportedObjectTypes() != null) {
175 objectTypeList.addAll(notifSubscription.getSupportedObjectTypes());
178 return RpcResultBuilder.success(new GetSupportedNotificationTypesOutputBuilder()
179 .setSupportedNotificationTypes(notificationTypeList)
180 .setSupportedObjectTypes(objectTypeList).build()).buildFuture();
184 public ListenableFuture<RpcResult<CreateNotificationSubscriptionServiceOutput>>
185 createNotificationSubscriptionService(CreateNotificationSubscriptionServiceInput input) {
186 for (Uuid uuid:input.getSubscriptionFilter().getRequestedObjectIdentifier()) {
187 LOG.info("Adding T-API topic: {} to Kafka server", uuid.getValue());
188 this.topicManager.addTapiTopic(uuid.getValue());
190 SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder()
191 .setName(input.getSubscriptionFilter().getName())
192 .setLocalId(input.getSubscriptionFilter().getLocalId())
193 .setIncludeContent(input.getSubscriptionFilter().getIncludeContent())
194 .setRequestedNotificationTypes(input.getSubscriptionFilter().getRequestedNotificationTypes())
195 .setRequestedLayerProtocols(input.getSubscriptionFilter().getRequestedLayerProtocols())
196 .setRequestedObjectIdentifier(input.getSubscriptionFilter().getRequestedObjectIdentifier())
197 .setRequestedObjectTypes(input.getSubscriptionFilter().getRequestedObjectTypes())
199 Uuid notifSubscriptionUuid = new Uuid(UUID.randomUUID().toString());
200 SubscriptionService subscriptionService = new SubscriptionServiceBuilder()
201 .setSubscriptionFilter(subscriptionFilter)
202 .setSubscriptionState(input.getSubscriptionState())
203 .setUuid(notifSubscriptionUuid)
206 NotifSubscriptionKey notifSubscriptionKey = new NotifSubscriptionKey(notifSubscriptionUuid);
207 Set<NotificationType> notificationTypes = (subscriptionFilter.getRequestedNotificationTypes() != null)
208 ? subscriptionFilter.getRequestedNotificationTypes()
209 : new HashSet<>(List.of(NotificationType.ALARMEVENT));
210 Set<ObjectType> objectTypes = (subscriptionFilter.getRequestedObjectTypes() != null)
211 ? subscriptionFilter.getRequestedObjectTypes()
212 : new HashSet<>(List.of(ObjectType.CONNECTIVITYSERVICE));
213 NotifSubscription notifSubscription = new NotifSubscriptionBuilder()
214 .setSubscriptionState(subscriptionService.getSubscriptionState())
215 .setSubscriptionFilter(subscriptionService.getSubscriptionFilter())
216 .setUuid(notifSubscriptionUuid)
217 .setSupportedNotificationTypes(notificationTypes)
218 .setSupportedObjectTypes(objectTypes)
219 .setName(subscriptionService.getName())
221 NotificationContext notificationContext = getNotificationContext();
222 Map<NotifSubscriptionKey, NotifSubscription> notifSubscriptions = new HashMap<>();
223 if (notificationContext != null && notificationContext.getNotifSubscription() != null) {
224 notifSubscriptions.putAll(notificationContext.getNotifSubscription());
226 notifSubscriptions.put(notifSubscriptionKey, notifSubscription);
227 NotificationContext notificationContext1 = new NotificationContextBuilder()
228 .setNotification(notificationContext == null ? new HashMap<>() : notificationContext.getNotification())
229 .setNotifSubscription(notifSubscriptions)
231 if (!updateNotificationContext(notificationContext1)) {
232 LOG.error("Failed to update Notification context");
233 return RpcResultBuilder.<CreateNotificationSubscriptionServiceOutput>failed()
234 .withError(ErrorType.RPC, "Failed to update notification context").buildFuture();
236 CreateNotificationSubscriptionServiceOutput serviceOutput =
237 new CreateNotificationSubscriptionServiceOutputBuilder()
238 .setSubscriptionService(subscriptionService)
240 return RpcResultBuilder.success(serviceOutput).buildFuture();
244 public ListenableFuture<RpcResult<UpdateNotificationSubscriptionServiceOutput>>
245 updateNotificationSubscriptionService(UpdateNotificationSubscriptionServiceInput input) {
246 // TODO --> Not yet implemented
247 return RpcResultBuilder.<UpdateNotificationSubscriptionServiceOutput>failed()
248 .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
253 public ListenableFuture<RpcResult<DeleteNotificationSubscriptionServiceOutput>>
254 deleteNotificationSubscriptionService(DeleteNotificationSubscriptionServiceInput input) {
256 if (input == null || input.getSubscriptionIdOrName() == null) {
257 LOG.warn("Missing mandatory params for input {}", input);
258 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
259 .withError(ErrorType.RPC, "Missing input parameters").buildFuture();
261 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
262 InstanceIdentifier<NotifSubscription> notifSubscriptionIID = InstanceIdentifier.builder(Context.class)
263 .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class,
264 new NotifSubscriptionKey(notifSubsUuid)).build();
265 Optional<NotifSubscription> optionalNotifSub = this.networkTransactionService.read(
266 LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get();
268 if (!optionalNotifSub.isPresent()) {
269 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
270 .withError(ErrorType.APPLICATION,
271 "Notification subscription doesnt exist").buildFuture();
273 NotifSubscription notifSubscription = optionalNotifSub.orElseThrow();
274 this.networkTransactionService.delete(LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID);
275 this.networkTransactionService.commit().get();
276 for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) {
277 this.topicManager.deleteTapiTopic(objectUuid.getValue());
279 return RpcResultBuilder.success(new DeleteNotificationSubscriptionServiceOutputBuilder().build())
281 } catch (InterruptedException | ExecutionException | NoSuchElementException e) {
282 LOG.error("Failed to delete Notification subscription service", e);
284 return RpcResultBuilder.<DeleteNotificationSubscriptionServiceOutput>failed()
285 .withError(ErrorType.APPLICATION,
286 "Failed to delete notification subscription service").buildFuture();
290 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceDetailsOutput>>
291 getNotificationSubscriptionServiceDetails(GetNotificationSubscriptionServiceDetailsInput input) {
292 if (input == null || input.getSubscriptionIdOrName() == null) {
293 LOG.warn("Missing mandatory params for input {}", input);
294 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
295 .withError(ErrorType.RPC, "Missing input parameters").buildFuture();
297 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
298 NotificationContext notificationContext = getNotificationContext();
299 if (notificationContext == null) {
300 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
301 .withError(ErrorType.APPLICATION, "Notification context is empty")
304 if (notificationContext.getNotifSubscription() == null) {
305 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
306 .setSubscriptionService(new org.opendaylight.yang.gen.v1
307 .urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service
308 .details.output.SubscriptionServiceBuilder().build()).build()).buildFuture();
310 if (!notificationContext.getNotifSubscription().containsKey(new NotifSubscriptionKey(notifSubsUuid))) {
311 return RpcResultBuilder.<GetNotificationSubscriptionServiceDetailsOutput>failed()
312 .withError(ErrorType.APPLICATION,
313 "Notification subscription service doesnt exist").buildFuture();
315 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceDetailsOutputBuilder()
316 .setSubscriptionService(new org.opendaylight.yang.gen.v1.urn
317 .onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service.details.output
318 .SubscriptionServiceBuilder(notificationContext.getNotifSubscription().get(
319 new NotifSubscriptionKey(notifSubsUuid))).build()).build()).buildFuture();
323 public ListenableFuture<RpcResult<GetNotificationSubscriptionServiceListOutput>>
324 getNotificationSubscriptionServiceList(GetNotificationSubscriptionServiceListInput input) {
325 NotificationContext notificationContext = getNotificationContext();
326 if (notificationContext == null) {
327 return RpcResultBuilder.<GetNotificationSubscriptionServiceListOutput>failed()
328 .withError(ErrorType.APPLICATION, "Notification context is empty")
331 if (notificationContext.getNotifSubscription() == null) {
332 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
333 .setSubscriptionService(new HashMap<>()).build()).buildFuture();
335 Map<SubscriptionServiceKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
336 .tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionService>
337 notifSubsMap = new HashMap<>();
338 for (NotifSubscription notifSubscription:notificationContext.getNotifSubscription().values()) {
339 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
340 .tapi.notification.rev181210.get.notification.subscription.service.list.output.SubscriptionService
341 subscriptionService = new org.opendaylight.yang.gen.v1
342 .urn.onf.otcc.yang.tapi.notification.rev181210.get.notification.subscription.service
343 .list.output.SubscriptionServiceBuilder(notifSubscription).build();
344 notifSubsMap.put(subscriptionService.key(), subscriptionService);
346 return RpcResultBuilder.success(new GetNotificationSubscriptionServiceListOutputBuilder()
347 .setSubscriptionService(notifSubsMap).build()).buildFuture();
351 public ListenableFuture<RpcResult<GetNotificationListOutput>> getNotificationList(GetNotificationListInput input) {
353 LOG.info("RPC getNotificationList received");
354 if (input == null || input.getSubscriptionIdOrName() == null) {
355 LOG.warn("Missing mandatory params for input {}", input);
356 return RpcResultBuilder.<GetNotificationListOutput>failed().withError(ErrorType.RPC,
357 "Missing input parameters").buildFuture();
359 Uuid notifSubsUuid = getUuidFromIput(input.getSubscriptionIdOrName());
360 InstanceIdentifier<NotifSubscription> notifSubscriptionIID = InstanceIdentifier.builder(Context.class)
361 .augmentation(Context1.class).child(NotificationContext.class).child(NotifSubscription.class,
362 new NotifSubscriptionKey(notifSubsUuid)).build();
363 Optional<NotifSubscription> optionalNotifSub = this.networkTransactionService.read(
364 LogicalDatastoreType.OPERATIONAL, notifSubscriptionIID).get();
366 if (!optionalNotifSub.isPresent()) {
367 return RpcResultBuilder.<GetNotificationListOutput>failed()
368 .withError(ErrorType.APPLICATION,
369 "Notification subscription doesnt exist").buildFuture();
371 NotifSubscription notifSubscription = optionalNotifSub.orElseThrow();
372 List<Notification> notificationTapiList = new ArrayList<>();
373 for (Uuid objectUuid:notifSubscription.getSubscriptionFilter().getRequestedObjectIdentifier()) {
374 if (!this.topicManager.getTapiTopicMap().containsKey(objectUuid.getValue())) {
375 LOG.warn("Topic doesnt exist for {}", objectUuid.getValue());
378 LOG.info("Going to get notifications for topic {}", objectUuid.getValue());
379 Subscriber<NotificationTapiService, Notification> subscriber = new Subscriber<>(
380 objectUuid.getValue(), objectUuid.getValue(), server, converterTapiService,
381 TapiNotificationDeserializer.class);
382 notificationTapiList.addAll(subscriber.subscribe(objectUuid.getValue(), Notification.QNAME));
384 LOG.info("TAPI notifications = {}", notificationTapiList);
385 Map<NotificationKey, Notification> notificationMap = new HashMap<>();
386 for (Notification notif:notificationTapiList) {
387 notificationMap.put(notif.key(), notif);
389 return RpcResultBuilder.success(new GetNotificationListOutputBuilder()
390 .setNotification(notificationMap).build()).buildFuture();
391 } catch (InterruptedException | ExecutionException | NoSuchElementException e) {
392 LOG.error("Failed to get Notifications from Kafka", e);
394 return RpcResultBuilder.<GetNotificationListOutput>failed()
395 .withError(ErrorType.APPLICATION,
396 "Notifications couldnt be retrieved from Kafka server").buildFuture();
399 public ImmutableClassToInstanceMap<Rpc<?, ?>> registerRPCs() {
400 return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
401 .put(GetNotificationsProcessService.class, this::getNotificationsProcessService)
402 .put(GetNotificationsAlarmService.class, this::getNotificationsAlarmService)
403 .put(GetSupportedNotificationTypes.class, this::getSupportedNotificationTypes)
404 .put(CreateNotificationSubscriptionService.class, this::createNotificationSubscriptionService)
405 .put(UpdateNotificationSubscriptionService.class, this::updateNotificationSubscriptionService)
406 .put(DeleteNotificationSubscriptionService.class, this::deleteNotificationSubscriptionService)
407 .put(GetNotificationSubscriptionServiceDetails.class, this::getNotificationSubscriptionServiceDetails)
408 .put(GetNotificationSubscriptionServiceList.class, this::getNotificationSubscriptionServiceList)
409 .put(GetNotificationList.class, this::getNotificationList)
413 private NotificationContext getNotificationContext() {
414 LOG.info("Getting tapi notification context");
416 InstanceIdentifier<NotificationContext> notificationcontextIID =
417 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
418 .child(NotificationContext.class).build();
419 Optional<NotificationContext> notificationContextOptional
420 = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, notificationcontextIID).get();
421 if (!notificationContextOptional.isPresent()) {
422 LOG.error("Could not get TAPI notification context");
425 return notificationContextOptional.orElseThrow();
426 } catch (InterruptedException | ExecutionException e) {
427 LOG.error("Could not get TAPI notification context");
432 private boolean updateNotificationContext(NotificationContext notificationContext1) {
434 InstanceIdentifier<NotificationContext> notificationcontextIID =
435 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
436 .child(NotificationContext.class).build();
437 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, notificationcontextIID,
438 notificationContext1);
439 this.networkTransactionService.commit().get();
441 } catch (InterruptedException | ExecutionException e) {
442 LOG.error("Could not update TAPI notification context");
447 private Uuid getUuidFromIput(String serviceIdOrName) {
449 UUID.fromString(serviceIdOrName);
450 LOG.info("Given attribute {} is a UUID", serviceIdOrName);
451 return new Uuid(serviceIdOrName);
452 } catch (IllegalArgumentException e) {
453 LOG.info("Given attribute {} is not a UUID", serviceIdOrName);
454 return new Uuid(UUID.nameUUIDFromBytes(serviceIdOrName.getBytes(StandardCharsets.UTF_8)).toString());