Remove renderer-blueprint
[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.rev211004.CreateOtsOmsInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackInput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.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         LOG.debug("DeviceRendererRPCImpl instantiated");
43     }
44
45     /**
46      * This method is the implementation of the 'service-path' RESTCONF service,
47      * which is one of the external APIs into the renderer application. The
48      * service provides two functions:
49      *
50      * <p>
51      * 1. Create This operation results in provisioning the device for a given
52      * wavelength and a list of nodes with each node listing its termination
53      * points.
54      *
55      * <p>
56      * 2. Delete This operation results in de-provisioning the device for a
57      * given wavelength and a list of nodes with each node listing its
58      * termination points.
59      *
60      * <p>
61      * The signature for this method was generated by yang tools from the
62      * renderer API model.
63      *
64      * @param input
65      *            Input parameter from the service-path yang model
66      *
67      * @return Result of the request
68      */
69     @Override
70     public ListenableFuture<RpcResult<ServicePathOutput>> servicePath(ServicePathInput input) {
71         if (input.getOperation() != null) {
72             if (input.getOperation().getIntValue() == 1) {
73                 LOG.info("Create operation request received");
74                 return RpcResultBuilder.success(
75                         this.deviceRenderer.setupServicePath(input, null))
76                         .buildFuture();
77             } else if (input.getOperation().getIntValue() == 2) {
78                 LOG.info("Delete operation request received");
79                 return RpcResultBuilder
80                         .success(this.deviceRenderer.deleteServicePath(input))
81                         .buildFuture();
82             }
83         }
84         return RpcResultBuilder
85             .success(new ServicePathOutputBuilder().setResult("Invalid operation").build())
86             .buildFuture();
87     }
88
89     @Override
90     public ListenableFuture<RpcResult<OtnServicePathOutput>> otnServicePath(OtnServicePathInput input) {
91         if (input.getOperation() != null && input.getServiceFormat() != null && input.getServiceRate() != null) {
92             String serviceType = ServiceTypes.getOtnServiceType(input.getServiceFormat(), input.getServiceRate());
93             if (input.getOperation().getIntValue() == 1) {
94                 LOG.info("Create operation request received");
95                 return RpcResultBuilder.success(this.otnDeviceRendererService
96                         .setupOtnServicePath(input, serviceType)).buildFuture();
97             } else if (input.getOperation().getIntValue() == 2) {
98                 LOG.info("Delete operation request received");
99                 return RpcResultBuilder.success(this.otnDeviceRendererService
100                         .deleteOtnServicePath(input, serviceType)).buildFuture();
101             }
102         }
103         return RpcResultBuilder
104             .success(new OtnServicePathOutputBuilder().setResult("Invalid operation").build())
105             .buildFuture();
106     }
107
108     /**
109      * Rollback created interfaces and cross connects specified by input.
110      *
111      * @param input
112      *            Lists of created interfaces and connections per node
113      * @return Success flag and nodes which failed to rollback
114      */
115     @Override
116     public ListenableFuture<RpcResult<RendererRollbackOutput>> rendererRollback(RendererRollbackInput input) {
117         return RpcResultBuilder.success(this.deviceRenderer.rendererRollback(input)).buildFuture();
118     }
119
120     @Override
121     public ListenableFuture<RpcResult<CreateOtsOmsOutput>> createOtsOms(CreateOtsOmsInput input) {
122         LOG.info("Request received to create oms and ots interfaces on {}: {}", input.getNodeId(), input
123             .getLogicalConnectionPoint());
124         try {
125             return RpcResultBuilder.success(deviceRenderer.createOtsOms(input)).buildFuture();
126         } catch (OpenRoadmInterfaceException e) {
127             LOG.error("failed to send request to create oms and ots interfaces on {}: {}", input.getNodeId(),
128                     input.getLogicalConnectionPoint(),e);
129         }
130         return null;
131     }
132 }