|
@@ -28,6 +28,8 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.jsp.JspWriter;
|
|
|
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.hdfs.protocol.Block;
|
|
|
import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
|
|
import org.apache.hadoop.hdfs.protocol.FSConstants.UpgradeAction;
|
|
|
import org.apache.hadoop.hdfs.server.common.JspHelper;
|
|
@@ -38,6 +40,8 @@ import org.apache.hadoop.util.ServletUtil;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
|
import org.apache.hadoop.util.VersionInfo;
|
|
|
|
|
|
+import org.znerd.xmlenc.*;
|
|
|
+
|
|
|
class NamenodeJspHelper {
|
|
|
static String getSafeModeText(FSNamesystem fsn) {
|
|
|
if (!fsn.isInSafeMode())
|
|
@@ -449,4 +453,195 @@ class NamenodeJspHelper {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // utility class used in block_info_xml.jsp
|
|
|
+ static class XMLBlockInfo {
|
|
|
+ final Block block;
|
|
|
+ final INodeFile inode;
|
|
|
+ final FSNamesystem fsn;
|
|
|
+
|
|
|
+ public XMLBlockInfo(FSNamesystem fsn, Long blockId) {
|
|
|
+ this.fsn = fsn;
|
|
|
+ if (blockId == null) {
|
|
|
+ this.block = null;
|
|
|
+ this.inode = null;
|
|
|
+ } else {
|
|
|
+ this.block = new Block(blockId);
|
|
|
+ this.inode = fsn.blockManager.getINode(block);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getLocalParentDir(INode inode) {
|
|
|
+ StringBuilder pathBuf = new StringBuilder();
|
|
|
+ INode node = inode;
|
|
|
+
|
|
|
+ // loop up to directory root, prepending each directory name to buffer
|
|
|
+ while ((node = node.getParent()) != null && node.getLocalName() != "") {
|
|
|
+ pathBuf.insert(0, '/').insert(0, node.getLocalName());
|
|
|
+ }
|
|
|
+
|
|
|
+ return pathBuf.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void toXML(XMLOutputter doc) throws IOException {
|
|
|
+ doc.startTag("block_info");
|
|
|
+ if (block == null) {
|
|
|
+ doc.startTag("error");
|
|
|
+ doc.pcdata("blockId must be a Long");
|
|
|
+ doc.endTag();
|
|
|
+ }else{
|
|
|
+ doc.startTag("block_id");
|
|
|
+ doc.pcdata(""+block.getBlockId());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("block_name");
|
|
|
+ doc.pcdata(block.getBlockName());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ if (inode != null) {
|
|
|
+ doc.startTag("file");
|
|
|
+
|
|
|
+ doc.startTag("local_name");
|
|
|
+ doc.pcdata(inode.getLocalName());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("local_directory");
|
|
|
+ doc.pcdata(getLocalParentDir(inode));
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("user_name");
|
|
|
+ doc.pcdata(inode.getUserName());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("group_name");
|
|
|
+ doc.pcdata(inode.getGroupName());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("is_directory");
|
|
|
+ doc.pcdata(""+inode.isDirectory());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("access_time");
|
|
|
+ doc.pcdata(""+inode.getAccessTime());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("is_under_construction");
|
|
|
+ doc.pcdata(""+inode.isUnderConstruction());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("ds_quota");
|
|
|
+ doc.pcdata(""+inode.getDsQuota());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("permission_status");
|
|
|
+ doc.pcdata(inode.getPermissionStatus().toString());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("replication");
|
|
|
+ doc.pcdata(""+inode.getReplication());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("disk_space_consumed");
|
|
|
+ doc.pcdata(""+inode.diskspaceConsumed());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("preferred_block_size");
|
|
|
+ doc.pcdata(""+inode.getPreferredBlockSize());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.endTag(); // </file>
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.startTag("replicas");
|
|
|
+
|
|
|
+ if (fsn.blockManager.blocksMap.contains(block)) {
|
|
|
+ Iterator<DatanodeDescriptor> it =
|
|
|
+ fsn.blockManager.blocksMap.nodeIterator(block);
|
|
|
+
|
|
|
+ while (it.hasNext()) {
|
|
|
+ doc.startTag("replica");
|
|
|
+
|
|
|
+ DatanodeDescriptor dd = it.next();
|
|
|
+
|
|
|
+ doc.startTag("host_name");
|
|
|
+ doc.pcdata(dd.getHostName());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ boolean isCorrupt = fsn.getCorruptReplicaBlockIds(0,
|
|
|
+ block.getBlockId()) != null;
|
|
|
+
|
|
|
+ doc.startTag("is_corrupt");
|
|
|
+ doc.pcdata(""+isCorrupt);
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.endTag(); // </replica>
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ doc.endTag(); // </replicas>
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.endTag(); // </block_info>
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // utility class used in corrupt_replicas_xml.jsp
|
|
|
+ static class XMLCorruptBlockInfo {
|
|
|
+ final FSNamesystem fsn;
|
|
|
+ final Configuration conf;
|
|
|
+ final Long startingBlockId;
|
|
|
+ final int numCorruptBlocks;
|
|
|
+
|
|
|
+ public XMLCorruptBlockInfo(FSNamesystem fsn, Configuration conf,
|
|
|
+ int numCorruptBlocks, Long startingBlockId) {
|
|
|
+ this.fsn = fsn;
|
|
|
+ this.conf = conf;
|
|
|
+ this.numCorruptBlocks = numCorruptBlocks;
|
|
|
+ this.startingBlockId = startingBlockId;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void toXML(XMLOutputter doc) throws IOException {
|
|
|
+
|
|
|
+ doc.startTag("corrupt_block_info");
|
|
|
+
|
|
|
+ if (numCorruptBlocks < 0 || numCorruptBlocks > 100) {
|
|
|
+ doc.startTag("error");
|
|
|
+ doc.pcdata("numCorruptBlocks must be >= 0 and <= 100");
|
|
|
+ doc.endTag();
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.startTag("dfs_replication");
|
|
|
+ doc.pcdata(""+conf.getInt("dfs.replication", 3));
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("num_missing_blocks");
|
|
|
+ doc.pcdata(""+fsn.getMissingBlocksCount());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("num_corrupt_replica_blocks");
|
|
|
+ doc.pcdata(""+fsn.getCorruptReplicaBlocks());
|
|
|
+ doc.endTag();
|
|
|
+
|
|
|
+ doc.startTag("corrupt_replica_block_ids");
|
|
|
+ long[] corruptBlockIds
|
|
|
+ = fsn.getCorruptReplicaBlockIds(numCorruptBlocks,
|
|
|
+ startingBlockId);
|
|
|
+ if (corruptBlockIds != null) {
|
|
|
+ for (Long blockId: corruptBlockIds) {
|
|
|
+ doc.startTag("block_id");
|
|
|
+ doc.pcdata(""+blockId);
|
|
|
+ doc.endTag();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ doc.endTag(); // </corrupt_replica_block_ids>
|
|
|
+
|
|
|
+ doc.endTag(); // </corrupt_block_info>
|
|
|
+
|
|
|
+ doc.getWriter().flush();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|