e201199c56417f185dc5a63540c1450c50646879
[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
12 import java.util.concurrent.ExecutionException;
13
14 import org.opendaylight.transportpce.pce.service.PathComputationService;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.CancelResourceReserveInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.CancelResourceReserveOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.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         CancelResourceReserveOutput output = null;
43         try {
44             output = this.pathComputationService.cancelResourceReserve(input).get();
45         } catch (InterruptedException | ExecutionException e) {
46             LOG.error("RPC cancelResourceReserve failed !", e);
47         }
48         return RpcResultBuilder.success(output).buildFuture();
49     }
50
51     @Override
52     public ListenableFuture<RpcResult<PathComputationRequestOutput>>
53             pathComputationRequest(PathComputationRequestInput input) {
54         LOG.info("RPC path computation request received");
55         PathComputationRequestOutput output = null;
56         try {
57             output = this.pathComputationService.pathComputationRequest(input).get();
58         } catch (InterruptedException | ExecutionException e) {
59             LOG.error("RPC path computation request failed !", e);
60         }
61         return RpcResultBuilder.success(output).buildFuture();
62     }
63 }