ResourceManager命令行解析部分

org.apache.hadoop.util.GenericOptionsParser mark

主要解析命令行传递给RM的参数,没什么好分析的用的Hadoop Cli工具,将命令工具参数设置到了YarnConfiguration当中

 

/**
* Modify configuration according user-specified generic options
* @param conf Configuration to be modified
* @param line User-specified generic options
*/
private void processGeneralOptions(Configuration conf,
    CommandLine line) throws IOException {
  if (line.hasOption("fs")) {
    FileSystem.setDefaultUri(conf, line.getOptionValue("fs"));
  }

  if (line.hasOption("jt")) {
    String optionValue = line.getOptionValue("jt");
    if (optionValue.equalsIgnoreCase("local")) {
      conf.set("mapreduce.framework.name", optionValue);
    }

    conf.set("yarn.resourcemanager.address", optionValue,
        "from -jt command line option");
  }
  if (line.hasOption("conf")) {
    String[] values = line.getOptionValues("conf");
    for(String value : values) {
      conf.addResource(new Path(value));
    }
  }

  if (line.hasOption(‘D‘)) {
    String[] property = line.getOptionValues(‘D‘);
    for(String prop : property) {
      String[] keyval = prop.split("=", 2);
      if (keyval.length == 2) {
        conf.set(keyval[0], keyval[1], "from command line");
      }
    }
  }

  if (line.hasOption("libjars")) {
    conf.set("tmpjars",
             validateFiles(line.getOptionValue("libjars"), conf),
             "from -libjars command line option");
    //setting libjars in client classpath
    URL[] libjars = getLibJars(conf);
    if(libjars!=null && libjars.length>0) {
      conf.setClassLoader(new URLClassLoader(libjars, conf.getClassLoader()));
      Thread.currentThread().setContextClassLoader(
          new URLClassLoader(libjars,
              Thread.currentThread().getContextClassLoader()));
    }
  }
  if (line.hasOption("files")) {
    conf.set("tmpfiles",
             validateFiles(line.getOptionValue("files"), conf),
             "from -files command line option");
  }
  if (line.hasOption("archives")) {
    conf.set("tmparchives",
              validateFiles(line.getOptionValue("archives"), conf),
              "from -archives command line option");
  }
  conf.setBoolean("mapreduce.client.genericoptionsparser.used", true);
 
  // tokensFile
  if(line.hasOption("tokenCacheFile")) {
    String fileName = line.getOptionValue("tokenCacheFile");
    // check if the local file exists
    FileSystem localFs = FileSystem.getLocal(conf);
    Path p = localFs.makeQualified(new Path(fileName));
    if (!localFs.exists(p)) {
        throw new FileNotFoundException("File "+fileName+" does not exist.");
    }
    if(LOG.isDebugEnabled()) {
      LOG.debug("setting conf tokensFile: " + fileName);
    }
    UserGroupInformation.getCurrentUser().addCredentials(
        Credentials.readTokenStorageFile(p, conf));
    conf.set("mapreduce.job.credentials.binary", p.toString(),
             "from -tokenCacheFile command line option");

  }
}

时间: 2024-08-28 17:22:31

ResourceManager命令行解析部分的相关文章

python命令行解析工具argparse模块【1】

argpaser是python中很好用的一个命令行解析模块,使用它我们可以很方便的创建用户友好型命令行程序.而且argparse会自动生成帮助信息和错误信息. 一.示例 例如下面的例子,从命令行中获取几个整数,然后获取它们的和或者最大值. import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('integers', metavar='N'

cmdline —— 轻量级的C++命令行解析库

平时用C++写一些命令行工具,需要解析命令行的输入参数,这是一项繁琐并且容易出错的工作,我们不应该将主要精力放在这上面,可以考虑使用开源的库,下面的cmdline就是其中非常好用的一款. cmdline介绍 cmdline 是一个非常简单好用的C++命令行解析库,其基于模板,所以使用很简单,写出的代码也很优雅.由于其只包含一个头文件,所以很容易集成到自己的项目中. cmdline项目托管地址Github:https://github.com/tanakh/cmdline cmdline使用 下面

ZMAN的学习笔记之Python篇:命令行解析

ZMAN的学习笔记之Python篇: 1.装饰器 2.函数“可变长参数” 3.命令行解析 注:本文全原创,作者:ZMAN  (http://www.cnblogs.com/zmanone/) 在Python中,对命令行的解析方式不唯一,本文将介绍两种方法:一种是用sys.argv手动设置,另一种是用argparse模块. 一.sys.argv是什么 首先看一个例子: import sys print(len(sys.argv)) for arg in sys.argv: print(arg) 将

【C++】cmdline —— 轻量级的C++命令行解析库

平时用C++写一些命令行工具,须要解析命令行的输入參数,这是一项繁琐而且easy出错的工作,我们不应该将主要精力放在这上面.能够考虑使用开源的库.以下的cmdline就是当中很好用的一款. cmdline介绍 cmdline 是一个非常easy好用的C++命令行解析库,其基于模板.所以使用非常easy,写出的代码也非常优雅. 因为其仅仅包括一个头文件.所以非常easy集成到自己的项目中. cmdline项目托管地址Github:https://github.com/tanakh/cmdline

docker命令行解析以及如何向服务器端发送请求

最近在看doccker的源码,最新的master分支(估计是1.12.4,因为最新的release是1.12.3)命令行解析全部都使用了第3方的包https://github.com/spf13/cobra.然后看了一下别的分支的代码,感觉结构确实清晰了很多,可读性变高了不少.先看一下如何去使用. 客户端main()在docker/docker/cmd/docker下,可以直接使用go build编译(把vendor下的依赖包移出来就可以了). L20-58: func newDockerCom

python之命令行解析工具argparse

以前写python的时候都会自己在文件开头写一个usgae函数,用来加上各种注释,给用这个脚本的人提供帮助文档. 今天才知道原来python已经有一个自带的命令行解析工具argparse,用了一下,效果还不错. argparse的官方文档请看 https://docs.python.org/2/howto/argparse.html#id1 from argparse import ArgumentParser p = ArgumentParser(usage='it is usage tip'

转:python命令行解析工具Argparse

转自:http://www.cnblogs.com/jianboqi/archive/2013/01/10/2854726.html 最近在研究pathon的命令行解析工具,argparse,它是Python标准库中推荐使用的编写命令行程序的工具. 以前老是做UI程序,今天试了下命令行程序,感觉相当好,不用再花大把时间去研究界面问题,尤其是vc++中尤其繁琐. 现在用python来实现命令行,核心计算模块可以用c自己写扩展库,效果挺好. 学习了argparse,在官方文档中找到一篇toturia

使用命令行解析php文件

使用命令行解析php文件,这样可以调用Log4PHP库中的一些demo,因为默认的输出使用命令行作为输出. 建一个bat文件: echo 以下是使用命令行解析php文件 C:\xampp\php\php.exe C:\xampp\htdocs\JsonDemo.php pause 直接执行即可.

【C++】cmdline——轻量级的C++命令行解析库

1.说明 cmdline是一个轻量级的c++命令行参数解析工具,全部源码只有一个cmdline.h头文件. 2.代码 20171210_命令行进行解析.cpp // 20171210_命令行进行解析.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "cmdline.h" #include <iostream> using std::cout; using std::string; using st