當前位置: 首頁>>代碼示例>>Java>>正文


Java UserGroupInformation.addCredentials方法代碼示例

本文整理匯總了Java中org.apache.hadoop.security.UserGroupInformation.addCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java UserGroupInformation.addCredentials方法的具體用法?Java UserGroupInformation.addCredentials怎麽用?Java UserGroupInformation.addCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.security.UserGroupInformation的用法示例。


在下文中一共展示了UserGroupInformation.addCredentials方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.hadoop.security.UserGroupInformation; //導入方法依賴的package包/類
public static void main(String[] argv)  {
  LOG.info("Starting Parameter Server");
  int serverIndex = Integer.valueOf(System.getenv(AngelEnvironment.PARAMETERSERVER_ID.name()));
  String appMasterHost = System.getenv(AngelEnvironment.LISTEN_ADDR.name());
  int appMasterPort = Integer.valueOf(System.getenv(AngelEnvironment.LISTEN_PORT.name()));

  int attemptIndex = Integer.valueOf(System.getenv(AngelEnvironment.PS_ATTEMPT_ID.name()));

  Configuration conf = new Configuration();
  conf.addResource(AngelConf.ANGEL_JOB_CONF_FILE);

  String user = System.getenv(ApplicationConstants.Environment.USER.name());
  UserGroupInformation.setConfiguration(conf);
  
  String runningMode = conf.get(AngelConf.ANGEL_RUNNING_MODE,
      AngelConf.DEFAULT_ANGEL_RUNNING_MODE);
  if(runningMode.equals(RunningMode.ANGEL_PS_WORKER.toString())){
    LOG.debug("AngelEnvironment.TASK_NUMBER.name()=" + AngelEnvironment.TASK_NUMBER.name());
    conf.set(AngelConf.ANGEL_TASK_ACTUAL_NUM,
        System.getenv(AngelEnvironment.TASK_NUMBER.name()));
  }

  final ParameterServer psServer =
      new ParameterServer(serverIndex, attemptIndex, appMasterHost, appMasterPort, conf);

  try{
    Credentials credentials =
      UserGroupInformation.getCurrentUser().getCredentials();
    UserGroupInformation psUGI = UserGroupInformation.createRemoteUser(System
      .getenv(ApplicationConstants.Environment.USER.toString()));
    // Add tokens to new user so that it may execute its task correctly.
    psUGI.addCredentials(credentials);

    psUGI.doAs(new PrivilegedExceptionAction<Object>() {
      @Override
      public Object run() throws Exception {
        psServer.initialize();
        psServer.start();
        return null;
      }
    });
  } catch (Throwable x) {
    LOG.fatal("Start PS failed ", x);
    psServer.failed(x.getMessage());
  }
  LOG.info("Starting Parameter Server successfully.");
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:48,代碼來源:ParameterServer.java


注:本文中的org.apache.hadoop.security.UserGroupInformation.addCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。