类org.apache.hadoop.util.ServletUtil源码实例Demo

下面列出了怎么用org.apache.hadoop.util.ServletUtil的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: HftpFileSystem.java
private void fetchList(String path, boolean recur) throws IOException {
  try {
    XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    HttpURLConnection connection = openConnection(
        "/listPaths" + ServletUtil.encodePath(path),
        "ugi=" + getEncodedUgiParameter() + (recur ? "&recursive=yes" : ""));
    InputStream resp = connection.getInputStream();
    xr.parse(new InputSource(resp));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  }
}
 
源代码2 项目: hadoop   文件: HftpFileSystem.java
private FileChecksum getFileChecksum(String f) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/fileChecksum" + ServletUtil.encodePath(f),
      "ugi=" + getEncodedUgiParameter());
  try {
    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(connection.getInputStream()));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  } finally {
    connection.disconnect();
  }
  return filechecksum;
}
 
源代码3 项目: hadoop   文件: FileChecksumServlets.java
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
  final PrintWriter out = response.getWriter();
  final String path = ServletUtil.getDecodedPath(request, "/getFileChecksum");
  final XMLOutputter xml = new XMLOutputter(out, "UTF-8");
  xml.declaration();

  final ServletContext context = getServletContext();
  final DataNode datanode = (DataNode) context.getAttribute("datanode");
  final Configuration conf = 
    new HdfsConfiguration(datanode.getConf());
  
  try {
    final DFSClient dfs = DatanodeJspHelper.getDFSClient(request, 
        datanode, conf, getUGI(request, conf));
    final MD5MD5CRC32FileChecksum checksum = dfs.getFileChecksum(path, Long.MAX_VALUE);
    MD5MD5CRC32FileChecksum.write(xml, checksum);
  } catch(IOException ioe) {
    writeXml(ioe, path, xml);
  } catch (InterruptedException e) {
    writeXml(e, path, xml);
  }
  xml.endDocument();
}
 
源代码4 项目: hadoop   文件: ListPathsServlet.java
/**
 * Build a map from the query string, setting values and defaults.
 */
protected Map<String,String> buildRoot(HttpServletRequest request,
    XMLOutputter doc) {
  final String path = ServletUtil.getDecodedPath(request, "/listPaths");
  final String exclude = request.getParameter("exclude") != null
    ? request.getParameter("exclude") : "";
  final String filter = request.getParameter("filter") != null
    ? request.getParameter("filter") : ".*";
  final boolean recur = request.getParameter("recursive") != null
    && "yes".equals(request.getParameter("recursive"));

  Map<String, String> root = new HashMap<String, String>();
  root.put("path", path);
  root.put("recursive", recur ? "yes" : "no");
  root.put("filter", filter);
  root.put("exclude", exclude);
  root.put("time", df.get().format(new Date()));
  root.put("version", VersionInfo.getVersion());
  return root;
}
 
源代码5 项目: big-c   文件: HftpFileSystem.java
private void fetchList(String path, boolean recur) throws IOException {
  try {
    XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    HttpURLConnection connection = openConnection(
        "/listPaths" + ServletUtil.encodePath(path),
        "ugi=" + getEncodedUgiParameter() + (recur ? "&recursive=yes" : ""));
    InputStream resp = connection.getInputStream();
    xr.parse(new InputSource(resp));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  }
}
 
源代码6 项目: big-c   文件: HftpFileSystem.java
private FileChecksum getFileChecksum(String f) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/fileChecksum" + ServletUtil.encodePath(f),
      "ugi=" + getEncodedUgiParameter());
  try {
    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(connection.getInputStream()));
  } catch(SAXException e) {
    final Exception embedded = e.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("invalid xml directory content", e);
  } finally {
    connection.disconnect();
  }
  return filechecksum;
}
 
