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;
}
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));
}
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));
}
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));
}
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/"));
}
Aggregations