use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.
the class ShardManager method onFlipShardMembersVotingStatus.
private void onFlipShardMembersVotingStatus(final FlipShardMembersVotingStatus flipMembersVotingStatus) {
LOG.debug("{}: onFlipShardMembersVotingStatus: {}", persistenceId(), flipMembersVotingStatus);
ActorRef sender = getSender();
final String shardName = flipMembersVotingStatus.getShardName();
findLocalShard(shardName, sender, localShardFound -> {
Future<Object> future = ask(localShardFound.getPath(), GetOnDemandRaftState.INSTANCE, Timeout.apply(30, TimeUnit.SECONDS));
future.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to access local shard %s", shardName), failure)), self());
return;
}
OnDemandRaftState raftState = (OnDemandRaftState) response;
Map<String, Boolean> serverVotingStatusMap = new HashMap<>();
for (Entry<String, Boolean> e : raftState.getPeerVotingStates().entrySet()) {
serverVotingStatusMap.put(e.getKey(), !e.getValue());
}
serverVotingStatusMap.put(getShardIdentifier(cluster.getCurrentMemberName(), shardName).toString(), !raftState.isVoting());
changeShardMembersVotingStatus(new ChangeServersVotingStatus(serverVotingStatusMap), shardName, localShardFound.getPath(), sender);
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
});
}
use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.
the class ShardStats method getOnDemandRaftState.
@SuppressWarnings("checkstyle:IllegalCatch")
private OnDemandRaftState getOnDemandRaftState() {
try {
final OnDemandRaftState state = stateCache.get();
statRetrievalError = null;
return state;
} catch (Exception e) {
statRetrievalError = e.getCause().toString();
return OnDemandRaftState.builder().build();
}
}
use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.
the class ShardTest method testPeerAddressResolved.
@Test
public void testPeerAddressResolved() throws Exception {
new ShardTestKit(getSystem()) {
{
final ShardIdentifier peerID = ShardIdentifier.create("inventory", MemberName.forName("member-2"), "config");
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().peerAddresses(Collections.<String, String>singletonMap(peerID.toString(), null)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), "testPeerAddressResolved");
final String address = "akka://foobar";
shard.tell(new PeerAddressResolved(peerID.toString(), address), ActorRef.noSender());
shard.tell(GetOnDemandRaftState.INSTANCE, getRef());
final OnDemandRaftState state = expectMsgClass(OnDemandRaftState.class);
assertEquals("getPeerAddress", address, state.getPeerAddresses().get(peerID.toString()));
}
};
}
use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.
the class AbstractEntityOwnershipTest method verifyRaftState.
static void verifyRaftState(final TestActorRef<? extends EntityOwnershipShard> shard, final Consumer<OnDemandRaftState> verifier) throws Exception {
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
FiniteDuration operationDuration = Duration.create(5, TimeUnit.SECONDS);
Future<Object> future = Patterns.ask(shard, GetOnDemandRaftState.INSTANCE, new Timeout(operationDuration));
OnDemandRaftState raftState = (OnDemandRaftState) Await.result(future, operationDuration);
try {
verifier.accept(raftState);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
use of org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState in project controller by opendaylight.
the class AbstractRaftActorIntegrationTest method verifyRaftState.
@SuppressWarnings("checkstyle:IllegalCatch")
static void verifyRaftState(final ActorRef raftActor, final Consumer<OnDemandRaftState> verifier) {
Timeout timeout = new Timeout(500, TimeUnit.MILLISECONDS);
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
try {
OnDemandRaftState raftState = (OnDemandRaftState) Await.result(ask(raftActor, GetOnDemandRaftState.INSTANCE, timeout), timeout.duration());
verifier.accept(raftState);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
} catch (Exception e) {
lastError = new AssertionError("OnDemandRaftState failed", e);
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
Aggregations