6f8df0ddb58293866d672fae5f9c78b9b82c33c7
[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 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
13 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
14 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.CreateOtsOmsOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackInput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.RendererRollbackOutput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.ServicePathOutputBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.TransportpceDeviceRendererService;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class DeviceRendererRPCImpl implements TransportpceDeviceRendererService {
32
33     private static final Logger LOG = LoggerFactory.getLogger(DeviceRendererRPCImpl.class);
34     private DeviceRendererService deviceRenderer;
35     private OtnDeviceRendererService otnDeviceRendererService;
36
37     public DeviceRendererRPCImpl(DeviceRendererService deviceRenderer,
38                                  OtnDeviceRendererService otnDeviceRendererService) {
39         this.deviceRenderer = deviceRenderer;
40         this.otnDeviceRendererService = otnDeviceRendererService;
41     }
42
43     /**
44      * This method is the implementation of the 'service-path' RESTCONF service,
45      * which is one of the external APIs into the renderer application. The
46      * service provides two functions:
47      *
48      * <p>
49      * 1. Create This operation results in provisioning the device for a given
50      * wavelength and a list of nodes with each node listing its termination
51      * points.
52      *
53      * <p>
54      * 2. Delete This operation results in de-provisioning the device for a
55      * given wavelength and a list of nodes with each node listing its
56      * termination points.
57      *
58      * <p>
59      * The signature for this method was generated by yang tools from the
60      * renderer API model.
61      *
62      * @param input
63      *            Input parameter from the service-path yang model
64      *
65      * @return Result of the request
66      */
67     @Override
68     public ListenableFuture<RpcResult<ServicePathOutput>> servicePath(ServicePathInput input) {
69         if (input.getOperation().getIntValue() == 1) {
70             LOG.info("Create operation request received");
71             return RpcResultBuilder.success(this.deviceRenderer.setupServicePath(input, null)).buildFuture();
72         } else if (input.getOperation().getIntValue() == 2) {
73             LOG.info("Delete operation request received");
74             return RpcResultBuilder.success(this.deviceRenderer.deleteServicePath(input)).buildFuture();
75         }
76         return RpcResultBuilder.success(new ServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
77     }
78
79     @Override
80     public ListenableFuture<RpcResult<OtnServicePathOutput>> otnServicePath(OtnServicePathInput input) {
81         if (input.getOperation().getIntValue() == 1) {
82             LOG.info("Create operation request received");
83             return RpcResultBuilder.success(this.otnDeviceRendererService.setupOtnServicePath(input)).buildFuture();
84         } else if (input.getOperation().getIntValue() == 2) {
85             LOG.info("Delete operation request received");
86             return RpcResultBuilder.success(this.otnDeviceRendererService.deleteOtnServicePath(input)).buildFuture();
87         }
88         return RpcResultBuilder.success(new OtnServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
89     }
90
91     /**
92      * Rollback created interfaces and cross connects specified by input.
93      *
94      * @param input
95      *            Lists of created interfaces and connections per node
96      * @return Success flag and nodes which failed to rollback
97      */
98     @Override
99     public ListenableFuture<RpcResult<RendererRollbackOutput>> rendererRollback(RendererRollbackInput input) {
100         return RpcResultBuilder.success(this.deviceRenderer.rendererRollback(input)).buildFuture();
101     }
102
103     @Override
104     public ListenableFuture<RpcResult<CreateOtsOmsOutput>> createOtsOms(CreateOtsOmsInput input) {
105         LOG.info("Request received to create oms and ots interfaces on {}: {}", input.getNodeId(), input
106             .getLogicalConnectionPoint());
107         try {
108             return RpcResultBuilder.success(deviceRenderer.createOtsOms(input)).buildFuture();
109         } catch (OpenRoadmInterfaceException e) {
110             LOG.error("failed to send request to create oms and ots interfaces on {}: {}", input.getNodeId(),
111                     input.getLogicalConnectionPoint(),e);
112         }
113         return null;
114     }
115 }