Database Reference
In-Depth Information
The Configuration API
Components in Hadoop are configured using Hadoop's own configuration API. An in-
stance of the
Configuration
class (found in the
org.apache.hadoop.conf
pack-
age) represents a collection of configuration
properties
and their values. Each property is
named by a
String
, and the type of a value may be one of several, including Java primit-
ives such as
boolean
,
int
,
long
, and
float
; other useful types such as
String
,
Class
, and
java.io.File
; and collections of
String
s.
Configuration
s read their properties from
resources
— XML files with a simple struc-
ture for defining name-value pairs. See
Example 6-1
.
Example 6-1. A simple configuration file, configuration-1.xml
<?xml version="1.0"?>
<configuration>
<property>
<name>
color
</name>
<value>
yellow
</value>
<description>
Color
</description>
</property>
<property>
<name>
size
</name>
<value>
10
</value>
<description>
Size
</description>
</property>
<property>
<name>
weight
</name>
<value>
heavy
</value>
<final>
true
</final>
<description>
Weight
</description>
</property>
<property>
<name>
size-weight
</name>
<value>
${size},${weight}
</value>
<description>
Size and weight
</description>
</property>
</configuration>
Assuming this
Configuration
is in a file called
configuration-1.xml
, we can access its
properties using a piece of code like this: