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