Search in sources :

Example 11 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManagerTest method testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards.

@Test
public void testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards() throws Exception {
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards starting");
    TestShardManager shardManager = newTestShardManager(newShardMgrProps(new MockConfiguration() {

        @Override
        public List<String> getMemberShardNames(final MemberName memberName) {
            return Arrays.asList("default", "astronauts");
        }
    }));
    // Initially will be false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make default shard leader
    String defaultShardId = "member-1-shard-default-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(defaultShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // default = Leader, astronauts is unknown so sync status remains false
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make astronauts shard leader as well
    String astronautsShardId = "member-1-shard-astronauts-" + shardMrgIDSuffix;
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Follower.name(), RaftState.Leader.name()));
    // Now sync status should be true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    // Make astronauts a Follower
    shardManager.onReceiveCommand(new RoleChangeNotification(astronautsShardId, RaftState.Leader.name(), RaftState.Follower.name()));
    // Sync status is not true
    assertEquals(false, shardManager.getMBean().getSyncStatus());
    // Make the astronauts follower sync status true
    shardManager.onReceiveCommand(new FollowerInitialSyncUpStatus(true, astronautsShardId));
    // Sync status is now true
    assertEquals(true, shardManager.getMBean().getSyncStatus());
    LOG.info("testWhenMultipleShardsPresentSyncStatusMustBeTrueForAllShards ending");
}
Also used : RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) AddressFromURIString(akka.actor.AddressFromURIString) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 12 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName 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 13 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method getPeerAddresses.

private Map<String, String> getPeerAddresses(final String shardName, final Collection<MemberName> members) {
    Map<String, String> peerAddresses = new HashMap<>();
    MemberName currentMemberName = this.cluster.getCurrentMemberName();
    for (MemberName memberName : members) {
        if (!currentMemberName.equals(memberName)) {
            ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
            String address = peerAddressResolver.getShardActorAddress(shardName, memberName);
            peerAddresses.put(shardId.toString(), address);
        }
    }
    return peerAddresses;
}
Also used : HashMap(java.util.HashMap) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 14 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method memberRemoved.

private void memberRemoved(final ClusterEvent.MemberRemoved message) {
    MemberName memberName = memberToName(message.member());
    LOG.info("{}: Received MemberRemoved: memberName: {}, address: {}", persistenceId(), memberName, message.member().address());
    peerAddressResolver.removePeerAddress(memberName);
    for (ShardInformation info : localShards.values()) {
        info.peerDown(memberName, getShardIdentifier(memberName, info.getShardName()).toString(), getSelf());
    }
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Example 15 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManager method memberUp.

private void memberUp(final ClusterEvent.MemberUp message) {
    MemberName memberName = memberToName(message.member());
    LOG.info("{}: Received MemberUp: memberName: {}, address: {}", persistenceId(), memberName, message.member().address());
    memberUp(memberName, message.member().address());
}
Also used : MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Aggregations

MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)32 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 ActorRef (akka.actor.ActorRef)4 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)3 AddressFromURIString (akka.actor.AddressFromURIString)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 Before (org.junit.Before)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 ModuleShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy)2 ShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy)2 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)2 Address (akka.actor.Address)1