public class ConfigHelper extends Object
| Constructor and Description |
|---|
ConfigHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addConfigMap(org.apache.hadoop.conf.Configuration config,
Iterable<Map.Entry<String,String>> map,
String origin)
Set an entire map full of values
|
static void |
addConfigMap(org.apache.hadoop.conf.Configuration config,
Map<String,String> map,
String origin)
Set an entire map full of values
|
static org.apache.hadoop.conf.Configuration |
addConfigurationFile(org.apache.hadoop.conf.Configuration conf,
File file,
boolean overwrite)
Add a configuration from a file to an existing configuration
|
static void |
addEnvironmentVariables(org.apache.hadoop.conf.Configuration conf,
String prefix)
Add the system env variables with the given prefix (by convention, env.)
|
static Map<String,String> |
buildMapFromConfiguration(org.apache.hadoop.conf.Configuration conf)
Take a configuration, return a hash map
|
static Set<String> |
dumpConf(org.apache.hadoop.conf.Configuration conf)
Dump the (sorted) configuration
|
static String |
dumpConfigToString(org.apache.hadoop.conf.Configuration conf)
For testing: dump a configuration
|
static URL |
getResourceUrl(String resource)
Get the URL to a resource, null if not on the CP
|
static boolean |
injectSliderXMLResource()
Inject the
SliderKeys.SLIDER_XML resource
into the configuration resources of all configurations. |
static byte[] |
loadBytes(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path) |
static org.apache.hadoop.conf.Configuration |
loadConfFromFile(File file)
Load a Hadoop configuration from a local file.
|
static org.apache.hadoop.conf.Configuration |
loadConfFromFile(File file,
boolean loadDefaults)
Load a Hadoop configuration from a local file.
|
static org.apache.hadoop.conf.Configuration |
loadConfiguration(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Load a configuration from ANY FS path.
|
static org.apache.hadoop.conf.Configuration |
loadFromResource(String resource)
Load a configuration from a resource on this classpath.
|
static org.apache.hadoop.conf.Configuration |
loadMandatoryResource(String resource)
Load a resource that must be on the classpath
|
static org.apache.hadoop.conf.Configuration |
loadSliderConfiguration()
Load a configuration with the
SliderKeys.SLIDER_XML resource
included |
static org.apache.hadoop.conf.Configuration |
loadTemplateConfiguration(org.apache.hadoop.conf.Configuration systemConf,
org.apache.hadoop.fs.Path confdir,
String templateFilename,
String fallbackResource)
looks for the config under $confdir/$templateFilename; if not there
loads it from /conf/templateFile.
|
static org.apache.hadoop.conf.Configuration |
loadTemplateConfiguration(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path templatePath,
String fallbackResource)
looks for the config under $confdir/$templateFilename; if not there
loads it from /conf/templateFile.
|
static org.apache.hadoop.conf.Configuration |
mergeConfigurations(org.apache.hadoop.conf.Configuration base,
Iterable<Map.Entry<String,String>> merge,
String origin,
boolean overwrite)
Merge in one configuration above another
|
Document |
parseConfiguration(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
This will load and parse a configuration to an XML document
|
static Document |
parseConfigXML(InputStream in)
Parse an XML Hadoop configuration into an XML document.
|
static boolean |
propagate(org.apache.hadoop.conf.Configuration dest,
org.apache.hadoop.conf.Configuration src,
String key)
Propagate a property from a source to a dest config, with a best-effort
attempt at propagating the origin.
|
static URL |
registerDefaultResource(String resource)
Register a resource as a default resource.
|
static void |
registerDeprecatedConfigItems()
Register anything we consider deprecated
|
static org.apache.hadoop.conf.Configuration |
resolveConfiguration(Iterable<Map.Entry<String,String>> keysource,
org.apache.hadoop.conf.Configuration valuesource)
This goes through the keyset of one configuration and retrieves each value
from a value source -a different or the same configuration.
|
static org.apache.hadoop.fs.Path |
saveConfig(org.apache.hadoop.conf.Configuration systemConf,
org.apache.hadoop.conf.Configuration confToSave,
org.apache.hadoop.fs.Path confdir,
String filename)
Save a config file in a destination directory on a given filesystem
|
static File |
saveConfig(org.apache.hadoop.conf.Configuration generatingConf,
File confdir,
String filename)
Generate a config file in a destination directory on the local filesystem
|
static void |
saveConfig(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path destPath,
org.apache.hadoop.conf.Configuration confToSave)
Save a config
|
static Set<String> |
sortedConfigKeys(Iterable<Map.Entry<String,String>> conf)
Take a configuration and return a sorted set
|
static String |
toXml(org.apache.hadoop.conf.Configuration conf)
Convert to an XML string
|
public static Set<String> dumpConf(org.apache.hadoop.conf.Configuration conf)
conf - configpublic static Set<String> sortedConfigKeys(Iterable<Map.Entry<String,String>> conf)
conf - configpublic static void addConfigMap(org.apache.hadoop.conf.Configuration config,
Map<String,String> map,
String origin)
throws BadConfigException
config - config to patchmap - map of dataorigin - origin dataBadConfigExceptionpublic static void addConfigMap(org.apache.hadoop.conf.Configuration config,
Iterable<Map.Entry<String,String>> map,
String origin)
throws BadConfigException
config - config to patchmap - map of dataorigin - origin dataBadConfigExceptionpublic static org.apache.hadoop.fs.Path saveConfig(org.apache.hadoop.conf.Configuration systemConf,
org.apache.hadoop.conf.Configuration confToSave,
org.apache.hadoop.fs.Path confdir,
String filename)
throws IOException
systemConf - system conf used for creating filesystemsconfToSave - config to saveconfdir - the directory path where the file is to gofilename - the filenameIOException - IO problemspublic static void saveConfig(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path destPath,
org.apache.hadoop.conf.Configuration confToSave)
throws IOException
fs - filesystemdestPath - dest to saveconfToSave - config to saveIOException - IO problemspublic static String toXml(org.apache.hadoop.conf.Configuration conf) throws IOException
conf - configurationIOExceptionpublic Document parseConfiguration(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path) throws IOException
fs - filesystempath - pathIOException - IO failurepublic static byte[] loadBytes(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
throws IOException
IOExceptionpublic static org.apache.hadoop.conf.Configuration loadConfiguration(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
throws IOException
fs - filesystempath - pathIOExceptionpublic static File saveConfig(org.apache.hadoop.conf.Configuration generatingConf, File confdir, String filename) throws IOException
confdir - the directory path where the file is to gofilename - the filenameIOExceptionpublic static Document parseConfigXML(InputStream in) throws ParserConfigurationException, IOException, SAXException
in - instreamParserConfigurationException - parser feature problemsIOException - IO problemsSAXException - XML is invalidpublic static org.apache.hadoop.conf.Configuration loadConfFromFile(File file) throws IOException
file - file to loadFileNotFoundException - file is not thereIOException - any other IO problempublic static org.apache.hadoop.conf.Configuration loadConfFromFile(File file, boolean loadDefaults) throws IOException
file - file to loadloadDefaults - flag to indicate if the defaults should be loaded yetFileNotFoundException - file is not thereIOException - any other IO problempublic static org.apache.hadoop.conf.Configuration addConfigurationFile(org.apache.hadoop.conf.Configuration conf,
File file,
boolean overwrite)
throws IOException
conf - existing configurationfile - file to loadoverwrite - flag to indicate new values should overwrite the predecessorIOExceptionpublic static void addEnvironmentVariables(org.apache.hadoop.conf.Configuration conf,
String prefix)
conf - existing configurationprefix - prefixpublic static org.apache.hadoop.conf.Configuration loadTemplateConfiguration(org.apache.hadoop.conf.Configuration systemConf,
org.apache.hadoop.fs.Path confdir,
String templateFilename,
String fallbackResource)
throws IOException
SliderXmlConfKeys.KEY_TEMPLATE_ORIGIN is set to the
origin to help debug what's happeningsystemConf - system confconfdir - conf dir in FStemplateFilename - filename in the confdirfallbackResource - resource to fall back onIOException - IO problemspublic static org.apache.hadoop.conf.Configuration loadTemplateConfiguration(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path templatePath,
String fallbackResource)
throws IOException
SliderXmlConfKeys.KEY_TEMPLATE_ORIGIN is set to the
origin to help debug what's happening.fs - FilesystemtemplatePath - HDFS path for templatefallbackResource - resource to fall back on, or "" for no fallbackIOException - IO problemsFileNotFoundException - if the path doesn't have a file and there
was no fallback.public static String dumpConfigToString(org.apache.hadoop.conf.Configuration conf)
conf - configurationpublic static org.apache.hadoop.conf.Configuration mergeConfigurations(org.apache.hadoop.conf.Configuration base,
Iterable<Map.Entry<String,String>> merge,
String origin,
boolean overwrite)
base - base configmerge - one to merge. This MUST be a non-default-load config to avoid
merge origin confusionorigin - description of the origin for the put operationoverwrite - flag to indicate new values should overwrite the predecessorpublic static URL registerDefaultResource(String resource)
resource - the resource namepublic static org.apache.hadoop.conf.Configuration loadFromResource(String resource)
resource - the resource namepublic static URL getResourceUrl(String resource)
resource - resource to look forpublic static org.apache.hadoop.conf.Configuration loadMandatoryResource(String resource) throws FileNotFoundException
resource - the resource nameFileNotFoundException - if the resource is missingpublic static boolean propagate(org.apache.hadoop.conf.Configuration dest,
org.apache.hadoop.conf.Configuration src,
String key)
dest - destinationsrc - sourcekey - key to try to copypublic static Map<String,String> buildMapFromConfiguration(org.apache.hadoop.conf.Configuration conf)
conf - confpublic static org.apache.hadoop.conf.Configuration resolveConfiguration(Iterable<Map.Entry<String,String>> keysource, org.apache.hadoop.conf.Configuration valuesource)
keysource - source of keysvaluesource - the source of valuesforeach key in keysource, get(key)==valuesource.get(key)public static void registerDeprecatedConfigItems()
public static org.apache.hadoop.conf.Configuration loadSliderConfiguration()
SliderKeys.SLIDER_XML resource
includedpublic static boolean injectSliderXMLResource()
SliderKeys.SLIDER_XML resource
into the configuration resources of all configurations.
This operation is idempotent.
If the resource is not on the classpath, downgrades, rather than fails.
Copyright © 2014–2015 The Apache Software Foundation. All rights reserved.