13fd7684d842a0e27c2f85f5122c19eb31690fa7
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / impl / PceServiceRPCImpl.java
1 /*
2  * Copyright © 2017 AT&T, 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.pce.impl;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.transportpce.pce.service.PathComputationService;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceService;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * PceService implementation.
27  */
28 public class PceServiceRPCImpl implements TransportpcePceService {
29
30     private static final Logger LOG = LoggerFactory.getLogger(PceServiceRPCImpl.class);
31
32     private final PathComputationService pathComputationService;
33
34     public PceServiceRPCImpl(PathComputationService pathComputationService) {
35         this.pathComputationService = pathComputationService;
36     }
37
38     @Override
39     public ListenableFuture<RpcResult<CancelResourceReserveOutput>>
40             cancelResourceReserve(CancelResourceReserveInput input) {
41         LOG.info("RPC cancelResourceReserve request received");
42         try {
43             return RpcResultBuilder
44                     .success(
45                             this.pathComputationService.cancelResourceReserve(input).get())
46                     .buildFuture();
47         } catch (InterruptedException | ExecutionException e) {
48             LOG.error("RPC cancelResourceReserve failed !", e);
49             return RpcResultBuilder.success((CancelResourceReserveOutput) null).buildFuture();
50         }
51     }
52
53     @Override
54     public ListenableFuture<RpcResult<PathComputationRequestOutput>>
55             pathComputationRequest(PathComputationRequestInput input) {
56         LOG.info("RPC path computation request received");
57         LOG.debug("input parameters are : input = {}", input);
58         try {
59             return RpcResultBuilder
60                     .success(
61                             this.pathComputationService.pathComputationRequest(input).get())
62                     .buildFuture();
63         } catch (InterruptedException | ExecutionException e) {
64             LOG.error("RPC path computation request failed !", e);
65         }
66         return RpcResultBuilder.success((PathComputationRequestOutput) null).buildFuture();
67     }
68
69     @Override
70     public ListenableFuture<RpcResult<PathComputationRerouteRequestOutput>> pathComputationRerouteRequest(
71             PathComputationRerouteRequestInput input) {
72         LOG.info("RPC path computation reroute request received");
73         LOG.debug("input parameters are : input = {}", input);
74         try {
75             return RpcResultBuilder
76                     .success(
77                             this.pathComputationService.pathComputationRerouteRequest(input).get())
78                     .buildFuture();
79         } catch (InterruptedException | ExecutionException e) {
80             LOG.error("RPC path computation request failed !", e);
81             return RpcResultBuilder.success((PathComputationRerouteRequestOutput) null).buildFuture();
82         }
83     }
84 }