|
@@ -50,6 +50,7 @@ import org.apache.hadoop.mapreduce.MRJobConfig;
|
|
import org.apache.hadoop.mapreduce.filecache.DistributedCache;
|
|
import org.apache.hadoop.mapreduce.filecache.DistributedCache;
|
|
import org.apache.hadoop.mapreduce.util.ConfigUtil;
|
|
import org.apache.hadoop.mapreduce.util.ConfigUtil;
|
|
import org.apache.hadoop.security.Credentials;
|
|
import org.apache.hadoop.security.Credentials;
|
|
|
|
+import org.apache.hadoop.util.ClassUtil;
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.hadoop.util.Tool;
|
|
import org.apache.log4j.Level;
|
|
import org.apache.log4j.Level;
|
|
@@ -453,7 +454,7 @@ public class JobConf extends Configuration {
|
|
* @param cls the example class.
|
|
* @param cls the example class.
|
|
*/
|
|
*/
|
|
public void setJarByClass(Class cls) {
|
|
public void setJarByClass(Class cls) {
|
|
- String jar = findContainingJar(cls);
|
|
|
|
|
|
+ String jar = ClassUtil.findContainingJar(cls);
|
|
if (jar != null) {
|
|
if (jar != null) {
|
|
setJar(jar);
|
|
setJar(jar);
|
|
}
|
|
}
|
|
@@ -1811,7 +1812,7 @@ public class JobConf extends Configuration {
|
|
return
|
|
return
|
|
(int)(Math.ceil((float)getMemoryForReduceTask() / (float)slotSizePerReduce));
|
|
(int)(Math.ceil((float)getMemoryForReduceTask() / (float)slotSizePerReduce));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Find a jar that contains a class of the same name, if any.
|
|
* Find a jar that contains a class of the same name, if any.
|
|
* It will return a jar file, even if that is not the first thing
|
|
* It will return a jar file, even if that is not the first thing
|
|
@@ -1822,35 +1823,9 @@ public class JobConf extends Configuration {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
public static String findContainingJar(Class my_class) {
|
|
public static String findContainingJar(Class my_class) {
|
|
- ClassLoader loader = my_class.getClassLoader();
|
|
|
|
- String class_file = my_class.getName().replaceAll("\\.", "/") + ".class";
|
|
|
|
- try {
|
|
|
|
- for(Enumeration itr = loader.getResources(class_file);
|
|
|
|
- itr.hasMoreElements();) {
|
|
|
|
- URL url = (URL) itr.nextElement();
|
|
|
|
- if ("jar".equals(url.getProtocol())) {
|
|
|
|
- String toReturn = url.getPath();
|
|
|
|
- if (toReturn.startsWith("file:")) {
|
|
|
|
- toReturn = toReturn.substring("file:".length());
|
|
|
|
- }
|
|
|
|
- // URLDecoder is a misnamed class, since it actually decodes
|
|
|
|
- // x-www-form-urlencoded MIME type rather than actual
|
|
|
|
- // URL encoding (which the file path has). Therefore it would
|
|
|
|
- // decode +s to ' 's which is incorrect (spaces are actually
|
|
|
|
- // either unencoded or encoded as "%20"). Replace +s first, so
|
|
|
|
- // that they are kept sacred during the decoding process.
|
|
|
|
- toReturn = toReturn.replaceAll("\\+", "%2B");
|
|
|
|
- toReturn = URLDecoder.decode(toReturn, "UTF-8");
|
|
|
|
- return toReturn.replaceAll("!.*$", "");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ return ClassUtil.findContainingJar(my_class);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Get the memory required to run a task of this job, in bytes. See
|
|
* Get the memory required to run a task of this job, in bytes. See
|
|
* {@link #MAPRED_TASK_MAXVMEM_PROPERTY}
|
|
* {@link #MAPRED_TASK_MAXVMEM_PROPERTY}
|