Search in sources :

Example 21 with Address

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

the class Follower method isLeaderAvailabilityKnown.

private boolean isLeaderAvailabilityKnown() {
    if (leaderId == null) {
        return false;
    }
    Optional<Cluster> cluster = context.getCluster();
    if (!cluster.isPresent()) {
        return false;
    }
    ActorSelection leaderActor = context.getPeerActorSelection(leaderId);
    if (leaderActor == null) {
        return false;
    }
    Address leaderAddress = leaderActor.anchorPath().address();
    CurrentClusterState state = cluster.get().state();
    Set<Member> unreachable = state.getUnreachable();
    log.debug("{}: Checking for leader {} in the cluster unreachable set {}", logName(), leaderAddress, unreachable);
    for (Member m : unreachable) {
        if (leaderAddress.equals(m.address())) {
            log.info("{}: Leader {} is unreachable", logName(), leaderAddress);
            return false;
        }
    }
    for (Member m : state.getMembers()) {
        if (leaderAddress.equals(m.address())) {
            if (m.status() == MemberStatus.up() || m.status() == MemberStatus.weaklyUp()) {
                log.debug("{}: Leader {} cluster status is {} - leader is available", logName(), leaderAddress, m.status());
                return true;
            } else {
                log.debug("{}: Leader {} cluster status is {} - leader is unavailable", logName(), leaderAddress, m.status());
                return false;
            }
        }
    }
    log.debug("{}: Leader {} not found in the cluster member set", logName(), leaderAddress);
    return false;
}
Also used : CurrentClusterState(akka.cluster.ClusterEvent.CurrentClusterState) ActorSelection(akka.actor.ActorSelection) Address(akka.actor.Address) Cluster(akka.cluster.Cluster) Member(akka.cluster.Member)

Example 22 with Address

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

the class ShardPeerAddressResolverTest method testGetShardManagerPeerActorAddresses.

@Test
public void testGetShardManagerPeerActorAddresses() {
    ShardPeerAddressResolver resolver = new ShardPeerAddressResolver("config", MEMBER_1);
    resolver.addPeerAddress(MEMBER_1, new Address("tcp", "system1"));
    Address address2 = new Address("tcp", "system2");
    resolver.addPeerAddress(MEMBER_2, address2);
    Address address3 = new Address("tcp", "system3");
    resolver.addPeerAddress(MEMBER_3, address3);
    Collection<String> peerAddresses = resolver.getShardManagerPeerActorAddresses();
    assertEquals("getShardManagerPeerActorAddresses", Sets.newHashSet(address2.toString() + "/user/shardmanager-config", address3.toString() + "/user/shardmanager-config"), Sets.newHashSet(peerAddresses));
}
Also used : Address(akka.actor.Address) Test(org.junit.Test)

Example 23 with Address

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

the class ShardPeerAddressResolverTest method testGetShardActorAddress.

@Test
public void testGetShardActorAddress() {
    ShardPeerAddressResolver resolver = new ShardPeerAddressResolver("config", MEMBER_1);
    assertEquals("getShardActorAddress", null, resolver.getShardActorAddress("default", MEMBER_2));
    Address address2 = new Address("tcp", "system2");
    resolver.addPeerAddress(MEMBER_2, address2);
    assertEquals("getPeerAddress", address2, resolver.getPeerAddress(MEMBER_2));
    Address address3 = new Address("tcp", "system3");
    resolver.addPeerAddress(MEMBER_3, address3);
    assertEquals("getPeerAddress", address3, resolver.getPeerAddress(MEMBER_3));
    assertEquals("getShardActorAddress", address2.toString() + "/user/shardmanager-config/member-2-shard-default-config", resolver.getShardActorAddress("default", MEMBER_2));
    assertEquals("getShardActorAddress", address3.toString() + "/user/shardmanager-config/member-3-shard-default-config", resolver.getShardActorAddress("default", MEMBER_3));
    assertEquals("getShardActorAddress", address2.toString() + "/user/shardmanager-config/member-2-shard-topology-config", resolver.getShardActorAddress("topology", MEMBER_2));
    resolver.removePeerAddress(MEMBER_2);
    assertEquals("getShardActorAddress", null, resolver.getShardActorAddress("default", MEMBER_2));
    assertEquals("getShardActorAddress", null, resolver.getShardActorAddress("topology", MEMBER_2));
    assertEquals("getShardActorAddress", address3.toString() + "/user/shardmanager-config/member-3-shard-default-config", resolver.getShardActorAddress("default", MEMBER_3));
}
Also used : Address(akka.actor.Address) Test(org.junit.Test)

Example 24 with Address

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

the class ShardPeerAddressResolverTest method testResolve.

@Test
public void testResolve() {
    String type = "config";
    ShardPeerAddressResolver resolver = new ShardPeerAddressResolver(type, MEMBER_1);
    MemberName memberName = MEMBER_2;
    String peerId = ShardIdentifier.create("default", memberName, type).toString();
    assertEquals("resolve", null, resolver.resolve(peerId));
    Address address = new Address("tcp", "system");
    resolver.addPeerAddress(memberName, address);
    String shardAddress = resolver.getShardActorAddress("default", memberName);
    assertEquals("getShardActorAddress", address.toString() + "/user/shardmanager-" + type + "/" + memberName.getName() + "-shard-default-" + type, shardAddress);
    assertEquals("resolve", shardAddress, resolver.resolve(peerId));
}
Also used : Address(akka.actor.Address) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test)

Example 25 with Address

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

the class ActorContextTest method testIsPathLocal.

@Test
public void testIsPathLocal() {
    MockClusterWrapper clusterWrapper = new MockClusterWrapper();
    ActorContext actorContext = null;
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal(null));
    assertEquals(false, actorContext.isPathLocal(""));
    clusterWrapper.setSelfAddress(null);
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal(""));
    // even if the path is in local format, match the primary path (first 3 elements) and return true
    clusterWrapper.setSelfAddress(new Address("akka", "test"));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://test/user/$a"));
    clusterWrapper.setSelfAddress(new Address("akka", "test"));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://test/user/$a"));
    clusterWrapper.setSelfAddress(new Address("akka", "test"));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://test/user/token2/token3/$a"));
    // self address of remote format,but Tx path local format.
    clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://system/user/shardmanager/shard/transaction"));
    // self address of local format,but Tx path remote format.
    clusterWrapper.setSelfAddress(new Address("akka", "system"));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal("akka://system@127.0.0.1:2550/user/shardmanager/shard/transaction"));
    // local path but not same
    clusterWrapper.setSelfAddress(new Address("akka", "test"));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://test1/user/$a"));
    // ip and port same
    clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(true, actorContext.isPathLocal("akka://system@127.0.0.1:2550/"));
    // forward-slash missing in address
    clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal("akka://system@127.0.0.1:2550"));
    // ips differ
    clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal("akka://system@127.1.0.1:2550/"));
    // ports differ
    clusterWrapper.setSelfAddress(new Address("akka", "system", "127.0.0.1", 2550));
    actorContext = new ActorContext(getSystem(), null, clusterWrapper, mock(Configuration.class));
    assertEquals(false, actorContext.isPathLocal("akka://system@127.0.0.1:2551/"));
}
Also used : Address(akka.actor.Address) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

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