当前位置: 首页>>代码示例>>Java>>正文


Java JspHelper.bestNode方法代码示例

本文整理汇总了Java中org.apache.hadoop.hdfs.server.common.JspHelper.bestNode方法的典型用法代码示例。如果您正苦于以下问题:Java JspHelper.bestNode方法的具体用法?Java JspHelper.bestNode怎么用?Java JspHelper.bestNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hdfs.server.common.JspHelper的用法示例。


在下文中一共展示了JspHelper.bestNode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pickSrcDatanode

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
/** Select a datanode to service this request.
 * Currently, this looks at no more than the first five blocks of a file,
 * selecting a datanode randomly from the most represented.
 * @param conf 
 */
private DatanodeID pickSrcDatanode(LocatedBlocks blks, HdfsFileStatus i,
    Configuration conf) throws IOException {
  if (i.getLen() == 0 || blks.getLocatedBlocks().size() <= 0) {
    // pick a random datanode
    NameNode nn = NameNodeHttpServer.getNameNodeFromContext(
        getServletContext());
    return NamenodeJspHelper.getRandomDatanode(nn);
  }
  return JspHelper.bestNode(blks, conf);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:FileDataServlet.java

示例2: pickSrcDatanode

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
/**
 * Select a datanode to service this request.
 * Currently, this looks at no more than the first five blocks of a file,
 * selecting a datanode randomly from the most represented.
 *
 * @param conf
 */
private DatanodeID pickSrcDatanode(LocatedBlocks blks, HdfsFileStatus i,
    Configuration conf) throws IOException {
  if (i.getLen() == 0 || blks.getLocatedBlocks().size() <= 0) {
    // pick a random datanode
    NameNode nn =
        NameNodeHttpServer.getNameNodeFromContext(getServletContext());
    return NamenodeJspHelper.getRandomDatanode(nn);
  }
  return JspHelper.bestNode(blks, conf);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:18,代码来源:FileDataServlet.java

示例3: pickSrcDatanode

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
/** Select a datanode to service this request.
 * Currently, this looks at no more than the first five blocks of a file,
 * selecting a datanode randomly from the most represented.
 */
private DatanodeID pickSrcDatanode(String parent, HdfsFileStatus i,
    ClientProtocol nnproxy) throws IOException {
  final LocatedBlocks blks = nnproxy.getBlockLocations(
      i.getFullPath(new Path(parent)).toUri().getPath(), 0, 1);
  if (i.getLen() == 0 || blks.getLocatedBlocks().size() <= 0) {
    // pick a random datanode
    NameNode nn = (NameNode)getServletContext().getAttribute("name.node");
    return nn.getNamesystem().getRandomDatanode();
  }
  return JspHelper.bestNode(blks);
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:16,代码来源:FileDataServlet.java

示例4: generateLinksForAdjacentBlock

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
private static String generateLinksForAdjacentBlock(final int direction,
    String authority, int datanodePort, long startOffset,
    int chunkSizeToView, long blockSize, long blockId, Long genStamp,
    final DFSClient dfs, final String filename, final Configuration conf,
    final String scheme, final String tokenString,
    final int namenodeInfoPort, final String nnAddr)
    throws AccessControlException, FileNotFoundException,
    UnresolvedLinkException, IOException {

  boolean found = false;
  if ((direction == NEXT_BLOCK && startOffset + chunkSizeToView < blockSize)
      || (direction == PREV_BLOCK && startOffset != 0)) {
    // we are in the same block
    found = true;

    if (direction == NEXT_BLOCK) {
      startOffset = startOffset + chunkSizeToView;
    } else {
      startOffset = Math.max(0, startOffset - chunkSizeToView);
    }
  } else {
    List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
        Long.MAX_VALUE).getLocatedBlocks();

    final long curBlockId = blockId;
    int curBlockIdx = Iterables.indexOf(blocks, new Predicate<LocatedBlock>() {
      @Override
      public boolean apply(LocatedBlock b) {
        return b.getBlock().getBlockId() == curBlockId;
      }
    });
    found = curBlockIdx != -1 &&
        ((direction == NEXT_BLOCK && curBlockIdx < blocks.size() - 1)
            || (direction == PREV_BLOCK && curBlockIdx > 0));

    if (found) {
      LocatedBlock nextBlock = blocks.get(curBlockIdx + direction);

      blockId = nextBlock.getBlock().getBlockId();
      genStamp = nextBlock.getBlock().getGenerationStamp();
      startOffset = 0;
      blockSize = nextBlock.getBlock().getNumBytes();
      DatanodeInfo d = JspHelper.bestNode(nextBlock, conf);
      datanodePort = d.getXferPort();
      authority = JspHelper.Url.authority(scheme, d);
    }
  }

  if (found) {
    return "///" + authority
        + "/browseBlock.jsp?blockId=" + blockId
        + "&blockSize=" + blockSize
        + "&startOffset=" + startOffset
        + "&genstamp=" + genStamp
        + "&filename=" + URLEncoder.encode(filename, "UTF-8")
        + "&chunkSizeToView=" + chunkSizeToView
        + "&datanodePort=" + datanodePort
        + "&namenodeInfoPort=" + namenodeInfoPort
        + JspHelper.getDelegationTokenUrlParam(tokenString)
        + JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnAddr);
  } else {
    return null;
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:65,代码来源:DatanodeJspHelper.java

示例5: chooseDatanode

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
static DatanodeInfo chooseDatanode(final NameNode namenode,
    final String path, final HttpOpParam.Op op, final long openOffset,
    final long blocksize, Configuration conf) throws IOException {
  final BlockManager bm = namenode.getNamesystem().getBlockManager();

  if (op == PutOpParam.Op.CREATE) {
    //choose a datanode near to client 
    final DatanodeDescriptor clientNode = bm.getDatanodeManager(
        ).getDatanodeByHost(getRemoteAddress());
    if (clientNode != null) {
      final DatanodeDescriptor[] datanodes = bm.getBlockPlacementPolicy()
          .chooseTarget(path, 1, clientNode,
              new ArrayList<DatanodeDescriptor>(), false, null, blocksize);
      if (datanodes.length > 0) {
        return datanodes[0];
      }
    }
  } else if (op == GetOpParam.Op.OPEN
      || op == GetOpParam.Op.GETFILECHECKSUM
      || op == PostOpParam.Op.APPEND) {
    //choose a datanode containing a replica 
    final NamenodeProtocols np = namenode.getRpcServer();
    final HdfsFileStatus status = np.getFileInfo(path);
    if (status == null) {
      throw new FileNotFoundException("File " + path + " not found.");
    }
    final long len = status.getLen();
    if (op == GetOpParam.Op.OPEN) {
      if (openOffset < 0L || (openOffset >= len && len > 0)) {
        throw new IOException("Offset=" + openOffset
            + " out of the range [0, " + len + "); " + op + ", path=" + path);
      }
    }

    if (len > 0) {
      final long offset = op == GetOpParam.Op.OPEN? openOffset: len - 1;
      final LocatedBlocks locations = np.getBlockLocations(path, offset, 1);
      final int count = locations.locatedBlockCount();
      if (count > 0) {
        return JspHelper.bestNode(locations.get(0).getLocations(), false, conf);
      }
    }
  } 

  return (DatanodeDescriptor)bm.getDatanodeManager().getNetworkTopology(
      ).chooseRandom(NodeBase.ROOT);
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:48,代码来源:NamenodeWebHdfsMethods.java

示例6: chooseDatanode

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
static DatanodeInfo chooseDatanode(final NameNode namenode, final String path,
    final HttpOpParam.Op op, final long openOffset, final long blocksize,
    Configuration conf) throws IOException {
  final BlockManager bm = namenode.getNamesystem().getBlockManager();

  if (op == PutOpParam.Op.CREATE) {
    //choose a datanode near to client 
    final DatanodeDescriptor clientNode =
        bm.getDatanodeManager().getDatanodeByHost(getRemoteAddress());
    if (clientNode != null) {
      final DatanodeDescriptor[] datanodes = bm.getBlockPlacementPolicy()
          .chooseTarget(path, 1, clientNode,
              new ArrayList<DatanodeDescriptor>(), false, null, blocksize);
      if (datanodes.length > 0) {
        return datanodes[0];
      }
    }
  } else if (op == GetOpParam.Op.OPEN ||
      op == GetOpParam.Op.GETFILECHECKSUM || op == PostOpParam.Op.APPEND) {
    //choose a datanode containing a replica 
    final NamenodeProtocols np = namenode.getRpcServer();
    final HdfsFileStatus status = np.getFileInfo(path);
    if (status == null) {
      throw new FileNotFoundException("File " + path + " not found.");
    }
    final long len = status.getLen();
    if (op == GetOpParam.Op.OPEN) {
      if (openOffset < 0L || (openOffset >= len && len > 0)) {
        throw new IOException(
            "Offset=" + openOffset + " out of the range [0, " + len + "); " +
                op + ", path=" + path);
      }
    }

    if (len > 0) {
      final long offset = op == GetOpParam.Op.OPEN ? openOffset : len - 1;
      final LocatedBlocks locations = np.getBlockLocations(path, offset, 1);
      final int count = locations.locatedBlockCount();
      if (count > 0) {
        return JspHelper
            .bestNode(locations.get(0).getLocations(), false, conf);
      }
    }
  }

  return (DatanodeDescriptor) bm.getDatanodeManager().getNetworkTopology()
      .chooseRandom(NodeBase.ROOT);
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:49,代码来源:NamenodeWebHdfsMethods.java

示例7: generateFileChunksForTail

import org.apache.hadoop.hdfs.server.common.JspHelper; //导入方法依赖的package包/类
static void generateFileChunksForTail(JspWriter out, HttpServletRequest req,
                                      Configuration conf
                                      ) throws IOException,
                                               InterruptedException {
  final String referrer = JspHelper.validateURL(req.getParameter("referrer"));
  boolean noLink = false;
  if (referrer == null) {
    noLink = true;
  }

  final String filename = JspHelper
      .validatePath(StringEscapeUtils.unescapeHtml(req.getParameter("filename")));
  if (filename == null) {
    out.print("Invalid input (file name absent)");
    return;
  }
  String tokenString = req.getParameter(JspHelper.DELEGATION_PARAMETER_NAME);
  UserGroupInformation ugi = JspHelper.getUGI(req, conf);

  String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
  int namenodeInfoPort = -1;
  if (namenodeInfoPortStr != null)
    namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);

  final int chunkSizeToView = JspHelper.string2ChunkSizeToView(req
      .getParameter("chunkSizeToView"), getDefaultChunkSize(conf));

  if (!noLink) {
    out.print("<h3>Tail of File: ");
    JspHelper.printPathWithLinks(filename, out, namenodeInfoPort, 
                                 tokenString);
    out.print("</h3><hr>");
    out.print("<a href=\"" + referrer + "\">Go Back to File View</a><hr>");
  } else {
    out.print("<h3>" + filename + "</h3>");
  }
  out.print("<b>Chunk size to view (in bytes, up to file's DFS block size): </b>");
  out.print("<input type=\"text\" name=\"chunkSizeToView\" value="
      + chunkSizeToView + " size=10 maxlength=10>");
  out.print("&nbsp;&nbsp;<input type=\"submit\" name=\"submit\" value=\"Refresh\"><hr>");
  out.print("<input type=\"hidden\" name=\"filename\" value=\"" + filename
      + "\">");
  out.print("<input type=\"hidden\" name=\"namenodeInfoPort\" value=\""
      + namenodeInfoPort + "\">");
  if (!noLink)
    out.print("<input type=\"hidden\" name=\"referrer\" value=\"" + referrer
        + "\">");

  // fetch the block from the datanode that has the last block for this file
  final DFSClient dfs = getDFSClient(ugi, datanode.getNameNodeAddrForClient(), conf);
  List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
      Long.MAX_VALUE).getLocatedBlocks();
  if (blocks == null || blocks.size() == 0) {
    out.print("No datanodes contain blocks of file " + filename);
    dfs.close();
    return;
  }
  LocatedBlock lastBlk = blocks.get(blocks.size() - 1);
  long blockSize = lastBlk.getBlock().getNumBytes();
  long blockId = lastBlk.getBlock().getBlockId();
  Token<BlockTokenIdentifier> accessToken = lastBlk.getBlockToken();
  long genStamp = lastBlk.getBlock().getGenerationStamp();
  DatanodeInfo chosenNode;
  try {
    chosenNode = JspHelper.bestNode(lastBlk);
  } catch (IOException e) {
    out.print(e.toString());
    dfs.close();
    return;
  }
  InetSocketAddress addr = NetUtils.createSocketAddr(chosenNode.getName());
  // view the last chunkSizeToView bytes while Tailing
  final long startOffset = blockSize >= chunkSizeToView ? blockSize
      - chunkSizeToView : 0;

  out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" style=\"width:100%\" READONLY>");
  JspHelper.streamBlockInAscii(addr, blockId, accessToken, genStamp,
      blockSize, startOffset, chunkSizeToView, out, conf);
  out.print("</textarea>");
  dfs.close();
}
 
开发者ID:cumulusyebl,项目名称:cumulus,代码行数:82,代码来源:DatanodeJspHelper.java


注:本文中的org.apache.hadoop.hdfs.server.common.JspHelper.bestNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。