Java 类org.apache.hadoop.hdfs.server.namenode.RenewDelegationTokenServlet 实例源码

项目:big-c    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 * @throws AuthenticationException
 */
static public long renewDelegationToken(URLConnectionFactory factory,
    URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException,
    AuthenticationException {
  StringBuilder buf = new StringBuilder(nnAddr.toString())
      .append(RenewDelegationTokenServlet.PATH_SPEC).append("?")
      .append(RenewDelegationTokenServlet.TOKEN).append("=")
      .append(tok.encodeToUrlString());

  HttpURLConnection connection = null;
  BufferedReader in = null;
  try {
    connection = run(factory, new URL(buf.toString()));
    in = new BufferedReader(new InputStreamReader(
        connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    if (e != null) {
      LOG.info("rethrowing exception from HTTP request: "
          + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  } finally {
    IOUtils.cleanup(LOG, in);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 * @throws AuthenticationException
 */
static public long renewDelegationToken(URLConnectionFactory factory,
    URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException,
    AuthenticationException {
  StringBuilder buf = new StringBuilder(nnAddr.toString())
      .append(RenewDelegationTokenServlet.PATH_SPEC).append("?")
      .append(RenewDelegationTokenServlet.TOKEN).append("=")
      .append(tok.encodeToUrlString());

  HttpURLConnection connection = null;
  BufferedReader in = null;
  try {
    connection = run(factory, new URL(buf.toString()));
    in = new BufferedReader(new InputStreamReader(
        connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    if (e != null) {
      LOG.info("rethrowing exception from HTTP request: "
          + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  } finally {
    IOUtils.cleanup(LOG, in);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
项目:hadoop-plus    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
    Token<DelegationTokenIdentifier> tok
) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;

  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
      throw new IOException("Error renewing token: " + 
          connection.getResponseMessage());
    }
    in = new BufferedReader(
        new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + 
               e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:FlexMap    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 * @throws AuthenticationException
 */
static public long renewDelegationToken(URLConnectionFactory factory,
    URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException,
    AuthenticationException {
  StringBuilder buf = new StringBuilder(nnAddr.toString())
      .append(RenewDelegationTokenServlet.PATH_SPEC).append("?")
      .append(RenewDelegationTokenServlet.TOKEN).append("=")
      .append(tok.encodeToUrlString());

  HttpURLConnection connection = null;
  BufferedReader in = null;
  try {
    connection = run(factory, new URL(buf.toString()));
    in = new BufferedReader(new InputStreamReader(
        connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    if (e != null) {
      LOG.info("rethrowing exception from HTTP request: "
          + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  } finally {
    IOUtils.cleanup(LOG, in);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
项目:hops    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 *
 * @param nnAddr
 *     the NameNode's address
 * @param tok
 *     the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
    Token<DelegationTokenIdentifier> tok) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;

  try {
    URL url = new URL(buf.toString());
    connection =
        (HttpURLConnection) SecurityUtil2.openSecureHttpConnection(url);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
      throw new IOException(
          "Error renewing token: " + connection.getResponseMessage());
    }
    in = new BufferedReader(
        new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    IOUtils.cleanup(LOG, in);
    if (e != null) {
      LOG.info("rethrowing exception from HTTP request: " +
          e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:hadoop-TCP    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
    Token<DelegationTokenIdentifier> tok
) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;

  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
      throw new IOException("Error renewing token: " + 
          connection.getResponseMessage());
    }
    in = new BufferedReader(
        new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + 
               e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:hadoop-on-lustre    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
                                        Token<DelegationTokenIdentifier> tok
                                        ) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;
  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    in = new BufferedReader(new InputStreamReader
                            (connection.getInputStream()));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = null;
    if(connection != null) {
      String resp = connection.getResponseMessage();
      e = getExceptionFromResponse(resp);
    }

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:hardfs    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
    Token<DelegationTokenIdentifier> tok
) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;

  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
      throw new IOException("Error renewing token: " + 
          connection.getResponseMessage());
    }
    in = new BufferedReader(
        new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + 
               e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:hadoop-on-lustre2    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 * @throws AuthenticationException
 */
static public long renewDelegationToken(URLConnectionFactory factory,
    URI nnAddr, Token<DelegationTokenIdentifier> tok) throws IOException,
    AuthenticationException {
  StringBuilder buf = new StringBuilder(nnAddr.toString())
      .append(RenewDelegationTokenServlet.PATH_SPEC).append("?")
      .append(RenewDelegationTokenServlet.TOKEN).append("=")
      .append(tok.encodeToUrlString());

  HttpURLConnection connection = null;
  BufferedReader in = null;
  try {
    connection = run(factory, new URL(buf.toString()));
    in = new BufferedReader(new InputStreamReader(
        connection.getInputStream(), Charsets.UTF_8));
    long result = Long.parseLong(in.readLine());
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = getExceptionFromResponse(connection);

    if (e != null) {
      LOG.info("rethrowing exception from HTTP request: "
          + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  } finally {
    IOUtils.cleanup(LOG, in);
    if (connection != null) {
      connection.disconnect();
    }
  }
}
项目:cumulus    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
    Token<DelegationTokenIdentifier> tok
) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  try {
    URL url = new URL(buf.toString());
    SecurityUtil.fetchServiceTicket(url);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
      throw new IOException("Error renewing token: " + 
          connection.getResponseMessage());
    }
    in = new BufferedReader(new InputStreamReader
        (connection.getInputStream()));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    IOUtils.cleanup(LOG, in);
    throw ie;
  }
}
项目:hortonworks-extension    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
                                        Token<DelegationTokenIdentifier> tok
                                        ) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;
  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    in = new BufferedReader(new InputStreamReader
                            (connection.getInputStream()));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = null;
    if(connection != null) {
      String resp = connection.getResponseMessage();
      e = getExceptionFromResponse(resp);
    }

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}
项目:hortonworks-extension    文件:DelegationTokenFetcher.java   
/**
 * Renew a Delegation Token.
 * @param nnAddr the NameNode's address
 * @param tok the token to renew
 * @return the Date that the token will expire next.
 * @throws IOException
 */
static public long renewDelegationToken(String nnAddr,
                                        Token<DelegationTokenIdentifier> tok
                                        ) throws IOException {
  StringBuilder buf = new StringBuilder();
  buf.append(nnAddr);
  buf.append(RenewDelegationTokenServlet.PATH_SPEC);
  buf.append("?");
  buf.append(RenewDelegationTokenServlet.TOKEN);
  buf.append("=");
  buf.append(tok.encodeToUrlString());
  BufferedReader in = null;
  HttpURLConnection connection = null;
  try {
    URL url = new URL(buf.toString());
    connection = (HttpURLConnection) SecurityUtil.openSecureHttpConnection(url);
    in = new BufferedReader(new InputStreamReader
                            (connection.getInputStream()));
    long result = Long.parseLong(in.readLine());
    in.close();
    return result;
  } catch (IOException ie) {
    LOG.info("error in renew over HTTP", ie);
    IOException e = null;
    if(connection != null) {
      String resp = connection.getResponseMessage();
      e = getExceptionFromResponse(resp);
    }

    IOUtils.cleanup(LOG, in);
    if(e!=null) {
      LOG.info("rethrowing exception from HTTP request: " + e.getLocalizedMessage());
      throw e;
    }
    throw ie;
  }
}