Do not use RpcService in pcep-topology-provider 01/108401/7
authorlubos-cicut <lubos.cicut@pantheon.tech>
Fri, 13 Oct 2023 14:41:32 +0000 (16:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 Nov 2023 09:55:03 +0000 (10:55 +0100)
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>
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyProvider.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyTracker.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgramming.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyRPCs.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpc.java [moved from pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcServiceImpl.java with 93% similarity]
pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractPCEPSessionTest.java
pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcTest.java [moved from pcep/topology/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyStatsRpcServiceImplTest.java with 95% similarity]

index 3281df9035f68628936d1828991645a86e5240bf..6399ba113e5bcad5246221e71fa5ad6d0a775c3b 100644 (file)
@@ -20,7 +20,6 @@ import io.netty.channel.epoll.EpollChannelOption;
 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;
@@ -30,8 +29,6 @@ import org.eclipse.jdt.annotation.Nullable;
 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;
@@ -247,10 +244,8 @@ final class PCEPTopologyProvider extends DefaultTopologyReference {
 
         // 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());
index 7e093363345cf3e277da9b703e886e51a28cf4c8..8b1920fb15bb7e486207ff07664dfbe885ff7c70 100644 (file)
@@ -37,7 +37,6 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvid
 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;
@@ -91,7 +90,7 @@ public final class PCEPTopologyTracker
     // 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:
@@ -113,8 +112,6 @@ public final class PCEPTopologyTracker
     private final ConcurrentMap<TopologyKey, PCEPTopologySingleton> instances = new ConcurrentHashMap<>();
     @GuardedBy("this")
     private Registration reg;
-    @GuardedBy("this")
-    private Registration statsReg;
 
     @Inject
     @Activate
@@ -132,8 +129,7 @@ public final class PCEPTopologyTracker
         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)
@@ -189,8 +185,6 @@ public final class PCEPTopologyTracker
         reg.close();
         reg = null;
 
-        statsReg.close();
-        statsReg = null;
         statsRpcs.close();
 
         // First pass: destroy all tracked instances
index d6d5b65ef00fca66e39645d91d94a68f17741e34..24dc727664e891908403fe764f463e7aa78e3e95 100644 (file)
@@ -9,33 +9,46 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 
 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;
 
@@ -44,59 +57,64 @@ final class TopologyProgramming implements NetworkTopologyPcepProgrammingService
         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);
@@ -105,35 +123,31 @@ final class TopologyProgramming implements NetworkTopologyPcepProgrammingService
         // 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()));
     }
 }
index 5ae64b6f877d1b3b69c00e9d67b0d3e9121afba1..84f8024f25050570db6aa741e9e484b85a7ba6aa 100644 (file)
@@ -9,78 +9,103 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 
 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());
     }
 }
@@ -7,6 +7,8 @@
  */
 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;
@@ -20,6 +22,7 @@ import org.opendaylight.mdsal.binding.api.DataBroker;
 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;
@@ -35,10 +38,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.sta
 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;
@@ -47,28 +50,30 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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
@@ -91,6 +96,10 @@ final class TopologyStatsRpcServiceImpl
 
     @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();
@@ -98,8 +107,8 @@ final class TopologyStatsRpcServiceImpl
         }
     }
 
-    @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) {
index 828e1ff9a86f6c2926819feed23f3e456bf1864b..a7f0c402cf2849db85e905797f81afc5acc077f3 100644 (file)
@@ -47,7 +47,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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;
@@ -90,7 +89,7 @@ public abstract class AbstractPCEPSessionTest extends AbstractConcurrentDataBrok
 
     List<Notification<?>> receivedMsgs;
     ServerSessionManager manager;
-    NetworkTopologyPcepService topologyRpcs;
+    TopologyRPCs topologyRpcs;
     @Mock
     private EventLoop eventLoop;
     @Mock
@@ -9,12 +9,19 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 
 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;
@@ -53,6 +60,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 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;
@@ -60,7 +68,8 @@ import org.opendaylight.yangtools.yang.common.Uint16;
 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";
@@ -71,11 +80,18 @@ public class TopologyStatsRpcServiceImplTest extends AbstractConcurrentDataBroke
     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)));