Migrated usage of RpcService to Rpc<?,?> for pcep-topology-provider.
JIRA: BGPCEP-1027
Change-Id: If7b9733e71e60f34d459165a544e76b0490f9a73
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
-import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.bgpcep.topology.DefaultTopologyReference;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.NetworkTopologyPcepProgrammingService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.NetworkTopologyPcepService;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yangtools.concepts.Registration;
// Register RPCs
final RpcProviderService rpcRegistry = dependencies.getRpcProviderRegistry();
- elementReg = rpcRegistry.registerRpcImplementation(NetworkTopologyPcepService.class,
- new TopologyRPCs(manager), Set.of(instanceIdentifier));
- networkReg = rpcRegistry.registerRpcImplementation(NetworkTopologyPcepProgrammingService.class,
- new TopologyProgramming(scheduler, manager), Set.of(instanceIdentifier));
+ elementReg = new TopologyRPCs(manager).register(rpcRegistry, instanceIdentifier);
+ networkReg = new TopologyProgramming(scheduler, manager).register(rpcRegistry, instanceIdentifier);
// We are now completely initialized
LOG.info("PCEP Topology Provider {} enabled", topologyId());
import org.opendaylight.protocol.pcep.MessageRegistry;
import org.opendaylight.protocol.pcep.PCEPDispatcher;
import org.opendaylight.protocol.pcep.spi.PCEPExtensionConsumerContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.PcepTopologyStatsRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TopologyTypes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.network.topology.topology.topology.types.TopologyPcep;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
// Statistics provider
private final @NonNull TopologyStatsProvider statsProvider;
// Statistics RPCs
- private final @NonNull TopologyStatsRpcServiceImpl statsRpcs;
+ private final @NonNull TopologyStatsRpc statsRpcs;
// We are reusing our monitor as the universal lock. We have to account for three distinct threads competing for
// our state:
private final ConcurrentMap<TopologyKey, PCEPTopologySingleton> instances = new ConcurrentHashMap<>();
@GuardedBy("this")
private Registration reg;
- @GuardedBy("this")
- private Registration statsReg;
@Inject
@Activate
this.instructionSchedulerFactory = requireNonNull(instructionSchedulerFactory);
this.pceServerProvider = requireNonNull(pceServerProvider);
statsProvider = new TopologyStatsProvider(timer);
- statsRpcs = new TopologyStatsRpcServiceImpl(dataBroker);
- statsReg = rpcProviderRegistry.registerRpcImplementation(PcepTopologyStatsRpcService.class, statsRpcs);
+ statsRpcs = new TopologyStatsRpc(dataBroker, rpcProviderRegistry);
reg = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(TopologyTypes.class)
reg.close();
reg = null;
- statsReg.close();
- statsReg = null;
statsRpcs.close();
// First pass: destroy all tracked instances
import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Set;
import org.opendaylight.bgpcep.pcep.topology.spi.AbstractInstructionExecutor;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.NetworkTopologyPcepProgrammingService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitAddLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitAddLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitAddLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitAddLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitEnsureLspOperational;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitEnsureLspOperationalInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitEnsureLspOperationalOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitEnsureLspOperationalOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitRemoveLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitRemoveLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitRemoveLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitRemoveLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitTriggerSync;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitTriggerSyncInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitTriggerSyncOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitTriggerSyncOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitUpdateLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitUpdateLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitUpdateLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev181109.SubmitUpdateLspOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.EnsureLspOperationalInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.OperationResult;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.RpcResult;
-final class TopologyProgramming implements NetworkTopologyPcepProgrammingService {
+final class TopologyProgramming {
private final InstructionScheduler scheduler;
private final ServerSessionManager manager;
this.manager = requireNonNull(manager);
}
- @Override
- public ListenableFuture<RpcResult<SubmitAddLspOutput>> submitAddLsp(final SubmitAddLspInput input) {
+ Registration register(final RpcProviderService rpcProviderService,
+ final KeyedInstanceIdentifier<Topology, TopologyKey> path) {
+ return rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(SubmitAddLsp.class, this::submitAddLsp)
+ .put(SubmitRemoveLsp.class, this::submitRemoveLsp)
+ .put(SubmitUpdateLsp.class, this::submitUpdateLsp)
+ .put(SubmitEnsureLspOperational.class, this::submitEnsureLspOperational)
+ .put(SubmitTriggerSync.class, this::submitTriggerSync)
+ .build(), Set.of(path));
+ }
+
+ @VisibleForTesting
+ ListenableFuture<RpcResult<SubmitAddLspOutput>> submitAddLsp(final SubmitAddLspInput input) {
Preconditions.checkArgument(input.getNode() != null);
Preconditions.checkArgument(input.getName() != null);
- final SubmitAddLspOutputBuilder b = new SubmitAddLspOutputBuilder();
- b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new AbstractInstructionExecutor(input) {
- @Override
- protected ListenableFuture<OperationResult> invokeOperation() {
- return TopologyProgramming.this.manager.addLsp(input);
- }
- }));
-
- final RpcResult<SubmitAddLspOutput> res = SuccessfulRpcResult.create(b.build());
- return Futures.immediateFuture(res);
+ return Futures.immediateFuture(SuccessfulRpcResult.create(new SubmitAddLspOutputBuilder()
+ .setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
+ @Override
+ protected ListenableFuture<OperationResult> invokeOperation() {
+ return manager.addLsp(input);
+ }
+ }))
+ .build()));
}
- @Override
- public ListenableFuture<RpcResult<SubmitRemoveLspOutput>> submitRemoveLsp(final SubmitRemoveLspInput input) {
+ @VisibleForTesting
+ ListenableFuture<RpcResult<SubmitRemoveLspOutput>> submitRemoveLsp(final SubmitRemoveLspInput input) {
Preconditions.checkArgument(input.getNode() != null);
Preconditions.checkArgument(input.getName() != null);
- final SubmitRemoveLspOutputBuilder b = new SubmitRemoveLspOutputBuilder();
- b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new AbstractInstructionExecutor(input) {
- @Override
- protected ListenableFuture<OperationResult> invokeOperation() {
- return TopologyProgramming.this.manager.removeLsp(input);
- }
- }));
-
- final RpcResult<SubmitRemoveLspOutput> res = SuccessfulRpcResult.create(b.build());
- return Futures.immediateFuture(res);
+ return Futures.immediateFuture(SuccessfulRpcResult.create(new SubmitRemoveLspOutputBuilder()
+ .setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
+ @Override
+ protected ListenableFuture<OperationResult> invokeOperation() {
+ return manager.removeLsp(input);
+ }
+ }))
+ .build()));
}
- @Override
- public ListenableFuture<RpcResult<SubmitUpdateLspOutput>> submitUpdateLsp(final SubmitUpdateLspInput input) {
+ @VisibleForTesting
+ ListenableFuture<RpcResult<SubmitUpdateLspOutput>> submitUpdateLsp(final SubmitUpdateLspInput input) {
Preconditions.checkArgument(input.getNode() != null);
Preconditions.checkArgument(input.getName() != null);
- final SubmitUpdateLspOutputBuilder b = new SubmitUpdateLspOutputBuilder();
- b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new AbstractInstructionExecutor(input) {
- @Override
- protected ListenableFuture<OperationResult> invokeOperation() {
- return TopologyProgramming.this.manager.updateLsp(input);
- }
- }));
-
- final RpcResult<SubmitUpdateLspOutput> res = SuccessfulRpcResult.create(b.build());
- return Futures.immediateFuture(res);
+ return Futures.immediateFuture(SuccessfulRpcResult.create(new SubmitUpdateLspOutputBuilder()
+ .setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
+ @Override
+ protected ListenableFuture<OperationResult> invokeOperation() {
+ return manager.updateLsp(input);
+ }
+ }))
+ .build()));
}
- @Override
- public ListenableFuture<RpcResult<SubmitEnsureLspOperationalOutput>> submitEnsureLspOperational(
+ @VisibleForTesting
+ ListenableFuture<RpcResult<SubmitEnsureLspOperationalOutput>> submitEnsureLspOperational(
final SubmitEnsureLspOperationalInput input) {
Preconditions.checkArgument(input.getNode() != null);
Preconditions.checkArgument(input.getName() != null);
// FIXME: can we validate this early?
// Preconditions.checkArgument(input.getArguments().getOperational() != null);
- final SubmitEnsureLspOperationalOutputBuilder b = new SubmitEnsureLspOperationalOutputBuilder();
- b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new AbstractInstructionExecutor(input) {
- @Override
- protected ListenableFuture<OperationResult> invokeOperation() {
- EnsureLspOperationalInputBuilder ensureLspOperationalInputBuilder =
+ return Futures.immediateFuture(SuccessfulRpcResult.create(new SubmitEnsureLspOperationalOutputBuilder()
+ .setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
+ @Override
+ protected ListenableFuture<OperationResult> invokeOperation() {
+ EnsureLspOperationalInputBuilder ensureLspOperationalInputBuilder =
new EnsureLspOperationalInputBuilder();
- ensureLspOperationalInputBuilder.fieldsFrom(input);
- return TopologyProgramming.this.manager.ensureLspOperational(ensureLspOperationalInputBuilder.build());
- }
- }));
-
- final RpcResult<SubmitEnsureLspOperationalOutput> res = SuccessfulRpcResult.create(b.build());
- return Futures.immediateFuture(res);
+ ensureLspOperationalInputBuilder.fieldsFrom(input);
+ return manager.ensureLspOperational(ensureLspOperationalInputBuilder.build());
+ }
+ }))
+ .build()));
}
- @Override
- public ListenableFuture<RpcResult<SubmitTriggerSyncOutput>> submitTriggerSync(final SubmitTriggerSyncInput input) {
+ @VisibleForTesting
+ ListenableFuture<RpcResult<SubmitTriggerSyncOutput>> submitTriggerSync(final SubmitTriggerSyncInput input) {
Preconditions.checkArgument(input.getNode() != null);
- final SubmitTriggerSyncOutputBuilder b = new SubmitTriggerSyncOutputBuilder();
- b.setResult(AbstractInstructionExecutor.schedule(this.scheduler, new AbstractInstructionExecutor(input) {
- @Override
- protected ListenableFuture<OperationResult> invokeOperation() {
- return TopologyProgramming.this.manager.triggerSync(input);
- }
- }));
-
- final RpcResult<SubmitTriggerSyncOutput> res = SuccessfulRpcResult.create(b.build());
- return Futures.immediateFuture(res);
+ return Futures.immediateFuture(SuccessfulRpcResult.create(new SubmitTriggerSyncOutputBuilder()
+ .setResult(AbstractInstructionExecutor.schedule(scheduler, new AbstractInstructionExecutor(input) {
+ @Override
+ protected ListenableFuture<OperationResult> invokeOperation() {
+ return manager.triggerSync(input);
+ }
+ }))
+ .build()));
}
}
import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Set;
import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.AddLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.AddLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.AddLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.AddLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.EnsureLspOperational;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.EnsureLspOperationalInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.EnsureLspOperationalOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.EnsureLspOperationalOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.NetworkTopologyPcepService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.RemoveLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.RemoveLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.RemoveLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.RemoveLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TearDownSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TearDownSessionInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TearDownSessionOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TearDownSessionOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TriggerSync;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TriggerSyncInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TriggerSyncOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.TriggerSyncOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.UpdateLsp;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.UpdateLspInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.UpdateLspOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.UpdateLspOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.RpcResult;
-final class TopologyRPCs implements NetworkTopologyPcepService {
+final class TopologyRPCs {
private final ServerSessionManager manager;
TopologyRPCs(final ServerSessionManager manager) {
this.manager = requireNonNull(manager);
}
- @Override
- public ListenableFuture<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
- return Futures.transform(this.manager.addLsp(input),
- input1 -> SuccessfulRpcResult.create(new AddLspOutputBuilder(input1).build()),
+ Registration register(final RpcProviderService rpcProviderService,
+ final KeyedInstanceIdentifier<Topology, TopologyKey> path) {
+ return rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(AddLsp.class, this::addLsp)
+ .put(RemoveLsp.class, this::removeLsp)
+ .put(TriggerSync.class, this::triggerSync)
+ .put(UpdateLsp.class, this::updateLsp)
+ .put(EnsureLspOperational.class, this::ensureLspOperational)
+ .put(TearDownSession.class, this::tearDownSession)
+ .build(), Set.of(path));
+ }
+
+ @VisibleForTesting
+ ListenableFuture<RpcResult<AddLspOutput>> addLsp(final AddLspInput input) {
+ return Futures.transform(manager.addLsp(input),
+ output -> SuccessfulRpcResult.create(new AddLspOutputBuilder(output).build()),
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
- return Futures.transform(this.manager.removeLsp(input),
- input1 -> SuccessfulRpcResult.create(new RemoveLspOutputBuilder(input1).build()),
+ @VisibleForTesting
+ ListenableFuture<RpcResult<RemoveLspOutput>> removeLsp(final RemoveLspInput input) {
+ return Futures.transform(manager.removeLsp(input),
+ output -> SuccessfulRpcResult.create(new RemoveLspOutputBuilder(output).build()),
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<TriggerSyncOutput>> triggerSync(final TriggerSyncInput input) {
- return Futures.transform(this.manager.triggerSync(input),
- input1 -> SuccessfulRpcResult.create(new TriggerSyncOutputBuilder(input1).build()),
+ private ListenableFuture<RpcResult<TriggerSyncOutput>> triggerSync(final TriggerSyncInput input) {
+ return Futures.transform(manager.triggerSync(input),
+ output -> SuccessfulRpcResult.create(new TriggerSyncOutputBuilder(output).build()),
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
- return Futures.transform(this.manager.updateLsp(input),
- input1 -> SuccessfulRpcResult.create(new UpdateLspOutputBuilder(input1).build()),
+ @VisibleForTesting
+ ListenableFuture<RpcResult<UpdateLspOutput>> updateLsp(final UpdateLspInput input) {
+ return Futures.transform(manager.updateLsp(input),
+ output -> SuccessfulRpcResult.create(new UpdateLspOutputBuilder(output).build()),
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<EnsureLspOperationalOutput>> ensureLspOperational(
+ @VisibleForTesting
+ ListenableFuture<RpcResult<EnsureLspOperationalOutput>> ensureLspOperational(
final EnsureLspOperationalInput input) {
- return Futures.transform(this.manager.ensureLspOperational(input),
- input1 -> SuccessfulRpcResult.create(new EnsureLspOperationalOutputBuilder(input1).build()),
+ return Futures.transform(manager.ensureLspOperational(input),
+ output -> SuccessfulRpcResult.create(new EnsureLspOperationalOutputBuilder(output).build()),
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<TearDownSessionOutput>> tearDownSession(final TearDownSessionInput input) {
- return Futures.transform(this.manager.tearDownSession(input),
- input1 -> SuccessfulRpcResult.create(new TearDownSessionOutputBuilder().build()),
+ @VisibleForTesting
+ ListenableFuture<RpcResult<TearDownSessionOutput>> tearDownSession(final TearDownSessionInput input) {
+ return Futures.transform(manager.tearDownSession(input),
+ output -> SuccessfulRpcResult.create(new TearDownSessionOutputBuilder().build()),
MoreExecutors.directExecutor());
}
}
*/
package org.opendaylight.bgpcep.pcep.topology.provider;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
import org.opendaylight.mdsal.binding.api.DataObjectModification;
import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev181109.PcepEntityIdRpcAugBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stateful.stats.rev181109.PcepEntityIdStatsAug;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.PeerCapabilitiesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.grouping.PcepSessionState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.stats.rev171113.pcep.session.state.grouping.PcepSessionStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.GetStats;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.GetStatsInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.GetStatsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.GetStatsOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.topology.stats.rpc.rev190321.PcepTopologyStatsRpcService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.stats.rev181109.PcepTopologyNodeStatsAug;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class TopologyStatsRpcServiceImpl
- implements PcepTopologyStatsRpcService, ClusteredDataTreeChangeListener<PcepSessionState>, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(TopologyStatsRpcServiceImpl.class);
+final class TopologyStatsRpc implements ClusteredDataTreeChangeListener<PcepSessionState>, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(TopologyStatsRpc.class);
private final ConcurrentMap<InstanceIdentifier<PcepSessionState>, PcepSessionState> sessionStateMap =
new ConcurrentHashMap<>();
- private ListenerRegistration<TopologyStatsRpcServiceImpl> listenerRegistration;
+ private Registration listenerRegistration;
+ private Registration rpcRegistration;
- TopologyStatsRpcServiceImpl(final DataBroker dataBroker) {
+ TopologyStatsRpc(final DataBroker dataBroker, final RpcProviderService rpcProviderService) {
LOG.info("Initializing PCEP Topology Stats RPC service.");
listenerRegistration = dataBroker.registerDataTreeChangeListener(
DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL,
InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class).child(Node.class)
.augmentation(PcepTopologyNodeStatsAug.class).child(PcepSessionState.class).build()),
this);
+ rpcRegistration = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.of(
+ GetStats.class, this::getStats));
}
@Override
@Override
public synchronized void close() {
+ if (rpcRegistration != null) {
+ rpcRegistration.close();
+ rpcRegistration = null;
+ }
if (listenerRegistration != null) {
LOG.info("Closing PCEP Topology Stats RPC service.");
listenerRegistration.close();
}
}
- @Override
- public ListenableFuture<RpcResult<GetStatsOutput>> getStats(final GetStatsInput input) {
+ @VisibleForTesting
+ ListenableFuture<RpcResult<GetStatsOutput>> getStats(final GetStatsInput input) {
final var iTopologies = input.getTopology();
final List<TopologyId> iTopologyIds;
if (iTopologies != null) {
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.NetworkTopologyPcepService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.Node1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.pcep.client.attributes.PathComputationClient;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
List<Notification<?>> receivedMsgs;
ServerSessionManager manager;
- NetworkTopologyPcepService topologyRpcs;
+ TopologyRPCs topologyRpcs;
@Mock
private EventLoop eventLoop;
@Mock
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.Uint32;
import org.opendaylight.yangtools.yang.common.Uint8;
-public class TopologyStatsRpcServiceImplTest extends AbstractConcurrentDataBrokerTest {
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class TopologyStatsRpcTest extends AbstractConcurrentDataBrokerTest {
private static final String TOPOLOGY_ID1 = "pcep-topology-1";
private static final String TOPOLOGY_ID2 = "pcep-topology-2";
private static final String NONEXISTENT_TOPOLOGY = "nonexistent-topology";
private static final String NONEXISTENT_NODE = "pcc://4.4.4.4";
private static final String NONPCEP_NODE = "nonpcep-node";
- TopologyStatsRpcServiceImpl rpcService;
+ @Mock
+ private RpcProviderService rpcProviderService;
+ @Mock
+ private Registration rpcReg;
+
+ TopologyStatsRpc rpcService;
@Before
public void setUp() throws Exception {
- rpcService = new TopologyStatsRpcServiceImpl(getDataBroker());
+ doReturn(rpcReg).when(rpcProviderService).registerRpcImplementations(any());
+ doNothing().when(rpcReg).close();
+ rpcService = new TopologyStatsRpc(getDataBroker(), rpcProviderService);
// PCEP topology with one PCC node
final Topology t1 = createTopology(TOPOLOGY_ID1, BindingMap.of(createPcepNode(NODE_ID1)));