1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
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;
64 final MaintenanceRPCServiceAPI maintenanceService;
66 final PushNotifications pushNotificationsListener;
68 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 = maintenanceService.getRequiredNetworkElementKeys();
107 result = RpcResultBuilder.success(outputBuilder);
108 } catch (Exception e) {
109 result = RpcResultBuilder.failed();
110 result.withError(ErrorType.APPLICATION, "Exception", e);
112 return result.buildFuture();
116 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
117 ShowRequiredNetworkElementInput input) {
119 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
120 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
123 ShowRequiredNetworkElementOutputBuilder outputBuilder = maintenanceService.showRequiredNetworkElement(input);
124 result = RpcResultBuilder.success(outputBuilder);
125 } catch (Exception e) {
126 result = RpcResultBuilder.failed();
127 result.withError(ErrorType.APPLICATION, "Exception", e);
129 return result.buildFuture();
133 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
135 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getNodeId());
136 RpcResultBuilder<SetMaintenanceModeOutput> result;
139 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
140 result = RpcResultBuilder.success(outputBuilder);
141 } catch (Exception e) {
142 result = RpcResultBuilder.failed();
143 result.withError(ErrorType.APPLICATION, "Exception", e);
145 return result.buildFuture();
152 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
154 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
155 RpcResultBuilder<GetMaintenanceModeOutput> result;
158 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
159 result = RpcResultBuilder.success(outputBuilder);
160 } catch (Exception e) {
161 result = RpcResultBuilder.failed();
162 result.withError(ErrorType.APPLICATION, "Exception", e);
164 return result.buildFuture();
169 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
170 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
171 RpcResultBuilder<TestMaintenanceModeOutput> result;
174 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
175 result = RpcResultBuilder.success(outputBuilder);
176 } catch (Exception e) {
177 result = RpcResultBuilder.failed();
178 result.withError(ErrorType.APPLICATION, "Exception", e);
180 return result.buildFuture();
186 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
187 ClearCurrentFaultByNodenameInput input) {
188 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
189 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
191 if(this.resyncCallbackListener!=null) {
192 List<String> nodeNames= 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();