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