Fix spotbugs issues of the renderer module
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / rpcs / DeviceRendererRPCImpl.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer.rpcs;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12
13 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
14 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
15 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathInput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackInput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathInput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutputBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.TransportpceDeviceRendererService;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class DeviceRendererRPCImpl implements TransportpceDeviceRendererService {
33
34     private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererRPCImpl.class);
35     private DeviceRendererService deviceRenderer;
36     private OtnDeviceRendererService otnDeviceRendererService;
37
38     public DeviceRendererRPCImpl(DeviceRendererService deviceRenderer,
39                                  OtnDeviceRendererService otnDeviceRendererService) {
40         this.deviceRenderer = deviceRenderer;
41         this.otnDeviceRendererService = otnDeviceRendererService;
42     }
43
44     /**
45      * This method is the implementation of the 'service-path' RESTCONF service,
46      * which is one of the external APIs into the renderer application. The
47      * service provides two functions:
48      *
49      * <p>
50      * 1. Create This operation results in provisioning the device for a given
51      * wavelength and a list of nodes with each node listing its termination
52      * points.
53      *
54      * <p>
55      * 2. Delete This operation results in de-provisioning the device for a
56      * given wavelength and a list of nodes with each node listing its
57      * termination points.
58      *
59      * <p>
60      * The signature for this method was generated by yang tools from the
61      * renderer API model.
62      *
63      * @param input
64      *            Input parameter from the service-path yang model
65      *
66      * @return Result of the request
67      */
68     @Override
69     public ListenableFuture<RpcResult<ServicePathOutput>> servicePath(ServicePathInput input) {
70         if (input.getOperation() != null) {
71             if (input.getOperation().getIntValue() == 1) {
72                 LOG.info("Create operation request received");
73                 return RpcResultBuilder.success(
74                         this.deviceRenderer.setupServicePath(input, null))
75                         .buildFuture();
76             } else if (input.getOperation().getIntValue() == 2) {
77                 LOG.info("Delete operation request received");
78                 return RpcResultBuilder
79                         .success(this.deviceRenderer.deleteServicePath(input))
80                         .buildFuture();
81             }
82         }
83         return RpcResultBuilder.success(new ServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
84     }
85
86     @Override
87     public ListenableFuture<RpcResult<OtnServicePathOutput>> otnServicePath(OtnServicePathInput input) {
88         if (input.getOperation() != null) {
89             if (input.getOperation().getIntValue() == 1) {
90                 LOG.info("Create operation request received");
91                 return RpcResultBuilder.success(this.otnDeviceRendererService
92                         .setupOtnServicePath(input)).buildFuture();
93             } else if (input.getOperation().getIntValue() == 2) {
94                 LOG.info("Delete operation request received");
95                 return RpcResultBuilder.success(this.otnDeviceRendererService
96                         .deleteOtnServicePath(input)).buildFuture();
97             }
98         }
99         return RpcResultBuilder.success(new OtnServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
100     }
101
102     /**
103      * Rollback created interfaces and cross connects specified by input.
104      *
105      * @param input
106      *            Lists of created interfaces and connections per node
107      * @return Success flag and nodes which failed to rollback
108      */
109     @Override
110     public ListenableFuture<RpcResult<RendererRollbackOutput>> rendererRollback(RendererRollbackInput input) {
111         return RpcResultBuilder.success(this.deviceRenderer.rendererRollback(input)).buildFuture();
112     }
113
114     @Override
115     public ListenableFuture<RpcResult<CreateOtsOmsOutput>> createOtsOms(CreateOtsOmsInput input) {
116         LOG.info("Request received to create oms and ots interfaces on {}: {}", input.getNodeId(), input
117             .getLogicalConnectionPoint());
118         try {
119             return RpcResultBuilder.success(deviceRenderer.createOtsOms(input)).buildFuture();
120         } catch (OpenRoadmInterfaceException e) {
121             LOG.error("failed to send request to create oms and ots interfaces on {}: {}", input.getNodeId(),
122                     input.getLogicalConnectionPoint(),e);
123         }
124         return null;
125     }
126 }