Turn PceServiceRPCImpl into a Component
[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.osgi.service.component.annotations.Activate;
23 import org.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.Reference;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * PceService implementation.
30  */
31 @Component
32 public class PceServiceRPCImpl implements TransportpcePceService {
33
34     private static final Logger LOG = LoggerFactory.getLogger(PceServiceRPCImpl.class);
35
36     private final PathComputationService pathComputationService;
37
38     @Activate
39     public PceServiceRPCImpl(@Reference PathComputationService pathComputationService) {
40         this.pathComputationService = pathComputationService;
41         LOG.info("PceServiceRPCImpl instantiated");
42     }
43
44     @Override
45     public ListenableFuture<RpcResult<CancelResourceReserveOutput>>
46             cancelResourceReserve(CancelResourceReserveInput input) {
47         LOG.info("RPC cancelResourceReserve request received");
48         try {
49             return RpcResultBuilder
50                     .success(
51                             this.pathComputationService.cancelResourceReserve(input).get())
52                     .buildFuture();
53         } catch (InterruptedException | ExecutionException e) {
54             LOG.error("RPC cancelResourceReserve failed !", e);
55             return RpcResultBuilder.success((CancelResourceReserveOutput) null).buildFuture();
56         }
57     }
58
59     @Override
60     public ListenableFuture<RpcResult<PathComputationRequestOutput>>
61             pathComputationRequest(PathComputationRequestInput input) {
62         LOG.info("RPC path computation request received");
63         LOG.debug("input parameters are : input = {}", input);
64         try {
65             return RpcResultBuilder
66                     .success(
67                             this.pathComputationService.pathComputationRequest(input).get())
68                     .buildFuture();
69         } catch (InterruptedException | ExecutionException e) {
70             LOG.error("RPC path computation request failed !", e);
71         }
72         return RpcResultBuilder.success((PathComputationRequestOutput) null).buildFuture();
73     }
74
75     @Override
76     public ListenableFuture<RpcResult<PathComputationRerouteRequestOutput>> pathComputationRerouteRequest(
77             PathComputationRerouteRequestInput input) {
78         LOG.info("RPC path computation reroute request received");
79         LOG.debug("input parameters are : input = {}", input);
80         try {
81             return RpcResultBuilder
82                     .success(
83                             this.pathComputationService.pathComputationRerouteRequest(input).get())
84                     .buildFuture();
85         } catch (InterruptedException | ExecutionException e) {
86             LOG.error("RPC path computation request failed !", e);
87             return RpcResultBuilder.success((PathComputationRerouteRequestOutput) null).buildFuture();
88         }
89     }
90 }