BUG-9079 Make PCEP session recoverable from exception
[bgpcep.git] / pcep / topology-provider / src / main / java / org / opendaylight / bgpcep / pcep / topology / provider / TopologyRPCs.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.bgpcep.pcep.topology.provider;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.Futures;
13 import java.util.concurrent.Future;
14 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
22
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.TriggerSyncOutputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutputBuilder;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33
34 final class TopologyRPCs implements NetworkTopologyPcepService {
35     private final ServerSessionManager manager;
36
37     TopologyRPCs(final ServerSessionManager manager) {
38         this.manager = requireNonNull(manager);
39     }
40
41     @Override
42     public Future<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
43         return Futures.transform(this.manager.addLsp(input), input1 -> SuccessfulRpcResult.create(new AddLspOutputBuilder(input1).build()));
44     }
45
46     @Override
47     public Future<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
48         return Futures.transform(this.manager.removeLsp(input), input1 -> SuccessfulRpcResult.create(new RemoveLspOutputBuilder(input1).build()));
49     }
50
51     @Override
52     public Future<RpcResult<TriggerSyncOutput>> triggerSync(final TriggerSyncInput input) {
53         return Futures.transform(this.manager.triggerSync(input), input1 -> SuccessfulRpcResult.create(new TriggerSyncOutputBuilder(input1).build()));
54     }
55
56     @Override
57     public Future<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
58         return Futures.transform(this.manager.updateLsp(input), input1 -> SuccessfulRpcResult.create(new UpdateLspOutputBuilder(input1).build()));
59     }
60
61     @Override
62     public Future<RpcResult<EnsureLspOperationalOutput>> ensureLspOperational(final EnsureLspOperationalInput input) {
63         return Futures.transform(this.manager.ensureLspOperational(input),
64             input1 -> SuccessfulRpcResult.create(new EnsureLspOperationalOutputBuilder(input1).build()));
65     }
66 }