Class Configuration
- Direct Known Subclasses:
JobConf,YarnConfiguration
Resources
Configurations are specified by resources. A resource contains a set of
name/value pairs as XML data. Each resource is named by either a
String or by a Path. If named by a String,
then the classpath is examined for a file with that name. If named by a
Path, then the local filesystem is examined directly, without
referring to the classpath.
Unless explicitly turned off, Hadoop by default specifies two resources, loaded in-order from the classpath:
core-default.xml: Read-only defaults for hadoop.core-site.xml: Site-specific configuration for a given hadoop installation.
Final Parameters
Configuration parameters may be declared final. Once a resource declares a value final, no subsequently-loaded resource can alter that value. For example, one might define a final parameter with:
<property>
<name>dfs.hosts.include</name>
<value>/etc/hadoop/conf/hosts.include</value>
<final>true</final>
</property>
Administrators typically define parameters as final in
core-site.xml for values that user applications may not alter.
Variable Expansion
Value strings are first processed for variable expansion. The available properties are:
- Other properties defined in this Configuration; and, if a name is undefined here,
- Environment variables in
System.getenv()if a name starts with "env.", or - Properties in
System.getProperties().
For example, if a configuration resource contains the following property definitions:
<property>
<name>basedir</name>
<value>/user/${user.name}</value>
</property>
<property>
<name>tempdir</name>
<value>${basedir}/tmp</value>
</property>
<property>
<name>otherdir</name>
<value>${env.BASE_DIR}/other</value>
</property>
When conf.get("tempdir") is called, then ${basedir}
will be resolved to another property in this Configuration, while
${user.name} would then ordinarily be resolved to the value
of the System property with that name.
When conf.get("otherdir") is called, then ${env.BASE_DIR}
will be resolved to the value of the ${BASE_DIR} environment variable.
It supports ${env.NAME:-default} and ${env.NAME-default} notations.
The former is resolved to "default" if ${NAME} environment variable is undefined
or its value is empty.
The latter behaves the same way only if ${NAME} is undefined.
By default, warnings will be given to any deprecated configuration
parameters and these are suppressible by configuring
log4j.logger.org.apache.hadoop.conf.Configuration.deprecation in
log4j.properties file.
Tags
Optionally we can tag related properties together by using tag attributes. System tags are defined by hadoop.tags.system property. Users can define there own custom tags in hadoop.tags.custom property.
For example, we can tag existing property as:
<property>
<name>dfs.replication</name>
<value>3</value>
<tag>HDFS,REQUIRED</tag>
</property>
<property>
<name>dfs.data.transfer.protection</name>
<value>3</value>
<tag>HDFS,SECURITY</tag>
</property>
Properties marked with tags can be retrieved with conf
.getAllPropertiesByTag("HDFS") or conf.getAllPropertiesByTags
(Arrays.asList("YARN","SECURITY")).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.conf.Configuration.DeprecationDeltaA pending addition to the global set of deprecated keys.static classorg.apache.hadoop.conf.Configuration.IntegerRangesA class that represents a set of positive integer ranges. -
Constructor Summary
ConstructorsConstructorDescriptionA new configuration.Configuration(boolean loadDefaults) A new configuration where the behavior of reading from the default resources can be turned off.Configuration(Configuration other) A new configuration with the same settings cloned from another. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDefaultResource(String name) Add a default resource.static voidaddDeprecation(String key, String newKey) Adds the deprecated key to the global deprecation map when no custom message is provided.static voidaddDeprecation(String key, String[] newKeys) Deprecated.static voidaddDeprecation(String key, String[] newKeys, String customMessage) Deprecated.static voidaddDeprecation(String key, String newKey, String customMessage) Adds the deprecated key to the global deprecation map.static voidaddDeprecations(org.apache.hadoop.conf.Configuration.DeprecationDelta[] deltas) Adds a set of deprecated keys to the global deprecations.voidAdd a configuration resource.voidaddResource(InputStream in, boolean restrictedParser) voidaddResource(InputStream in, String name) Add a configuration resource.voidaddResource(InputStream in, String name, boolean restrictedParser) voidaddResource(String name) Add a configuration resource.voidaddResource(String name, boolean restrictedParser) voidaddResource(URL url) Add a configuration resource.voidaddResource(URL url, boolean restrictedParser) voidaddResource(Configuration conf) Add a configuration resource.voidaddResource(Path file) Add a configuration resource.voidaddResource(Path file, boolean restrictedParser) voidaddTags(Properties prop) Add tags defined in HADOOP_TAGS_SYSTEM, HADOOP_TAGS_CUSTOM.voidclear()Clears all keys from the configuration.static voiddumpConfiguration(Configuration config, Writer out) Writes out all properties and their attributes (final and resource) to the givenWriter, the format of the output would be,static voiddumpConfiguration(Configuration config, String propertyName, Writer out) Writes properties and their attributes (final and resource) to the givenWriter.static voidGet the value of thenameproperty,nullif no such property exists.Get the value of thename.Get all properties belonging to tag.getAllPropertiesByTags(List<String> tagList) Get all properties belonging to list of input tags.booleangetBoolean(String name, boolean defaultValue) Get the value of thenameproperty as aboolean.Class<?>Get the value of thenameproperty as aClass.<U> Class<? extends U>Get the value of thenameproperty as aClassimplementing the interface specified byxface.Class<?>getClassByName(String name) Load a class by name.Class<?>getClassByNameOrNull(String name) Load a class by name, returning null rather than throwing an exception if it couldn't be loaded.Class<?>[]getClasses(String name, Class<?>... defaultValue) Get the value of thenameproperty as an array ofClass.Get theClassLoaderfor this job.Get an input stream attached to the configuration resource with the givenname.Get aReaderattached to the configuration resource with the givenname.doubleGet the value of thenameproperty as adouble.<T extends Enum<T>>
TReturn value matching this enumerated type.getEnumSet(String key, Class<E> enumClass, boolean ignoreUnknown) Build an enumset from a comma separated list of values.Get a local file name under a directory named in dirsProp with the given path.Get the set of parameters marked final.floatGet the value of thenameproperty as afloat.<U> List<U>getInstances(String name, Class<U> xface) Get the value of thenameproperty as aListof objects implementing the interface specified byxface.intGet the value of thenameproperty as anint.int[]Get the value of thenameproperty as a set of comma-delimitedintvalues.getLocalPath(String dirsProp, String path) Get a local file under a directory named by dirsProp with the given path.longGet the value of thenameproperty as along.longgetLongBytes(String name, long defaultValue) Get the value of thenameproperty as alongor human readable format.char[]getPassword(String name) Get the value for a known password configuration element.protected char[]getPasswordFromConfig(String name) Fallback to clear text passwords in configuration.char[]Try and resolve the provided element name as a credential provider alias.getPattern(String name, Pattern defaultValue) Get the value of thenameproperty as aPattern.String[]getPropertySources(String name) Gets information about why a property was set.protected PropertiesgetProps()getPropsWithPrefix(String confPrefix) Constructs a mapping of configuration and includes all properties that start with the specified configuration prefix.org.apache.hadoop.conf.Configuration.IntegerRangesParse the given attribute as a set of integer ranges.Get the value of thenameproperty, without doing variable expansion.If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null.getResource(String name) Get theURLfor the named resource.getSocketAddr(String name, String defaultAddress, int defaultPort) Get the socket address fornameproperty as aInetSocketAddress.getSocketAddr(String hostProperty, String addressProperty, String defaultAddressValue, int defaultPort) Get the socket address forhostPropertyas aInetSocketAddress.doublegetStorageSize(String name, double defaultValue, StorageUnit targetUnit) Gets storage size from a config file.doublegetStorageSize(String name, String defaultValue, StorageUnit targetUnit) Gets the Storage Size from the config, or returns the defaultValue.getStringCollection(String name) Get the comma delimited values of thenameproperty as a collection ofStrings.String[]getStrings(String name) Get the comma delimited values of thenameproperty as an array ofStrings.String[]getStrings(String name, String... defaultValue) Get the comma delimited values of thenameproperty as an array ofStrings.longgetTimeDuration(String name, long defaultValue, TimeUnit unit) Return time duration in the given time unit.longgetTimeDuration(String name, long defaultValue, TimeUnit defaultUnit, TimeUnit returnUnit) Return time duration in the given time unit.longgetTimeDuration(String name, String defaultValue, TimeUnit unit) longgetTimeDuration(String name, String defaultValue, TimeUnit defaultUnit, TimeUnit returnUnit) longgetTimeDurationHelper(String name, String vStr, TimeUnit unit) Return time duration in the given time unit.long[]getTimeDurations(String name, TimeUnit unit) getTrimmed(String name) Get the value of thenameproperty as a trimmedString,nullif no such property exists.getTrimmed(String name, String defaultValue) Get the value of thenameproperty as a trimmedString,defaultValueif no such property exists.Get the comma delimited values of thenameproperty as a collection ofStrings, trimmed of the leading and trailing whitespace.String[]getTrimmedStrings(String name) Get the comma delimited values of thenameproperty as an array ofStrings, trimmed of the leading and trailing whitespace.String[]getTrimmedStrings(String name, String... defaultValue) Get the comma delimited values of thenameproperty as an array ofStrings, trimmed of the leading and trailing whitespace.getValByRegex(String regex) get keys matching the the regex.static booleanhasWarnedDeprecation(String name) Returns whether or not a deprecated name has been warned.static booleanisDeprecated(String key) checks whether the givenkeyis deprecated.booleanisPropertyTag(String tagStr) Get Property tag Enum corresponding to given source.iterator()Get anIteratorto go through the list ofStringkey-value pairs in the configuration.static voidFor debugging.booleanonlyKeyExists(String name) Return existence of thenameproperty, but only for names which have no valid value, usually non-existent or commented out in XML.voidreadFields(DataInput in) Deserialize the fields of this object fromin.voidReload configuration from previously added resources.static voidReload existing configuration instances.voidSet thevalueof thenameproperty.voidSet thevalueof thenameproperty.voidsetAllowNullValueProperties(boolean val) Set Configuration to allow keys without values during setup.voidsetBoolean(String name, boolean value) Set the value of thenameproperty to aboolean.voidsetBooleanIfUnset(String name, boolean value) Set the given property, if it is currently unset.voidSet the value of thenameproperty to the name of atheClassimplementing the given interfacexface.voidsetClassLoader(ClassLoader classLoader) Set the class loader that will be used to load the various objects.voidSets all deprecated properties that are not currently set but have a corresponding new property that is set.voidSet the value of thenameproperty to adouble.<T extends Enum<T>>
voidSet the value of thenameproperty to the given type.voidSet the value of thenameproperty to afloat.voidsetIfUnset(String name, String value) Sets a property if it is currently unset.voidSet the value of thenameproperty to anint.voidSet the value of thenameproperty to along.voidsetPattern(String name, Pattern pattern) Set the given property toPattern.voidsetQuietMode(boolean quietmode) Set the quietness-mode.voidsetRestrictSystemProperties(boolean val) static voidsetRestrictSystemPropertiesDefault(boolean val) voidsetRestrictSystemProps(boolean val) voidsetSocketAddr(String name, InetSocketAddress addr) Set the socket address for thenameproperty as ahost:port.voidsetStorageSize(String name, double value, StorageUnit unit) Sets Storage Size for the specified key.voidsetStrings(String name, String... values) Set the array of string values for thenameproperty as as comma delimited values.voidsetTimeDuration(String name, long value, TimeUnit unit) Set the value ofnameto the given time duration.intsize()Return the number of keys in the configuration.Provides a public wrapper over substituteVars in order to avoid compatibility issues.toString()voidUnset a previously set property.updateConnectAddr(String hostProperty, String addressProperty, String defaultAddressValue, InetSocketAddress addr) Set the socket address a client can use to connect for thenameproperty as ahost:port.updateConnectAddr(String name, InetSocketAddress addr) Set the socket address a client can use to connect for thenameproperty as ahost:port.voidwrite(DataOutput out) Serialize the fields of this object toout.voidwriteXml(OutputStream out) Write out the non-default properties in this configuration to the givenOutputStreamusing UTF-8 encoding.voidvoidvoidwriteXml(String propertyName, Writer out, Configuration config) Write out the non-default properties in this configuration to the givenWriter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Configuration
public Configuration()A new configuration. -
Configuration
public Configuration(boolean loadDefaults) A new configuration where the behavior of reading from the default resources can be turned off. If the parameterloadDefaultsis false, the new instance will not load resources from the default files.- Parameters:
loadDefaults- specifies whether to load from the default files
-
Configuration
A new configuration with the same settings cloned from another.- Parameters:
other- the configuration from which to clone settings.
-
-
Method Details
-
addDeprecations
public static void addDeprecations(org.apache.hadoop.conf.Configuration.DeprecationDelta[] deltas) Adds a set of deprecated keys to the global deprecations. This method is lockless. It works by means of creating a new DeprecationContext based on the old one, and then atomically swapping in the new context. If someone else updated the context in between us reading the old context and swapping in the new one, we try again until we win the race.- Parameters:
deltas- The deprecations to add.
-
addDeprecation
Deprecated.Adds the deprecated key to the global deprecation map. It does not override any existing entries in the deprecation map. This is to be used only by the developers in order to add deprecation of keys, and attempts to call this method after loading resources once, would lead toUnsupportedOperationExceptionIf a key is deprecated in favor of multiple keys, they are all treated as aliases of each other, and setting any one of them resets all the others to the new value. If you have multiple deprecation entries to add, it is more efficient to use #addDeprecations(DeprecationDelta[] deltas) instead.- Parameters:
key- to be deprecatednewKeys- list of keys that take up the values of deprecated keycustomMessage- depcrication message
-
addDeprecation
Adds the deprecated key to the global deprecation map. It does not override any existing entries in the deprecation map. This is to be used only by the developers in order to add deprecation of keys, and attempts to call this method after loading resources once, would lead toUnsupportedOperationExceptionIf you have multiple deprecation entries to add, it is more efficient to use #addDeprecations(DeprecationDelta[] deltas) instead.- Parameters:
key- to be deprecatednewKey- key that take up the values of deprecated keycustomMessage- deprecation message
-
addDeprecation
Deprecated.useaddDeprecation(String key, String newKey)insteadAdds the deprecated key to the global deprecation map when no custom message is provided. It does not override any existing entries in the deprecation map. This is to be used only by the developers in order to add deprecation of keys, and attempts to call this method after loading resources once, would lead toUnsupportedOperationExceptionIf a key is deprecated in favor of multiple keys, they are all treated as aliases of each other, and setting any one of them resets all the others to the new value. If you have multiple deprecation entries to add, it is more efficient to use #addDeprecations(DeprecationDelta[] deltas) instead.- Parameters:
key- Key that is to be deprecatednewKeys- list of keys that take up the values of deprecated key
-
addDeprecation
Adds the deprecated key to the global deprecation map when no custom message is provided. It does not override any existing entries in the deprecation map. This is to be used only by the developers in order to add deprecation of keys, and attempts to call this method after loading resources once, would lead toUnsupportedOperationExceptionIf you have multiple deprecation entries to add, it is more efficient to use #addDeprecations(DeprecationDelta[] deltas) instead.- Parameters:
key- Key that is to be deprecatednewKey- key that takes up the value of deprecated key
-
isDeprecated
checks whether the givenkeyis deprecated.- Parameters:
key- the parameter which is to be checked for deprecation- Returns:
trueif the key is deprecated andfalseotherwise.
-
setDeprecatedProperties
public void setDeprecatedProperties()Sets all deprecated properties that are not currently set but have a corresponding new property that is set. Useful for iterating the properties when all deprecated properties for currently set properties need to be present. -
reloadExistingConfigurations
public static void reloadExistingConfigurations()Reload existing configuration instances. -
addDefaultResource
Add a default resource. Resources are loaded in the order of the resources added.- Parameters:
name- file name. File should be present in the classpath.
-
setRestrictSystemPropertiesDefault
public static void setRestrictSystemPropertiesDefault(boolean val) -
setRestrictSystemProperties
public void setRestrictSystemProperties(boolean val) -
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final.- Parameters:
name- resource to be added, the classpath is examined for a file with that name.
-
addResource
-
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final.- Parameters:
url- url of the resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
-
addResource
-
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final.- Parameters:
file- file-path of resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
-
addResource
-
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final. WARNING: The contents of the InputStream will be cached, by this method. So use this sparingly because it does increase the memory consumption.- Parameters:
in- InputStream to deserialize the object from. In will be read from when a get or set is called next. After it is read the stream will be closed.
-
addResource
-
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final.- Parameters:
in- InputStream to deserialize the object from.name- the name of the resource because InputStream.toString is not very descriptive some times.
-
addResource
-
addResource
Add a configuration resource. The properties of this resource will override properties of previously added resources, unless they were marked final.- Parameters:
conf- Configuration object from which to load properties
-
reloadConfiguration
public void reloadConfiguration()Reload configuration from previously added resources. This method will clear all the configuration read from the added resources, and final parameters. This will make the resources to be read again before accessing the values. Values that are added via set methods will overlay values read from the resources. -
substituteCommonVariables
Provides a public wrapper over substituteVars in order to avoid compatibility issues. See HADOOP-18021 for further details.- Parameters:
expr- the literal value of a config key- Returns:
- null if expr is null, otherwise the value resulting from expanding expr using the algorithm above.
- Throws:
IllegalArgumentException- when more thanMAX_SUBSTreplacements are required
-
get
Get the value of thenameproperty,nullif no such property exists. If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null. Values are processed for variable expansion before being returned. As a side effect get loads the properties from the sources if called for the first time as a lazy init.- Parameters:
name- the property name, will be trimmed before get value.- Returns:
- the value of the
nameor its replacing property, or null if no such property exists.
-
setAllowNullValueProperties
@VisibleForTesting public void setAllowNullValueProperties(boolean val) Set Configuration to allow keys without values during setup. Intended for use during testing.- Parameters:
val- If true, will allow Configuration to store keys without values
-
setRestrictSystemProps
public void setRestrictSystemProps(boolean val) -
onlyKeyExists
Return existence of thenameproperty, but only for names which have no valid value, usually non-existent or commented out in XML.- Parameters:
name- the property name- Returns:
- true if the property
nameexists without value
-
getTrimmed
Get the value of thenameproperty as a trimmedString,nullif no such property exists. If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null Values are processed for variable expansion before being returned.- Parameters:
name- the property name.- Returns:
- the value of the
nameor its replacing property, or null if no such property exists.
-
getTrimmed
Get the value of thenameproperty as a trimmedString,defaultValueif no such property exists. See @{Configuration#getTrimmed} for more details.- Parameters:
name- the property name.defaultValue- the property default value.- Returns:
- the value of the
nameor defaultValue if it is not set.
-
getRaw
Get the value of thenameproperty, without doing variable expansion.If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null.- Parameters:
name- the property name.- Returns:
- the value of the
nameproperty or its replacing property and null if no such property exists.
-
set
Set thevalueof thenameproperty. Ifnameis deprecated or there is a deprecated name associated to it, it sets the value to both names. Name will be trimmed before put into configuration.- Parameters:
name- property name.value- property value.
-
set
Set thevalueof thenameproperty. Ifnameis deprecated, it also sets thevalueto the keys that replace the deprecated key. Name will be trimmed before put into configuration.- Parameters:
name- property name.value- property value.source- the place that this configuration value came from (For debugging).- Throws:
IllegalArgumentException- when the value or name is null.
-
unset
Unset a previously set property.- Parameters:
name- the property name
-
setIfUnset
Sets a property if it is currently unset.- Parameters:
name- the property namevalue- the new value
-
get
Get the value of thename. If the key is deprecated, it returns the value of the first key which replaces the deprecated key and is not null. If no such property exists, thendefaultValueis returned.- Parameters:
name- property name, will be trimmed before get value.defaultValue- default value.- Returns:
- property value, or
defaultValueif the property doesn't exist.
-
getInt
Get the value of thenameproperty as anint. If no such property exists, the provided default value is returned, or if the specified value is not a validint, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as an
int, ordefaultValue. - Throws:
NumberFormatException- when the value is invalid
-
getInts
Get the value of thenameproperty as a set of comma-delimitedintvalues. If no such property exists, an empty array is returned.- Parameters:
name- property name- Returns:
- property value interpreted as an array of comma-delimited
intvalues
-
setInt
Set the value of thenameproperty to anint.- Parameters:
name- property name.value-intvalue of the property.
-
getLong
Get the value of thenameproperty as along. If no such property exists, the provided default value is returned, or if the specified value is not a validlong, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as a
long, ordefaultValue. - Throws:
NumberFormatException- when the value is invalid
-
getLongBytes
Get the value of thenameproperty as alongor human readable format. If no such property exists, the provided default value is returned, or if the specified value is not a validlongor human readable format, then an error is thrown. You can use the following suffix (case insensitive): k(kilo), m(mega), g(giga), t(tera), p(peta), e(exa)- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as a
long, ordefaultValue. - Throws:
NumberFormatException- when the value is invalid
-
setLong
Set the value of thenameproperty to along.- Parameters:
name- property name.value-longvalue of the property.
-
getFloat
Get the value of thenameproperty as afloat. If no such property exists, the provided default value is returned, or if the specified value is not a validfloat, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as a
float, ordefaultValue. - Throws:
NumberFormatException- when the value is invalid
-
setFloat
Set the value of thenameproperty to afloat.- Parameters:
name- property name.value- property value.
-
getDouble
Get the value of thenameproperty as adouble. If no such property exists, the provided default value is returned, or if the specified value is not a validdouble, then an error is thrown.- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as a
double, ordefaultValue. - Throws:
NumberFormatException- when the value is invalid
-
setDouble
Set the value of thenameproperty to adouble.- Parameters:
name- property name.value- property value.
-
getBoolean
Get the value of thenameproperty as aboolean. If no such property is specified, or if the specified value is not a validboolean, thendefaultValueis returned.- Parameters:
name- property name.defaultValue- default value.- Returns:
- property value as a
boolean, ordefaultValue.
-
setBoolean
Set the value of thenameproperty to aboolean.- Parameters:
name- property name.value-booleanvalue of the property.
-
setBooleanIfUnset
Set the given property, if it is currently unset.- Parameters:
name- property namevalue- new value
-
setEnum
Set the value of thenameproperty to the given type. This is equivalent toset(<name>, value.toString()).- Type Parameters:
T- enumeration type- Parameters:
name- property namevalue- new value
-
getEnum
Return value matching this enumerated type. Note that the returned value is trimmed by this method.- Type Parameters:
T- enumeration type- Parameters:
name- Property namedefaultValue- Value returned if no mapping exists- Returns:
- enumeration type
- Throws:
IllegalArgumentException- If mapping is illegal for the type provided
-
getEnumSet
public <E extends Enum<E>> EnumSet<E> getEnumSet(String key, Class<E> enumClass, boolean ignoreUnknown) throws IllegalArgumentException Build an enumset from a comma separated list of values. Case independent. Special handling of "*" meaning: all values.- Type Parameters:
E- enumeration type- Parameters:
key- key to look forenumClass- class of enumignoreUnknown- should unknown values raise an exception?- Returns:
- a mutable set of the identified enum values declared in the configuration
- Throws:
IllegalArgumentException- if one of the entries was unknown and ignoreUnknown is false, or there are two entries in the enum which differ only by case.
-
setTimeDuration
Set the value ofnameto the given time duration. This is equivalent toset(<name>, value + <time suffix>).- Parameters:
name- Property namevalue- Time durationunit- Unit of time
-
getTimeDuration
Return time duration in the given time unit. Valid units are encoded in properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds (ms), seconds (s), minutes (m), hours (h), and days (d).- Parameters:
name- Property namedefaultValue- Value returned if no mapping exists.unit- Unit to convert the stored property, if it exists.- Returns:
- time duration in given time unit
- Throws:
NumberFormatException- If the property stripped of its unit is not a number
-
getTimeDuration
-
getTimeDuration
public long getTimeDuration(String name, long defaultValue, TimeUnit defaultUnit, TimeUnit returnUnit) Return time duration in the given time unit. Valid units are encoded in properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds (ms), seconds (s), minutes (m), hours (h), and days (d). If no unit is provided, the default unit is applied.- Parameters:
name- Property namedefaultValue- Value returned if no mapping exists.defaultUnit- Default time unit if no valid suffix is provided.returnUnit- The unit used for the returned value.- Returns:
- time duration in given time unit
- Throws:
NumberFormatException- If the property stripped of its unit is not a number
-
getTimeDuration
-
getTimeDurationHelper
Return time duration in the given time unit. Valid units are encoded in properties as suffixes: nanoseconds (ns), microseconds (us), milliseconds (ms), seconds (s), minutes (m), hours (h), and days (d).- Parameters:
name- Property namevStr- The string value with time unit suffix to be converted.unit- Unit to convert the stored property, if it exists.- Returns:
- time duration in given time unit.
-
getTimeDurations
-
getStorageSize
Gets the Storage Size from the config, or returns the defaultValue. The unit of return value is specified in target unit.- Parameters:
name- - Key NamedefaultValue- - Default Value -- e.g. 100MBtargetUnit- - The units that we want result to be in.- Returns:
- double -- formatted in target Units
-
getStorageSize
Gets storage size from a config file.- Parameters:
name- - Key to read.defaultValue- - The default value to return in case the key is not present.targetUnit- - The Storage unit that should be used for the return value.- Returns:
- - double value in the Storage Unit specified.
-
setStorageSize
Sets Storage Size for the specified key.- Parameters:
name- - Key to set.value- - The numeric value to set.unit- - Storage Unit to be used.
-
getPattern
Get the value of thenameproperty as aPattern. If no such property is specified, or if the specified value is not a validPattern, thenDefaultValueis returned. Note that the returned value is NOT trimmed by this method.- Parameters:
name- property namedefaultValue- default value- Returns:
- property value as a compiled Pattern, or defaultValue
-
setPattern
Set the given property toPattern. If the pattern is passed as null, sets the empty pattern which results in further calls to getPattern(...) returning the default value.- Parameters:
name- property namepattern- new value
-
getPropertySources
Gets information about why a property was set. Typically this is the path to the resource objects (file, URL, etc.) the property came from, but it can also indicate that it was set programmatically, or because of the command line.- Parameters:
name- - The property name to get the source of.- Returns:
- null - If the property or its source wasn't found. Otherwise, returns a list of the sources of the resource. The older sources are the first ones in the list. So for example if a configuration is set from the command line, and then written out to a file that is read back in the first entry would indicate that it was set from the command line, while the second one would indicate the file that the new configuration was read in from.
-
getRange
public org.apache.hadoop.conf.Configuration.IntegerRanges getRange(String name, String defaultValue) Parse the given attribute as a set of integer ranges.- Parameters:
name- the attribute namedefaultValue- the default value if it is not set- Returns:
- a new set of ranges from the configured value
-
getStringCollection
Get the comma delimited values of thenameproperty as a collection ofStrings. If no such property is specified then empty collection is returned.This is an optimized version of
getStrings(String)- Parameters:
name- property name.- Returns:
- property value as a collection of
Strings.
-
getStrings
Get the comma delimited values of thenameproperty as an array ofStrings. If no such property is specified thennullis returned.- Parameters:
name- property name.- Returns:
- property value as an array of
Strings, ornull.
-
getStrings
Get the comma delimited values of thenameproperty as an array ofStrings. If no such property is specified then default value is returned.- Parameters:
name- property name.defaultValue- The default value- Returns:
- property value as an array of
Strings, or default value.
-
getTrimmedStringCollection
Get the comma delimited values of thenameproperty as a collection ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then emptyCollectionis returned.- Parameters:
name- property name.- Returns:
- property value as a collection of
Strings, or emptyCollection
-
getTrimmedStrings
Get the comma delimited values of thenameproperty as an array ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then an empty array is returned.- Parameters:
name- property name.- Returns:
- property value as an array of trimmed
Strings, or empty array.
-
getTrimmedStrings
Get the comma delimited values of thenameproperty as an array ofStrings, trimmed of the leading and trailing whitespace. If no such property is specified then default value is returned.- Parameters:
name- property name.defaultValue- The default value- Returns:
- property value as an array of trimmed
Strings, or default value.
-
setStrings
Set the array of string values for thenameproperty as as comma delimited values.- Parameters:
name- property name.values- The values
-
getPassword
Get the value for a known password configuration element. In order to enable the elimination of clear text passwords in config, this method attempts to resolve the property name as an alias through the CredentialProvider API and conditionally fallsback to config.- Parameters:
name- property name- Returns:
- password
- Throws:
IOException- when error in fetching password
-
getPasswordFromCredentialProviders
Try and resolve the provided element name as a credential provider alias.- Parameters:
name- alias of the provisioned credential- Returns:
- password or null if not found
- Throws:
IOException- when error in fetching password
-
getPasswordFromConfig
Fallback to clear text passwords in configuration.- Parameters:
name- the property name.- Returns:
- clear text password or null
-
getSocketAddr
public InetSocketAddress getSocketAddr(String hostProperty, String addressProperty, String defaultAddressValue, int defaultPort) Get the socket address forhostPropertyas aInetSocketAddress. IfhostPropertyisnull,addressPropertywill be used. This is useful for cases where we want to differentiate between host bind address and address clients should use to establish connection.- Parameters:
hostProperty- bind host property name.addressProperty- address property name.defaultAddressValue- the default valuedefaultPort- the default port- Returns:
- InetSocketAddress
-
getSocketAddr
Get the socket address fornameproperty as aInetSocketAddress.- Parameters:
name- property name.defaultAddress- the default valuedefaultPort- the default port- Returns:
- InetSocketAddress
-
setSocketAddr
Set the socket address for thenameproperty as ahost:port.- Parameters:
name- property name.addr- inetSocketAddress addr.
-
updateConnectAddr
public InetSocketAddress updateConnectAddr(String hostProperty, String addressProperty, String defaultAddressValue, InetSocketAddress addr) Set the socket address a client can use to connect for thenameproperty as ahost:port. The wildcard address is replaced with the local host's address. If the host and address properties are configured the host component of the address will be combined with the port component of the addr to generate the address. This is to allow optional control over which host name is used in multi-home bind-host cases where a host can have multiple names- Parameters:
hostProperty- the bind-host configuration nameaddressProperty- the service address configuration namedefaultAddressValue- the service default address configuration valueaddr- InetSocketAddress of the service listener- Returns:
- InetSocketAddress for clients to connect
-
updateConnectAddr
Set the socket address a client can use to connect for thenameproperty as ahost:port. The wildcard address is replaced with the local host's address.- Parameters:
name- property name.addr- InetSocketAddress of a listener to store in the given property- Returns:
- InetSocketAddress for clients to connect
-
getClassByName
Load a class by name.- Parameters:
name- the class name.- Returns:
- the class object.
- Throws:
ClassNotFoundException- if the class is not found.
-
getClassByNameOrNull
Load a class by name, returning null rather than throwing an exception if it couldn't be loaded. This is to avoid the overhead of creating an exception.- Parameters:
name- the class name- Returns:
- the class object, or null if it could not be found.
-
getClasses
Get the value of thenameproperty as an array ofClass. The value of the property specifies a list of comma separated class names. If no such property is specified, thendefaultValueis returned.- Parameters:
name- the property name.defaultValue- default value.- Returns:
- property value as a
Class[], ordefaultValue.
-
getClass
Get the value of thenameproperty as aClass. If no such property is specified, thendefaultValueis returned.- Parameters:
name- the conf key name.defaultValue- default value.- Returns:
- property value as a
Class, ordefaultValue.
-
getClass
public <U> Class<? extends U> getClass(String name, Class<? extends U> defaultValue, Class<U> xface) Get the value of thenameproperty as aClassimplementing the interface specified byxface. If no such property is specified, thendefaultValueis returned. An exception is thrown if the returned class does not implement the named interface.- Type Parameters:
U- Interface class type.- Parameters:
name- the conf key name.defaultValue- default value.xface- the interface implemented by the named class.- Returns:
- property value as a
Class, ordefaultValue.
-
getInstances
Get the value of thenameproperty as aListof objects implementing the interface specified byxface. An exception is thrown if any of the classes does not exist, or if it does not implement the named interface.- Type Parameters:
U- Interface class type.- Parameters:
name- the property name.xface- the interface implemented by the classes named byname.- Returns:
- a
Listof objects implementingxface.
-
setClass
Set the value of thenameproperty to the name of atheClassimplementing the given interfacexface. An exception is thrown iftheClassdoes not implement the interfacexface.- Parameters:
name- property name.theClass- property value.xface- the interface implemented by the named class.
-
getLocalPath
Get a local file under a directory named by dirsProp with the given path. If dirsProp contains multiple directories, then one is chosen based on path's hash code. If the selected directory does not exist, an attempt is made to create it.- Parameters:
dirsProp- directory in which to locate the file.path- file-path.- Returns:
- local file under the directory with the given path.
- Throws:
IOException- raised on errors performing I/O.
-
getFile
Get a local file name under a directory named in dirsProp with the given path. If dirsProp contains multiple directories, then one is chosen based on path's hash code. If the selected directory does not exist, an attempt is made to create it.- Parameters:
dirsProp- directory in which to locate the file.path- file-path.- Returns:
- local file under the directory with the given path.
- Throws:
IOException- raised on errors performing I/O.
-
getResource
Get theURLfor the named resource.- Parameters:
name- resource name.- Returns:
- the url for the named resource.
-
getConfResourceAsInputStream
Get an input stream attached to the configuration resource with the givenname.- Parameters:
name- configuration resource name.- Returns:
- an input stream attached to the resource.
-
getConfResourceAsReader
Get aReaderattached to the configuration resource with the givenname.- Parameters:
name- configuration resource name.- Returns:
- a reader attached to the resource.
-
getFinalParameters
Get the set of parameters marked final.- Returns:
- final parameter set.
-
getProps
-
size
public int size()Return the number of keys in the configuration.- Returns:
- number of keys in the configuration.
-
clear
public void clear()Clears all keys from the configuration. -
iterator
Get anIteratorto go through the list ofStringkey-value pairs in the configuration. -
getPropsWithPrefix
Constructs a mapping of configuration and includes all properties that start with the specified configuration prefix. Property names in the mapping are trimmed to remove the configuration prefix.- Parameters:
confPrefix- configuration prefix- Returns:
- mapping of configuration properties with prefix stripped
-
addTags
Add tags defined in HADOOP_TAGS_SYSTEM, HADOOP_TAGS_CUSTOM.- Parameters:
prop- properties.
-
writeXml
Write out the non-default properties in this configuration to the givenOutputStreamusing UTF-8 encoding.- Parameters:
out- the output stream to write to.- Throws:
IOException- raised on errors performing I/O.
-
writeXml
- Throws:
IOException
-
writeXml
public void writeXml(@Nullable String propertyName, Writer out, Configuration config) throws IOException, IllegalArgumentException Write out the non-default properties in this configuration to the givenWriter.-
When property name is not empty and the property exists in the
configuration, this method writes the property and its attributes
to the
Writer. -
When property name is null or empty, this method writes all the
configuration properties and their attributes to the
Writer. -
When property name is not empty but the property doesn't exist in
the configuration, this method throws an
IllegalArgumentException.
- Parameters:
propertyName- xml property name.out- the writer to write to.config- configuration.- Throws:
IOException- raised on errors performing I/O.IllegalArgumentException
-
When property name is not empty and the property exists in the
configuration, this method writes the property and its attributes
to the
-
writeXml
public void writeXml(@Nullable String propertyName, Writer out) throws IOException, IllegalArgumentException - Throws:
IOExceptionIllegalArgumentException
-
dumpConfiguration
public static void dumpConfiguration(Configuration config, String propertyName, Writer out) throws IOException Writes properties and their attributes (final and resource) to the givenWriter.-
When propertyName is not empty, and the property exists
in the configuration, the format of the output would be,
{ "property": { "key" : "key1", "value" : "value1", "isFinal" : "key1.isFinal", "resource" : "key1.resource" } } -
When propertyName is null or empty, it behaves same as
dumpConfiguration(Configuration, Writer), the output would be,{ "properties" : [ { key : "key1", value : "value1", isFinal : "key1.isFinal", resource : "key1.resource" }, { key : "key2", value : "value2", isFinal : "ke2.isFinal", resource : "key2.resource" } ] } -
When propertyName is not empty, and the property is not
found in the configuration, this method will throw an
IllegalArgumentException.
- Parameters:
config- the configurationpropertyName- property nameout- the Writer to write to- Throws:
IOException- raised on errors performing I/O.IllegalArgumentException- when property name is not empty and the property is not found in configuration
-
When propertyName is not empty, and the property exists
in the configuration, the format of the output would be,
-
dumpConfiguration
Writes out all properties and their attributes (final and resource) to the givenWriter, the format of the output would be,{ "properties" : [ { key : "key1", value : "value1", isFinal : "key1.isFinal", resource : "key1.resource" }, { key : "key2", value : "value2", isFinal : "ke2.isFinal", resource : "key2.resource" } ] }It does not output the properties of the configuration object which is loaded from an input stream.- Parameters:
config- the configurationout- the Writer to write to- Throws:
IOException- raised on errors performing I/O.
-
getClassLoader
Get theClassLoaderfor this job.- Returns:
- the correct class loader.
-
setClassLoader
Set the class loader that will be used to load the various objects.- Parameters:
classLoader- the new class loader.
-
toString
-
setQuietMode
public void setQuietMode(boolean quietmode) Set the quietness-mode. In the quiet-mode, error and informational messages might not be logged.- Parameters:
quietmode-trueto set quiet-mode on,falseto turn it off.
-
main
For debugging. List non-default properties to the terminal and exit.- Parameters:
args- the argument to be parsed.- Throws:
Exception- exception.
-
readFields
Description copied from interface:WritableDeserialize the fields of this object fromin.For efficiency, implementations should attempt to re-use storage in the existing object where possible.
- Specified by:
readFieldsin interfaceWritable- Parameters:
in-DataInputto deseriablize this object from.- Throws:
IOException- any other problem for readFields.
-
write
Description copied from interface:WritableSerialize the fields of this object toout.- Specified by:
writein interfaceWritable- Parameters:
out-DataOuputto serialize this object into.- Throws:
IOException- any other problem for write.
-
getValByRegex
get keys matching the the regex.- Parameters:
regex- the regex to match against.- Returns:
- Map<String,String> with matching keys
-
dumpDeprecatedKeys
public static void dumpDeprecatedKeys() -
hasWarnedDeprecation
Returns whether or not a deprecated name has been warned. If the name is not deprecated then always return false- Parameters:
name- proprties.- Returns:
- true if name is a warned deprecation.
-
getAllPropertiesByTag
Get all properties belonging to tag.- Parameters:
tag- tag- Returns:
- Properties with matching tag
-
getAllPropertiesByTags
Get all properties belonging to list of input tags. Calls getAllPropertiesByTag internally.- Parameters:
tagList- list of input tags- Returns:
- Properties with matching tags
-
isPropertyTag
Get Property tag Enum corresponding to given source.- Parameters:
tagStr- String representation of Enum- Returns:
- true if tagStr is a valid tag
-
addDeprecation(String key, String newKey)instead