源代码7 项目: big-c   文件: FileChecksumServlets.java
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
  final PrintWriter out = response.getWriter();
  final String path = ServletUtil.getDecodedPath(request, "/getFileChecksum");
  final XMLOutputter xml = new XMLOutputter(out, "UTF-8");
  xml.declaration();

  final ServletContext context = getServletContext();
  final DataNode datanode = (DataNode) context.getAttribute("datanode");
  final Configuration conf = 
    new HdfsConfiguration(datanode.getConf());
  
  try {
    final DFSClient dfs = DatanodeJspHelper.getDFSClient(request, 
        datanode, conf, getUGI(request, conf));
    final MD5MD5CRC32FileChecksum checksum = dfs.getFileChecksum(path, Long.MAX_VALUE);
    MD5MD5CRC32FileChecksum.write(xml, checksum);
  } catch(IOException ioe) {
    writeXml(ioe, path, xml);
  } catch (InterruptedException e) {
    writeXml(e, path, xml);
  }
  xml.endDocument();
}
 
源代码8 项目: big-c   文件: ListPathsServlet.java
/**
 * Build a map from the query string, setting values and defaults.
 */
protected Map<String,String> buildRoot(HttpServletRequest request,
    XMLOutputter doc) {
  final String path = ServletUtil.getDecodedPath(request, "/listPaths");
  final String exclude = request.getParameter("exclude") != null
    ? request.getParameter("exclude") : "";
  final String filter = request.getParameter("filter") != null
    ? request.getParameter("filter") : ".*";
  final boolean recur = request.getParameter("recursive") != null
    && "yes".equals(request.getParameter("recursive"));

  Map<String, String> root = new HashMap<String, String>();
  root.put("path", path);
  root.put("recursive", recur ? "yes" : "no");
  root.put("filter", filter);
  root.put("exclude", exclude);
  root.put("time", df.get().format(new Date()));
  root.put("version", VersionInfo.getVersion());
  return root;
}
 
源代码9 项目: hadoop   文件: HftpFileSystem.java
/**
 * Get encoded UGI parameter string for a URL.
 *
 * @return user_shortname,group1,group2...
 */
private String getEncodedUgiParameter() {
  StringBuilder ugiParameter = new StringBuilder(
      ServletUtil.encodeQueryValue(ugi.getShortUserName()));
  for(String g: ugi.getGroupNames()) {
    ugiParameter.append(",");
    ugiParameter.append(ServletUtil.encodeQueryValue(g));
  }
  return ugiParameter.toString();
}
 
源代码10 项目: hadoop   文件: HftpFileSystem.java
@Override
public FSDataInputStream open(Path f, int buffersize) throws IOException {
  f = f.makeQualified(getUri(), getWorkingDirectory());
  String path = "/data" + ServletUtil.encodePath(f.toUri().getPath());
  String query = addDelegationTokenParam("ugi=" + getEncodedUgiParameter());
  URL u = getNamenodeURL(path, query);
  return new FSDataInputStream(new RangeHeaderInputStream(connectionFactory, u));
}
 
源代码11 项目: hadoop   文件: HftpFileSystem.java
/**
 * Connect to the name node and get content summary.
 * @param path The path
 * @return The content summary for the path.
 * @throws IOException
 */
private ContentSummary getContentSummary(String path) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/contentSummary" + ServletUtil.encodePath(path),
      "ugi=" + getEncodedUgiParameter());
  InputStream in = null;
  try {
    in = connection.getInputStream();

    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(in));
  } catch(FileNotFoundException fnfe) {
    //the server may not support getContentSummary
    return null;
  } catch(SAXException saxe) {
    final Exception embedded = saxe.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("Invalid xml format", saxe);
  } finally {
    if (in != null) {
      in.close();
    }
    connection.disconnect();
  }
  return contentsummary;
}
 
源代码12 项目: hadoop   文件: FileChecksumServlets.java
/** Create a redirection URL */
private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
    HttpServletRequest request, NameNode nn) 
    throws IOException {
  final String hostname = host instanceof DatanodeInfo 
      ? host.getHostName() : host.getIpAddr();
  final String scheme = request.getScheme();
  int port = host.getInfoPort();
  if ("https".equals(scheme)) {
    final Integer portObject = (Integer) getServletContext().getAttribute(
        DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY);
    if (portObject != null) {
      port = portObject;
    }
  }
  final String encodedPath = ServletUtil.getRawPath(request, "/fileChecksum");

  String dtParam = "";
  if (UserGroupInformation.isSecurityEnabled()) {
    String tokenString = ugi.getTokens().iterator().next().encodeToUrlString();
    dtParam = JspHelper.getDelegationTokenUrlParam(tokenString);
  }
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port, 
      "/getFileChecksum" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + 
      dtParam + addrParam);
}
 
