Package org.apache.flink.util
Class ParameterTool
- java.lang.Object
-
- org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters
-
- org.apache.flink.util.AbstractParameterTool
-
- org.apache.flink.util.ParameterTool
-
- All Implemented Interfaces:
Serializable,Cloneable
@Public public class ParameterTool extends AbstractParameterTool
This class provides simple utility methods for reading and parsing program arguments from different sources. Only single value parameter could be supported in args.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,String>data-
Fields inherited from class org.apache.flink.util.AbstractParameterTool
DEFAULT_UNDEFINED, defaultData, NO_VALUE_KEY, unrequestedParameters
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Objectclone()voidcreatePropertiesFile(String pathToFile)Create a properties file with all the known parameters (call after the last get*() call).voidcreatePropertiesFile(String pathToFile, boolean overwrite)Create a properties file with all the known parameters (call after the last get*() call).booleanequals(Object o)static ParameterToolfromArgs(String[] args)ReturnsParameterToolfor the given arguments.static ParameterToolfromMap(Map<String,String> map)ReturnsParameterToolfor the given map.static ParameterToolfromPropertiesFile(File file)ReturnsParameterToolfor the givenPropertiesfile.static ParameterToolfromPropertiesFile(InputStream inputStream)ReturnsParameterToolfor the given InputStream fromPropertiesfile.static ParameterToolfromPropertiesFile(String path)ReturnsParameterToolfor the givenPropertiesfile.static ParameterToolfromSystemProperties()ReturnsParameterToolfrom the system properties.Stringget(String key)Returns the String value for the given key.ConfigurationgetConfiguration()Returns aConfigurationobject from thisParameterTool.intgetNumberOfParameters()Returns number of parameters inParameterTool.PropertiesgetProperties()Returns aPropertiesobject from thisParameterTool.booleanhas(String value)Check if value is set.inthashCode()ParameterToolmergeWith(ParameterTool other)Merges twoParameterTool.Map<String,String>toMap()Convert UserConfig into aMap<String, String>representation.-
Methods inherited from class org.apache.flink.util.AbstractParameterTool
addToDefaults, get, getBoolean, getBoolean, getByte, getByte, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getRequired, getShort, getShort, getUnrequestedParameters
-
-
-
-
Method Detail
-
fromArgs
public static ParameterTool fromArgs(String[] args)
ReturnsParameterToolfor the given arguments. The arguments are keys followed by values. Keys have to start with '-' or '--'Example arguments: --key1 value1 --key2 value2 -key3 value3
- Parameters:
args- Input array arguments- Returns:
- A
ParameterTool
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(String path) throws IOException
ReturnsParameterToolfor the givenPropertiesfile.- Parameters:
path- Path to the properties file- Returns:
- A
ParameterTool - Throws:
IOException- If the file does not exist- See Also:
Properties
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(File file) throws IOException
ReturnsParameterToolfor the givenPropertiesfile.- Parameters:
file- File object to the properties file- Returns:
- A
ParameterTool - Throws:
IOException- If the file does not exist- See Also:
Properties
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(InputStream inputStream) throws IOException
ReturnsParameterToolfor the given InputStream fromPropertiesfile.- Parameters:
inputStream- InputStream from the properties file- Returns:
- A
ParameterTool - Throws:
IOException- If the file does not exist- See Also:
Properties
-
fromMap
public static ParameterTool fromMap(Map<String,String> map)
ReturnsParameterToolfor the given map.- Parameters:
map- A map of arguments. Both Key and Value have to be Strings- Returns:
- A
ParameterTool
-
fromSystemProperties
public static ParameterTool fromSystemProperties()
ReturnsParameterToolfrom the system properties. Example on how to pass system properties: -Dkey1=value1 -Dkey2=value2- Returns:
- A
ParameterTool
-
equals
public boolean equals(Object o)
- Overrides:
equalsin classExecutionConfig.GlobalJobParameters
-
hashCode
public int hashCode()
- Overrides:
hashCodein classExecutionConfig.GlobalJobParameters
-
getNumberOfParameters
public int getNumberOfParameters()
Returns number of parameters inParameterTool.- Specified by:
getNumberOfParametersin classAbstractParameterTool
-
get
public String get(String key)
Returns the String value for the given key. If the key does not exist it will return null.- Specified by:
getin classAbstractParameterTool
-
has
public boolean has(String value)
Check if value is set.- Specified by:
hasin classAbstractParameterTool
-
getConfiguration
public Configuration getConfiguration()
Returns aConfigurationobject from thisParameterTool.- Returns:
- A
Configuration
-
getProperties
public Properties getProperties()
Returns aPropertiesobject from thisParameterTool.- Returns:
- A
Properties
-
createPropertiesFile
public void createPropertiesFile(String pathToFile) throws IOException
Create a properties file with all the known parameters (call after the last get*() call). Set the default value, if available.Use this method to create a properties file skeleton.
- Parameters:
pathToFile- Location of the default properties file.- Throws:
IOException
-
createPropertiesFile
public void createPropertiesFile(String pathToFile, boolean overwrite) throws IOException
Create a properties file with all the known parameters (call after the last get*() call). Set the default value, if overwrite is true.- Parameters:
pathToFile- Location of the default properties file.overwrite- Boolean flag indicating whether or not to overwrite the file- Throws:
IOException- If overwrite is not allowed and the file exists
-
clone
protected Object clone() throws CloneNotSupportedException
- Specified by:
clonein classAbstractParameterTool- Throws:
CloneNotSupportedException
-
mergeWith
public ParameterTool mergeWith(ParameterTool other)
Merges twoParameterTool.- Parameters:
other- OtherParameterToolobject- Returns:
- The Merged
ParameterTool
-
toMap
public Map<String,String> toMap()
Description copied from class:ExecutionConfig.GlobalJobParametersConvert UserConfig into aMap<String, String>representation. This can be used by the runtime, for example for presenting the user config in the web frontend.- Specified by:
toMapin classAbstractParameterTool- Returns:
- Key/Value representation of the UserConfig
-
-