Author: cdouglas
Date: Fri Feb 27 22:59:08 2009
New Revision: 748731
URL: http://svn.apache.org/viewvc?rev=748731&view=rev
Log:
HADOOP-4546. Fix DF reporting for AIX. Contributed by Bill Habermaas.
Added:
hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestDFVariations.java
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/core/org/apache/hadoop/fs/DF.java
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=748731&r1=748730&r2=748731&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Feb 27 22:59:08 2009
@@ -143,6 +143,8 @@
HADOOP-5232. Enable patch testing to occur on more than one host.
(Giri Kesavan via nigel)
+ HADOOP-4546. Fix DF reporting for AIX. (Bill Habermaas via cdouglas)
+
OPTIMIZATIONS
BUG FIXES
Modified: hadoop/core/trunk/src/core/org/apache/hadoop/fs/DF.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/fs/DF.java?rev=748731&r1=748730&r2=748731&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/fs/DF.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/fs/DF.java Fri Feb 27 22:59:08
2009
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.BufferedReader;
+import java.util.EnumSet;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
@@ -31,14 +32,45 @@
public class DF extends Shell {
public static final long DF_INTERVAL_DEFAULT = 3 * 1000; // default DF
refresh interval
- private String dirPath;
+ private String dirPath;
private String filesystem;
private long capacity;
private long used;
private long available;
private int percentUsed;
private String mount;
-
+
+ enum OSType {
+ OS_TYPE_UNIX("UNIX"),
+ OS_TYPE_WIN("Windows"),
+ OS_TYPE_SOLARIS("SunOS"),
+ OS_TYPE_MAC("Mac"),
+ OS_TYPE_AIX("AIX");
+
+ private String id;
+ OSType(String id) {
+ this.id = id;
+ }
+ public boolean match(String osStr) {
+ return osStr != null && osStr.indexOf(id) >= 0;
+ }
+ String getId() {
+ return id;
+ }
+ }
+
+ private static final String OS_NAME = System.getProperty("os.name");
+ private static final OSType OS_TYPE = getOSType(OS_NAME);
+
+ protected static OSType getOSType(String osName) {
+ for (OSType ost : EnumSet.allOf(OSType.class)) {
+ if (ost.match(osName)) {
+ return ost;
+ }
+ }
+ return OSType.OS_TYPE_UNIX;
+ }
+
public DF(File path, Configuration conf) throws IOException {
this(path, conf.getLong("dfs.df.interval", DF.DF_INTERVAL_DEFAULT));
}
@@ -47,6 +79,10 @@
super(dfInterval);
this.dirPath = path.getCanonicalPath();
}
+
+ protected OSType getOSType() {
+ return OS_TYPE;
+ }
/// ACCESSORS
@@ -95,12 +131,14 @@
mount;
}
+ @Override
protected String[] getExecString() {
// ignoring the error since the exit code it enough
return new String[] {"bash","-c","exec 'df' '-k' '" + dirPath
+ "' 2>/dev/null"};
}
-
+
+ @Override
protected void parseExecResult(BufferedReader lines) throws IOException {
lines.readLine(); // skip headings
@@ -119,11 +157,30 @@
}
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());
- this.mount = tokens.nextToken();
+
+ switch(getOSType()) {
+ case OS_TYPE_AIX:
+ this.capacity = Long.parseLong(tokens.nextToken()) * 1024;
+ this.available = Long.parseLong(tokens.nextToken()) * 1024;
+ this.percentUsed = Integer.parseInt(tokens.nextToken());
+ tokens.nextToken();
+ tokens.nextToken();
+ this.mount = tokens.nextToken();
+ this.used = this.capacity - this.available;
+ break;
+
+ case OS_TYPE_WIN:
+ case OS_TYPE_SOLARIS:
+ case OS_TYPE_MAC:
+ case OS_TYPE_UNIX:
+ default:
+ 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());
+ this.mount = tokens.nextToken();
+ break;
+ }
}
public static void main(String[] args) throws Exception {
Added: hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestDFVariations.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestDFVariations.java?rev=748731&view=auto
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestDFVariations.java
(added)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/fs/TestDFVariations.java Fri
Feb 27 22:59:08 2009
@@ -0,0 +1,63 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.hadoop.fs;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.EnumSet;
+
+public class TestDFVariations extends TestCase {
+
+ public static class XXDF extends DF {
+ private final String osName;
+ public XXDF(String osName) throws IOException {
+ super(new File(System.getProperty("test.build.data","/tmp")), 0L);
+ this.osName = osName;
+ }
+ @Override
+ public DF.OSType getOSType() {
+ return DF.getOSType(osName);
+ }
+ @Override
+ protected String[] getExecString() {
+ switch(getOSType()) {
+ case OS_TYPE_AIX:
+ return new String[] { "echo", "IGNORE\n", "/dev/sda3",
+ "453115160", "400077240", "11%", "18", "skip%", "/foo/bar", "\n" };
+ default:
+ return new String[] { "echo", "IGNORE\n", "/dev/sda3",
+ "453115160", "53037920", "400077240", "11%", "/foo/bar", "\n" };
+ }
+ }
+ }
+
+ public void testOSParsing() throws Exception {
+ for (DF.OSType ost : EnumSet.allOf(DF.OSType.class)) {
+ XXDF df = new XXDF(ost.getId());
+ assertEquals(ost.getId() + " total", 453115160 * 1024L,
df.getCapacity());
+ assertEquals(ost.getId() + " used", 53037920 * 1024L, df.getUsed());
+ assertEquals(ost.getId() + " avail", 400077240 * 1024L,
df.getAvailable());
+ assertEquals(ost.getId() + " pcnt used", 11, df.getPercentUsed());
+ assertEquals(ost.getId() + " mount", "/foo/bar", df.getMount());
+ }
+ }
+
+}
+