Define PCEP LSP operational state instruction
[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 java.util.concurrent.Future;
11
12 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalOutputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspOutputBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutputBuilder;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28
29 import com.google.common.base.Function;
30 import com.google.common.base.Preconditions;
31 import com.google.common.util.concurrent.Futures;
32
33 final class TopologyRPCs implements NetworkTopologyPcepService {
34         private final ServerSessionManager manager;
35
36         TopologyRPCs(final ServerSessionManager manager) {
37                 this.manager = Preconditions.checkNotNull(manager);
38         }
39
40         @Override
41         public Future<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
42                 return Futures.transform(manager.realAddLsp(input), new Function<OperationResult, RpcResult<AddLspOutput>>() {
43                         @Override
44                         public RpcResult<AddLspOutput> apply(final OperationResult input) {
45                                 return SuccessfulRpcResult.create(new AddLspOutputBuilder(input).build());
46                         }
47                 });
48         }
49
50         @Override
51         public Future<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
52                 return Futures.transform(manager.realRemoveLsp(input), new Function<OperationResult, RpcResult<RemoveLspOutput>>() {
53                         @Override
54                         public RpcResult<RemoveLspOutput> apply(final OperationResult input) {
55                                 return SuccessfulRpcResult.create(new RemoveLspOutputBuilder(input).build());
56                         }
57                 });
58         }
59
60         @Override
61         public Future<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
62                 return Futures.transform(manager.realUpdateLsp(input), new Function<OperationResult, RpcResult<UpdateLspOutput>>() {
63                         @Override
64                         public RpcResult<UpdateLspOutput> apply(final OperationResult input) {
65                                 return SuccessfulRpcResult.create(new UpdateLspOutputBuilder(input).build());
66                         }
67                 });
68         }
69
70         @Override
71         public Future<RpcResult<EnsureLspOperationalOutput>> ensureLspOperational(final EnsureLspOperationalInput input) {
72                 return Futures.transform(manager.realEnsureLspOperational(input), new Function<OperationResult, RpcResult<EnsureLspOperationalOutput>>() {
73                         @Override
74                         public RpcResult<EnsureLspOperationalOutput> apply(final OperationResult input) {
75                                 return SuccessfulRpcResult.create(new EnsureLspOperationalOutputBuilder(input).build());
76                         }
77                 });
78         }
79 }