HBASE-9003 TableMapReduceUtil should not rely on org.apache.hadoop.util.JarFinder#getJar (Esteban Gutierrez)

Signed-off-by: stack <stack@apache.org>
This commit is contained in:
Nick Dimiduk 2014-10-30 18:51:19 -07:00 committed by stack
parent 646f1d5f8f
commit a71dd16a70
3 changed files with 9 additions and 26 deletions

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License. See accompanying LICENSE file.
*/
package org.apache.hadoop.hbase.mapreduce.hadoopbackport;
package org.apache.hadoop.hbase.mapreduce;
import com.google.common.base.Preconditions;
@ -36,7 +36,7 @@ import java.util.zip.ZipOutputStream;
* classpath, it creates a Jar on the fly with the contents of the directory
* and returns the path to that Jar. If a Jar is created, it is created in
* the system temporary directory.
*
*
* This file was forked from hadoop/common/branches/branch-2@1377176.
*/
public class JarFinder {
@ -161,6 +161,7 @@ public class JarFinder {
}
File tempJar = File.createTempFile("hadoop-", "", testDir);
tempJar = new File(tempJar.getAbsolutePath() + ".jar");
tempJar.deleteOnExit();
createJar(baseDir, tempJar);
return tempJar.getAbsolutePath();
}

View File

@ -20,8 +20,6 @@ package org.apache.hadoop.hbase.mapreduce;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
@ -49,7 +47,6 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
import org.apache.hadoop.hbase.mapreduce.hadoopbackport.JarFinder;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
import org.apache.hadoop.hbase.security.User;
@ -836,8 +833,7 @@ public class TableMapReduceUtil {
}
/**
* If org.apache.hadoop.util.JarFinder is available (0.23+ hadoop), finds
* the Jar for a class or creates it if it doesn't exist. If the class is in
* Finds the Jar for a class or creates it if it doesn't exist. If the class is in
* a directory in the classpath, it creates a Jar on the fly with the
* contents of the directory and returns the path to that Jar. If a Jar is
* created, it is created in the system temporary directory. Otherwise,
@ -931,29 +927,16 @@ public class TableMapReduceUtil {
}
/**
* Invoke 'getJar' on a JarFinder implementation. Useful for some job
* configuration contexts (HBASE-8140) and also for testing on MRv2. First
* check if we have HADOOP-9426. Lacking that, fall back to the backport.
* Invoke 'getJar' on a custom JarFinder implementation. Useful for some job
* configuration contexts (HBASE-8140) and also for testing on MRv2.
* check if we have HADOOP-9426.
* @param my_class the class to find.
* @return a jar file that contains the class, or null.
*/
private static String getJar(Class<?> my_class) {
String ret = null;
String hadoopJarFinder = "org.apache.hadoop.util.JarFinder";
Class<?> jarFinder = null;
try {
LOG.debug("Looking for " + hadoopJarFinder + ".");
jarFinder = Class.forName(hadoopJarFinder);
LOG.debug(hadoopJarFinder + " found.");
Method getJar = jarFinder.getMethod("getJar", Class.class);
ret = (String) getJar.invoke(null, my_class);
} catch (ClassNotFoundException e) {
LOG.debug("Using backported JarFinder.");
ret = JarFinder.getJar(my_class);
} catch (InvocationTargetException e) {
// function was properly called, but threw it's own exception. Unwrap it
// and pass it on.
throw new RuntimeException(e.getCause());
} catch (Exception e) {
// toss all other exceptions, related to reflection failure
throw new RuntimeException("getJar invocation failed.", e);

View File

@ -16,10 +16,9 @@
* limitations under the License.
*/
package org.apache.hadoop.hbase.mapreduce.hadoopbackport;
package org.apache.hadoop.hbase.mapreduce;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.testclassification.MapReduceTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Assert;
import org.junit.Test;
@ -42,7 +41,7 @@ import java.util.jar.Manifest;
/**
* This file was forked from hadoop/common/branches/branch-2@1350012.
*/
@Category({MapReduceTests.class, SmallTests.class})
@Category(SmallTests.class)
public class TestJarFinder {
@Test