@Override public void open(MetricConfig config) { boolean filterLabelValueCharacters = config.getBoolean( FILTER_LABEL_VALUE_CHARACTER.key(), FILTER_LABEL_VALUE_CHARACTER.defaultValue()); if (!filterLabelValueCharacters) { labelValueCharactersFilter = input -> input; } }
private static <T> ConfigOption<T> prefixOption(ConfigOption<T> option, String prefix) { String key = prefix + option.key(); List<FallbackKey> deprecatedKeys; if (option.hasFallbackKeys()) { deprecatedKeys = new ArrayList<>(); for (FallbackKey dk : option.fallbackKeys()) { deprecatedKeys.add(createDeprecatedKey(prefix + dk.getKey())); } } else { deprecatedKeys = Collections.emptyList(); } FallbackKey[] deprecated = deprecatedKeys.toArray(new FallbackKey[0]); return new ConfigOption<>(key, option.description(), option.defaultValue(), deprecated); } }
/** * Checks whether there is an entry for the given config option. * * @param configOption The configuration option * * @return <tt>true</tt> if a valid (current or deprecated) key of the config option is stored, * <tt>false</tt> otherwise */ @PublicEvolving public boolean contains(ConfigOption<?> configOption) { synchronized (this.confData){ // first try the current key if (this.confData.containsKey(configOption.key())) { return true; } else if (configOption.hasFallbackKeys()) { // try the fallback keys for (FallbackKey fallbackKey : configOption.fallbackKeys()) { if (this.confData.containsKey(fallbackKey.getKey())) { loggingFallback(fallbackKey, configOption); return true; } } } return false; } }
/** * Gets the number of threads used to transfer files while snapshotting/restoring. */ public int getNumberOfTransferingThreads() { return numberOfTransferingThreads == UNDEFINED_NUMBER_OF_TRANSFERING_THREADS ? CHECKPOINT_TRANSFER_THREAD_NUM.defaultValue() : numberOfTransferingThreads; }
private static void sortOptions(List<OptionWithMetaInfo> configOptions) { configOptions.sort(Comparator.comparing(option -> option.option.key())); }
public long getExtraConfLong(ConfigOption<Long> config) { Object o = extras().get(config.key()); if (config.hasDefaultValue()) { return o == null ? config.defaultValue() : Long.parseLong(o.toString()); } else { throw new IllegalArgumentException("Unspecified config " + config.key()); } } }
/** * Removes given config option from the configuration. * * @param configOption config option to remove * @param <T> Type of the config option * @return true is config has been removed, false otherwise */ public <T> boolean removeConfig(ConfigOption<T> configOption){ synchronized (this.confData){ // try the current key Object oldValue = this.confData.remove(configOption.key()); if (oldValue == null){ for (FallbackKey fallbackKey : configOption.fallbackKeys()){ oldValue = this.confData.remove(fallbackKey.getKey()); if (oldValue != null){ loggingFallback(fallbackKey, configOption); return true; } } return false; } return true; } }
/** * Transforms option to table row. * * @param optionWithMetaInfo option to transform * @return row with the option description */ private static String toHtmlString(final OptionWithMetaInfo optionWithMetaInfo) { ConfigOption<?> option = optionWithMetaInfo.option; String defaultValue = stringifyDefault(optionWithMetaInfo); return "" + " <tr>\n" + " <td><h5>" + escapeCharacters(option.key()) + "</h5></td>\n" + " <td style=\"word-wrap: break-word;\">" + escapeCharacters(addWordBreakOpportunities(defaultValue)) + "</td>\n" + " <td>" + formatter.format(option.description()) + "</td>\n" + " </tr>\n"; }
/** * Creates a new config option, using this option's key and default value, and * adding the given description. The given description is used when generation the configuration documention. * * @param description The description for this option. * @return A new config option, with given description. */ public ConfigOption<T> withDescription(final Description description) { return new ConfigOption<>(key, description, defaultValue, fallbackKeys); }
/** * Creates a new job graph generator that uses the default values for its resource configuration. */ public JobGraphGenerator() { this.defaultMaxFan = AlgorithmOptions.SPILLING_MAX_FAN.defaultValue(); this.defaultSortSpillingThreshold = AlgorithmOptions.SORT_SPILLING_THRESHOLD.defaultValue(); this.useLargeRecordHandler = ConfigConstants.DEFAULT_USE_LARGE_RECORD_HANDLER; }
private static void checkLimit(int value, ConfigOption<Integer> option) { if (value < -1) { throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + value); } }
private Object getRawValueFromOption(ConfigOption<?> configOption) { // first try the current key Object o = getRawValue(configOption.key()); if (o != null) { // found a value for the current proper key return o; } else if (configOption.hasFallbackKeys()) { // try the deprecated keys for (FallbackKey fallbackKey : configOption.fallbackKeys()) { Object oo = getRawValue(fallbackKey.getKey()); if (oo != null) { loggingFallback(fallbackKey, configOption); return oo; } } } return null; }
/** * Creates a string-valued option with no default value. * String-valued options are the only ones that can have no * default value. * * @return The created ConfigOption. */ public ConfigOption<String> noDefaultValue() { return new ConfigOption<>(key, null); } }
static boolean isSimulateFailures(ParameterTool pt) { return pt.getBoolean(TEST_SIMULATE_FAILURE.key(), TEST_SIMULATE_FAILURE.defaultValue()); }
/** * Gets whether incremental checkpoints are enabled for this state backend. */ public boolean isIncrementalCheckpointsEnabled() { return enableIncrementalCheckpointing.getOrDefault(CheckpointingOptions.INCREMENTAL_CHECKPOINTS.defaultValue()); }
private static void checkTimeout(long timeout, ConfigOption<Long> option) { if (timeout < 0) { throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + timeout); } } }
/** * Creates a new config option, using this option's key and default value, and * adding the given deprecated keys. * * <p>When obtaining a value from the configuration via {@link Configuration#getValue(ConfigOption)}, * the deprecated keys will be checked in the order provided to this method. The first key for which * a value is found will be used - that value will be returned. * * @param deprecatedKeys The deprecated keys, in the order in which they should be checked. * @return A new config options, with the given deprecated keys. */ public ConfigOption<T> withDeprecatedKeys(String... deprecatedKeys) { FallbackKey[] fallbackKeys = Arrays.stream(deprecatedKeys) .map(FallbackKey::createDeprecatedKey) .toArray(FallbackKey[]::new); return new ConfigOption<>(key, description, defaultValue, fallbackKeys); }
static MapFunction<Event, Event> createFailureMapper(ParameterTool pt) { return new FailureMapper<>( pt.getLong( TEST_SIMULATE_FAILURE_NUM_RECORDS.key(), TEST_SIMULATE_FAILURE_NUM_RECORDS.defaultValue()), pt.getLong( TEST_SIMULATE_FAILURE_NUM_CHECKPOINTS.key(), TEST_SIMULATE_FAILURE_NUM_CHECKPOINTS.defaultValue()), pt.getInt( TEST_SIMULATE_FAILURE_MAX_FAILURES.key(), TEST_SIMULATE_FAILURE_MAX_FAILURES.defaultValue())); }
private Object getValueOrDefaultFromOption(ConfigOption<?> configOption) { Object o = getRawValueFromOption(configOption); return o != null ? o : configOption.defaultValue(); }
private static boolean isOriginalJobVariant(final ParameterTool pt) { switch (pt.get(TEST_JOB_VARIANT.key())) { case TEST_JOB_VARIANT_ORIGINAL: return true; case TEST_JOB_VARIANT_UPGRADED: return false; default: throw new IllegalArgumentException(String.format("'--test.job.variant' can be either '%s' or '%s'", TEST_JOB_VARIANT_ORIGINAL, TEST_JOB_VARIANT_UPGRADED)); } }