Search in sources :

Example 1 with Duration

use of scala.concurrent.duration.Duration in project flink by apache.

the class TaskManagerConfiguration method fromConfiguration.

// --------------------------------------------------------------------------------------------
//  Static factory methods
// --------------------------------------------------------------------------------------------
public static TaskManagerConfiguration fromConfiguration(Configuration configuration) {
    int numberSlots = configuration.getInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, 1);
    if (numberSlots == -1) {
        numberSlots = 1;
    }
    final String[] tmpDirPaths = configuration.getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH).split(",|" + File.pathSeparator);
    final Time timeout;
    try {
        timeout = Time.milliseconds(AkkaUtils.getTimeout(configuration).toMillis());
    } catch (Exception e) {
        throw new IllegalArgumentException("Invalid format for '" + ConfigConstants.AKKA_ASK_TIMEOUT + "'.Use formats like '50 s' or '1 min' to specify the timeout.");
    }
    LOG.info("Messages have a max timeout of " + timeout);
    final long cleanupInterval = configuration.getLong(ConfigConstants.LIBRARY_CACHE_MANAGER_CLEANUP_INTERVAL, ConfigConstants.DEFAULT_LIBRARY_CACHE_MANAGER_CLEANUP_INTERVAL) * 1000;
    final Time finiteRegistrationDuration;
    try {
        Duration maxRegistrationDuration = Duration.create(configuration.getString(ConfigConstants.TASK_MANAGER_MAX_REGISTRATION_DURATION, ConfigConstants.DEFAULT_TASK_MANAGER_MAX_REGISTRATION_DURATION));
        if (maxRegistrationDuration.isFinite()) {
            finiteRegistrationDuration = Time.milliseconds(maxRegistrationDuration.toMillis());
        } else {
            finiteRegistrationDuration = null;
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid format for parameter " + ConfigConstants.TASK_MANAGER_MAX_REGISTRATION_DURATION, e);
    }
    final Time initialRegistrationPause;
    try {
        Duration pause = Duration.create(configuration.getString(ConfigConstants.TASK_MANAGER_INITIAL_REGISTRATION_PAUSE, ConfigConstants.DEFAULT_TASK_MANAGER_INITIAL_REGISTRATION_PAUSE));
        if (pause.isFinite()) {
            initialRegistrationPause = Time.milliseconds(pause.toMillis());
        } else {
            throw new IllegalArgumentException("The initial registration pause must be finite: " + pause);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid format for parameter " + ConfigConstants.TASK_MANAGER_INITIAL_REGISTRATION_PAUSE, e);
    }
    final Time maxRegistrationPause;
    try {
        Duration pause = Duration.create(configuration.getString(ConfigConstants.TASK_MANAGER_MAX_REGISTARTION_PAUSE, ConfigConstants.DEFAULT_TASK_MANAGER_MAX_REGISTRATION_PAUSE));
        if (pause.isFinite()) {
            maxRegistrationPause = Time.milliseconds(pause.toMillis());
        } else {
            throw new IllegalArgumentException("The maximum registration pause must be finite: " + pause);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid format for parameter " + ConfigConstants.TASK_MANAGER_INITIAL_REGISTRATION_PAUSE, e);
    }
    final Time refusedRegistrationPause;
    try {
        Duration pause = Duration.create(configuration.getString(ConfigConstants.TASK_MANAGER_REFUSED_REGISTRATION_PAUSE, ConfigConstants.DEFAULT_TASK_MANAGER_REFUSED_REGISTRATION_PAUSE));
        if (pause.isFinite()) {
            refusedRegistrationPause = Time.milliseconds(pause.toMillis());
        } else {
            throw new IllegalArgumentException("The refused registration pause must be finite: " + pause);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Invalid format for parameter " + ConfigConstants.TASK_MANAGER_INITIAL_REGISTRATION_PAUSE, e);
    }
    final boolean exitOnOom = configuration.getBoolean(TaskManagerOptions.KILL_ON_OUT_OF_MEMORY);
    return new TaskManagerConfiguration(numberSlots, tmpDirPaths, timeout, finiteRegistrationDuration, initialRegistrationPause, maxRegistrationPause, refusedRegistrationPause, cleanupInterval, configuration, exitOnOom);
}
Also used : Time(org.apache.flink.api.common.time.Time) Duration(scala.concurrent.duration.Duration)

Example 2 with Duration

use of scala.concurrent.duration.Duration in project flink by apache.

the class MesosApplicationMasterRunner method createMesosConfig.

/**
	 * Loads and validates the ResourceManager Mesos configuration from the given Flink configuration.
	 */
public static MesosConfiguration createMesosConfig(Configuration flinkConfig, String hostname) {
    Protos.FrameworkInfo.Builder frameworkInfo = Protos.FrameworkInfo.newBuilder().setHostname(hostname);
    Protos.Credential.Builder credential = null;
    if (!flinkConfig.containsKey(ConfigConstants.MESOS_MASTER_URL)) {
        throw new IllegalConfigurationException(ConfigConstants.MESOS_MASTER_URL + " must be configured.");
    }
    String masterUrl = flinkConfig.getString(ConfigConstants.MESOS_MASTER_URL, null);
    Duration failoverTimeout = FiniteDuration.apply(flinkConfig.getInteger(ConfigConstants.MESOS_FAILOVER_TIMEOUT_SECONDS, ConfigConstants.DEFAULT_MESOS_FAILOVER_TIMEOUT_SECS), TimeUnit.SECONDS);
    frameworkInfo.setFailoverTimeout(failoverTimeout.toSeconds());
    frameworkInfo.setName(flinkConfig.getString(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_NAME, ConfigConstants.DEFAULT_MESOS_RESOURCEMANAGER_FRAMEWORK_NAME));
    frameworkInfo.setRole(flinkConfig.getString(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_ROLE, ConfigConstants.DEFAULT_MESOS_RESOURCEMANAGER_FRAMEWORK_ROLE));
    frameworkInfo.setUser(flinkConfig.getString(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_USER, ConfigConstants.DEFAULT_MESOS_RESOURCEMANAGER_FRAMEWORK_USER));
    if (flinkConfig.containsKey(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_PRINCIPAL)) {
        frameworkInfo.setPrincipal(flinkConfig.getString(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_PRINCIPAL, null));
        credential = Protos.Credential.newBuilder();
        credential.setPrincipal(frameworkInfo.getPrincipal());
        // and thus don't set the 'secret' configuration setting
        if (flinkConfig.containsKey(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_SECRET)) {
            credential.setSecret(flinkConfig.getString(ConfigConstants.MESOS_RESOURCEMANAGER_FRAMEWORK_SECRET, null));
        }
    }
    MesosConfiguration mesos = new MesosConfiguration(masterUrl, frameworkInfo, scala.Option.apply(credential));
    return mesos;
}
Also used : MesosConfiguration(org.apache.flink.mesos.util.MesosConfiguration) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) FiniteDuration(scala.concurrent.duration.FiniteDuration) Duration(scala.concurrent.duration.Duration)

Example 3 with Duration

use of scala.concurrent.duration.Duration in project flink by apache.

the class FailureRateRestartStrategy method createFactory.

public static FailureRateRestartStrategyFactory createFactory(Configuration configuration) throws Exception {
    int maxFailuresPerInterval = configuration.getInteger(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_MAX_FAILURES_PER_INTERVAL, 1);
    String failuresIntervalString = configuration.getString(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_FAILURE_RATE_INTERVAL, Duration.apply(1, TimeUnit.MINUTES).toString());
    String timeoutString = configuration.getString(ConfigConstants.AKKA_WATCH_HEARTBEAT_INTERVAL, ConfigConstants.DEFAULT_AKKA_ASK_TIMEOUT);
    String delayString = configuration.getString(ConfigConstants.RESTART_STRATEGY_FAILURE_RATE_DELAY, timeoutString);
    Duration failuresInterval = Duration.apply(failuresIntervalString);
    Duration delay = Duration.apply(delayString);
    return new FailureRateRestartStrategyFactory(maxFailuresPerInterval, Time.milliseconds(failuresInterval.toMillis()), Time.milliseconds(delay.toMillis()));
}
Also used : Duration(scala.concurrent.duration.Duration)

Aggregations

Duration (scala.concurrent.duration.Duration)3 Time (org.apache.flink.api.common.time.Time)1 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)1 MesosConfiguration (org.apache.flink.mesos.util.MesosConfiguration)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1