Created
May 17, 2013 13:46
Fix PigUnit on Windows env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.pig; | |
import javassist.CannotCompileException; | |
import javassist.ClassPool; | |
import javassist.CtClass; | |
import javassist.CtMethod; | |
import javassist.NotFoundException; | |
public class FixHadoopOnWindows { | |
/** | |
* Fix the followind Hadoop problem on Windows: | |
* 1) mapReduceLayer.Launcher: Backend error message during job submission java.io.IOException: Failed to set permissions of path: \tmp\hadoop-MyUsername\mapred\staging\ | |
* 2) java.io.IOException: Failed to set permissions of path: bla-bla-bla\.staging to 0700 | |
*/ | |
public static void runFix() throws NotFoundException, CannotCompileException { | |
if( isWindows() ) { // run fix only on Windows | |
setUpSystemVariables(); | |
fixCheckReturnValueMethod(); | |
} | |
} | |
// set up correct temporary directory on windows | |
private static void setUpSystemVariables() { | |
System.getProperties().setProperty("java.io.tmpdir", "D:/TMP/"); | |
} | |
/** | |
* org.apache.hadoop.fs.FileUtil#checkReturnValue doesn't work on Windows at all | |
* so, let's change method body with Javassist on empty body | |
*/ | |
private static void fixCheckReturnValueMethod() throws NotFoundException, CannotCompileException { | |
ClassPool cp = new ClassPool(true); | |
CtClass ctClass = cp.get("org.apache.hadoop.fs.FileUtil"); | |
CtMethod ctMethod = ctClass.getDeclaredMethod("checkReturnValue"); | |
ctMethod.setBody("{ }"); | |
ctClass.toClass(); | |
} | |
private static boolean isWindows() { | |
String OS = System.getProperty("os.name"); | |
return OS.startsWith("Windows"); | |
} | |
private FixHadoopOnWindows() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment