Bump upstream dependencies to Ca
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / rpcs / ServicePathImpl.java
1 /*
2  * Copyright © 2024 Orange, Inc. 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 package org.opendaylight.transportpce.renderer.rpcs;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePath;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
18 import org.opendaylight.yangtools.yang.common.RpcResult;
19 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23
24 /**
25  * This class is the implementation of the 'service-path' RESTCONF service,
26  * which is one of the external APIs into the renderer application. The
27  * service provides two functions:
28  *
29  * <p>
30  * 1. Create This operation results in provisioning the device for a given
31  * wavelength and a list of nodes with each node listing its termination
32  * points.
33  *
34  * <p>
35  * 2. Delete This operation results in de-provisioning the device for a
36  * given wavelength and a list of nodes with each node listing its
37  * termination points.
38  *
39  * <p>
40  * The signature for this method was generated by yang tools from the
41  * renderer API model.
42  */
43 public class ServicePathImpl implements ServicePath {
44     private static final Logger LOG = LoggerFactory.getLogger(ServicePathImpl.class);
45     private DeviceRendererService deviceRendererService;
46
47     public ServicePathImpl(final DeviceRendererService deviceRendererService) {
48         this.deviceRendererService = requireNonNull(deviceRendererService);
49     }
50
51     @Override
52     public ListenableFuture<RpcResult<ServicePathOutput>> invoke(ServicePathInput input) {
53         if (input.getOperation() != null) {
54             if (input.getOperation().getIntValue() == 1) {
55                 LOG.info("Create operation request received");
56                 return RpcResultBuilder.success(
57                         this.deviceRendererService.setupServicePath(input, null))
58                         .buildFuture();
59             } else if (input.getOperation().getIntValue() == 2) {
60                 LOG.info("Delete operation request received");
61                 return RpcResultBuilder
62                         .success(this.deviceRendererService.deleteServicePath(input))
63                         .buildFuture();
64             }
65         }
66         return RpcResultBuilder
67             .success(new ServicePathOutputBuilder().setResult("Invalid operation").build())
68             .buildFuture();
69     }
70
71 }