Search in sources :

Example 1 with LeaderRetrievalException

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException in project flink by apache.

the class LeaderRetrievalUtils method retrieveLeaderConnectionInfo.

/**
	 * Retrieves the leader akka url and the current leader session ID. The values are stored in a
	 * {@link LeaderConnectionInfo} instance.
	 *
	 * @param leaderRetrievalService Leader retrieval service to retrieve the leader connection
	 *                               information
	 * @param timeout Timeout when to give up looking for the leader
	 * @return LeaderConnectionInfo containing the leader's akka URL and the current leader session
	 * ID
	 * @throws LeaderRetrievalException
	 */
public static LeaderConnectionInfo retrieveLeaderConnectionInfo(LeaderRetrievalService leaderRetrievalService, FiniteDuration timeout) throws LeaderRetrievalException {
    LeaderConnectionInfoListener listener = new LeaderConnectionInfoListener();
    try {
        leaderRetrievalService.start(listener);
        Future<LeaderConnectionInfo> connectionInfoFuture = listener.getLeaderConnectionInfoFuture();
        return Await.result(connectionInfoFuture, timeout);
    } catch (Exception e) {
        throw new LeaderRetrievalException("Could not retrieve the leader address and leader " + "session ID.", e);
    } finally {
        try {
            leaderRetrievalService.stop();
        } catch (Exception fe) {
            LOG.warn("Could not stop the leader retrieval service.", fe);
        }
    }
}
Also used : IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException)

Example 2 with LeaderRetrievalException

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException in project flink by apache.

the class LeaderRetrievalUtils method retrieveLeaderGateway.

/**
	 * Retrieves the current leader gateway using the given {@link LeaderRetrievalService}. If the
	 * current leader could not be retrieved after the given timeout, then a
	 * {@link LeaderRetrievalException} is thrown.
	 *
	 * @param leaderRetrievalService {@link LeaderRetrievalService} which is used for the leader retrieval
	 * @param actorSystem ActorSystem which is used for the {@link LeaderRetrievalListener} implementation
	 * @param timeout Timeout value for the retrieval call
	 * @return The current leader gateway
	 * @throws LeaderRetrievalException If the actor gateway could not be retrieved or the timeout has been exceeded
	 */
public static ActorGateway retrieveLeaderGateway(LeaderRetrievalService leaderRetrievalService, ActorSystem actorSystem, FiniteDuration timeout) throws LeaderRetrievalException {
    LeaderGatewayListener listener = new LeaderGatewayListener(actorSystem, timeout);
    try {
        leaderRetrievalService.start(listener);
        Future<ActorGateway> actorGatewayFuture = listener.getActorGatewayFuture();
        return Await.result(actorGatewayFuture, timeout);
    } catch (Exception e) {
        throw new LeaderRetrievalException("Could not retrieve the leader gateway", e);
    } finally {
        try {
            leaderRetrievalService.stop();
        } catch (Exception fe) {
            LOG.warn("Could not stop the leader retrieval service.", fe);
        }
    }
}
Also used : AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException)

Example 3 with LeaderRetrievalException

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException in project flink by apache.

the class LeaderRetrievalUtils method findConnectingAddress.

public static InetAddress findConnectingAddress(LeaderRetrievalService leaderRetrievalService, FiniteDuration timeout) throws LeaderRetrievalException {
    ConnectionUtils.LeaderConnectingAddressListener listener = new ConnectionUtils.LeaderConnectingAddressListener();
    try {
        leaderRetrievalService.start(listener);
        LOG.info("Trying to select the network interface and address to use " + "by connecting to the leading JobManager.");
        LOG.info("TaskManager will try to connect for " + timeout + " before falling back to heuristics");
        return listener.findConnectingAddress(timeout);
    } catch (Exception e) {
        throw new LeaderRetrievalException("Could not find the connecting address by " + "connecting to the current leader.", e);
    } finally {
        try {
            leaderRetrievalService.stop();
        } catch (Exception fe) {
            LOG.warn("Could not stop the leader retrieval service.", fe);
        }
    }
}
Also used : ConnectionUtils(org.apache.flink.runtime.net.ConnectionUtils) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException)

Aggregations

IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)3 LeaderRetrievalException (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException)3 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)1 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)1 ConnectionUtils (org.apache.flink.runtime.net.ConnectionUtils)1