源代码13 项目: hadoop   文件: ImageServlet.java
/**
 * @param request the object from which this servlet reads the url contents
 * @param response the object into which this servlet writes the url contents
 * @throws IOException if the request is bad
 */
public GetImageParams(HttpServletRequest request,
                      HttpServletResponse response
                       ) throws IOException {
  @SuppressWarnings("unchecked")
  Map<String, String[]> pmap = request.getParameterMap();
  isGetImage = isGetEdit = fetchLatest = false;

  for (Map.Entry<String, String[]> entry : pmap.entrySet()) {
    String key = entry.getKey();
    String[] val = entry.getValue();
    if (key.equals("getimage")) { 
      isGetImage = true;
      try {
        txId = ServletUtil.parseLongParam(request, TXID_PARAM);
        String imageType = ServletUtil.getParameter(request, IMAGE_FILE_TYPE);
        nnf = imageType == null ? NameNodeFile.IMAGE : NameNodeFile
            .valueOf(imageType);
      } catch (NumberFormatException nfe) {
        if (request.getParameter(TXID_PARAM).equals(LATEST_FSIMAGE_VALUE)) {
          fetchLatest = true;
        } else {
          throw nfe;
        }
      }
    } else if (key.equals("getedit")) { 
      isGetEdit = true;
      startTxId = ServletUtil.parseLongParam(request, START_TXID_PARAM);
      endTxId = ServletUtil.parseLongParam(request, END_TXID_PARAM);
    } else if (key.equals(STORAGEINFO_PARAM)) {
      storageInfoString = val[0];
    }
  }

  int numGets = (isGetImage?1:0) + (isGetEdit?1:0);
  if ((numGets > 1) || (numGets == 0)) {
    throw new IOException("Illegal parameters to TransferFsImage");
  }
}
 
源代码14 项目: hadoop   文件: ImageServlet.java
public PutImageParams(HttpServletRequest request,
    HttpServletResponse response, Configuration conf) throws IOException {
  txId = ServletUtil.parseLongParam(request, TXID_PARAM);
  storageInfoString = ServletUtil.getParameter(request, STORAGEINFO_PARAM);
  fileSize = ServletUtil.parseLongParam(request,
      TransferFsImage.FILE_LENGTH);
  String imageType = ServletUtil.getParameter(request, IMAGE_FILE_TYPE);
  nnf = imageType == null ? NameNodeFile.IMAGE : NameNodeFile
      .valueOf(imageType);
  if (fileSize == 0 || txId == -1 || storageInfoString == null
      || storageInfoString.isEmpty()) {
    throw new IOException("Illegal parameters to TransferFsImage");
  }
}
 
源代码15 项目: hadoop   文件: FileDataServlet.java
/** Create a redirection URL */
private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, 
    UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt)
    throws IOException {
  String scheme = request.getScheme();
  final LocatedBlocks blks = nnproxy.getBlockLocations(
      status.getFullPath(new Path(path)).toUri().getPath(), 0, 1);
  final Configuration conf = NameNodeHttpServer.getConfFromContext(
      getServletContext());
  final DatanodeID host = pickSrcDatanode(blks, status, conf);
  final String hostname;
  if (host instanceof DatanodeInfo) {
    hostname = host.getHostName();
  } else {
    hostname = host.getIpAddr();
  }

  int port = "https".equals(scheme) ? host.getInfoSecurePort() : host
      .getInfoPort();

  String dtParam = "";
  if (dt != null) {
    dtParam = JspHelper.getDelegationTokenUrlParam(dt);
  }

  // Add namenode address to the url params
  NameNode nn = NameNodeHttpServer.getNameNodeFromContext(
      getServletContext());
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);
  
  return new URL(scheme, hostname, port,
      "/streamFile" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) +
      dtParam + addrParam);
}
 
