org.apache.hadoop.mapreduce.v2.api.HSClientProtocol#org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier源码实例Demo

下面列出了org.apache.hadoop.mapreduce.v2.api.HSClientProtocol#org.apache.hadoop.mapreduce.security.token.delegation.DelegationTokenIdentifier 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: incubator-gobblin   文件: TokenUtils.java
private static void getJtToken(Credentials cred) throws IOException {
  try {
    JobConf jobConf = new JobConf();
    JobClient jobClient = new JobClient(jobConf);
    LOG.info("Pre-fetching JT token from JobTracker");

    Token<DelegationTokenIdentifier> mrdt = jobClient.getDelegationToken(getMRTokenRenewerInternal(jobConf));
    if (mrdt == null) {
      LOG.error("Failed to fetch JT token");
      throw new IOException("Failed to fetch JT token.");
    }
    LOG.info("Created JT token: " + mrdt.toString());
    LOG.info("Token kind: " + mrdt.getKind());
    LOG.info("Token id: " + Arrays.toString(mrdt.getIdentifier()));
    LOG.info("Token service: " + mrdt.getService());
    cred.addToken(mrdt.getService(), mrdt);
  } catch (InterruptedException ie) {
    throw new IOException(ie);
  }
}
 
private void cancelMRJobTrackerToken(
    final Token<? extends TokenIdentifier> t, String userToProxy)
    throws HadoopSecurityManagerException {
  try {
    getProxiedUser(userToProxy).doAs(new PrivilegedExceptionAction<Void>() {
      @SuppressWarnings("unchecked")
      @Override
      public Void run() throws Exception {
        cancelToken((Token<DelegationTokenIdentifier>) t);
        return null;
      }

      private void cancelToken(Token<DelegationTokenIdentifier> jt)
          throws IOException, InterruptedException {
        JobConf jc = new JobConf(conf);
        JobClient jobClient = new JobClient(jc);
        jobClient.cancelDelegationToken(jt);
      }
    });
  } catch (Exception e) {
    throw new HadoopSecurityManagerException("Failed to cancel token. "
        + e.getMessage() + e.getCause(), e);
  }
}
 
private void cancelMRJobTrackerToken(
    final Token<? extends TokenIdentifier> t, String userToProxy)
    throws HadoopSecurityManagerException {
  try {
    getProxiedUser(userToProxy).doAs(new PrivilegedExceptionAction<Void>() {
      @SuppressWarnings("unchecked")
      @Override
      public Void run() throws Exception {
        cancelToken((Token<DelegationTokenIdentifier>) t);
        return null;
      }

      private void cancelToken(Token<DelegationTokenIdentifier> jt)
          throws IOException, InterruptedException {
        JobConf jc = new JobConf(conf);
        JobClient jobClient = new JobClient(jc);
        jobClient.cancelDelegationToken(jt);
      }
    });
  } catch (Exception e) {
    e.printStackTrace();
    throw new HadoopSecurityManagerException("Failed to cancel Token. "
        + e.getMessage() + e.getCause());
  }
}
 
源代码4 项目: hadoop   文件: YARNRunner.java
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
    throws IOException, InterruptedException {
  // The token is only used for serialization. So the type information
  // mismatch should be fine.
  return resMgrDelegate.getDelegationToken(renewer);
}
 
源代码5 项目: hadoop   文件: JobClient.java
/**
 * Get a delegation token for the user from the JobTracker.
 * @param renewer the user who can renew the token
 * @return the new token
 * @throws IOException
 */
public Token<DelegationTokenIdentifier> 
  getDelegationToken(final Text renewer) throws IOException, InterruptedException {
  return clientUgi.doAs(new 
      PrivilegedExceptionAction<Token<DelegationTokenIdentifier>>() {
    public Token<DelegationTokenIdentifier> run() throws IOException, 
    InterruptedException {
      return cluster.getDelegationToken(renewer);
    }
  });
}
 
源代码6 项目: big-c   文件: YARNRunner.java
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
    throws IOException, InterruptedException {
  // The token is only used for serialization. So the type information
  // mismatch should be fine.
  return resMgrDelegate.getDelegationToken(renewer);
}
 
