use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testChangeMemberVotingStatesForAllShards.
@Test
public void testChangeMemberVotingStatesForAllShards() throws Exception {
String name = "testChangeMemberVotingStatesForAllShards";
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();
verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2", "member-3");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
// Invoke RPC service on member-3 to change voting status
ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
RpcResult<ChangeMemberVotingStatesForAllShardsOutput> rpcResult = service3.changeMemberVotingStatesForAllShards(new ChangeMemberVotingStatesForAllShardsInputBuilder().setMemberVotingState(ImmutableList.of(new MemberVotingStateBuilder().setMemberName("member-2").setVoting(FALSE).build(), new MemberVotingStateBuilder().setMemberName("member-3").setVoting(FALSE).build())).build()).get(10, TimeUnit.SECONDS);
ChangeMemberVotingStatesForAllShardsOutput 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", FALSE), new SimpleEntry<>("member-3", FALSE));
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testBackupDatastore.
@Test
public void testBackupDatastore() throws Exception {
MemberNode node = MemberNode.builder(memberNodes).akkaConfig("Member1").moduleShardsConfig("module-shards-member1.conf").waitForShardLeader("cars", "people").testName("testBackupDatastore").build();
String fileName = "target/testBackupDatastore";
new File(fileName).delete();
ClusterAdminRpcService service = new ClusterAdminRpcService(node.configDataStore(), node.operDataStore(), null);
RpcResult<Void> rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
try (FileInputStream fis = new FileInputStream(fileName)) {
List<DatastoreSnapshot> snapshots = SerializationUtils.deserialize(fis);
assertEquals("DatastoreSnapshot size", 2, snapshots.size());
ImmutableMap<String, DatastoreSnapshot> map = ImmutableMap.of(snapshots.get(0).getType(), snapshots.get(0), snapshots.get(1).getType(), snapshots.get(1));
verifyDatastoreSnapshot(node.configDataStore().getActorContext().getDataStoreName(), map.get(node.configDataStore().getActorContext().getDataStoreName()), "cars", "people");
} finally {
new File(fileName).delete();
}
// Test failure by killing a shard.
node.configDataStore().getActorContext().getShardManager().tell(node.datastoreContextBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), ActorRef.noSender());
ActorRef carsShardActor = node.configDataStore().getActorContext().findLocalShard("cars").get();
node.kit().watch(carsShardActor);
carsShardActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
node.kit().expectTerminated(carsShardActor);
rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
assertFalse("isSuccessful", rpcResult.isSuccessful());
assertEquals("getErrors", 1, rpcResult.getErrors().size());
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testGetShardRole.
@Test
public void testGetShardRole() throws Exception {
String name = "testGetShardRole";
String moduleShardsConfig = "module-shards-default-member-1.conf";
final MemberNode member1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).build();
member1.kit().waitUntilLeader(member1.configDataStore().getActorContext(), "default");
final RpcResult<GetShardRoleOutput> successResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "default");
verifySuccessfulRpcResult(successResult);
assertEquals("Leader", successResult.getResult().getRole());
final RpcResult<GetShardRoleOutput> failedResult = getShardRole(member1, Mockito.mock(BindingNormalizedNodeSerializer.class), "cars");
verifyFailedRpcResult(failedResult);
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);
final RpcResult<GetPrefixShardRoleOutput> prefixSuccessResult = getPrefixShardRole(member1, identifier, serializer);
verifySuccessfulRpcResult(prefixSuccessResult);
assertEquals("Leader", prefixSuccessResult.getResult().getRole());
final InstanceIdentifier<People> peopleId = InstanceIdentifier.create(People.class);
Mockito.doReturn(PeopleModel.BASE_PATH).when(serializer).toYangInstanceIdentifier(peopleId);
final RpcResult<GetPrefixShardRoleOutput> prefixFail = getPrefixShardRole(member1, peopleId, serializer);
verifyFailedRpcResult(prefixFail);
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddShardReplica.
@Test
public void testAddShardReplica() throws Exception {
String name = "testAddShardReplica";
String moduleShardsConfig = "module-shards-cars-member-1.conf";
MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).waitForShardLeader("cars").build();
MemberNode newReplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.waitForMembersUp("member-2");
doAddShardReplica(newReplicaNode2, "cars", "member-1");
MemberNode newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.waitForMembersUp("member-3");
newReplicaNode2.waitForMembersUp("member-3");
doAddShardReplica(newReplicaNode3, "cars", "member-1", "member-2");
verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "cars", "member-1", "member-3");
verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "cars", "member-1", "member-3");
// Write data to member-2's config datastore and read/verify via member-3
final NormalizedNode<?, ?> configCarsNode = writeCarsNodeAndVerify(newReplicaNode2.configDataStore(), newReplicaNode3.configDataStore());
// Write data to member-3's oper datastore and read/verify via member-2
writeCarsNodeAndVerify(newReplicaNode3.operDataStore(), newReplicaNode2.operDataStore());
// Verify all data has been replicated. We expect 4 log entries and thus last applied index of 3 -
// 2 ServerConfigurationPayload entries, the transaction payload entry plus a purge payload.
RaftStateVerifier verifier = raftState -> {
assertEquals("Commit index", 3, raftState.getCommitIndex());
assertEquals("Last applied index", 3, raftState.getLastApplied());
};
verifyRaftState(leaderNode1.configDataStore(), "cars", verifier);
verifyRaftState(leaderNode1.operDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode2.configDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode2.operDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
verifyRaftState(newReplicaNode3.operDataStore(), "cars", verifier);
// Restart member-3 and verify the cars config shard is re-instated.
Cluster.get(leaderNode1.kit().getSystem()).down(Cluster.get(newReplicaNode3.kit().getSystem()).selfAddress());
newReplicaNode3.cleanup();
newReplicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).createOperDatastore(false).build();
verifyRaftState(newReplicaNode3.configDataStore(), "cars", verifier);
readCarsNodeAndVerify(newReplicaNode3.configDataStore(), configCarsNode);
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testRemoveShardLeaderReplica.
@Test
public void testRemoveShardLeaderReplica() throws Exception {
String name = "testRemoveShardLeaderReplica";
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");
replicaNode2.waitForMembersUp("member-1", "member-3");
replicaNode3.waitForMembersUp("member-1", "member-2");
// Invoke RPC service on leader member-1 to remove it's local shard
ClusterAdminRpcService service1 = new ClusterAdminRpcService(leaderNode1.configDataStore(), leaderNode1.operDataStore(), null);
RpcResult<Void> rpcResult = service1.removeShardReplica(new RemoveShardReplicaInputBuilder().setShardName("cars").setMemberName("member-1").setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
verifyRaftState(replicaNode2.configDataStore(), "cars", raftState -> assertThat("Leader Id", raftState.getLeader(), anyOf(containsString("member-2"), containsString("member-3"))));
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-3");
verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-2");
verifyNoShardPresent(leaderNode1.configDataStore(), "cars");
}
Aggregations