42fda976fd0647ed272660c4d94c2e1cd3fdbfb8
[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.rev200128.CancelResourceReserveInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.CancelResourceReserveOutput;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceService;
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  * PceService implementation.
25  */
26 public class PceServiceRPCImpl implements TransportpcePceService {
27
28     private static final Logger LOG = LoggerFactory.getLogger(PceServiceRPCImpl.class);
29
30     private final PathComputationService pathComputationService;
31
32     public PceServiceRPCImpl(PathComputationService pathComputationService) {
33         this.pathComputationService = pathComputationService;
34     }
35
36     @Override
37     public ListenableFuture<RpcResult<CancelResourceReserveOutput>>
38             cancelResourceReserve(CancelResourceReserveInput input) {
39         LOG.info("RPC cancelResourceReserve request received");
40         CancelResourceReserveOutput output = null;
41         try {
42             output = this.pathComputationService.cancelResourceReserve(input).get();
43         } catch (InterruptedException | ExecutionException e) {
44             LOG.error("RPC cancelResourceReserve failed !", e);
45         }
46         return RpcResultBuilder.success(output).buildFuture();
47     }
48
49     @Override
50     public ListenableFuture<RpcResult<PathComputationRequestOutput>>
51             pathComputationRequest(PathComputationRequestInput input) {
52         LOG.info("RPC path computation request received");
53         PathComputationRequestOutput output = null;
54         try {
55             output = this.pathComputationService.pathComputationRequest(input).get();
56         } catch (InterruptedException | ExecutionException e) {
57             LOG.error("RPC path computation request failed !", e);
58         }
59         return RpcResultBuilder.success(output).buildFuture();
60     }
61 }