|
@@ -25,6 +25,7 @@ import java.net.URI;
|
|
|
import java.net.URL;
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -371,65 +372,96 @@ public class DFSAdmin extends FsShell {
|
|
|
* Gives a report on how the FileSystem is doing.
|
|
|
* @exception IOException if the filesystem does not exist.
|
|
|
*/
|
|
|
- public void report() throws IOException {
|
|
|
- DistributedFileSystem dfs = getDFS();
|
|
|
- FsStatus ds = dfs.getStatus();
|
|
|
- long capacity = ds.getCapacity();
|
|
|
- long used = ds.getUsed();
|
|
|
- long remaining = ds.getRemaining();
|
|
|
- long presentCapacity = used + remaining;
|
|
|
- boolean mode = dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET);
|
|
|
- if (mode) {
|
|
|
- System.out.println("Safe mode is ON");
|
|
|
- }
|
|
|
- System.out.println("Configured Capacity: " + capacity
|
|
|
- + " (" + StringUtils.byteDesc(capacity) + ")");
|
|
|
- System.out.println("Present Capacity: " + presentCapacity
|
|
|
- + " (" + StringUtils.byteDesc(presentCapacity) + ")");
|
|
|
- System.out.println("DFS Remaining: " + remaining
|
|
|
- + " (" + StringUtils.byteDesc(remaining) + ")");
|
|
|
- System.out.println("DFS Used: " + used
|
|
|
- + " (" + StringUtils.byteDesc(used) + ")");
|
|
|
- System.out.println("DFS Used%: "
|
|
|
- + StringUtils.formatPercent(used/(double)presentCapacity, 2));
|
|
|
-
|
|
|
- /* These counts are not always upto date. They are updated after
|
|
|
- * iteration of an internal list. Should be updated in a few seconds to
|
|
|
- * minutes. Use "-metaSave" to list of all such blocks and accurate
|
|
|
- * counts.
|
|
|
- */
|
|
|
- System.out.println("Under replicated blocks: " +
|
|
|
- dfs.getUnderReplicatedBlocksCount());
|
|
|
- System.out.println("Blocks with corrupt replicas: " +
|
|
|
- dfs.getCorruptBlocksCount());
|
|
|
- System.out.println("Missing blocks: " +
|
|
|
- dfs.getMissingBlocksCount());
|
|
|
-
|
|
|
- System.out.println();
|
|
|
+ public void report(String[] argv, int i) throws IOException {
|
|
|
+ DistributedFileSystem dfs = getDFS();
|
|
|
+ FsStatus ds = dfs.getStatus();
|
|
|
+ long capacity = ds.getCapacity();
|
|
|
+ long used = ds.getUsed();
|
|
|
+ long remaining = ds.getRemaining();
|
|
|
+ long presentCapacity = used + remaining;
|
|
|
+ boolean mode = dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_GET);
|
|
|
+ if (mode) {
|
|
|
+ System.out.println("Safe mode is ON");
|
|
|
+ }
|
|
|
+ System.out.println("Configured Capacity: " + capacity
|
|
|
+ + " (" + StringUtils.byteDesc(capacity) + ")");
|
|
|
+ System.out.println("Present Capacity: " + presentCapacity
|
|
|
+ + " (" + StringUtils.byteDesc(presentCapacity) + ")");
|
|
|
+ System.out.println("DFS Remaining: " + remaining
|
|
|
+ + " (" + StringUtils.byteDesc(remaining) + ")");
|
|
|
+ System.out.println("DFS Used: " + used
|
|
|
+ + " (" + StringUtils.byteDesc(used) + ")");
|
|
|
+ System.out.println("DFS Used%: "
|
|
|
+ + StringUtils.formatPercent(used/(double)presentCapacity, 2));
|
|
|
+
|
|
|
+ /* These counts are not always upto date. They are updated after
|
|
|
+ * iteration of an internal list. Should be updated in a few seconds to
|
|
|
+ * minutes. Use "-metaSave" to list of all such blocks and accurate
|
|
|
+ * counts.
|
|
|
+ */
|
|
|
+ System.out.println("Under replicated blocks: " +
|
|
|
+ dfs.getUnderReplicatedBlocksCount());
|
|
|
+ System.out.println("Blocks with corrupt replicas: " +
|
|
|
+ dfs.getCorruptBlocksCount());
|
|
|
+ System.out.println("Missing blocks: " +
|
|
|
+ dfs.getMissingBlocksCount());
|
|
|
|
|
|
- System.out.println("-------------------------------------------------");
|
|
|
-
|
|
|
+ System.out.println();
|
|
|
+
|
|
|
+ System.out.println("-------------------------------------------------");
|
|
|
+
|
|
|
+ // Parse arguments for filtering the node list
|
|
|
+ List<String> args = Arrays.asList(argv);
|
|
|
+ // Truncate already handled arguments before parsing report()-specific ones
|
|
|
+ args = new ArrayList<String>(args.subList(i, args.size()));
|
|
|
+ final boolean listLive = StringUtils.popOption("-live", args);
|
|
|
+ final boolean listDead = StringUtils.popOption("-dead", args);
|
|
|
+ final boolean listDecommissioning =
|
|
|
+ StringUtils.popOption("-decommissioning", args);
|
|
|
+
|
|
|
+ // If no filter flags are found, then list all DN types
|
|
|
+ boolean listAll = (!listLive && !listDead && !listDecommissioning);
|
|
|
+
|
|
|
+ if (listAll || listLive) {
|
|
|
DatanodeInfo[] live = dfs.getDataNodeStats(DatanodeReportType.LIVE);
|
|
|
- DatanodeInfo[] dead = dfs.getDataNodeStats(DatanodeReportType.DEAD);
|
|
|
- System.out.println("Datanodes available: " + live.length +
|
|
|
- " (" + (live.length + dead.length) + " total, " +
|
|
|
- dead.length + " dead)\n");
|
|
|
-
|
|
|
- if(live.length > 0) {
|
|
|
- System.out.println("Live datanodes:");
|
|
|
+ if (live.length > 0 || listLive) {
|
|
|
+ System.out.println("Live datanodes (" + live.length + "):\n");
|
|
|
+ }
|
|
|
+ if (live.length > 0) {
|
|
|
for (DatanodeInfo dn : live) {
|
|
|
System.out.println(dn.getDatanodeReport());
|
|
|
System.out.println();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if(dead.length > 0) {
|
|
|
- System.out.println("Dead datanodes:");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (listAll || listDead) {
|
|
|
+ DatanodeInfo[] dead = dfs.getDataNodeStats(DatanodeReportType.DEAD);
|
|
|
+ if (dead.length > 0 || listDead) {
|
|
|
+ System.out.println("Dead datanodes (" + dead.length + "):\n");
|
|
|
+ }
|
|
|
+ if (dead.length > 0) {
|
|
|
for (DatanodeInfo dn : dead) {
|
|
|
System.out.println(dn.getDatanodeReport());
|
|
|
System.out.println();
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (listAll || listDecommissioning) {
|
|
|
+ DatanodeInfo[] decom =
|
|
|
+ dfs.getDataNodeStats(DatanodeReportType.DECOMMISSIONING);
|
|
|
+ if (decom.length > 0 || listDecommissioning) {
|
|
|
+ System.out.println("Decommissioning datanodes (" + decom.length
|
|
|
+ + "):\n");
|
|
|
+ }
|
|
|
+ if (decom.length > 0) {
|
|
|
+ for (DatanodeInfo dn : decom) {
|
|
|
+ System.out.println(dn.getDatanodeReport());
|
|
|
+ System.out.println();
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -639,7 +671,9 @@ public class DFSAdmin extends FsShell {
|
|
|
private void printHelp(String cmd) {
|
|
|
String summary = "hadoop dfsadmin performs DFS administrative commands.\n" +
|
|
|
"The full syntax is: \n\n" +
|
|
|
- "hadoop dfsadmin [-report] [-safemode <enter | leave | get | wait>]\n" +
|
|
|
+ "hadoop dfsadmin\n" +
|
|
|
+ "\t[-report [-live] [-dead] [-decommissioning]]\n" +
|
|
|
+ "\t[-safemode <enter | leave | get | wait>]\n" +
|
|
|
"\t[-saveNamespace]\n" +
|
|
|
"\t[-rollEdits]\n" +
|
|
|
"\t[-restoreFailedStorage true|false|check]\n" +
|
|
@@ -665,8 +699,11 @@ public class DFSAdmin extends FsShell {
|
|
|
"\t[-getDatanodeInfo <datanode_host:ipc_port>\n" +
|
|
|
"\t[-help [cmd]]\n";
|
|
|
|
|
|
- String report ="-report: \tReports basic filesystem information and statistics.\n";
|
|
|
-
|
|
|
+ String report ="-report [-live] [-dead] [-decommissioning]:\n" +
|
|
|
+ "\tReports basic filesystem information and statistics.\n" +
|
|
|
+ "\tOptional flags may be used to filter the list of displayed DNs.\n";
|
|
|
+
|
|
|
+
|
|
|
String safemode = "-safemode <enter|leave|get|wait>: Safe mode maintenance command.\n" +
|
|
|
"\t\tSafe mode is a Namenode state in which it\n" +
|
|
|
"\t\t\t1. does not accept changes to the name space (read-only)\n" +
|
|
@@ -1069,7 +1106,7 @@ public class DFSAdmin extends FsShell {
|
|
|
private static void printUsage(String cmd) {
|
|
|
if ("-report".equals(cmd)) {
|
|
|
System.err.println("Usage: java DFSAdmin"
|
|
|
- + " [-report]");
|
|
|
+ + " [-report] [-live] [-dead] [-decommissioning]");
|
|
|
} else if ("-safemode".equals(cmd)) {
|
|
|
System.err.println("Usage: java DFSAdmin"
|
|
|
+ " [-safemode enter | leave | get | wait]");
|
|
@@ -1210,7 +1247,7 @@ public class DFSAdmin extends FsShell {
|
|
|
return exitCode;
|
|
|
}
|
|
|
} else if ("-report".equals(cmd)) {
|
|
|
- if (argv.length != 1) {
|
|
|
+ if (argv.length < 1) {
|
|
|
printUsage(cmd);
|
|
|
return exitCode;
|
|
|
}
|
|
@@ -1312,7 +1349,7 @@ public class DFSAdmin extends FsShell {
|
|
|
exitCode = 0;
|
|
|
try {
|
|
|
if ("-report".equals(cmd)) {
|
|
|
- report();
|
|
|
+ report(argv, i);
|
|
|
} else if ("-safemode".equals(cmd)) {
|
|
|
setSafeMode(argv, i);
|
|
|
} else if ("-allowSnapshot".equalsIgnoreCase(cmd)) {
|