源代码7 项目: big-c   文件: JobClient.java
/**
 * Get a delegation token for the user from the JobTracker.
 * @param renewer the user who can renew the token
 * @return the new token
 * @throws IOException
 */
public Token<DelegationTokenIdentifier> 
  getDelegationToken(final Text renewer) throws IOException, InterruptedException {
  return clientUgi.doAs(new 
      PrivilegedExceptionAction<Token<DelegationTokenIdentifier>>() {
    public Token<DelegationTokenIdentifier> run() throws IOException, 
    InterruptedException {
      return cluster.getDelegationToken(renewer);
    }
  });
}
 
源代码8 项目: incubator-gobblin   文件: TokenUtils.java
/**
 * function to fetch hcat token as per the specified hive configuration and then store the token
 * in to the credential store specified .
 *
 * @param userToProxy String value indicating the name of the user the token will be fetched for.
 * @param hiveConf the configuration based off which the hive client will be initialized.
 */
private static Token<DelegationTokenIdentifier> fetchHcatToken(final String userToProxy, final HiveConf hiveConf,
    final String tokenSignatureOverwrite, final IMetaStoreClient hiveClient)
    throws IOException, TException, InterruptedException {

  LOG.info(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname + ": " + hiveConf.get(
      HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname));

  LOG.info(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname + ": " + hiveConf.get(
      HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname));

  final Token<DelegationTokenIdentifier> hcatToken = new Token<>();

  hcatToken.decodeFromUrlString(
      hiveClient.getDelegationToken(userToProxy, UserGroupInformation.getLoginUser().getShortUserName()));

  // overwrite the value of the service property of the token if the signature
  // override is specified.
  // If the service field is set, do not overwrite that
  if (hcatToken.getService().getLength() <= 0 && tokenSignatureOverwrite != null
      && tokenSignatureOverwrite.trim().length() > 0) {
    hcatToken.setService(new Text(tokenSignatureOverwrite.trim().toLowerCase()));

    LOG.info(HIVE_TOKEN_SIGNATURE_KEY + ":" + tokenSignatureOverwrite);
  }

  LOG.info("Created hive metastore token for user:" + userToProxy + " with kind[" + hcatToken.getKind() + "]"
      + " and service[" + hcatToken.getService() + "]");
  return hcatToken;
}
 
/**
 * function to fetch hcat token as per the specified hive configuration and
 * then store the token in to the credential store specified .
 *
 * @param userToProxy String value indicating the name of the user the token
 *          will be fetched for.
 * @param hiveConf the configuration based off which the hive client will be
 *          initialized.
 * @param logger the logger instance which writes the logging content to the
 *          job logs.
 *
 * @throws IOException
 * @throws TException
 * @throws MetaException
 *
 * */
private Token<DelegationTokenIdentifier> fetchHcatToken(String userToProxy,
    HiveConf hiveConf, String tokenSignatureOverwrite, final Logger logger)
    throws IOException, MetaException, TException {

  logger.info(HiveConf.ConfVars.METASTOREURIS.varname + ": "
      + hiveConf.get(HiveConf.ConfVars.METASTOREURIS.varname));

  logger.info(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname + ": "
      + hiveConf.get(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL.varname));

  logger.info(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname + ": "
      + hiveConf.get(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL.varname));

  HiveMetaStoreClient hiveClient = new HiveMetaStoreClient(hiveConf);
  String hcatTokenStr =
      hiveClient.getDelegationToken(userToProxy, UserGroupInformation
          .getLoginUser().getShortUserName());
  Token<DelegationTokenIdentifier> hcatToken =
      new Token<DelegationTokenIdentifier>();
  hcatToken.decodeFromUrlString(hcatTokenStr);

  // overwrite the value of the service property of the token if the signature
  // override is specified.
  if (tokenSignatureOverwrite != null
      && tokenSignatureOverwrite.trim().length() > 0) {
    hcatToken.setService(new Text(tokenSignatureOverwrite.trim()
        .toLowerCase()));

    logger.info(HIVE_TOKEN_SIGNATURE_KEY + ":"
        + (tokenSignatureOverwrite == null ? "" : tokenSignatureOverwrite));
  }

  logger.info("Created hive metastore token: " + hcatTokenStr);
  logger.info("Token kind: " + hcatToken.getKind());
  logger.info("Token id: " + hcatToken.getIdentifier());
  logger.info("Token service: " + hcatToken.getService());
  return hcatToken;
}
 
