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.devicemanager.impl;
20 import java.util.List;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementsListener;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceRPCServiceAPI;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
25 import org.opendaylight.mdsal.binding.api.RpcProviderService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.DevicemanagerService;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeInput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutputBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementInput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutputBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeInput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutputBuilder;
49 import org.opendaylight.yangtools.concepts.ObjectRegistration;
50 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
52 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 import com.google.common.util.concurrent.ListenableFuture;
58 public class DeviceManagerApiServiceImpl implements DevicemanagerService, AutoCloseable {
60 private static final Logger LOG = LoggerFactory.getLogger(DevicemanagerService.class);
62 private final ObjectRegistration<DevicemanagerService> rpcReg;
63 private @Nullable final MaintenanceRPCServiceAPI maintenanceService;
64 private @Nullable final PushNotifications pushNotificationsListener;
65 private @Nullable final ResyncNetworkElementsListener resyncCallbackListener;
67 public DeviceManagerApiServiceImpl(final RpcProviderService rpcProviderRegistry,
68 MaintenanceServiceImpl maintenanceService, ResyncNetworkElementsListener listener,
69 PushNotifications pushNotificationsListener) {
70 this.maintenanceService = maintenanceService;
71 this.pushNotificationsListener = pushNotificationsListener;
72 this.resyncCallbackListener = listener;
74 // Register ourselves as the REST API RPC implementation
75 LOG.info("Register RPC Service " + DevicemanagerService.class.getSimpleName());
76 this.rpcReg = rpcProviderRegistry.registerRpcImplementation(DevicemanagerService.class, this);
80 public void close() throws Exception {
81 LOG.info("Close RPC Service");
87 /*-------------------------------
88 * Interfaces for MaintenanceService
92 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys(
93 GetRequiredNetworkElementKeysInput input) {
94 return getRequiredNetworkElementKeys();
97 // For casablanca version no input was generated.
98 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys() {
100 LOG.info("RPC Request: getRequiredNetworkElementKeys");
101 RpcResultBuilder<GetRequiredNetworkElementKeysOutput> result;
103 GetRequiredNetworkElementKeysOutputBuilder outputBuilder =
104 maintenanceService.getRequiredNetworkElementKeys();
105 result = RpcResultBuilder.success(outputBuilder);
106 } catch (Exception e) {
107 result = RpcResultBuilder.failed();
108 result.withError(ErrorType.APPLICATION, "Exception", e);
110 return result.buildFuture();
114 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
115 ShowRequiredNetworkElementInput input) {
117 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
118 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
121 ShowRequiredNetworkElementOutputBuilder outputBuilder =
122 maintenanceService.showRequiredNetworkElement(input);
123 result = RpcResultBuilder.success(outputBuilder);
124 } catch (Exception e) {
125 result = RpcResultBuilder.failed();
126 result.withError(ErrorType.APPLICATION, "Exception", e);
128 return result.buildFuture();
132 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
134 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getNodeId());
135 RpcResultBuilder<SetMaintenanceModeOutput> result;
138 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
139 result = RpcResultBuilder.success(outputBuilder);
140 } catch (Exception e) {
141 result = RpcResultBuilder.failed();
142 result.withError(ErrorType.APPLICATION, "Exception", e);
144 return result.buildFuture();
151 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
153 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
154 RpcResultBuilder<GetMaintenanceModeOutput> result;
157 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
158 result = RpcResultBuilder.success(outputBuilder);
159 } catch (Exception e) {
160 result = RpcResultBuilder.failed();
161 result.withError(ErrorType.APPLICATION, "Exception", e);
163 return result.buildFuture();
168 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
169 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
170 RpcResultBuilder<TestMaintenanceModeOutput> result;
173 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
174 result = RpcResultBuilder.success(outputBuilder);
175 } catch (Exception e) {
176 result = RpcResultBuilder.failed();
177 result.withError(ErrorType.APPLICATION, "Exception", e);
179 return result.buildFuture();
185 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
186 ClearCurrentFaultByNodenameInput input) {
187 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
188 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
190 if (this.resyncCallbackListener != null) {
191 List<String> nodeNames =
192 this.resyncCallbackListener.doClearCurrentFaultByNodename(input.getNodenames());
193 ClearCurrentFaultByNodenameOutputBuilder outputBuilder = new ClearCurrentFaultByNodenameOutputBuilder();
194 outputBuilder.setNodenames(nodeNames);
195 result = RpcResultBuilder.success(outputBuilder);
197 result = RpcResultBuilder.failed();
198 result.withError(ErrorType.APPLICATION, "Startup running");
200 } catch (Exception e) {
201 result = RpcResultBuilder.failed();
202 result.withError(ErrorType.APPLICATION, "Exception", e);
204 return result.buildFuture();
208 public ListenableFuture<RpcResult<PushFaultNotificationOutput>> pushFaultNotification(
209 PushFaultNotificationInput input) {
210 LOG.info("RPC Received fault notification {}", input);
211 RpcResultBuilder<PushFaultNotificationOutput> result;
213 pushNotificationsListener.pushFaultNotification(input);
214 result = RpcResultBuilder.success();
215 } catch (Exception e) {
216 result = RpcResultBuilder.failed();
217 result.withError(ErrorType.APPLICATION, "Exception", e);
219 return result.buildFuture();
223 public ListenableFuture<RpcResult<PushAttributeChangeNotificationOutput>> pushAttributeChangeNotification(
224 PushAttributeChangeNotificationInput input) {
225 LOG.info("RPC Received change notification {}", input);
226 RpcResultBuilder<PushAttributeChangeNotificationOutput> result;
228 pushNotificationsListener.pushAttributeChangeNotification(input);
229 result = RpcResultBuilder.success();
230 } catch (Exception e) {
231 result = RpcResultBuilder.failed();
232 result.withError(ErrorType.APPLICATION, "Exception", e);
234 return result.buildFuture();