Search in sources :

Example 1 with AddOrUpdateRoutes

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.

the class RpcRegistryTest method testRpcAddedOnMultiNodes.

/**
 * Three node cluster. Register rpc on 2 nodes. Ensure 3rd gets updated.
 */
@Test
public void testRpcAddedOnMultiNodes() throws Exception {
    final TestKit testKit = new TestKit(node3);
    // Add rpc on node 1
    List<DOMRpcIdentifier> addedRouteIds1 = createRouteIds();
    registry1.tell(new AddOrUpdateRoutes(addedRouteIds1), ActorRef.noSender());
    final UpdateRemoteEndpoints req1 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
    // Add rpc on node 2
    List<DOMRpcIdentifier> addedRouteIds2 = createRouteIds();
    registry2.tell(new AddOrUpdateRoutes(addedRouteIds2), ActorRef.noSender());
    final UpdateRemoteEndpoints req2 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
    Address node2Address = node2.provider().getDefaultAddress();
    Address node1Address = node1.provider().getDefaultAddress();
    Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry3, testKit, node1Address, node2Address);
    verifyBucket(buckets.get(node1Address), addedRouteIds1);
    verifyBucket(buckets.get(node2Address), addedRouteIds2);
    Map<Address, Long> versions = retrieveVersions(registry3, testKit);
    Assert.assertEquals("Version for bucket " + node1Address, (Long) buckets.get(node1Address).getVersion(), versions.get(node1Address));
    Assert.assertEquals("Version for bucket " + node2Address, (Long) buckets.get(node2Address).getVersion(), versions.get(node2Address));
    assertEndpoints(req1, node1Address, invoker1);
    assertEndpoints(req2, node2Address, invoker2);
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) UpdateRemoteEndpoints(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints) Test(org.junit.Test)

Example 2 with AddOrUpdateRoutes

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.

the class RpcRegistryTest method testRpcAddRemoveInCluster.

/**
 * Three node cluster. 1. Register rpc on 1 node, ensure 2nd node gets updated 2. Remove rpc on
 * 1 node, ensure 2nd node gets updated
 */
@Test
public void testRpcAddRemoveInCluster() throws Exception {
    LOG.info("testRpcAddRemoveInCluster starting");
    List<DOMRpcIdentifier> addedRouteIds = createRouteIds();
    Address node1Address = node1.provider().getDefaultAddress();
    // Add rpc on node 1
    registry1.tell(new AddOrUpdateRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets
    final TestKit testKit = new TestKit(node2);
    Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry2, testKit, node1Address);
    verifyBucket(buckets.get(node1Address), addedRouteIds);
    // Now remove
    registry1.tell(new RemoveRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets.
    // Wait for the bucket for node1 to be empty.
    verifyEmptyBucket(testKit, registry2, node1Address);
    LOG.info("testRpcAddRemoveInCluster ending");
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoveRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes) Test(org.junit.Test)

Example 3 with AddOrUpdateRoutes

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.

the class RpcRegistryTest method testAddRoutesConcurrency.

@Test
public void testAddRoutesConcurrency() {
    final TestKit testKit = new TestKit(node1);
    final int nRoutes = 500;
    final Collection<DOMRpcIdentifier> added = new ArrayList<>(nRoutes);
    for (int i = 0; i < nRoutes; i++) {
        final DOMRpcIdentifier routeId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create(URI.create("/mockrpc"), "type" + i)));
        added.add(routeId);
        // Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        registry1.tell(new AddOrUpdateRoutes(Arrays.asList(routeId)), ActorRef.noSender());
    }
    FiniteDuration duration = Duration.create(3, TimeUnit.SECONDS);
    int numTries = 0;
    while (true) {
        registry1.tell(GET_ALL_BUCKETS, testKit.getRef());
        @SuppressWarnings("unchecked") Map<Address, Bucket<RoutingTable>> buckets = testKit.expectMsgClass(duration, Map.class);
        Bucket<RoutingTable> localBucket = buckets.values().iterator().next();
        RoutingTable table = localBucket.getData();
        if (table != null && table.size() == nRoutes) {
            for (DOMRpcIdentifier r : added) {
                Assert.assertTrue("RoutingTable contains " + r, table.contains(r));
            }
            break;
        }
        if (++numTries >= 50) {
            Assert.fail("Expected # routes: " + nRoutes + ", Actual: " + table.size());
        }
        Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
    }
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) ArrayList(java.util.ArrayList) FiniteDuration(scala.concurrent.duration.FiniteDuration) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) Test(org.junit.Test)

Example 4 with AddOrUpdateRoutes

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.

the class RpcRegistryTest method testAddRemoveRpcOnSameNode.

/**
 * One node cluster. 1. Register rpc, ensure router can be found 2. Then remove rpc, ensure its
 * deleted
 */
@Test
public void testAddRemoveRpcOnSameNode() throws Exception {
    LOG.info("testAddRemoveRpcOnSameNode starting");
    Address nodeAddress = node1.provider().getDefaultAddress();
    // Add rpc on node 1
    List<DOMRpcIdentifier> addedRouteIds = createRouteIds();
    registry1.tell(new AddOrUpdateRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store should get an update bucket message. Updated bucket contains added rpc.
    final TestKit testKit = new TestKit(node1);
    Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry1, testKit, nodeAddress);
    verifyBucket(buckets.get(nodeAddress), addedRouteIds);
    Map<Address, Long> versions = retrieveVersions(registry1, testKit);
    Assert.assertEquals("Version for bucket " + nodeAddress, (Long) buckets.get(nodeAddress).getVersion(), versions.get(nodeAddress));
    // Now remove rpc
    registry1.tell(new RemoveRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store should get an update bucket message. Rpc is removed in the updated bucket
    verifyEmptyBucket(testKit, registry1, nodeAddress);
    LOG.info("testAddRemoveRpcOnSameNode ending");
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoveRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes) Test(org.junit.Test)

Example 5 with AddOrUpdateRoutes

use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes in project controller by opendaylight.

the class RpcListener method onRpcAvailable.

@Override
public void onRpcAvailable(@Nonnull final Collection<DOMRpcIdentifier> rpcs) {
    Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null.");
    LOG.debug("Adding registration for [{}]", rpcs);
    rpcRegistry.tell(new AddOrUpdateRoutes(rpcs), ActorRef.noSender());
}
Also used : AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes)

Aggregations

AddOrUpdateRoutes (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes)5 Address (akka.actor.Address)4 UniqueAddress (akka.cluster.UniqueAddress)4 TestKit (akka.testkit.javadsl.TestKit)4 Test (org.junit.Test)4 DOMRpcIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier)4 Bucket (org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)4 RemoveRoutes (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes)2 ArrayList (java.util.ArrayList)1 UpdateRemoteEndpoints (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints)1 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1