源代码10 项目: incubator-tez   文件: YARNRunner.java
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
    throws IOException, InterruptedException {
  // The token is only used for serialization. So the type information
  // mismatch should be fine.
  return resMgrDelegate.getDelegationToken(renewer);
}
 
源代码11 项目: tez   文件: YARNRunner.java
@Override
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
    throws IOException, InterruptedException {
  // The token is only used for serialization. So the type information
  // mismatch should be fine.
  return resMgrDelegate.getDelegationToken(renewer);
}
 
源代码12 项目: hadoop   文件: YARNRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码13 项目: hadoop   文件: YARNRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码14 项目: hadoop   文件: LocalJobRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token
                                     ) throws IOException,
                                              InterruptedException {
}
 
源代码15 项目: hadoop   文件: LocalJobRunner.java
@Override
public Token<DelegationTokenIdentifier> 
   getDelegationToken(Text renewer) throws IOException, InterruptedException {
  return null;
}
 
源代码16 项目: hadoop   文件: LocalJobRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> token
                                    ) throws IOException,InterruptedException{
  return 0;
}
 
源代码17 项目: big-c   文件: YARNRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码18 项目: big-c   文件: YARNRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码19 项目: big-c   文件: LocalJobRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token
                                     ) throws IOException,
                                              InterruptedException {
}
 
源代码20 项目: big-c   文件: LocalJobRunner.java
@Override
public Token<DelegationTokenIdentifier> 
   getDelegationToken(Text renewer) throws IOException, InterruptedException {
  return null;
}
 
源代码21 项目: big-c   文件: LocalJobRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> token
                                    ) throws IOException,InterruptedException{
  return 0;
}
 
源代码22 项目: ignite   文件: HadoopClientProtocol.java
/** {@inheritDoc} */
@Override public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer) throws IOException,
    InterruptedException {
    return null;
}
 
源代码23 项目: ignite   文件: HadoopClientProtocol.java
/** {@inheritDoc} */
@Override public long renewDelegationToken(Token<DelegationTokenIdentifier> token) throws IOException,
    InterruptedException {
    return 0;
}
 
源代码24 项目: ignite   文件: HadoopClientProtocol.java
/** {@inheritDoc} */
@Override public void cancelDelegationToken(Token<DelegationTokenIdentifier> token) throws IOException,
    InterruptedException {
    // No-op.
}
 
源代码25 项目: incubator-tez   文件: YARNRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码26 项目: incubator-tez   文件: YARNRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码27 项目: tez   文件: YARNRunner.java
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码28 项目: tez   文件: YARNRunner.java
@Override
public long renewDelegationToken(Token<DelegationTokenIdentifier> arg0)
    throws IOException, InterruptedException {
  throw new UnsupportedOperationException("Use Token.renew instead");
}
 
源代码29 项目: hadoop   文件: JobClient.java
/**
 * Renew a delegation token
 * @param token the token to renew
 * @return true if the renewal went well
 * @throws InvalidToken
 * @throws IOException
 * @deprecated Use {@link Token#renew} instead
 */
public long renewDelegationToken(Token<DelegationTokenIdentifier> token
                                 ) throws InvalidToken, IOException, 
                                          InterruptedException {
  return token.renew(getConf());
}
 
源代码30 项目: hadoop   文件: JobClient.java
/**
 * Cancel a delegation token from the JobTracker
 * @param token the token to cancel
 * @throws IOException
 * @deprecated Use {@link Token#cancel} instead
 */
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token
                                  ) throws InvalidToken, IOException, 
                                           InterruptedException {
  token.cancel(getConf());
}