Search in sources :

Example 11 with Address

use of akka.actor.Address in project controller by opendaylight.

the class GossiperTest method testReceiveGossipWhenNotAddressedToSelfShouldIgnore.

@SuppressWarnings("unchecked")
@Test
public void testReceiveGossipWhenNotAddressedToSelfShouldIgnore() {
    doNothing().when(mockGossiper).updateRemoteBuckets(anyMap());
    Address notSelf = new Address("tcp", "not-self");
    mockGossiper.receiveGossip(new GossipEnvelope(notSelf, notSelf, mock(Map.class)));
    verify(mockGossiper, times(0)).updateRemoteBuckets(anyMap());
}
Also used : Address(akka.actor.Address) Test(org.junit.Test)

Example 12 with Address

use of akka.actor.Address in project controller by opendaylight.

the class GossiperTest method testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus.

@Test
public void testReceiveGossipTick_WhenRemoteMemberExistsShouldSendStatus() {
    mockGossiper.setClusterMembers(new Address("tcp", "member"));
    doNothing().when(mockGossiper).getLocalStatusAndSendTo(any(ActorSelection.class));
    mockGossiper.receiveGossipTick();
    verify(mockGossiper, times(1)).getLocalStatusAndSendTo(any(ActorSelection.class));
}
Also used : Address(akka.actor.Address) ActorSelection(akka.actor.ActorSelection) Test(org.junit.Test)

Example 13 with Address

use of akka.actor.Address in project controller by opendaylight.

the class Gossiper method receiveGossipTick.

/**
 * Sends Gossip status to other members in the cluster.
 * <br>
 * 1. If there are no member, ignore the tick. <br>
 * 2. If there's only 1 member, send gossip status (bucket versions) to it. <br>
 * 3. If there are more than one member, randomly pick one and send gossip status (bucket versions) to it.
 */
@VisibleForTesting
void receiveGossipTick() {
    final Address address;
    switch(clusterMembers.size()) {
        case 0:
            // no members to send gossip status to
            return;
        case 1:
            address = clusterMembers.get(0);
            break;
        default:
            final int randomIndex = ThreadLocalRandom.current().nextInt(0, clusterMembers.size());
            address = clusterMembers.get(randomIndex);
            break;
    }
    LOG.trace("Gossiping to [{}]", address);
    getLocalStatusAndSendTo(Verify.verifyNotNull(peers.get(address)));
}
Also used : Address(akka.actor.Address) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with Address

use of akka.actor.Address in project controller by opendaylight.

the class Gossiper method setClusterMembers.

// /
// /Getter Setters
// /
@VisibleForTesting
void setClusterMembers(final Address... members) {
    clusterMembers.clear();
    peers.clear();
    for (Address addr : members) {
        addPeer(addr);
    }
}
Also used : Address(akka.actor.Address) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 15 with Address

use of akka.actor.Address in project controller by opendaylight.

the class Gossiper method processRemoteStatus.

private void processRemoteStatus(final ActorRef remote, final GossipStatus status, final Map<Address, Long> localVersions) {
    final Map<Address, Long> remoteVersions = status.versions();
    // diff between remote list and local
    final Set<Address> localIsOlder = new HashSet<>(remoteVersions.keySet());
    localIsOlder.removeAll(localVersions.keySet());
    // diff between local list and remote
    final Set<Address> localIsNewer = new HashSet<>(localVersions.keySet());
    localIsNewer.removeAll(remoteVersions.keySet());
    for (Entry<Address, Long> entry : remoteVersions.entrySet()) {
        Address address = entry.getKey();
        Long remoteVersion = entry.getValue();
        Long localVersion = localVersions.get(address);
        if (localVersion == null || remoteVersion == null) {
            // this condition is taken care of by above diffs
            continue;
        }
        if (localVersion < remoteVersion) {
            localIsOlder.add(address);
        } else if (localVersion > remoteVersion) {
            localIsNewer.add(address);
        }
    }
    if (!localIsOlder.isEmpty()) {
        remote.tell(new GossipStatus(selfAddress, localVersions), getSelf());
    }
    if (!localIsNewer.isEmpty()) {
        // send newer buckets to remote
        bucketStore.getBucketsByMembers(localIsNewer, buckets -> {
            LOG.trace("Buckets to send from {}: {}", selfAddress, buckets);
            remote.tell(new GossipEnvelope(selfAddress, remote.path().address(), buckets), getSelf());
        });
    }
}
Also used : Address(akka.actor.Address) HashSet(java.util.HashSet)

Aggregations

Address (akka.actor.Address)36 Test (org.junit.Test)15 Bucket (org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)9 UniqueAddress (akka.cluster.UniqueAddress)7 HashMap (java.util.HashMap)6 DOMRpcIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier)6 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)6 TestKit (akka.testkit.javadsl.TestKit)5 Optional (java.util.Optional)5 AddOrUpdateRoutes (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes)4 UpdateRemoteEndpoints (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints)4 ActorRef (akka.actor.ActorRef)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ActorSelection (akka.actor.ActorSelection)2 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)2 WebMonitor (org.apache.flink.runtime.webmonitor.WebMonitor)2