源代码16 项目: hadoop   文件: TestHftpFileSystem.java
private void testDataNodeRedirect(Path path) throws IOException {
  // Create the file
  if (hdfs.exists(path)) {
    hdfs.delete(path, true);
  }
  FSDataOutputStream out = hdfs.create(path, (short) 1);
  out.writeBytes("0123456789");
  out.close();

  // Get the path's block location so we can determine
  // if we were redirected to the right DN.
  BlockLocation[] locations = hdfs.getFileBlockLocations(path, 0, 10);
  String xferAddr = locations[0].getNames()[0];

  // Connect to the NN to get redirected
  URL u = hftpFs.getNamenodeURL(
      "/data" + ServletUtil.encodePath(path.toUri().getPath()),
      "ugi=userx,groupy");
  HttpURLConnection conn = (HttpURLConnection) u.openConnection();
  HttpURLConnection.setFollowRedirects(true);
  conn.connect();
  conn.getInputStream();

  boolean checked = false;
  // Find the datanode that has the block according to locations
  // and check that the URL was redirected to this DN's info port
  for (DataNode node : cluster.getDataNodes()) {
    DatanodeRegistration dnR = DataNodeTestUtils.getDNRegistrationForBP(node,
        blockPoolId);
    if (dnR.getXferAddr().equals(xferAddr)) {
      checked = true;
      assertEquals(dnR.getInfoPort(), conn.getURL().getPort());
    }
  }
  assertTrue("The test never checked that location of "
      + "the block and hftp desitnation are the same", checked);
}
 
源代码17 项目: hadoop   文件: LogLevel.java
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {

  // Do the authorization
  if (!HttpServer2.hasAdministratorAccess(getServletContext(), request,
      response)) {
    return;
  }

  PrintWriter out = ServletUtil.initHTML(response, "Log Level");
  String logName = ServletUtil.getParameter(request, "log");
  String level = ServletUtil.getParameter(request, "level");

  if (logName != null) {
    out.println("<br /><hr /><h3>Results</h3>");
    out.println(MARKER
        + "Submitted Log Name: <b>" + logName + "</b><br />");

    Log log = LogFactory.getLog(logName);
    out.println(MARKER
        + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
    if (level != null) {
      out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
    }

    if (log instanceof Log4JLogger) {
      process(((Log4JLogger)log).getLogger(), level, out);
    }
    else if (log instanceof Jdk14Logger) {
      process(((Jdk14Logger)log).getLogger(), level, out);
    }
    else {
      out.println("Sorry, " + log.getClass() + " not supported.<br />");
    }
  }

  out.println(FORMS);
  out.println(ServletUtil.HTML_TAIL);
}
 
源代码18 项目: big-c   文件: HftpFileSystem.java
/**
 * Get encoded UGI parameter string for a URL.
 *
 * @return user_shortname,group1,group2...
 */
private String getEncodedUgiParameter() {
  StringBuilder ugiParameter = new StringBuilder(
      ServletUtil.encodeQueryValue(ugi.getShortUserName()));
  for(String g: ugi.getGroupNames()) {
    ugiParameter.append(",");
    ugiParameter.append(ServletUtil.encodeQueryValue(g));
  }
  return ugiParameter.toString();
}
 
源代码19 项目: big-c   文件: HftpFileSystem.java
@Override
public FSDataInputStream open(Path f, int buffersize) throws IOException {
  f = f.makeQualified(getUri(), getWorkingDirectory());
  String path = "/data" + ServletUtil.encodePath(f.toUri().getPath());
  String query = addDelegationTokenParam("ugi=" + getEncodedUgiParameter());
  URL u = getNamenodeURL(path, query);
  return new FSDataInputStream(new RangeHeaderInputStream(connectionFactory, u));
}
 
源代码20 项目: big-c   文件: HftpFileSystem.java
/**
 * Connect to the name node and get content summary.
 * @param path The path
 * @return The content summary for the path.
 * @throws IOException
 */
private ContentSummary getContentSummary(String path) throws IOException {
  final HttpURLConnection connection = openConnection(
      "/contentSummary" + ServletUtil.encodePath(path),
      "ugi=" + getEncodedUgiParameter());
  InputStream in = null;
  try {
    in = connection.getInputStream();

    final XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(this);
    xr.parse(new InputSource(in));
  } catch(FileNotFoundException fnfe) {
    //the server may not support getContentSummary
    return null;
  } catch(SAXException saxe) {
    final Exception embedded = saxe.getException();
    if (embedded != null && embedded instanceof IOException) {
      throw (IOException)embedded;
    }
    throw new IOException("Invalid xml format", saxe);
  } finally {
    if (in != null) {
      in.close();
    }
    connection.disconnect();
  }
  return contentsummary;
}
 
源代码21 项目: big-c   文件: FileChecksumServlets.java
/** Create a redirection URL */
private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
    HttpServletRequest request, NameNode nn) 
    throws IOException {
  final String hostname = host instanceof DatanodeInfo 
      ? host.getHostName() : host.getIpAddr();
  final String scheme = request.getScheme();
  int port = host.getInfoPort();
  if ("https".equals(scheme)) {
    final Integer portObject = (Integer) getServletContext().getAttribute(
        DFSConfigKeys.DFS_DATANODE_HTTPS_PORT_KEY);
    if (portObject != null) {
      port = portObject;
    }
  }
  final String encodedPath = ServletUtil.getRawPath(request, "/fileChecksum");

  String dtParam = "";
  if (UserGroupInformation.isSecurityEnabled()) {
    String tokenString = ugi.getTokens().iterator().next().encodeToUrlString();
    dtParam = JspHelper.getDelegationTokenUrlParam(tokenString);
  }
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);

  return new URL(scheme, hostname, port, 
      "/getFileChecksum" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) + 
      dtParam + addrParam);
}
 
