5a709d6ab7387551b0fcc2cb04ba00e082880089
[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.device.renderer.rev210618.CreateOtsOmsInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.CreateOtsOmsOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.OtnServicePathOutputBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackInput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.RendererRollbackOutput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.ServicePathOutputBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev210618.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() != null) {
70             if (input.getOperation().getIntValue() == 1) {
71                 LOG.info("Create operation request received");
72                 return RpcResultBuilder.success(
73                         this.deviceRenderer.setupServicePath(input, null))
74                         .buildFuture();
75             } else if (input.getOperation().getIntValue() == 2) {
76                 LOG.info("Delete operation request received");
77                 return RpcResultBuilder
78                         .success(this.deviceRenderer.deleteServicePath(input))
79                         .buildFuture();
80             }
81         }
82         return RpcResultBuilder.success(new ServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
83     }
84
85     @Override
86     public ListenableFuture<RpcResult<OtnServicePathOutput>> otnServicePath(OtnServicePathInput input) {
87         if (input.getOperation() != null) {
88             if (input.getOperation().getIntValue() == 1) {
89                 LOG.info("Create operation request received");
90                 return RpcResultBuilder.success(this.otnDeviceRendererService
91                         .setupOtnServicePath(input)).buildFuture();
92             } else if (input.getOperation().getIntValue() == 2) {
93                 LOG.info("Delete operation request received");
94                 return RpcResultBuilder.success(this.otnDeviceRendererService
95                         .deleteOtnServicePath(input)).buildFuture();
96             }
97         }
98         return RpcResultBuilder.success(new OtnServicePathOutputBuilder().setResult("Invalid operation")).buildFuture();
99     }
100
101     /**
102      * Rollback created interfaces and cross connects specified by input.
103      *
104      * @param input
105      *            Lists of created interfaces and connections per node
106      * @return Success flag and nodes which failed to rollback
107      */
108     @Override
109     public ListenableFuture<RpcResult<RendererRollbackOutput>> rendererRollback(RendererRollbackInput input) {
110         return RpcResultBuilder.success(this.deviceRenderer.rendererRollback(input)).buildFuture();
111     }
112
113     @Override
114     public ListenableFuture<RpcResult<CreateOtsOmsOutput>> createOtsOms(CreateOtsOmsInput input) {
115         LOG.info("Request received to create oms and ots interfaces on {}: {}", input.getNodeId(), input
116             .getLogicalConnectionPoint());
117         try {
118             return RpcResultBuilder.success(deviceRenderer.createOtsOms(input)).buildFuture();
119         } catch (OpenRoadmInterfaceException e) {
120             LOG.error("failed to send request to create oms and ots interfaces on {}: {}", input.getNodeId(),
121                     input.getLogicalConnectionPoint(),e);
122         }
123         return null;
124     }
125 }