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 com.google.common.util.concurrent.ListenableFuture;
21 import java.util.List;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
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.controller.sal.binding.api.RpcProviderRegistry;
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.SetMaintenanceModeInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.SetMaintenanceModeOutputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.ShowRequiredNetworkElementOutputBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.devicemanager.rev190109.TestMaintenanceModeOutputBuilder;
45 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
46 import org.opendaylight.yangtools.yang.common.RpcResult;
47 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 public class DeviceManagerApiServiceImpl implements DevicemanagerService, AutoCloseable {
53 private static final Logger LOG = LoggerFactory.getLogger(DevicemanagerService.class);
55 private final RpcRegistration<DevicemanagerService> rpcReg;
57 private MaintenanceRPCServiceAPI maintenanceService;
58 private ResyncNetworkElementsListener resyncCallbackListener;
60 DeviceManagerApiServiceImpl(final RpcProviderRegistry rpcProviderRegistry) {
61 // Register ourselves as the REST API RPC implementation
62 LOG.info("Register RPC Service "+DevicemanagerService.class.getSimpleName());
63 this.maintenanceService = null;
64 this.rpcReg = rpcProviderRegistry.addRpcImplementation(DevicemanagerService.class, this);
67 public void setMaintenanceService(MaintenanceServiceImpl maintenanceService2) {
68 this.maintenanceService = maintenanceService2;
72 public void close() throws Exception {
73 LOG.info("Close RPC Service");
79 /*-------------------------------
80 * Interfaces for MaintenanceService
84 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys(
85 GetRequiredNetworkElementKeysInput input) {
86 return getRequiredNetworkElementKeys();
89 // For casablanca version no input was generated.
90 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys() {
92 LOG.info("RPC Request: getRequiredNetworkElementKeys");
93 RpcResultBuilder<GetRequiredNetworkElementKeysOutput> result;
95 GetRequiredNetworkElementKeysOutputBuilder outputBuilder = maintenanceService.getRequiredNetworkElementKeys();
96 result = RpcResultBuilder.success(outputBuilder);
97 } catch (Exception e) {
98 result = RpcResultBuilder.failed();
99 result.withError(ErrorType.APPLICATION, "Exception", e);
101 return result.buildFuture();
105 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
106 ShowRequiredNetworkElementInput input) {
108 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
109 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
112 ShowRequiredNetworkElementOutputBuilder outputBuilder = maintenanceService.showRequiredNetworkElement(input);
113 result = RpcResultBuilder.success(outputBuilder);
114 } catch (Exception e) {
115 result = RpcResultBuilder.failed();
116 result.withError(ErrorType.APPLICATION, "Exception", e);
118 return result.buildFuture();
122 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
124 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getMountpointName());
125 RpcResultBuilder<SetMaintenanceModeOutput> result;
128 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
129 result = RpcResultBuilder.success(outputBuilder);
130 } catch (Exception e) {
131 result = RpcResultBuilder.failed();
132 result.withError(ErrorType.APPLICATION, "Exception", e);
134 return result.buildFuture();
141 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
143 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
144 RpcResultBuilder<GetMaintenanceModeOutput> result;
147 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
148 result = RpcResultBuilder.success(outputBuilder);
149 } catch (Exception e) {
150 result = RpcResultBuilder.failed();
151 result.withError(ErrorType.APPLICATION, "Exception", e);
153 return result.buildFuture();
158 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
159 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
160 RpcResultBuilder<TestMaintenanceModeOutput> result;
163 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
164 result = RpcResultBuilder.success(outputBuilder);
165 } catch (Exception e) {
166 result = RpcResultBuilder.failed();
167 result.withError(ErrorType.APPLICATION, "Exception", e);
169 return result.buildFuture();
175 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
176 ClearCurrentFaultByNodenameInput input) {
177 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
178 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
180 if(this.resyncCallbackListener!=null) {
181 List<String> nodeNames= this.resyncCallbackListener.doClearCurrentFaultByNodename(input.getNodenames());
182 ClearCurrentFaultByNodenameOutputBuilder outputBuilder = new ClearCurrentFaultByNodenameOutputBuilder();
183 outputBuilder.setNodenames(nodeNames);
184 result = RpcResultBuilder.success(outputBuilder);
186 result = RpcResultBuilder.failed();
187 result.withError(ErrorType.APPLICATION, "Startup running" );
189 } catch(Exception e) {
190 result = RpcResultBuilder.failed();
191 result.withError(ErrorType.APPLICATION, "Exception", e);
193 return result.buildFuture();
196 public void setResyncListener(ResyncNetworkElementsListener listener) {
197 this.resyncCallbackListener = listener;