HDFS-3735. NameNode WebUI should allow sorting live datanode list by fields Block Pool Used, Block Pool Used(%) and Failed Volumes. Contributed by Brahma Reddy Battula.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1394385 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2012-10-05 07:02:52 +00:00
parent a41f808c3c
commit dfb8369c29
3 changed files with 67 additions and 0 deletions

View File

@ -143,6 +143,10 @@ Trunk (Unreleased)
HDFS-3995. Use DFSTestUtil.createFile() for file creation and
writing in test cases. (Jing Zhao via suresh)
HDFS-3735. NameNode WebUI should allow sorting live datanode list by fields
Block Pool Used, Block Pool Used(%) and Failed Volumes.
(Brahma Reddy Battula via suresh)
OPTIMIZATIONS
BUG FIXES

View File

@ -276,6 +276,9 @@ class NodeComapare implements Comparator<DatanodeDescriptor> {
FIELD_PERCENT_REMAINING = 9,
FIELD_ADMIN_STATE = 10,
FIELD_DECOMMISSIONED = 11,
FIELD_BLOCKPOOL_USED = 12,
FIELD_PERBLOCKPOOL_USED = 13,
FIELD_FAILED_VOLUMES = 14,
SORT_ORDER_ASC = 1,
SORT_ORDER_DSC = 2;
@ -303,6 +306,12 @@ public NodeComapare(String field, String order) {
sortField = FIELD_ADMIN_STATE;
} else if (field.equals("decommissioned")) {
sortField = FIELD_DECOMMISSIONED;
} else if (field.equals("bpused")) {
sortField = FIELD_BLOCKPOOL_USED;
} else if (field.equals("pcbpused")) {
sortField = FIELD_PERBLOCKPOOL_USED;
} else if (field.equals("volfails")) {
sortField = FIELD_FAILED_VOLUMES;
} else {
sortField = FIELD_NAME;
}
@ -361,6 +370,18 @@ public int compare(DatanodeDescriptor d1,
case FIELD_NAME:
ret = d1.getHostName().compareTo(d2.getHostName());
break;
case FIELD_BLOCKPOOL_USED:
dlong = d1.getBlockPoolUsed() - d2.getBlockPoolUsed();
ret = (dlong < 0) ? -1 : ((dlong > 0) ? 1 : 0);
break;
case FIELD_PERBLOCKPOOL_USED:
ddbl = d1.getBlockPoolUsedPercent() - d2.getBlockPoolUsedPercent();
ret = (ddbl < 0) ? -1 : ((ddbl > 0) ? 1 : 0);
break;
case FIELD_FAILED_VOLUMES:
int dint = d1.getVolumeFailures() - d2.getVolumeFailures();
ret = (dint < 0) ? -1 : ((dint > 0) ? 1 : 0);
break;
}
return (sortOrder == SORT_ORDER_DSC) ? -ret : ret;
}

View File

@ -22,6 +22,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -29,7 +30,9 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.protocol.DatanodeID;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer;
import org.apache.hadoop.hdfs.web.resources.DoAsParam;
import org.apache.hadoop.hdfs.web.resources.UserParam;
@ -399,4 +402,43 @@ private void checkUgiFromToken(UserGroupInformation ugi) {
ugi.getAuthenticationMethod());
}
}
@Test
public void testSortNodeByFields() throws Exception {
DatanodeID dnId1 = new DatanodeID("127.0.0.1", "localhost1", "storage1",
1234, 2345, 3456);
DatanodeID dnId2 = new DatanodeID("127.0.0.2", "localhost2", "storage2",
1235, 2346, 3457);
DatanodeDescriptor dnDesc1 = new DatanodeDescriptor(dnId1, "rack1", 1024,
100, 924, 100, 10, 2);
DatanodeDescriptor dnDesc2 = new DatanodeDescriptor(dnId2, "rack2", 2500,
200, 1848, 200, 20, 1);
ArrayList<DatanodeDescriptor> live = new ArrayList<DatanodeDescriptor>();
live.add(dnDesc1);
live.add(dnDesc2);
// Test sorting by failed volumes
JspHelper.sortNodeList(live, "volfails", "ASC");
Assert.assertEquals(dnDesc2, live.get(0));
Assert.assertEquals(dnDesc1, live.get(1));
JspHelper.sortNodeList(live, "volfails", "DSC");
Assert.assertEquals(dnDesc1, live.get(0));
Assert.assertEquals(dnDesc2, live.get(1));
// Test sorting by Blockpool used
JspHelper.sortNodeList(live, "bpused", "ASC");
Assert.assertEquals(dnDesc1, live.get(0));
Assert.assertEquals(dnDesc2, live.get(1));
JspHelper.sortNodeList(live, "bpused", "DSC");
Assert.assertEquals(dnDesc2, live.get(0));
Assert.assertEquals(dnDesc1, live.get(1));
// Test sorting by Percentage Blockpool used
JspHelper.sortNodeList(live, "pcbpused", "ASC");
Assert.assertEquals(dnDesc2, live.get(0));
Assert.assertEquals(dnDesc1, live.get(1));
JspHelper.sortNodeList(live, "pcbpused", "DSC");
Assert.assertEquals(dnDesc1, live.get(0));
Assert.assertEquals(dnDesc2, live.get(1));
}
}