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.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import org.opendaylight.transportpce.common.converter.JsonStringConverter;
13 import org.opendaylight.transportpce.nbinotifications.consumer.Subscriber;
14 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationAlarmServiceDeserializer;
15 import org.opendaylight.transportpce.nbinotifications.serialization.NotificationServiceDeserializer;
16 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceInput;
17 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceOutput;
18 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsAlarmServiceOutputBuilder;
19 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceInput;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceOutput;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.GetNotificationsProcessServiceOutputBuilder;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NbiNotificationsService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationAlarmService;
24 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.NotificationProcessService;
25 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.alarm.service.output.NotificationsAlarmService;
26 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210813.get.notifications.process.service.output.NotificationsProcessService;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class NbiNotificationsImpl implements NbiNotificationsService {
33 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsImpl.class);
34 private final JsonStringConverter<NotificationProcessService> converterService;
35 private final JsonStringConverter<NotificationAlarmService> converterAlarmService;
36 private final String server;
38 public NbiNotificationsImpl(JsonStringConverter<NotificationProcessService> converterService,
39 JsonStringConverter<NotificationAlarmService> converterAlarmService, String server) {
40 this.converterService = converterService;
41 this.converterAlarmService = converterAlarmService;
46 public ListenableFuture<RpcResult<GetNotificationsProcessServiceOutput>> getNotificationsProcessService(
47 GetNotificationsProcessServiceInput input) {
48 LOG.info("RPC getNotificationsService received");
49 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
50 LOG.warn("Missing mandatory params for input {}", input);
51 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder().build()).buildFuture();
53 Subscriber<NotificationProcessService, NotificationsProcessService> subscriber = new Subscriber<>(
54 input.getIdConsumer(), input.getGroupId(), server, converterService,
55 NotificationServiceDeserializer.class);
56 List<NotificationsProcessService> notificationServiceList = subscriber
57 .subscribe(input.getConnectionType().getName(), NotificationsProcessService.QNAME);
58 return RpcResultBuilder.success(new GetNotificationsProcessServiceOutputBuilder()
59 .setNotificationsProcessService(notificationServiceList).build()).buildFuture();
63 public ListenableFuture<RpcResult<GetNotificationsAlarmServiceOutput>> getNotificationsAlarmService(
64 GetNotificationsAlarmServiceInput input) {
65 LOG.info("RPC getNotificationsAlarmService received");
66 if (input == null || input.getIdConsumer() == null || input.getGroupId() == null) {
67 LOG.warn("Missing mandatory params for input {}", input);
68 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder().build()).buildFuture();
70 Subscriber<NotificationAlarmService, NotificationsAlarmService> subscriber = new Subscriber<>(
71 input.getIdConsumer(), input.getGroupId(), server, converterAlarmService,
72 NotificationAlarmServiceDeserializer.class);
73 List<NotificationsAlarmService> notificationAlarmServiceList = subscriber
74 .subscribe("alarm" + input.getConnectionType().getName(), NotificationsAlarmService.QNAME);
75 return RpcResultBuilder.success(new GetNotificationsAlarmServiceOutputBuilder()
76 .setNotificationsAlarmService(notificationAlarmServiceList).build()).buildFuture();