源代码22 项目: big-c   文件: ImageServlet.java
/**
 * @param request the object from which this servlet reads the url contents
 * @param response the object into which this servlet writes the url contents
 * @throws IOException if the request is bad
 */
public GetImageParams(HttpServletRequest request,
                      HttpServletResponse response
                       ) throws IOException {
  @SuppressWarnings("unchecked")
  Map<String, String[]> pmap = request.getParameterMap();
  isGetImage = isGetEdit = fetchLatest = false;

  for (Map.Entry<String, String[]> entry : pmap.entrySet()) {
    String key = entry.getKey();
    String[] val = entry.getValue();
    if (key.equals("getimage")) { 
      isGetImage = true;
      try {
        txId = ServletUtil.parseLongParam(request, TXID_PARAM);
        String imageType = ServletUtil.getParameter(request, IMAGE_FILE_TYPE);
        nnf = imageType == null ? NameNodeFile.IMAGE : NameNodeFile
            .valueOf(imageType);
      } catch (NumberFormatException nfe) {
        if (request.getParameter(TXID_PARAM).equals(LATEST_FSIMAGE_VALUE)) {
          fetchLatest = true;
        } else {
          throw nfe;
        }
      }
    } else if (key.equals("getedit")) { 
      isGetEdit = true;
      startTxId = ServletUtil.parseLongParam(request, START_TXID_PARAM);
      endTxId = ServletUtil.parseLongParam(request, END_TXID_PARAM);
    } else if (key.equals(STORAGEINFO_PARAM)) {
      storageInfoString = val[0];
    }
  }

  int numGets = (isGetImage?1:0) + (isGetEdit?1:0);
  if ((numGets > 1) || (numGets == 0)) {
    throw new IOException("Illegal parameters to TransferFsImage");
  }
}
 
源代码23 项目: big-c   文件: ImageServlet.java
public PutImageParams(HttpServletRequest request,
    HttpServletResponse response, Configuration conf) throws IOException {
  txId = ServletUtil.parseLongParam(request, TXID_PARAM);
  storageInfoString = ServletUtil.getParameter(request, STORAGEINFO_PARAM);
  fileSize = ServletUtil.parseLongParam(request,
      TransferFsImage.FILE_LENGTH);
  String imageType = ServletUtil.getParameter(request, IMAGE_FILE_TYPE);
  nnf = imageType == null ? NameNodeFile.IMAGE : NameNodeFile
      .valueOf(imageType);
  if (fileSize == 0 || txId == -1 || storageInfoString == null
      || storageInfoString.isEmpty()) {
    throw new IOException("Illegal parameters to TransferFsImage");
  }
}
 
