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.ForwardingListenableFuture;
23 import com.google.common.util.concurrent.ListenableFuture;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.stream.Collectors;
29 import org.eclipse.jdt.annotation.NonNull;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementsListener;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceRPCServiceAPI;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
34 import org.opendaylight.mdsal.binding.api.RpcProviderService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameInput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ClearCurrentFaultByNodenameOutputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.DevicemanagerService;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetMaintenanceModeOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.GetRequiredNetworkElementKeysOutputBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushAttributeChangeNotificationOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushCmNotificationInput;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushCmNotificationOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationInput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.PushFaultNotificationOutput;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutputBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementInput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeInput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutput;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutputBuilder;
60 import org.opendaylight.yangtools.concepts.ObjectRegistration;
61 import org.opendaylight.yangtools.yang.common.ErrorType;
62 import org.opendaylight.yangtools.yang.common.RpcResult;
63 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
67 public class DeviceManagerApiServiceImpl implements DevicemanagerService, AutoCloseable {
69 private static final Logger LOG = LoggerFactory.getLogger(DevicemanagerService.class);
71 private final ObjectRegistration<DevicemanagerService> rpcReg;
72 private @Nullable final MaintenanceRPCServiceAPI maintenanceService;
73 private @Nullable final PushNotifications pushNotificationsListener;
74 private @Nullable final ResyncNetworkElementsListener resyncCallbackListener;
76 public DeviceManagerApiServiceImpl(final RpcProviderService rpcProviderRegistry,
77 MaintenanceServiceImpl maintenanceService, ResyncNetworkElementsListener listener,
78 PushNotifications pushNotificationsListener) {
79 this.maintenanceService = maintenanceService;
80 this.pushNotificationsListener = pushNotificationsListener;
81 this.resyncCallbackListener = listener;
83 // Register ourselves as the REST API RPC implementation
84 LOG.info("Register RPC Service " + DevicemanagerService.class.getSimpleName());
85 this.rpcReg = rpcProviderRegistry.registerRpcImplementation(DevicemanagerService.class, this);
89 public void close() throws Exception {
90 LOG.info("Close RPC Service");
96 /*-------------------------------
97 * Interfaces for MaintenanceService
101 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys(
102 GetRequiredNetworkElementKeysInput input) {
103 return getRequiredNetworkElementKeys();
106 // For casablanca version no input was generated.
107 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys() {
109 LOG.info("RPC Request: getRequiredNetworkElementKeys");
110 RpcResultBuilder<GetRequiredNetworkElementKeysOutput> result;
112 GetRequiredNetworkElementKeysOutputBuilder outputBuilder =
113 maintenanceService.getRequiredNetworkElementKeys();
114 result = RpcResultBuilder.success(outputBuilder.build());
115 } catch (Exception e) {
116 result = RpcResultBuilder.failed();
117 result.withError(ErrorType.APPLICATION, "Exception", e);
119 return result.buildFuture();
123 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
124 ShowRequiredNetworkElementInput input) {
126 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
127 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
130 ShowRequiredNetworkElementOutputBuilder outputBuilder =
131 maintenanceService.showRequiredNetworkElement(input);
132 result = RpcResultBuilder.success(outputBuilder.build());
133 } catch (Exception e) {
134 result = RpcResultBuilder.failed();
135 result.withError(ErrorType.APPLICATION, "Exception", e);
137 return result.buildFuture();
141 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
143 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getNodeId());
144 RpcResultBuilder<SetMaintenanceModeOutput> result;
147 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
148 result = RpcResultBuilder.success(outputBuilder.build());
149 } catch (Exception e) {
150 result = RpcResultBuilder.failed();
151 result.withError(ErrorType.APPLICATION, "Exception", e);
153 return result.buildFuture();
159 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
161 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
162 @NonNull RpcResultBuilder<GetMaintenanceModeOutput> result;
165 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
166 result = RpcResultBuilder.success(outputBuilder.build());
167 } catch (Exception e) {
168 result = RpcResultBuilder.failed();
169 result.withError(ErrorType.APPLICATION, "Exception", e);
171 return result.buildFuture();
176 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
177 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
178 RpcResultBuilder<TestMaintenanceModeOutput> result;
181 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
182 result = RpcResultBuilder.success(outputBuilder.build());
183 } catch (Exception e) {
184 result = RpcResultBuilder.failed();
185 result.withError(ErrorType.APPLICATION, "Exception", e);
187 return result.buildFuture();
193 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
194 ClearCurrentFaultByNodenameInput input) {
195 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
196 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
198 if (this.resyncCallbackListener != null) {
199 List<String> nodeNames =
200 this.resyncCallbackListener.doClearCurrentFaultByNodename(input.getNodenames().stream().collect(Collectors.toList()));
201 ClearCurrentFaultByNodenameOutputBuilder outputBuilder = new ClearCurrentFaultByNodenameOutputBuilder();
202 outputBuilder.setNodenames(new HashSet<>(nodeNames));
203 result = RpcResultBuilder.success(outputBuilder.build());
205 result = RpcResultBuilder.failed();
206 result.withError(ErrorType.APPLICATION, "Startup running");
208 } catch (Exception e) {
209 result = RpcResultBuilder.failed();
210 result.withError(ErrorType.APPLICATION, "Exception", e);
212 return result.buildFuture();
216 public ListenableFuture<RpcResult<PushFaultNotificationOutput>> pushFaultNotification(
217 PushFaultNotificationInput input) {
218 LOG.info("RPC Received fault notification {}", input);
219 RpcResultBuilder<PushFaultNotificationOutput> result;
221 pushNotificationsListener.pushFaultNotification(input);
222 result = RpcResultBuilder.success();
223 } catch (Exception e) {
224 result = RpcResultBuilder.failed();
225 result.withError(ErrorType.APPLICATION, "Exception", e);
227 return result.buildFuture();
231 public ListenableFuture<RpcResult<PushCmNotificationOutput>> pushCmNotification(PushCmNotificationInput input) {
232 LOG.info("RPC Received CM notification {}", input);
233 RpcResultBuilder<PushCmNotificationOutput> result;
235 pushNotificationsListener.pushCMNotification(input);
236 result = RpcResultBuilder.success();
237 } catch (Exception e) {
238 result = RpcResultBuilder.failed();
239 result.withError(ErrorType.APPLICATION, "Exception", e);
241 return result.buildFuture();
245 public ListenableFuture<RpcResult<PushAttributeChangeNotificationOutput>> pushAttributeChangeNotification(
246 PushAttributeChangeNotificationInput input) {
247 LOG.info("RPC Received change notification {}", input);
248 RpcResultBuilder<PushAttributeChangeNotificationOutput> result;
250 pushNotificationsListener.pushAttributeChangeNotification(input);
251 result = RpcResultBuilder.success();
252 } catch (Exception e) {
253 result = RpcResultBuilder.failed();
254 result.withError(ErrorType.APPLICATION, "Exception", e);
256 return result.buildFuture();