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 java.util.Optional;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
15 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
16 import org.opendaylight.transportpce.nbinotifications.impl.rpc.CreateNotificationSubscriptionServiceImpl;
17 import org.opendaylight.transportpce.nbinotifications.impl.rpc.DeleteNotificationSubscriptionServiceImpl;
18 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationListImpl;
19 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceDetailsImpl;
20 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationSubscriptionServiceListImpl;
21 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsAlarmServiceImpl;
22 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetNotificationsProcessServiceImpl;
23 import org.opendaylight.transportpce.nbinotifications.impl.rpc.GetSupportedNotificationTypesImpl;
24 import org.opendaylight.transportpce.nbinotifications.utils.TopicManager;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsAlarmService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.GetNotificationsProcessService;
27 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationAlarmService;
28 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
29 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationTapiService;
30 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.Context1;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionService;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.DeleteNotificationSubscriptionService;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationList;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceDetails;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationSubscriptionServiceList;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetSupportedNotificationTypes;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContext;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.binding.Rpc;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 public class NbiNotificationsImpl {
45 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class);
46 private final JsonStringConverter<NotificationProcessService> converterService;
47 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
48 private final JsonStringConverter<NotificationTapiService> converterTapiService;
49 private final String server;
50 private final NetworkTransactionService networkTransactionService;
51 private final TopicManager topicManager;
53 public NbiNotificationsImpl(JsonStringConverter<NotificationProcessService> converterService,
54 JsonStringConverter<NotificationAlarmService> converterAlarmService,
55 JsonStringConverter<NotificationTapiService> converterTapiService, String server,
56 NetworkTransactionService networkTransactionService, TopicManager topicManager) {
57 this.converterService = converterService;
58 this.converterAlarmService = converterAlarmService;
59 this.converterTapiService = converterTapiService;
61 this.networkTransactionService = networkTransactionService;
62 this.topicManager = topicManager;
65 public ImmutableClassToInstanceMap<Rpc<?, ?>> registerRPCs() {
66 return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
67 .put(GetNotificationsProcessService.class, new GetNotificationsProcessServiceImpl(converterService, server))
68 .put(GetNotificationsAlarmService.class,
69 new GetNotificationsAlarmServiceImpl(converterAlarmService, server))
70 .put(GetSupportedNotificationTypes.class, new GetSupportedNotificationTypesImpl(this))
71 .put(CreateNotificationSubscriptionService.class,
72 new CreateNotificationSubscriptionServiceImpl(this, topicManager))
73 .put(DeleteNotificationSubscriptionService.class,
74 new DeleteNotificationSubscriptionServiceImpl(networkTransactionService, topicManager))
75 .put(GetNotificationSubscriptionServiceDetails.class,
76 new GetNotificationSubscriptionServiceDetailsImpl(this))
77 .put(GetNotificationSubscriptionServiceList.class, new GetNotificationSubscriptionServiceListImpl(this))
78 .put(GetNotificationList.class,
79 new GetNotificationListImpl(converterTapiService, server, networkTransactionService, topicManager))
83 public NotificationContext getNotificationContext() {
84 LOG.info("Getting tapi notification context");
86 InstanceIdentifier<NotificationContext> notificationcontextIID =
87 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
88 .child(NotificationContext.class).build();
89 Optional<NotificationContext> notificationContextOptional
90 = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, notificationcontextIID).get();
91 if (!notificationContextOptional.isPresent()) {
92 LOG.error("Could not get TAPI notification context");
95 return notificationContextOptional.orElseThrow();
96 } catch (InterruptedException | ExecutionException e) {
97 LOG.error("Could not get TAPI notification context");
102 public boolean updateNotificationContext(NotificationContext notificationContext1) {
104 InstanceIdentifier<NotificationContext> notificationcontextIID =
105 InstanceIdentifier.builder(Context.class).augmentation(Context1.class)
106 .child(NotificationContext.class).build();
107 this.networkTransactionService.merge(LogicalDatastoreType.OPERATIONAL, notificationcontextIID,
108 notificationContext1);
109 this.networkTransactionService.commit().get();
111 } catch (InterruptedException | ExecutionException e) {
112 LOG.error("Could not update TAPI notification context");