Search in sources :

Example 1 with LeaderAddressAndId

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");
        }
    }
}
Also used : LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) LeaderAddressAndId(org.apache.flink.runtime.leaderelection.LeaderAddressAndId) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) ResourceManagerGateway(org.apache.flink.runtime.resourcemanager.ResourceManagerGateway)

Aggregations

JobExecutionException (org.apache.flink.runtime.client.JobExecutionException)1 LeaderAddressAndId (org.apache.flink.runtime.leaderelection.LeaderAddressAndId)1 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)1 ResourceManagerGateway (org.apache.flink.runtime.resourcemanager.ResourceManagerGateway)1