HADOOP-6243. Fix a NullPointerException in processing deprecated keys. Contributed by Sreekanth Ramakrishnan.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@812455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d09ade4d0b
commit
4a4dd27571
|
@ -984,6 +984,9 @@ Trunk (unreleased changes)
|
||||||
HADOOP-6229. Attempt to make a directory under an existing file on
|
HADOOP-6229. Attempt to make a directory under an existing file on
|
||||||
LocalFileSystem should throw an Exception. (Boris Shkolnik via tomwhite)
|
LocalFileSystem should throw an Exception. (Boris Shkolnik via tomwhite)
|
||||||
|
|
||||||
|
HADOOP-6243. Fix a NullPointerException in processing deprecated keys.
|
||||||
|
(Sreekanth Ramakrishnan via yhemanth)
|
||||||
|
|
||||||
Release 0.20.1 - Unreleased
|
Release 0.20.1 - Unreleased
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -485,11 +485,4 @@
|
||||||
IP address.
|
IP address.
|
||||||
</description>
|
</description>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
<property>
|
|
||||||
<name>hadoop.conf.extra.classes</name>
|
|
||||||
<value>org.apache.hadoop.mapred.JobConf</value>
|
|
||||||
<final>true</final>
|
|
||||||
</property>
|
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -336,6 +336,12 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
}
|
}
|
||||||
addDefaultResource("core-default.xml");
|
addDefaultResource("core-default.xml");
|
||||||
addDefaultResource("core-site.xml");
|
addDefaultResource("core-site.xml");
|
||||||
|
//Add code for managing deprecated key mapping
|
||||||
|
//for example
|
||||||
|
//addDeprecation("oldKey1",new String[]{"newkey1","newkey2"});
|
||||||
|
//adds deprecation for oldKey1 to two new keys(newkey1, newkey2).
|
||||||
|
//so get or set of oldKey1 will correctly populate/access values of
|
||||||
|
//newkey1 and newkey2
|
||||||
}
|
}
|
||||||
|
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
@ -1364,56 +1370,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
||||||
loadResource(properties, resource, quiet);
|
loadResource(properties, resource, quiet);
|
||||||
}
|
}
|
||||||
// process for deprecation.
|
// process for deprecation.
|
||||||
processDeprecation();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag to ensure that the classes mentioned in the value of the property
|
|
||||||
* <code>hadoop.conf.extra.classes</code> are loaded only once for
|
|
||||||
* all instances of <code>Configuration</code>
|
|
||||||
*/
|
|
||||||
private static AtomicBoolean loadedDeprecation = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
private static final String extraConfKey = "hadoop.conf.extra.classes";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds all the deprecations to the deprecatedKeyMap and updates the values of
|
|
||||||
* the appropriate keys
|
|
||||||
*/
|
|
||||||
private void processDeprecation() {
|
|
||||||
populateDeprecationMapping();
|
|
||||||
processDeprecatedKeys();
|
processDeprecatedKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all the classes in mapred and hdfs that extend Configuration and that
|
|
||||||
* have deprecations to be added into deprecatedKeyMap
|
|
||||||
*/
|
|
||||||
private synchronized void populateDeprecationMapping() {
|
|
||||||
if (!loadedDeprecation.get()) {
|
|
||||||
// load classes from mapred and hdfs which extend Configuration and have
|
|
||||||
// deprecations added in their static blocks
|
|
||||||
String classnames = substituteVars(properties.getProperty(extraConfKey));
|
|
||||||
if (classnames == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String[] classes = StringUtils.getStrings(classnames);
|
|
||||||
for (String className : classes) {
|
|
||||||
try {
|
|
||||||
Class.forName(className);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
LOG.warn(className + " is not in the classpath");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// make deprecatedKeyMap unmodifiable in order to prevent changes to
|
|
||||||
// it in user's code.
|
|
||||||
deprecatedKeyMap = Collections.unmodifiableMap(deprecatedKeyMap);
|
|
||||||
// ensure that deprecation processing is done only once for all
|
|
||||||
// instances of this object
|
|
||||||
loadedDeprecation.set(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the keys that are replacing the deprecated keys and removes the
|
* Updates the keys that are replacing the deprecated keys and removes the
|
||||||
* deprecated keys from memory.
|
* deprecated keys from memory.
|
||||||
|
|
|
@ -81,30 +81,27 @@ public class TestConfigurationDeprecation {
|
||||||
out.write("</property>\n");
|
out.write("</property>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static class MyConf extends Configuration {
|
private void addDeprecationToConfiguration() {
|
||||||
static {
|
Configuration.addDeprecation("old.key1", new String[]{"new.key1"});
|
||||||
// add deprecation mappings.
|
Configuration.addDeprecation("old.key2", new String[]{"new.key2"});
|
||||||
Configuration.addDeprecation("old.key1", new String[]{"new.key1"});
|
Configuration.addDeprecation("old.key3", new String[]{"new.key3"});
|
||||||
Configuration.addDeprecation("old.key2", new String[]{"new.key2"});
|
Configuration.addDeprecation("old.key4", new String[]{"new.key4"});
|
||||||
Configuration.addDeprecation("old.key3", new String[]{"new.key3"});
|
Configuration.addDeprecation("old.key5", new String[]{"new.key5"});
|
||||||
Configuration.addDeprecation("old.key4", new String[]{"new.key4"});
|
Configuration.addDeprecation("old.key6", new String[]{"new.key6"});
|
||||||
Configuration.addDeprecation("old.key5", new String[]{"new.key5"});
|
Configuration.addDeprecation("old.key7", new String[]{"new.key7"});
|
||||||
Configuration.addDeprecation("old.key6", new String[]{"new.key6"});
|
Configuration.addDeprecation("old.key8", new String[]{"new.key8"});
|
||||||
Configuration.addDeprecation("old.key7", new String[]{"new.key7"});
|
Configuration.addDeprecation("old.key9", new String[]{"new.key9"});
|
||||||
Configuration.addDeprecation("old.key8", new String[]{"new.key8"});
|
Configuration.addDeprecation("old.key10", new String[]{"new.key10"});
|
||||||
Configuration.addDeprecation("old.key9", new String[]{"new.key9"});
|
Configuration.addDeprecation("old.key11", new String[]{"new.key11"});
|
||||||
Configuration.addDeprecation("old.key10", new String[]{"new.key10"});
|
Configuration.addDeprecation("old.key12", new String[]{"new.key12"});
|
||||||
Configuration.addDeprecation("old.key11", new String[]{"new.key11"});
|
Configuration.addDeprecation("old.key13", new String[]{"new.key13"});
|
||||||
Configuration.addDeprecation("old.key12", new String[]{"new.key12"});
|
Configuration.addDeprecation("old.key14", new String[]{"new.key14"});
|
||||||
Configuration.addDeprecation("old.key13", new String[]{"new.key13"});
|
Configuration.addDeprecation("old.key15", new String[]{"new.key15"});
|
||||||
Configuration.addDeprecation("old.key14", new String[]{"new.key14"});
|
Configuration.addDeprecation("old.key16", new String[]{"new.key16"});
|
||||||
Configuration.addDeprecation("old.key15", new String[]{"new.key15"});
|
Configuration.addDeprecation("A", new String[]{"B"});
|
||||||
Configuration.addDeprecation("old.key16", new String[]{"new.key16"});
|
Configuration.addDeprecation("C", new String[]{"D"});
|
||||||
Configuration.addDeprecation("A", new String[]{"B"});
|
Configuration.addDeprecation("E", new String[]{"F"});
|
||||||
Configuration.addDeprecation("C", new String[]{"D"});
|
Configuration.addDeprecation("G", new String[]{"H","I"});
|
||||||
Configuration.addDeprecation("E", new String[]{"F"});
|
|
||||||
Configuration.addDeprecation("G", new String[]{"H","I"});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,8 +120,6 @@ public class TestConfigurationDeprecation {
|
||||||
public void testDeprecation() throws IOException {
|
public void testDeprecation() throws IOException {
|
||||||
out=new BufferedWriter(new FileWriter(CONFIG));
|
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||||
startConfig();
|
startConfig();
|
||||||
appendProperty("hadoop.conf.extra.classes", MyConf.class.getName()
|
|
||||||
+ ",myconf1");
|
|
||||||
// load keys with default values. Some of them are set to final to
|
// load keys with default values. Some of them are set to final to
|
||||||
// test the precedence order between deprecation and being final
|
// test the precedence order between deprecation and being final
|
||||||
appendProperty("new.key1","default.value1",true);
|
appendProperty("new.key1","default.value1",true);
|
||||||
|
@ -145,6 +140,7 @@ public class TestConfigurationDeprecation {
|
||||||
appendProperty("new.key16","default.value16");
|
appendProperty("new.key16","default.value16");
|
||||||
endConfig();
|
endConfig();
|
||||||
Path fileResource = new Path(CONFIG);
|
Path fileResource = new Path(CONFIG);
|
||||||
|
addDeprecationToConfiguration();
|
||||||
conf.addResource(fileResource);
|
conf.addResource(fileResource);
|
||||||
|
|
||||||
out=new BufferedWriter(new FileWriter(CONFIG2));
|
out=new BufferedWriter(new FileWriter(CONFIG2));
|
||||||
|
|
Loading…
Reference in New Issue