源代码24 项目: big-c   文件: FileDataServlet.java
/** Create a redirection URL */
private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, 
    UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt)
    throws IOException {
  String scheme = request.getScheme();
  final LocatedBlocks blks = nnproxy.getBlockLocations(
      status.getFullPath(new Path(path)).toUri().getPath(), 0, 1);
  final Configuration conf = NameNodeHttpServer.getConfFromContext(
      getServletContext());
  final DatanodeID host = pickSrcDatanode(blks, status, conf);
  final String hostname;
  if (host instanceof DatanodeInfo) {
    hostname = host.getHostName();
  } else {
    hostname = host.getIpAddr();
  }

  int port = "https".equals(scheme) ? host.getInfoSecurePort() : host
      .getInfoPort();

  String dtParam = "";
  if (dt != null) {
    dtParam = JspHelper.getDelegationTokenUrlParam(dt);
  }

  // Add namenode address to the url params
  NameNode nn = NameNodeHttpServer.getNameNodeFromContext(
      getServletContext());
  String addr = nn.getNameNodeAddressHostPortString();
  String addrParam = JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, addr);
  
  return new URL(scheme, hostname, port,
      "/streamFile" + encodedPath + '?' +
      "ugi=" + ServletUtil.encodeQueryValue(ugi.getShortUserName()) +
      dtParam + addrParam);
}
 
源代码25 项目: big-c   文件: TestHftpFileSystem.java
private void testDataNodeRedirect(Path path) throws IOException {
  // Create the file
  if (hdfs.exists(path)) {
    hdfs.delete(path, true);
  }
  FSDataOutputStream out = hdfs.create(path, (short) 1);
  out.writeBytes("0123456789");
  out.close();

  // Get the path's block location so we can determine
  // if we were redirected to the right DN.
  BlockLocation[] locations = hdfs.getFileBlockLocations(path, 0, 10);
  String xferAddr = locations[0].getNames()[0];

  // Connect to the NN to get redirected
  URL u = hftpFs.getNamenodeURL(
      "/data" + ServletUtil.encodePath(path.toUri().getPath()),
      "ugi=userx,groupy");
  HttpURLConnection conn = (HttpURLConnection) u.openConnection();
  HttpURLConnection.setFollowRedirects(true);
  conn.connect();
  conn.getInputStream();

  boolean checked = false;
  // Find the datanode that has the block according to locations
  // and check that the URL was redirected to this DN's info port
  for (DataNode node : cluster.getDataNodes()) {
    DatanodeRegistration dnR = DataNodeTestUtils.getDNRegistrationForBP(node,
        blockPoolId);
    if (dnR.getXferAddr().equals(xferAddr)) {
      checked = true;
      assertEquals(dnR.getInfoPort(), conn.getURL().getPort());
    }
  }
  assertTrue("The test never checked that location of "
      + "the block and hftp desitnation are the same", checked);
}
 
