Hadoop - 作业提交过程(源码)未完待续

提交作业

hadoop jar word-count.jar /user/1.txt,/user/2.txt,/user/3.txt /user/output

hadoop shell 关键代码

#core commands  
  *)
    # the core commands
    if [ "$COMMAND" = "fs" ] ; then
      CLASS=org.apache.hadoop.fs.FsShell
    elif [ "$COMMAND" = "version" ] ; then
      CLASS=org.apache.hadoop.util.VersionInfo
    elif [ "$COMMAND" = "jar" ] ; then
      CLASS=org.apache.hadoop.util.RunJar
      if [[ -n "${YARN_OPTS}" ]] || [[ -n "${YARN_CLIENT_OPTS}" ]]; then
        echo "WARNING: Use \"yarn jar\" to launch YARN applications." 1>&2
      fi
    elif [ "$COMMAND" = "key" ] ; then
      CLASS=org.apache.hadoop.crypto.key.KeyShell
    ......
    ......
    fi
		......
		......
    exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
    ;;
esac

org.apache.hadoop.util.RunJar.main

public static void main(String[] args) throws Throwable {
   
    new RunJar().run(args);
}

public void run(String[] args) throws Throwable {
   
    String usage = "RunJar jarFile [mainClass] args...";

    if (args.length < 1) {
   
        System.err.println(usage);
        System.exit(-1);
    }

    int firstArg = 0;
    String fileName = args[firstArg++];
    File file = new File(fileName); // 例子中 word-count.jar
    if (!file.exists() || !file.isFile()) {
   
        System.err.println("JAR does not exist or is not a normal file: " +
                file.getCanonicalPath());
        System.exit(-1);
    }
    String mainClassName = null;
	
    JarFile jarFile;
    try {
   
        jarFile = new JarFile(fileName);
    } catch(IOException io) {
   
        throw new IOException("Error opening job jar: " + fileName)
                .initCause(io);
    }
	// 获取主类
    Manifest manifest = jarFile.getManifest();
    if (manifest != null) {
   
        mainClassName = manifest.getMainAttributes().getValue("Main-Class");
    }
    jarFile.close();

    if (mainClassName == null) {
   
        if (args.length < 2) {
   
            System.err.println(usage);
            System.exit(-1);
        }
        mainClassName = args[firstArg++];
    }
    mainClassName = mainClassName.replaceAll("/", ".");
	// 创建临时目录
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    ensureDirectory(tmpDir);
	// 创建工作目录
    final File workDir;
    try {
   
        workDir = File.createTempFile("hadoop-unjar", "", tmpDir);
    } catch (IOException ioe) {
   
        // If user has insufficient perms to write to tmpDir, default
        // "Permission denied" message doesn't specify a filename.
        System.err.println("Error creating temp dir in java.io.tmpdir "
                + tmpDir + " due to " + ioe.getMessage());
        System.exit(-1);
        return;
    }

    if (!workDir.delete()) {
   
        System.err.println("Delete failed for " + workDir);
        System.exit(-1);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值