Java Code Examples for org.apache.flink.configuration.ConfigOption#key()

The following examples show how to use org.apache.flink.configuration.ConfigOption#key() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractFileStateBackend.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Path parameterOrConfigured(@Nullable Path path, Configuration config, ConfigOption<String> option) {
	if (path != null) {
		return path;
	}
	else {
		String configValue = config.getString(option);
		try {
			return configValue == null ? null : new Path(configValue);
		}
		catch (IllegalArgumentException e) {
			throw new IllegalConfigurationException("Cannot parse value for " + option.key() +
					" : " + configValue + " . Not a valid path.");
		}
	}
}
 
Example 2
Source File: GenericCLITest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void testIsActiveHelper(final String executorOption) throws CliArgsException {
	final String expectedExecutorName = "test-executor";
	final ConfigOption<Integer> configOption = key("test.int").intType().noDefaultValue();
	final int expectedValue = 42;

	final GenericCLI cliUnderTest = new GenericCLI(
			new Configuration(),
			tmp.getRoot().getAbsolutePath());

	final String[] args = {executorOption, expectedExecutorName, "-D" + configOption.key() + "=" + expectedValue};
	final CommandLine commandLine = CliFrontendParser.parse(testOptions, args, true);

	final Configuration configuration = cliUnderTest.applyCommandLineOptionsToConfiguration(commandLine);
	assertEquals(expectedExecutorName, configuration.get(DeploymentOptions.TARGET));
	assertEquals(expectedValue, configuration.getInteger(configOption));
}
 
Example 3
Source File: AbstractFileStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Path parameterOrConfigured(@Nullable Path path, ReadableConfig config, ConfigOption<String> option) {
	if (path != null) {
		return path;
	}
	else {
		String configValue = config.get(option);
		try {
			return configValue == null ? null : new Path(configValue);
		}
		catch (IllegalArgumentException e) {
			throw new IllegalConfigurationException("Cannot parse value for " + option.key() +
					" : " + configValue + " . Not a valid path.");
		}
	}
}
 
Example 4
Source File: AbstractFileStateBackend.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Path parameterOrConfigured(@Nullable Path path, Configuration config, ConfigOption<String> option) {
	if (path != null) {
		return path;
	}
	else {
		String configValue = config.getString(option);
		try {
			return configValue == null ? null : new Path(configValue);
		}
		catch (IllegalArgumentException e) {
			throw new IllegalConfigurationException("Cannot parse value for " + option.key() +
					" : " + configValue + " . Not a valid path.");
		}
	}
}
 
Example 5
Source File: FactoryUtil.java    From flink with Apache License 2.0 5 votes vote down vote up
private String formatPrefix(Factory formatFactory, ConfigOption<String> formatOption) {
	String identifier = formatFactory.factoryIdentifier();
	if (formatOption.key().equals(FORMAT_KEY)) {
		return identifier + ".";
	} else if (formatOption.key().endsWith(FORMAT_SUFFIX)) {
		// extract the key prefix, e.g. extract 'key' from 'key.format'
		String keyPrefix = formatOption.key().substring(0, formatOption.key().length() - FORMAT_SUFFIX.length());
		return keyPrefix + "." + identifier + ".";
	} else {
		throw new ValidationException(
			"Format identifier key should be 'format' or suffix with '.format', " +
				"don't support format identifier key '" + formatOption.key() + "'.");
	}
}
 
Example 6
Source File: GenericCLITest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithPreexistingConfigurationInConstructor() throws CliArgsException {
	final Configuration loadedConfig = new Configuration();
	loadedConfig.setInteger(CoreOptions.DEFAULT_PARALLELISM, 2);
	loadedConfig.setBoolean(DeploymentOptions.ATTACHED, false);

	final ConfigOption<List<Integer>> listOption = key("test.list")
			.intType()
			.asList()
			.noDefaultValue();

	final List<Integer> listValue = Arrays.asList(41, 42, 23);
	final String encodedListValue = listValue
			.stream()
			.map(Object::toString)
			.collect(Collectors.joining(";"));

	final String[] args = {
			"-e", "test-executor",
			"-D" + listOption.key() + "=" + encodedListValue,
			"-D" + CoreOptions.DEFAULT_PARALLELISM.key() + "=5"
	};

	final GenericCLI cliUnderTest = new GenericCLI(
			loadedConfig,
			tmp.getRoot().getAbsolutePath());
	final CommandLine commandLine = CliFrontendParser.parse(testOptions, args, true);

	final Configuration configuration = cliUnderTest.applyCommandLineOptionsToConfiguration(commandLine);

	assertEquals("test-executor", configuration.getString(DeploymentOptions.TARGET));
	assertEquals(5, configuration.getInteger(CoreOptions.DEFAULT_PARALLELISM));
	assertFalse(configuration.getBoolean(DeploymentOptions.ATTACHED));
	assertEquals(listValue, configuration.get(listOption));
}
 
