use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testModuleShardLeaderMovement.
@Test
public void testModuleShardLeaderMovement() throws Exception {
String name = "testModuleShardLeaderMovement";
String moduleShardsConfig = "module-shards-member1.conf";
final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).waitForShardLeader("cars").moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
member1.waitForMembersUp("member-2", "member-3");
replicaNode2.waitForMembersUp("member-1");
replicaNode3.waitForMembersUp("member-1", "member-2");
doAddShardReplica(replicaNode2, "cars", "member-1");
doAddShardReplica(replicaNode3, "cars", "member-1", "member-2");
verifyRaftPeersPresent(member1.configDataStore(), "cars", "member-2", "member-3");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
doMakeShardLeaderLocal(member1, "cars", "member-1");
verifyRaftState(replicaNode2.configDataStore(), "cars", raftState -> assertThat(raftState.getLeader(), containsString("member-1")));
verifyRaftState(replicaNode3.configDataStore(), "cars", raftState -> assertThat(raftState.getLeader(), containsString("member-1")));
doMakeShardLeaderLocal(replicaNode2, "cars", "member-2");
verifyRaftState(member1.configDataStore(), "cars", raftState -> assertThat(raftState.getLeader(), containsString("member-2")));
verifyRaftState(replicaNode3.configDataStore(), "cars", raftState -> assertThat(raftState.getLeader(), containsString("member-2")));
replicaNode2.waitForMembersUp("member-3");
doMakeShardLeaderLocal(replicaNode3, "cars", "member-3");
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddShardReplicaFailures.
@Test
public void testAddShardReplicaFailures() throws Exception {
String name = "testAddShardReplicaFailures";
MemberNode memberNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig("module-shards-cars-member-1.conf").build();
ClusterAdminRpcService service = new ClusterAdminRpcService(memberNode.configDataStore(), memberNode.operDataStore(), null);
RpcResult<Void> rpcResult = service.addShardReplica(new AddShardReplicaInputBuilder().setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
verifyFailedRpcResult(rpcResult);
rpcResult = service.addShardReplica(new AddShardReplicaInputBuilder().setShardName("cars").build()).get(10, TimeUnit.SECONDS);
verifyFailedRpcResult(rpcResult);
rpcResult = service.addShardReplica(new AddShardReplicaInputBuilder().setShardName("people").setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
verifyFailedRpcResult(rpcResult);
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddRemovePrefixShardReplica.
@Test
public void testAddRemovePrefixShardReplica() throws Exception {
String name = "testAddPrefixShardReplica";
String moduleShardsConfig = "module-shards-default.conf";
final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
member1.waitForMembersUp("member-2", "member-3");
replicaNode2.kit().waitForMembersUp("member-1", "member-3");
replicaNode3.kit().waitForMembersUp("member-1", "member-2");
final ActorRef shardManager1 = member1.configDataStore().getActorContext().getShardManager();
shardManager1.tell(new PrefixShardCreated(new PrefixShardConfiguration(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH), "prefix", Collections.singleton(MEMBER_1))), ActorRef.noSender());
member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
final InstanceIdentifier<Cars> identifier = InstanceIdentifier.create(Cars.class);
final BindingNormalizedNodeSerializer serializer = Mockito.mock(BindingNormalizedNodeSerializer.class);
Mockito.doReturn(CarsModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(identifier);
addPrefixShardReplica(replicaNode2, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
addPrefixShardReplica(replicaNode3, identifier, serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1", "member-2");
verifyRaftPeersPresent(member1.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2", "member-3");
removePrefixShardReplica(member1, identifier, "member-3", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-2");
verifyNoShardPresent(replicaNode3.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
verifyRaftPeersPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH), "member-1");
removePrefixShardReplica(member1, identifier, "member-2", serializer, ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
verifyNoShardPresent(replicaNode2.configDataStore(), ClusterUtils.getCleanShardName(CarsModel.BASE_PATH));
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testFlipMemberVotingStates.
@Test
public void testFlipMemberVotingStates() throws Exception {
String name = "testFlipMemberVotingStates";
ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList(new ServerInfo("member-1", true), new ServerInfo("member-2", true), new ServerInfo("member-3", false)));
setupPersistedServerConfigPayload(persistedServerConfig, "member-1", name, "cars", "people");
setupPersistedServerConfigPayload(persistedServerConfig, "member-2", name, "cars", "people");
setupPersistedServerConfigPayload(persistedServerConfig, "member-3", name, "cars", "people");
String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
final MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.configDataStore().waitTillReady();
leaderNode1.operDataStore().waitTillReady();
replicaNode3.configDataStore().waitTillReady();
replicaNode3.operDataStore().waitTillReady();
verifyVotingStates(leaderNode1.configDataStore(), "cars", new SimpleEntry<>("member-1", TRUE), new SimpleEntry<>("member-2", TRUE), new SimpleEntry<>("member-3", FALSE));
ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
RpcResult<FlipMemberVotingStatesForAllShardsOutput> rpcResult = service3.flipMemberVotingStatesForAllShards().get(10, TimeUnit.SECONDS);
FlipMemberVotingStatesForAllShardsOutput result = verifySuccessfulRpcResult(rpcResult);
verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
verifyVotingStates(new AbstractDataStore[] { leaderNode1.configDataStore(), leaderNode1.operDataStore(), replicaNode2.configDataStore(), replicaNode2.operDataStore(), replicaNode3.configDataStore(), replicaNode3.operDataStore() }, new String[] { "cars", "people" }, new SimpleEntry<>("member-1", FALSE), new SimpleEntry<>("member-2", FALSE), new SimpleEntry<>("member-3", TRUE));
// Leadership should have transferred to member 3 since it is the only remaining voting member.
verifyRaftState(leaderNode1.configDataStore(), "cars", raftState -> {
assertNotNull("Expected non-null leader Id", raftState.getLeader());
assertTrue("Expected leader member-1. Actual: " + raftState.getLeader(), raftState.getLeader().contains("member-3"));
});
verifyRaftState(leaderNode1.operDataStore(), "cars", raftState -> {
assertNotNull("Expected non-null leader Id", raftState.getLeader());
assertTrue("Expected leader member-1. Actual: " + raftState.getLeader(), raftState.getLeader().contains("member-3"));
});
// Flip the voting states back to the original states.
rpcResult = service3.flipMemberVotingStatesForAllShards().get(10, TimeUnit.SECONDS);
result = verifySuccessfulRpcResult(rpcResult);
verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
verifyVotingStates(new AbstractDataStore[] { leaderNode1.configDataStore(), leaderNode1.operDataStore(), replicaNode2.configDataStore(), replicaNode2.operDataStore(), replicaNode3.configDataStore(), replicaNode3.operDataStore() }, new String[] { "cars", "people" }, new SimpleEntry<>("member-1", TRUE), new SimpleEntry<>("member-2", TRUE), new SimpleEntry<>("member-3", FALSE));
// Leadership should have transferred to member 1 or 2.
verifyRaftState(leaderNode1.configDataStore(), "cars", raftState -> {
assertNotNull("Expected non-null leader Id", raftState.getLeader());
assertTrue("Expected leader member-1 or member-2. Actual: " + raftState.getLeader(), raftState.getLeader().contains("member-1") || raftState.getLeader().contains("member-2"));
});
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testRemoveAllShardReplicas.
@Test
public void testRemoveAllShardReplicas() throws Exception {
String name = "testRemoveAllShardReplicas";
String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
final MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.configDataStore().waitTillReady();
verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2", "member-3");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
ModuleShardConfiguration petsModuleConfig = new ModuleShardConfiguration(URI.create("pets-ns"), "pets-module", "pets", null, Arrays.asList(MEMBER_1, MEMBER_2, MEMBER_3));
leaderNode1.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), leaderNode1.kit().getRef());
leaderNode1.kit().expectMsgClass(Success.class);
replicaNode2.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), replicaNode2.kit().getRef());
replicaNode2.kit().expectMsgClass(Success.class);
replicaNode3.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), replicaNode3.kit().getRef());
replicaNode3.kit().expectMsgClass(Success.class);
verifyRaftPeersPresent(leaderNode1.configDataStore(), "pets", "member-2", "member-3");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "pets", "member-1", "member-3");
verifyRaftPeersPresent(replicaNode3.configDataStore(), "pets", "member-1", "member-2");
ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
RpcResult<RemoveAllShardReplicasOutput> rpcResult = service3.removeAllShardReplicas(new RemoveAllShardReplicasInputBuilder().setMemberName("member-3").build()).get(10, TimeUnit.SECONDS);
RemoveAllShardReplicasOutput result = verifySuccessfulRpcResult(rpcResult);
verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("pets", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2");
verifyRaftPeersPresent(leaderNode1.configDataStore(), "people", "member-2");
verifyRaftPeersPresent(leaderNode1.configDataStore(), "pets", "member-2");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "people", "member-1");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "pets", "member-1");
verifyNoShardPresent(replicaNode3.configDataStore(), "cars");
verifyNoShardPresent(replicaNode3.configDataStore(), "people");
verifyNoShardPresent(replicaNode3.configDataStore(), "pets");
}
Aggregations