2 * Copyright © 2017 AT&T, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.pce.impl;
10 import com.google.common.collect.ImmutableClassToInstanceMap;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.transportpce.pce.service.PathComputationService;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserve;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequest;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequest;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.TransportpcePceService;
25 import org.opendaylight.yangtools.concepts.Registration;
26 import org.opendaylight.yangtools.yang.binding.Rpc;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Deactivate;
32 import org.osgi.service.component.annotations.Reference;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
37 * PceService implementation.
39 @Component(immediate = true)
40 public class PceServiceRPCImpl implements TransportpcePceService {
42 private static final Logger LOG = LoggerFactory.getLogger(PceServiceRPCImpl.class);
44 private final PathComputationService pathComputationService;
45 private Registration reg;
48 public PceServiceRPCImpl(@Reference RpcProviderService rpcProviderService,
49 @Reference PathComputationService pathComputationService) {
50 this.pathComputationService = pathComputationService;
51 this.reg = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
52 .put(CancelResourceReserve.class, this::cancelResourceReserve)
53 .put(PathComputationRequest.class, this::pathComputationRequest)
54 .put(PathComputationRerouteRequest.class, this::pathComputationRerouteRequest)
57 LOG.info("PceServiceRPCImpl instantiated");
63 LOG.info("PceServiceRPCImpl Closed");
67 public final ListenableFuture<RpcResult<CancelResourceReserveOutput>>
68 cancelResourceReserve(CancelResourceReserveInput input) {
69 LOG.info("RPC cancelResourceReserve request received");
71 return RpcResultBuilder
73 this.pathComputationService.cancelResourceReserve(input).get())
75 } catch (InterruptedException | ExecutionException e) {
76 LOG.error("RPC cancelResourceReserve failed !", e);
77 return RpcResultBuilder.success((CancelResourceReserveOutput) null).buildFuture();
82 public final ListenableFuture<RpcResult<PathComputationRequestOutput>>
83 pathComputationRequest(PathComputationRequestInput input) {
84 LOG.info("RPC path computation request received");
85 LOG.debug("input parameters are : input = {}", input);
87 return RpcResultBuilder
89 this.pathComputationService.pathComputationRequest(input).get())
91 } catch (InterruptedException | ExecutionException e) {
92 LOG.error("RPC path computation request failed !", e);
94 return RpcResultBuilder.success((PathComputationRequestOutput) null).buildFuture();
98 public final ListenableFuture<RpcResult<PathComputationRerouteRequestOutput>> pathComputationRerouteRequest(
99 PathComputationRerouteRequestInput input) {
100 LOG.info("RPC path computation reroute request received");
101 LOG.debug("input parameters are : input = {}", input);
103 return RpcResultBuilder
105 this.pathComputationService.pathComputationRerouteRequest(input).get())
107 } catch (InterruptedException | ExecutionException e) {
108 LOG.error("RPC path computation request failed !", e);
109 return RpcResultBuilder.success((PathComputationRerouteRequestOutput) null).buildFuture();
113 public Registration getRegisteredRpc() {