2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.rpc;
20 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.VesNotificationListener;
21 import org.opendaylight.mdsal.binding.api.RpcProviderService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.AttributeChangeNotificationBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.FaultNotificationBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.GetStatusInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.GetStatusOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.GetStatusOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.NetconfnodeStateService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.PushAttributeChangeNotificationInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.PushAttributeChangeNotificationOutput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.PushFaultNotificationInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconfnode.state.rev191011.PushFaultNotificationOutput;
32 import org.opendaylight.yangtools.concepts.ObjectRegistration;
33 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 import com.google.common.util.concurrent.ListenableFuture;
40 import java.util.List;
42 public class NetconfnodeStateServiceRpcApiImpl implements NetconfnodeStateService, AutoCloseable {
44 private static final Logger LOG = LoggerFactory.getLogger(NetconfnodeStateServiceRpcApiImpl.class);
46 private final ObjectRegistration<NetconfnodeStateServiceRpcApiImpl> rpcReg;
47 private RpcApigetStateCallback getStatusCallback;
48 private final List<VesNotificationListener> vesNotificationListenerList;
50 public NetconfnodeStateServiceRpcApiImpl(final RpcProviderService rpcProviderRegistry,
51 List<VesNotificationListener> vesNotificationListenerList) {
53 this.vesNotificationListenerList = vesNotificationListenerList;
55 // Register ourselves as the REST API RPC implementation
56 LOG.info("Register RPC Service " + NetconfnodeStateService.class.getSimpleName());
57 rpcReg = rpcProviderRegistry.registerRpcImplementation(NetconfnodeStateService.class, this);
58 this.getStatusCallback = null;
61 public NetconfnodeStateServiceRpcApiImpl setStatusCallback(RpcApigetStateCallback getStatusCallback) {
62 this.getStatusCallback = getStatusCallback;
67 public void close() throws Exception {
68 LOG.info("Close RPC Service");
74 /*-------------------------------
75 * Interfaces for getting information
78 public ListenableFuture<RpcResult<GetStatusOutput>> getStatus(GetStatusInput input) {
80 LOG.info("RPC Request: getStatus input: {}", input);
81 RpcResultBuilder<GetStatusOutput> result;
84 GetStatusOutputBuilder outputBuilder = new GetStatusOutputBuilder();
85 getStatusCallback.getStatus(input);
86 result = RpcResultBuilder.success(outputBuilder);
87 } catch (Exception e) {
88 result = RpcResultBuilder.failed();
89 result.withError(ErrorType.APPLICATION, "Exception", e);
91 return result.buildFuture();
95 public ListenableFuture<RpcResult<PushFaultNotificationOutput>> pushFaultNotification(
96 PushFaultNotificationInput input) {
98 RpcResultBuilder<PushFaultNotificationOutput> result;
100 FaultNotificationBuilder faultNotificationBuilder = new FaultNotificationBuilder();
101 faultNotificationBuilder.fieldsFrom(input);
102 vesNotificationListenerList.forEach(item -> item.onNotification(faultNotificationBuilder.build()));
103 result = RpcResultBuilder.success();
104 } catch (Exception e) {
105 result = RpcResultBuilder.failed();
106 result.withError(ErrorType.APPLICATION, "Exception", e);
108 return result.buildFuture();
112 public ListenableFuture<RpcResult<PushAttributeChangeNotificationOutput>> pushAttributeChangeNotification(
113 PushAttributeChangeNotificationInput input) {
114 RpcResultBuilder<PushAttributeChangeNotificationOutput> result;
116 AttributeChangeNotificationBuilder attributeChangeNotificationBuilder =
117 new AttributeChangeNotificationBuilder();
118 attributeChangeNotificationBuilder.fieldsFrom(input);
119 vesNotificationListenerList
120 .forEach(item -> item.onNotification(attributeChangeNotificationBuilder.build()));
121 result = RpcResultBuilder.success();
122 } catch (Exception e) {
123 result = RpcResultBuilder.failed();
124 result.withError(ErrorType.APPLICATION, "Exception", e);
126 return result.buildFuture();