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 @SuppressWarnings("deprecation")
52 public class DeviceManagerApiServiceImpl implements DevicemanagerService, AutoCloseable {
54 private static final Logger LOG = LoggerFactory.getLogger(DevicemanagerService.class);
56 private final RpcRegistration<DevicemanagerService> rpcReg;
58 private MaintenanceRPCServiceAPI maintenanceService;
59 private ResyncNetworkElementsListener resyncCallbackListener;
61 DeviceManagerApiServiceImpl(final RpcProviderRegistry rpcProviderRegistry) {
62 // Register ourselves as the REST API RPC implementation
63 LOG.info("Register RPC Service "+DevicemanagerService.class.getSimpleName());
64 this.maintenanceService = null;
65 this.rpcReg = rpcProviderRegistry.addRpcImplementation(DevicemanagerService.class, this);
68 public void setMaintenanceService(MaintenanceServiceImpl maintenanceService2) {
69 this.maintenanceService = maintenanceService2;
73 public void close() throws Exception {
74 LOG.info("Close RPC Service");
80 /*-------------------------------
81 * Interfaces for MaintenanceService
85 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys(
86 GetRequiredNetworkElementKeysInput input) {
87 return getRequiredNetworkElementKeys();
90 // For casablanca version no input was generated.
91 public ListenableFuture<RpcResult<GetRequiredNetworkElementKeysOutput>> getRequiredNetworkElementKeys() {
93 LOG.info("RPC Request: getRequiredNetworkElementKeys");
94 RpcResultBuilder<GetRequiredNetworkElementKeysOutput> result;
96 GetRequiredNetworkElementKeysOutputBuilder outputBuilder = maintenanceService.getRequiredNetworkElementKeys();
97 result = RpcResultBuilder.success(outputBuilder);
98 } catch (Exception e) {
99 result = RpcResultBuilder.failed();
100 result.withError(ErrorType.APPLICATION, "Exception", e);
102 return result.buildFuture();
106 public ListenableFuture<RpcResult<ShowRequiredNetworkElementOutput>> showRequiredNetworkElement(
107 ShowRequiredNetworkElementInput input) {
109 LOG.info("RPC Request: showRequiredNetworkElement input: {}", input.getMountpointName());
110 RpcResultBuilder<ShowRequiredNetworkElementOutput> result;
113 ShowRequiredNetworkElementOutputBuilder outputBuilder = maintenanceService.showRequiredNetworkElement(input);
114 result = RpcResultBuilder.success(outputBuilder);
115 } catch (Exception e) {
116 result = RpcResultBuilder.failed();
117 result.withError(ErrorType.APPLICATION, "Exception", e);
119 return result.buildFuture();
123 public ListenableFuture<RpcResult<SetMaintenanceModeOutput>> setMaintenanceMode(SetMaintenanceModeInput input) {
125 LOG.info("RPC Request: setMaintenanceMode input: {}", input.getMountpointName());
126 RpcResultBuilder<SetMaintenanceModeOutput> result;
129 SetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.setMaintenanceMode(input);
130 result = RpcResultBuilder.success(outputBuilder);
131 } catch (Exception e) {
132 result = RpcResultBuilder.failed();
133 result.withError(ErrorType.APPLICATION, "Exception", e);
135 return result.buildFuture();
142 public ListenableFuture<RpcResult<GetMaintenanceModeOutput>> getMaintenanceMode(GetMaintenanceModeInput input) {
144 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
145 RpcResultBuilder<GetMaintenanceModeOutput> result;
148 GetMaintenanceModeOutputBuilder outputBuilder = maintenanceService.getMaintenanceMode(input);
149 result = RpcResultBuilder.success(outputBuilder);
150 } catch (Exception e) {
151 result = RpcResultBuilder.failed();
152 result.withError(ErrorType.APPLICATION, "Exception", e);
154 return result.buildFuture();
159 public ListenableFuture<RpcResult<TestMaintenanceModeOutput>> testMaintenanceMode(TestMaintenanceModeInput input) {
160 LOG.info("RPC Request: getMaintenanceMode input: {}", input.getMountpointName());
161 RpcResultBuilder<TestMaintenanceModeOutput> result;
164 TestMaintenanceModeOutputBuilder outputBuilder = maintenanceService.testMaintenanceMode(input);
165 result = RpcResultBuilder.success(outputBuilder);
166 } catch (Exception e) {
167 result = RpcResultBuilder.failed();
168 result.withError(ErrorType.APPLICATION, "Exception", e);
170 return result.buildFuture();
176 public ListenableFuture<RpcResult<ClearCurrentFaultByNodenameOutput>> clearCurrentFaultByNodename(
177 ClearCurrentFaultByNodenameInput input) {
178 LOG.info("RPC Request: clearNetworkElementAlarms input: {}", input.getNodenames());
179 RpcResultBuilder<ClearCurrentFaultByNodenameOutput> result;
181 if(this.resyncCallbackListener!=null) {
182 List<String> nodeNames= this.resyncCallbackListener.doClearCurrentFaultByNodename(input.getNodenames());
183 ClearCurrentFaultByNodenameOutputBuilder outputBuilder = new ClearCurrentFaultByNodenameOutputBuilder();
184 outputBuilder.setNodenames(nodeNames);
185 result = RpcResultBuilder.success(outputBuilder);
187 result = RpcResultBuilder.failed();
188 result.withError(ErrorType.APPLICATION, "Startup running" );
190 } catch(Exception e) {
191 result = RpcResultBuilder.failed();
192 result.withError(ErrorType.APPLICATION, "Exception", e);
194 return result.buildFuture();
197 public void setResyncListener(ResyncNetworkElementsListener listener) {
198 this.resyncCallbackListener = listener;