use of org.apache.flink.runtime.leaderelection.LeaderAddressAndId in project flink by apache.
the class MiniCluster method waitUntilTaskManagerRegistrationsComplete.
public void waitUntilTaskManagerRegistrationsComplete() throws Exception {
LeaderRetrievalService rmMasterListener = null;
Future<LeaderAddressAndId> addressAndIdFuture;
try {
synchronized (lock) {
checkState(running, "FlinkMiniCluster is not running");
OneTimeLeaderListenerFuture listenerFuture = new OneTimeLeaderListenerFuture();
rmMasterListener = haServices.getResourceManagerLeaderRetriever();
rmMasterListener.start(listenerFuture);
addressAndIdFuture = listenerFuture.future();
}
final LeaderAddressAndId addressAndId = addressAndIdFuture.get();
final ResourceManagerGateway resourceManager = commonRpcService.connect(addressAndId.leaderAddress(), ResourceManagerGateway.class).get();
final int numTaskManagersToWaitFor = taskManagerRunners.length;
// poll and wait until enough TaskManagers are available
while (true) {
int numTaskManagersAvailable = resourceManager.getNumberOfRegisteredTaskManagers(addressAndId.leaderId()).get();
if (numTaskManagersAvailable >= numTaskManagersToWaitFor) {
break;
}
Thread.sleep(2);
}
} finally {
try {
if (rmMasterListener != null) {
rmMasterListener.stop();
}
} catch (Exception e) {
LOG.warn("Error shutting down leader listener for ResourceManager");
}
}
}
Aggregations