You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 05:09:15 UTC
svn commit: r1077380 -
/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java
Author: omalley
Date: Fri Mar 4 04:09:15 2011
New Revision: 1077380
URL: http://svn.apache.org/viewvc?rev=1077380&view=rev
Log:
commit ca78e91eb1e3e5a2621462d8c8ea4943cb0f29ff
Author: Chris Douglas <cd...@apache.org>
Date: Fri Apr 2 17:30:00 2010 -0700
. Replace fork of DF with library call. (cdouglas via omalley)
+++ b/YAHOO-CHANGES.txt
+ . Replace fork of DF with library call. (cdouglas via omalley)
+
Modified:
hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java
Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java?rev=1077380&r1=1077379&r2=1077380&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/DF.java Fri Mar 4 04:09:15 2011
@@ -26,17 +26,19 @@ import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.Shell;
-/** Filesystem disk space usage statistics. Uses the unix 'df' program.
- * Tested on Linux, FreeBSD, Cygwin. */
+/**
+ * Filesystem disk space usage statistics. Uses the unix 'df' program to get
+ * mount points, and java.io.File for space utilization. Tested on Linux,
+ * FreeBSD, Cygwin.
+ */
public class DF extends Shell {
- public static final long DF_INTERVAL_DEFAULT = 3 * 1000; // default DF refresh interval
+
+ /** Default DF refresh interval. */
+ public static final long DF_INTERVAL_DEFAULT = 3 * 1000;
- private String dirPath;
+ private final String dirPath;
+ private final File dirFile;
private String filesystem;
- private long capacity;
- private long used;
- private long available;
- private int percentUsed;
private String mount;
public DF(File path, Configuration conf) throws IOException {
@@ -46,39 +48,45 @@ public class DF extends Shell {
public DF(File path, long dfInterval) throws IOException {
super(dfInterval);
this.dirPath = path.getCanonicalPath();
+ this.dirFile = path.getCanonicalFile();
}
/// ACCESSORS
+ /** @return the canonical path to the volume we're checking. */
public String getDirPath() {
return dirPath;
}
-
- public String getFilesystem() throws IOException {
- run();
- return filesystem;
+
+ /** @return a string indicating which filesystem volume we're checking. */
+ public String getFilesystem() throws IOException {
+ run();
+ return filesystem;
}
-
- public long getCapacity() throws IOException {
- run();
- return capacity;
+
+ /** @return the capacity of the measured filesystem in bytes. */
+ public long getCapacity() {
+ return dirFile.getTotalSpace();
}
-
- public long getUsed() throws IOException {
- run();
- return used;
+
+ /** @return the total used space on the filesystem in bytes. */
+ public long getUsed() {
+ return dirFile.getTotalSpace() - dirFile.getFreeSpace();
}
-
- public long getAvailable() throws IOException {
- run();
- return available;
+
+ /** @return the usable space remaining on the filesystem in bytes. */
+ public long getAvailable() {
+ return dirFile.getUsableSpace();
}
-
- public int getPercentUsed() throws IOException {
- run();
- return percentUsed;
+
+ /** @return the amount of the volume full, as a percent. */
+ public int getPercentUsed() {
+ final double cap = (double) getCapacity();
+ final double used = (cap - (double) getAvailable());
+ return (int) (used * 100.0 / cap);
}
+ /** @return the filesystem mount point for the indicated volume */
public String getMount() throws IOException {
run();
return mount;
@@ -88,10 +96,10 @@ public class DF extends Shell {
return
"df -k " + mount +"\n" +
filesystem + "\t" +
- capacity / 1024 + "\t" +
- used / 1024 + "\t" +
- available / 1024 + "\t" +
- percentUsed + "%\t" +
+ getCapacity() / 1024 + "\t" +
+ getUsed() / 1024 + "\t" +
+ getAvailable() / 1024 + "\t" +
+ getPercentUsed() + "%\t" +
mount;
}
@@ -119,10 +127,10 @@ public class DF extends Shell {
}
tokens = new StringTokenizer(line, " \t\n\r\f%");
}
- this.capacity = Long.parseLong(tokens.nextToken()) * 1024;
- this.used = Long.parseLong(tokens.nextToken()) * 1024;
- this.available = Long.parseLong(tokens.nextToken()) * 1024;
- this.percentUsed = Integer.parseInt(tokens.nextToken());
+ Long.parseLong(tokens.nextToken()); // skip capacity
+ Long.parseLong(tokens.nextToken()); // skip used
+ Long.parseLong(tokens.nextToken()); // skip available
+ Integer.parseInt(tokens.nextToken()); // skip percentUsed
this.mount = tokens.nextToken();
}