2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Update Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
8 * =================================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
10 * in compliance with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software distributed under the License
15 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
16 * or implied. See the License for the specific language governing permissions and limitations under
18 * ============LICENSE_END==========================================================================
20 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
22 import com.google.common.util.concurrent.ListenableFuture;
23 import java.util.List;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementsListener;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceRPCServiceAPI;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
28 import org.opendaylight.mdsal.binding.api.RpcProviderService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutputBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.DevicemanagerService;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushCmNotificationInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushCmNotificationOutput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutputBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutputBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutputBuilder;
54 import org.opendaylight.yangtools.concepts.ObjectRegistration;
55 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
56 import org.opendaylight.yangtools.yang.common.RpcResult;
57 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
61 public class DeviceManagerApiServiceImpl implements DevicemanagerService, AutoCloseable {
63 private static final Logger LOG = LoggerFactory.getLogger(DevicemanagerService.class);
65 private final ObjectRegistration<DevicemanagerService> rpcReg;
66 private @Nullable final MaintenanceRPCServiceAPI maintenanceService;
67 private @Nullable final PushNotifications pushNotificationsListener;
68 private @Nullable final ResyncNetworkElementsListener resyncCallbackListener;
70 public DeviceManagerApiServiceImpl(final RpcProviderService rpcProviderRegistry,
71 MaintenanceServiceImpl maintenanceService, ResyncNetworkElementsListener listener,
72 PushNotifications pushNotificationsListener) {
73 this.maintenanceService = maintenanceService;
74 this.pushNotificationsListener = pushNotificationsListener;
75 this.resyncCallbackListener = listener;
77 // Register ourselves as the REST API RPC implementation
78 LOG.info("Register RPC Service " + DevicemanagerService.class.getSimpleName());
79 this.rpcReg = rpcProviderRegistry.registerRpcImplementation(DevicemanagerService.class, this);
83 public void close() throws Exception {
84 LOG.info("Close RPC Service");
90 /*-------------------------------
91 * Interfaces for MaintenanceService
95 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys(
96 GetRequiredNetworkElementKeysInput input) {
97 return getRequiredNetworkElementKeys();
100 // For casablanca version no input was generated.
101 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys() {
103 LOG.info("RPC Request: getRequiredNetworkElementKeys");
104 RpcResultBuilder<GetRequiredNetworkElementKeysOutput> result;
106 GetRequiredNetworkElementKeysOutputBuilder outputBuilder =
107 maintenanceService.getRequiredNetworkElementKeys();
108 result = RpcResultBuilder.success(outputBuilder);
109 } catch (Exception e) {
110 result = RpcResultBuilder.failed();
111 result.withError(ErrorType.APPLICATION, "Exception", e);
113 return result.buildFuture();
117 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
118 ShowRequiredNetworkElementInput input) {
120 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
121 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
124 ShowRequiredNetworkElementOutputBuilder outputBuilder =
125 maintenanceService.showRequiredNetworkElement(input);
126 result = RpcResultBuilder.success(outputBuilder);
127 } catch (Exception e) {
128 result = RpcResultBuilder.failed();
129 result.withError(ErrorType.APPLICATION, "Exception", e);
131 return result.buildFuture();
135 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
137 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getNodeId());
138 RpcResultBuilder<SetMaintenanceModeOutput> result;
141 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
142 result = RpcResultBuilder.success(outputBuilder);
143 } catch (Exception e) {
144 result = RpcResultBuilder.failed();
145 result.withError(ErrorType.APPLICATION, "Exception", e);
147 return result.buildFuture();
154 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
156 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
157 RpcResultBuilder<GetMaintenanceModeOutput> result;
160 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
161 result = RpcResultBuilder.success(outputBuilder);
162 } catch (Exception e) {
163 result = RpcResultBuilder.failed();
164 result.withError(ErrorType.APPLICATION, "Exception", e);
166 return result.buildFuture();
171 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
172 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
173 RpcResultBuilder<TestMaintenanceModeOutput> result;
176 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
177 result = RpcResultBuilder.success(outputBuilder);
178 } catch (Exception e) {
179 result = RpcResultBuilder.failed();
180 result.withError(ErrorType.APPLICATION, "Exception", e);
182 return result.buildFuture();
188 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
189 ClearCurrentFaultByNodenameInput input) {
190 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
191 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
193 if (this.resyncCallbackListener != null) {
194 List<String> nodeNames =
195 this.resyncCallbackListener.doClearCurrentFaultByNodename(input.getNodenames());
196 ClearCurrentFaultByNodenameOutputBuilder outputBuilder = new ClearCurrentFaultByNodenameOutputBuilder();
197 outputBuilder.setNodenames(nodeNames);
198 result = RpcResultBuilder.success(outputBuilder);
200 result = RpcResultBuilder.failed();
201 result.withError(ErrorType.APPLICATION, "Startup running");
203 } catch (Exception e) {
204 result = RpcResultBuilder.failed();
205 result.withError(ErrorType.APPLICATION, "Exception", e);
207 return result.buildFuture();
211 public ListenableFuture<RpcResult<PushFaultNotificationOutput>> pushFaultNotification(
212 PushFaultNotificationInput input) {
213 LOG.info("RPC Received fault notification {}", input);
214 RpcResultBuilder<PushFaultNotificationOutput> result;
216 pushNotificationsListener.pushFaultNotification(input);
217 result = RpcResultBuilder.success();
218 } catch (Exception e) {
219 result = RpcResultBuilder.failed();
220 result.withError(ErrorType.APPLICATION, "Exception", e);
222 return result.buildFuture();
226 public ListenableFuture<RpcResult<PushCmNotificationOutput>> pushCmNotification(PushCmNotificationInput input) {
227 LOG.info("RPC Received CM notification {}", input);
228 RpcResultBuilder<PushCmNotificationOutput> result;
230 pushNotificationsListener.pushCMNotification(input);
231 result = RpcResultBuilder.success();
232 } catch (Exception e) {
233 result = RpcResultBuilder.failed();
234 result.withError(ErrorType.APPLICATION, "Exception", e);
236 return result.buildFuture();
240 public ListenableFuture<RpcResult<PushAttributeChangeNotificationOutput>> pushAttributeChangeNotification(
241 PushAttributeChangeNotificationInput input) {
242 LOG.info("RPC Received change notification {}", input);
243 RpcResultBuilder<PushAttributeChangeNotificationOutput> result;
245 pushNotificationsListener.pushAttributeChangeNotification(input);
246 result = RpcResultBuilder.success();
247 } catch (Exception e) {
248 result = RpcResultBuilder.failed();
249 result.withError(ErrorType.APPLICATION, "Exception", e);
251 return result.buildFuture();