源代码26 项目: big-c   文件: LogLevel.java
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {

  // Do the authorization
  if (!HttpServer2.hasAdministratorAccess(getServletContext(), request,
      response)) {
    return;
  }

  PrintWriter out = ServletUtil.initHTML(response, "Log Level");
  String logName = ServletUtil.getParameter(request, "log");
  String level = ServletUtil.getParameter(request, "level");

  if (logName != null) {
    out.println("<br /><hr /><h3>Results</h3>");
    out.println(MARKER
        + "Submitted Log Name: <b>" + logName + "</b><br />");

    Log log = LogFactory.getLog(logName);
    out.println(MARKER
        + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
    if (level != null) {
      out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
    }

    if (log instanceof Log4JLogger) {
      process(((Log4JLogger)log).getLogger(), level, out);
    }
    else if (log instanceof Jdk14Logger) {
      process(((Jdk14Logger)log).getLogger(), level, out);
    }
    else {
      out.println("Sorry, " + log.getClass() + " not supported.<br />");
    }
  }

  out.println(FORMS);
  out.println(ServletUtil.HTML_TAIL);
}
 
源代码27 项目: RDFS   文件: LogLevel.java
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
  PrintWriter out = ServletUtil.initHTML(response, "Log Level");
  String logName = ServletUtil.getParameter(request, "log");
  String level = ServletUtil.getParameter(request, "level");

  if (logName != null) {
    out.println("<br /><hr /><h3>Results</h3>");
    out.println(MARKER
        + "Submitted Log Name: <b>" + logName + "</b><br />");

    Log log = LogFactory.getLog(logName);
    out.println(MARKER
        + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
    if (level != null) {
      out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
    }

    if (log instanceof Log4JLogger) {
      process(((Log4JLogger)log).getLogger(), level, out);
    }
    else if (log instanceof Jdk14Logger) {
      process(((Jdk14Logger)log).getLogger(), level, out);
    }
    else {
      out.println("Sorry, " + log.getClass() + " not supported.<br />");
    }
  }

  out.println(FORMS);
  out.println(ServletUtil.HTML_TAIL);
}
 
源代码28 项目: hadoop-gpu   文件: LogLevel.java
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws ServletException, IOException {
  PrintWriter out = ServletUtil.initHTML(response, "Log Level");
  String logName = ServletUtil.getParameter(request, "log");
  String level = ServletUtil.getParameter(request, "level");

  if (logName != null) {
    out.println("<br /><hr /><h3>Results</h3>");
    out.println(MARKER
        + "Submitted Log Name: <b>" + logName + "</b><br />");

    Log log = LogFactory.getLog(logName);
    out.println(MARKER
        + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
    if (level != null) {
      out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
    }

    if (log instanceof Log4JLogger) {
      process(((Log4JLogger)log).getLogger(), level, out);
    }
    else if (log instanceof Jdk14Logger) {
      process(((Jdk14Logger)log).getLogger(), level, out);
    }
    else {
      out.println("Sorry, " + log.getClass() + " not supported.<br />");
    }
  }

  out.println(FORMS);
  out.println(ServletUtil.HTML_TAIL);
}
 
源代码29 项目: hadoop   文件: ContentSummaryServlet.java
@Override
public void doGet(final HttpServletRequest request,
    final HttpServletResponse response) throws ServletException, IOException {
  final Configuration conf = 
    (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
  final UserGroupInformation ugi = getUGI(request, conf);
  try {
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        final String path = ServletUtil.getDecodedPath(request, "/contentSummary");
        final PrintWriter out = response.getWriter();
        final XMLOutputter xml = new XMLOutputter(out, "UTF-8");
        xml.declaration();
        try {
          //get content summary
          final ClientProtocol nnproxy = createNameNodeProxy();
          final ContentSummary cs = nnproxy.getContentSummary(path);

          //write xml
          xml.startTag(ContentSummary.class.getName());
          if (cs != null) {
            xml.attribute("length"        , "" + cs.getLength());
            xml.attribute("fileCount"     , "" + cs.getFileCount());
            xml.attribute("directoryCount", "" + cs.getDirectoryCount());
            xml.attribute("quota"         , "" + cs.getQuota());
            xml.attribute("spaceConsumed" , "" + cs.getSpaceConsumed());
            xml.attribute("spaceQuota"    , "" + cs.getSpaceQuota());
          }
          xml.endTag();
        } catch(IOException ioe) {
          writeXml(ioe, path, xml);
        }
        xml.endDocument();
        return null;
      }
    });
  } catch (InterruptedException e) {
    throw new IOException(e);
  }
}
 
源代码30 项目: big-c   文件: ContentSummaryServlet.java
@Override
public void doGet(final HttpServletRequest request,
    final HttpServletResponse response) throws ServletException, IOException {
  final Configuration conf = 
    (Configuration) getServletContext().getAttribute(JspHelper.CURRENT_CONF);
  final UserGroupInformation ugi = getUGI(request, conf);
  try {
    ugi.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        final String path = ServletUtil.getDecodedPath(request, "/contentSummary");
        final PrintWriter out = response.getWriter();
        final XMLOutputter xml = new XMLOutputter(out, "UTF-8");
        xml.declaration();
        try {
          //get content summary
          final ClientProtocol nnproxy = createNameNodeProxy();
          final ContentSummary cs = nnproxy.getContentSummary(path);

          //write xml
          xml.startTag(ContentSummary.class.getName());
          if (cs != null) {
            xml.attribute("length"        , "" + cs.getLength());
            xml.attribute("fileCount"     , "" + cs.getFileCount());
            xml.attribute("directoryCount", "" + cs.getDirectoryCount());
            xml.attribute("quota"         , "" + cs.getQuota());
            xml.attribute("spaceConsumed" , "" + cs.getSpaceConsumed());
            xml.attribute("spaceQuota"    , "" + cs.getSpaceQuota());
          }
          xml.endTag();
        } catch(IOException ioe) {
          writeXml(ioe, path, xml);
        }
        xml.endDocument();
        return null;
      }
    });
  } catch (InterruptedException e) {
    throw new IOException(e);
  }
}
 
 类所在包
 类方法
 同包方法