use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class DistributedEntityOwnershipIntegrationTest method testCloseCandidateRegistrationInQuickSuccession.
/**
* Reproduces bug <a href="https://bugs.opendaylight.org/show_bug.cgi?id=4554">4554</a>.
*/
@Test
public void testCloseCandidateRegistrationInQuickSuccession() throws Exception {
String name = "testCloseCandidateRegistrationInQuickSuccession";
MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
leaderDistributedDataStore.waitTillReady();
follower1Node.configDataStore().waitTillReady();
follower2Node.configDataStore().waitTillReady();
final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
final DOMEntityOwnershipService follower2EntityOwnershipService = newOwnershipService(follower2Node.configDataStore());
leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
follower1EntityOwnershipService.registerListener(ENTITY_TYPE1, follower1MockListener);
follower2EntityOwnershipService.registerListener(ENTITY_TYPE1, follower2MockListener);
final DOMEntityOwnershipCandidateRegistration candidate1 = leaderEntityOwnershipService.registerCandidate(ENTITY1);
verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, true, true));
final DOMEntityOwnershipCandidateRegistration candidate2 = follower1EntityOwnershipService.registerCandidate(ENTITY1);
verify(follower1MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
final DOMEntityOwnershipCandidateRegistration candidate3 = follower2EntityOwnershipService.registerCandidate(ENTITY1);
verify(follower2MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
Mockito.reset(leaderMockListener, follower1MockListener, follower2MockListener);
ArgumentCaptor<DOMEntityOwnershipChange> leaderChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
ArgumentCaptor<DOMEntityOwnershipChange> follower1ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
ArgumentCaptor<DOMEntityOwnershipChange> follower2ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
doNothing().when(leaderMockListener).ownershipChanged(leaderChangeCaptor.capture());
doNothing().when(follower1MockListener).ownershipChanged(follower1ChangeCaptor.capture());
doNothing().when(follower2MockListener).ownershipChanged(follower2ChangeCaptor.capture());
candidate1.close();
candidate2.close();
candidate3.close();
boolean passed = false;
for (int i = 0; i < 100; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
final Optional<EntityOwnershipState> leaderState = leaderEntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<EntityOwnershipState> follower1State = follower1EntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<EntityOwnershipState> follower2State = follower2EntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<DOMEntityOwnershipChange> leaderChange = getValueSafely(leaderChangeCaptor);
final Optional<DOMEntityOwnershipChange> follower1Change = getValueSafely(follower1ChangeCaptor);
final Optional<DOMEntityOwnershipChange> follower2Change = getValueSafely(follower2ChangeCaptor);
if (!leaderState.isPresent() || leaderState.get() == EntityOwnershipState.NO_OWNER && follower1State.isPresent() && follower1State.get() == EntityOwnershipState.NO_OWNER && follower2State.isPresent() && follower2State.get() == EntityOwnershipState.NO_OWNER && leaderChange.isPresent() && !leaderChange.get().getState().hasOwner() && follower1Change.isPresent() && !follower1Change.get().getState().hasOwner() && follower2Change.isPresent() && !follower2Change.get().getState().hasOwner()) {
passed = true;
break;
}
}
assertTrue("No ownership change message was sent with hasOwner=false", passed);
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testGetPrefixShardRole.
@Test
public void testGetPrefixShardRole() throws Exception {
String name = "testGetPrefixShardRole";
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");
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testRemoveShardReplica.
@Test
public void testRemoveShardReplica() throws Exception {
String name = "testRemoveShardReplica";
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();
replicaNode3.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");
// Invoke RPC service on member-3 to remove it's local shard
ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
RpcResult<Void> rpcResult = service3.removeShardReplica(new RemoveShardReplicaInputBuilder().setShardName("cars").setMemberName("member-3").setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2");
verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1");
verifyNoShardPresent(replicaNode3.configDataStore(), "cars");
// Restart member-2 and verify member-3 isn't present.
Cluster.get(leaderNode1.kit().getSystem()).down(Cluster.get(replicaNode2.kit().getSystem()).selfAddress());
replicaNode2.cleanup();
MemberNode newPeplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
newPeplicaNode2.configDataStore().waitTillReady();
verifyRaftPeersPresent(newPeplicaNode2.configDataStore(), "cars", "member-1");
// Invoke RPC service on member-1 to remove member-2
ClusterAdminRpcService service1 = new ClusterAdminRpcService(leaderNode1.configDataStore(), leaderNode1.operDataStore(), null);
rpcResult = service1.removeShardReplica(new RemoveShardReplicaInputBuilder().setShardName("cars").setMemberName("member-2").setDataStoreType(DataStoreType.Config).build()).get(10, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars");
verifyNoShardPresent(newPeplicaNode2.configDataStore(), "cars");
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testAddReplicasForAllShards.
@Test
public void testAddReplicasForAllShards() throws Exception {
String name = "testAddReplicasForAllShards";
String moduleShardsConfig = "module-shards-member1.conf";
MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).waitForShardLeader("cars", "people").build();
ModuleShardConfiguration petsModuleConfig = new ModuleShardConfiguration(URI.create("pets-ns"), "pets-module", "pets", null, Collections.singletonList(MEMBER_1));
leaderNode1.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), leaderNode1.kit().getRef());
leaderNode1.kit().expectMsgClass(Success.class);
leaderNode1.kit().waitUntilLeader(leaderNode1.configDataStore().getActorContext(), "pets");
MemberNode newReplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
leaderNode1.waitForMembersUp("member-2");
newReplicaNode2.waitForMembersUp("member-1");
newReplicaNode2.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), newReplicaNode2.kit().getRef());
newReplicaNode2.kit().expectMsgClass(Success.class);
newReplicaNode2.operDataStore().getActorContext().getShardManager().tell(new CreateShard(new ModuleShardConfiguration(URI.create("no-leader-ns"), "no-leader-module", "no-leader", null, Collections.singletonList(MEMBER_1)), Shard.builder(), null), newReplicaNode2.kit().getRef());
newReplicaNode2.kit().expectMsgClass(Success.class);
ClusterAdminRpcService service = new ClusterAdminRpcService(newReplicaNode2.configDataStore(), newReplicaNode2.operDataStore(), null);
RpcResult<AddReplicasForAllShardsOutput> rpcResult = service.addReplicasForAllShards().get(10, TimeUnit.SECONDS);
AddReplicasForAllShardsOutput 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), failedShardResult("no-leader", DataStoreType.Operational));
verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "cars", "member-1");
verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "people", "member-1");
verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "pets", "member-1");
verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "cars", "member-1");
verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "people", "member-1");
}
use of org.opendaylight.controller.cluster.datastore.MemberNode in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testChangeMemberVotingStatesForSingleNodeShard.
@Test
public void testChangeMemberVotingStatesForSingleNodeShard() throws Exception {
String name = "testChangeMemberVotingStatesForSingleNodeShard";
String moduleShardsConfig = "module-shards-member1.conf";
MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
leaderNode.configDataStore().waitTillReady();
// Invoke RPC service on member-3 to change voting status
ClusterAdminRpcService service = new ClusterAdminRpcService(leaderNode.configDataStore(), leaderNode.operDataStore(), null);
RpcResult<Void> rpcResult = service.changeMemberVotingStatesForShard(new ChangeMemberVotingStatesForShardInputBuilder().setShardName("cars").setDataStoreType(DataStoreType.Config).setMemberVotingState(ImmutableList.of(new MemberVotingStateBuilder().setMemberName("member-1").setVoting(FALSE).build())).build()).get(10, TimeUnit.SECONDS);
verifyFailedRpcResult(rpcResult);
verifyVotingStates(leaderNode.configDataStore(), "cars", new SimpleEntry<>("member-1", TRUE));
}
Aggregations