Example 7
Source File: ProcessMemoryUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static MemorySize getMemorySizeFromConfig(Configuration config, ConfigOption<MemorySize> option) {
	try {
		return Preconditions.checkNotNull(config.get(option), "The memory option is not set and has no default value.");
	} catch (Throwable t) {
		throw new IllegalConfigurationException("Cannot read memory size from config option '" + option.key() + "'.", t);
	}
}
 
Example 8
Source File: DefaultConfigurableOptionsFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to check whether the (key,value) is valid through given configuration and returns the formatted value.
 *
 * @param option The configuration key which is configurable in {@link RocksDBConfigurableOptions}.
 * @param value The value within given configuration.
 */
private static void checkArgumentValid(ConfigOption<?> option, Object value) {
	final String key = option.key();

	if (POSITIVE_INT_CONFIG_SET.contains(option)) {
		Preconditions.checkArgument((Integer) value  > 0,
			"Configured value for key: " + key + " must be larger than 0.");
	} else if (SIZE_CONFIG_SET.contains(option)) {
		Preconditions.checkArgument(((MemorySize) value).getBytes() > 0,
			"Configured size for key" + key + " must be larger than 0.");
	}
}
 
Example 9
Source File: KubernetesUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parse a valid port for the config option. A fixed port is expected, and do not support a range of ports.
 *
 * @param flinkConfig flink config
 * @param port port config option
 * @return valid port
 */
public static Integer parsePort(Configuration flinkConfig, ConfigOption<String> port) {
	checkNotNull(flinkConfig.get(port), port.key() + " should not be null.");

	try {
		return Integer.parseInt(flinkConfig.get(port));
	} catch (NumberFormatException ex) {
		throw new FlinkRuntimeException(
			port.key() + " should be specified to a fixed port. Do not support a range of ports.",
			ex);
	}
}
 
Example 10
Source File: TableConfigUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns time in milli second.
 *
 * @param tableConfig TableConfig object
 * @param config config to fetch
 * @return time in milli second.
 */
public static Long getMillisecondFromConfigDuration(TableConfig tableConfig, ConfigOption<String> config) {
	String timeStr = tableConfig.getConfiguration().getString(config);
	if (timeStr != null) {
		Duration duration = Duration.create(timeStr);
		if (duration.isFinite()) {
			return duration.toMillis();
		} else {
			throw new IllegalArgumentException(config.key() + " must be finite.");
		}
	} else {
		return null;
	}
}
 
Example 11
Source File: AthenaXConfiguration.java    From AthenaX with Apache License 2.0 5 votes vote down vote up
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());
  }
}
 
Example 12
Source File: SSLUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
private static String getAndCheckOption(Configuration config, ConfigOption<String> primaryOption, ConfigOption<String> fallbackOption) {
	String value = config.getString(primaryOption, config.getString(fallbackOption));
	if (value != null) {
		return value;
	}
	else {
		throw new IllegalConfigurationException("The config option " + primaryOption.key() +
				" or " + fallbackOption.key() + " is missing.");
	}
}
 
Example 13
Source File: TableConfigUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns time in milli second.
 *
 * @param tableConfig TableConfig object
 * @param config config to fetch
 * @return time in milli second.
 */
public static Long getMillisecondFromConfigDuration(TableConfig tableConfig, ConfigOption<String> config) {
	String timeStr = tableConfig.getConfiguration().getString(config);
	if (timeStr != null) {
		Duration duration = Duration.create(timeStr);
		if (duration.isFinite()) {
			return duration.toMillis();
		} else {
			throw new IllegalArgumentException(config.key() + " must be finite.");
		}
	} else {
		return null;
	}
}
 
Example 14
Source File: SSLUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static String getAndCheckOption(Configuration config, ConfigOption<String> primaryOption, ConfigOption<String> fallbackOption) {
	String value = config.getString(primaryOption, config.getString(fallbackOption));
	if (value != null) {
		return value;
	}
	else {
		throw new IllegalConfigurationException("The config option " + primaryOption.key() +
				" or " + fallbackOption.key() + " is missing.");
	}
}
 
Example 15
Source File: LimitedConnectionsFileSystem.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void checkLimit(int value, ConfigOption<Integer> option) {
	if (value < -1) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + value);
	}
}
 
Example 16
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void checkLimit(int value, ConfigOption<Integer> option) {
	if (value < -1) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + value);
	}
}
 
Example 17
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void checkTimeout(long timeout, ConfigOption<Long> option) {
	if (timeout < 0) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + timeout);
	}
}
 
Example 18
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void checkTimeout(long timeout, ConfigOption<Long> option) {
	if (timeout < 0) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + timeout);
	}
}
 
Example 19
Source File: LimitedConnectionsFileSystem.java    From flink with Apache License 2.0 4 votes vote down vote up
private static void checkLimit(int value, ConfigOption<Integer> option) {
	if (value < -1) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + value);
	}
}
 
Example 20
Source File: LimitedConnectionsFileSystem.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private static void checkTimeout(long timeout, ConfigOption<Long> option) {
	if (timeout < 0) {
		throw new IllegalConfigurationException("Invalid value for '" + option.key() + "': " + timeout);
	}
}