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