Package org.apache.flink.configuration
Class ConfigurationUtils
- java.lang.Object
-
- org.apache.flink.configuration.ConfigurationUtils
-
public class ConfigurationUtils extends Object
Utility class forConfigurationrelated helper functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringassembleDynamicConfigsStr(Map<String,String> config)Creates a dynamic parameter listStringof the passed configuration map.static booleancanBePrefixMap(ConfigOption<?> configOption)Maps can be represented in two ways.static List<String>convertConfigToWritableLines(Configuration configuration, boolean flattenYaml)Converts the provided configuration data into a format suitable for writing to a file, based on theflattenYamlflag and thestandardYamlattribute of the configuration object.static <E extends Enum<?>>
EconvertToEnum(Object o, Class<E> clazz)static <T> TconvertToList(Object rawValue, Class<?> atomicClass)static <T> TconvertValue(Object rawValue, Class<?> clazz)Tries to convert the raw value into the provided type.static ConfigurationcreateConfiguration(Properties properties)Creates a newConfigurationfrom the givenProperties.static booleanfilterPrefixMapKey(String key, String candidate)Filter condition for prefix map keys.static ConfigOption<Boolean>getBooleanConfigOption(String key)static ConfigOption<Double>getDoubleConfigOption(String key)static ConfigOption<Float>getFloatConfigOption(String key)static ConfigOption<Integer>getIntConfigOption(String key)static ConfigOption<Long>getLongConfigOption(String key)static Map<String,String>getPrefixedKeyValuePairs(String prefix, Configuration configuration)Extract and parse Flink configuration properties with a given name prefix and return the result as a Map.static FilegetRandomTempDirectory(Configuration configuration)Picks a temporary directory randomly from the given configuration.static DurationgetStandaloneClusterStartupPeriodTime(Configuration configuration)static Optional<Duration>getSystemResourceMetricsProbingInterval(Configuration configuration)static Map<String,String>hideSensitiveValues(Map<String,String> keyValuePairs)Replaces values whose keys are sensitive according toGlobalConfiguration.isSensitive(String)withGlobalConfiguration.HIDDEN_CONTENT.static Map<String,String>parseJvmArgString(String jvmParamsStr)static String[]parseLocalStateDirectories(Configuration configuration)Extracts the local state directories as defined byCheckpointingOptions.LOCAL_RECOVERY_TASK_MANAGER_STATE_ROOT_DIRS.static StringparseMapToString(Map<String,String> map)static Map<String,String>parseStringToMap(String stringSerializedMap)Parses a string as a map of strings.static String[]parseTempDirectories(Configuration configuration)Extracts the task manager directories for temporary files as defined byCoreOptions.TMP_DIRS.static Map<String,String>parseTmResourceDynamicConfigs(String dynamicConfigsStr)static String[]splitPaths(String separatedPaths)
-
-
-
Method Detail
-
getSystemResourceMetricsProbingInterval
public static Optional<Duration> getSystemResourceMetricsProbingInterval(Configuration configuration)
- Returns:
- extracted
MetricOptions.SYSTEM_RESOURCE_METRICS_PROBING_INTERVALorOptional.empty()ifMetricOptions.SYSTEM_RESOURCE_METRICSare disabled.
-
parseTempDirectories
@Nonnull public static String[] parseTempDirectories(Configuration configuration)
Extracts the task manager directories for temporary files as defined byCoreOptions.TMP_DIRS.- Parameters:
configuration- configuration object- Returns:
- array of configured directories (in order)
-
getRandomTempDirectory
@Nonnull public static File getRandomTempDirectory(Configuration configuration)
Picks a temporary directory randomly from the given configuration.- Parameters:
configuration- to extract the temp directory from- Returns:
- a randomly picked temporary directory
-
parseLocalStateDirectories
@Nonnull public static String[] parseLocalStateDirectories(Configuration configuration)
Extracts the local state directories as defined byCheckpointingOptions.LOCAL_RECOVERY_TASK_MANAGER_STATE_ROOT_DIRS.- Parameters:
configuration- configuration object- Returns:
- array of configured directories (in order)
-
parseStringToMap
public static Map<String,String> parseStringToMap(String stringSerializedMap)
Parses a string as a map of strings. The expected format of the map to be parsed` by FLINK parser is:key1:value1,key2:value2
The expected format of the map to be parsed by standard YAML parser is:
{key1: value1, key2: value2}Parts of the string can be escaped by wrapping with single or double quotes.
- Parameters:
stringSerializedMap- a string to parse- Returns:
- parsed map
-
getStandaloneClusterStartupPeriodTime
public static Duration getStandaloneClusterStartupPeriodTime(Configuration configuration)
-
createConfiguration
@Nonnull public static Configuration createConfiguration(Properties properties)
Creates a newConfigurationfrom the givenProperties.- Parameters:
properties- to convert into aConfiguration- Returns:
Configurationwhich has been populated by the values of the givenProperties
-
hideSensitiveValues
@Nonnull public static Map<String,String> hideSensitiveValues(Map<String,String> keyValuePairs)
Replaces values whose keys are sensitive according toGlobalConfiguration.isSensitive(String)withGlobalConfiguration.HIDDEN_CONTENT.This can be useful when displaying configuration values.
- Parameters:
keyValuePairs- for which to hide sensitive values- Returns:
- A map where all sensitive value are hidden
-
convertConfigToWritableLines
public static List<String> convertConfigToWritableLines(Configuration configuration, boolean flattenYaml)
Converts the provided configuration data into a format suitable for writing to a file, based on theflattenYamlflag and thestandardYamlattribute of the configuration object.Only when
flattenYamlis set tofalseand the configuration object is standard yaml, a nested YAML format is used. Otherwise, a flat key-value pair format is output.Each entry in the returned list represents a single line that can be written directly to a file.
Example input (flat map configuration data):
{ "parent.child": "value1", "parent.child2": "value2" }Example output when
flattenYamlisfalseand the configuration object is standard yaml:parent: child: value1 child2: value2Otherwise, the Example output is:
parent.child: value1 parent.child2: value2- Parameters:
configuration- The configuration to be converted.flattenYaml- A boolean flag indicating if the configuration data should be output in a flattened format.- Returns:
- A list of strings, where each string represents a line of the file-writable data in the chosen format.
-
assembleDynamicConfigsStr
public static String assembleDynamicConfigsStr(Map<String,String> config)
Creates a dynamic parameter listStringof the passed configuration map.- Parameters:
config- AMapcontaining parameter/value entries that shall be used in the dynamic parameter list.- Returns:
- The dynamic parameter list
String.
-
parseTmResourceDynamicConfigs
@VisibleForTesting public static Map<String,String> parseTmResourceDynamicConfigs(String dynamicConfigsStr)
-
parseJvmArgString
@VisibleForTesting public static Map<String,String> parseJvmArgString(String jvmParamsStr)
-
getPrefixedKeyValuePairs
public static Map<String,String> getPrefixedKeyValuePairs(String prefix, Configuration configuration)
Extract and parse Flink configuration properties with a given name prefix and return the result as a Map.
-
convertValue
public static <T> T convertValue(Object rawValue, Class<?> clazz)
Tries to convert the raw value into the provided type.- Type Parameters:
T- type of the result- Parameters:
rawValue- rawValue to convert into the provided type clazzclazz- clazz specifying the target type- Returns:
- the converted value if rawValue is of type clazz
- Throws:
IllegalArgumentException- if the rawValue cannot be converted in the specified target type clazz
-
canBePrefixMap
public static boolean canBePrefixMap(ConfigOption<?> configOption)
Maps can be represented in two ways.With constant key space:
avro-confluent.properties = schema: 1, other-prop: 2Or with variable key space (i.e. prefix notation):
avro-confluent.properties.schema = 1 avro-confluent.properties.other-prop = 2
-
filterPrefixMapKey
public static boolean filterPrefixMapKey(String key, String candidate)
Filter condition for prefix map keys.
-
getBooleanConfigOption
public static ConfigOption<Boolean> getBooleanConfigOption(String key)
-
getDoubleConfigOption
public static ConfigOption<Double> getDoubleConfigOption(String key)
-
getFloatConfigOption
public static ConfigOption<Float> getFloatConfigOption(String key)
-
getIntConfigOption
public static ConfigOption<Integer> getIntConfigOption(String key)
-
getLongConfigOption
public static ConfigOption<Long> getLongConfigOption(String key)
-
-