Return-Path: Delivered-To: apmail-hadoop-hdfs-commits-archive@minotaur.apache.org Received: (qmail 99436 invoked from network); 14 Apr 2011 21:35:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Apr 2011 21:35:43 -0000 Received: (qmail 7734 invoked by uid 500); 14 Apr 2011 21:35:43 -0000 Delivered-To: apmail-hadoop-hdfs-commits-archive@hadoop.apache.org Received: (qmail 7708 invoked by uid 500); 14 Apr 2011 21:35:43 -0000 Mailing-List: contact hdfs-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-commits@hadoop.apache.org Received: (qmail 7699 invoked by uid 99); 14 Apr 2011 21:35:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Apr 2011 21:35:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Apr 2011 21:35:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4E34F238890A; Thu, 14 Apr 2011 21:35:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1092524 - in /hadoop/hdfs/trunk: CHANGES.txt src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java Date: Thu, 14 Apr 2011 21:35:18 -0000 To: hdfs-commits@hadoop.apache.org From: boryas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110414213518.4E34F238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: boryas Date: Thu Apr 14 21:35:17 2011 New Revision: 1092524 URL: http://svn.apache.org/viewvc?rev=1092524&view=rev Log: HDFS-1824. delay instantiation of file system object until it is needed (linked to HADOOP-7207) Modified: hadoop/hdfs/trunk/CHANGES.txt hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java Modified: hadoop/hdfs/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/CHANGES.txt?rev=1092524&r1=1092523&r2=1092524&view=diff ============================================================================== --- hadoop/hdfs/trunk/CHANGES.txt (original) +++ hadoop/hdfs/trunk/CHANGES.txt Thu Apr 14 21:35:17 2011 @@ -178,6 +178,9 @@ Trunk (unreleased changes) HDFS-1828. TestBlocksWithNotEnoughRacks intermittently fails assert. (Matt Foley via eli) + HDFS-1824. delay instantiation of file system object until it is + needed (linked to HADOOP-7207) (boryas) + Release 0.22.0 - Unreleased NEW FEATURES Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java?rev=1092524&r1=1092523&r2=1092524&view=diff ============================================================================== --- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java (original) +++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java Thu Apr 14 21:35:17 2011 @@ -266,13 +266,21 @@ public class DFSAdmin extends FsShell { super(conf); } + protected DistributedFileSystem getDFS() throws IOException { + FileSystem fs = getFS(); + if (!(fs instanceof DistributedFileSystem)) { + throw new IllegalArgumentException("FileSystem " + fs.getUri() + + " is not a distributed file system"); + } + return (DistributedFileSystem)fs; + } + /** * Gives a report on how the FileSystem is doing. * @exception IOException if the filesystem does not exist. */ public void report() throws IOException { - if (fs instanceof DistributedFileSystem) { - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); FsStatus ds = dfs.getStatus(); long capacity = ds.getCapacity(); long used = ds.getUsed(); @@ -339,7 +347,6 @@ public class DFSAdmin extends FsShell { System.out.println(); } } - } } /** @@ -350,10 +357,6 @@ public class DFSAdmin extends FsShell { * @exception IOException if the filesystem does not exist. */ public void setSafeMode(String[] argv, int idx) throws IOException { - if (!(fs instanceof DistributedFileSystem)) { - System.err.println("FileSystem is " + fs.getUri()); - return; - } if (idx != argv.length - 1) { printUsage("-safemode"); return; @@ -374,7 +377,7 @@ public class DFSAdmin extends FsShell { printUsage("-safemode"); return; } - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); boolean inSafeMode = dfs.setSafeMode(action); // @@ -404,12 +407,7 @@ public class DFSAdmin extends FsShell { public int saveNamespace() throws IOException { int exitCode = -1; - if (!(fs instanceof DistributedFileSystem)) { - System.err.println("FileSystem is " + fs.getUri()); - return exitCode; - } - - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); dfs.saveNamespace(); exitCode = 0; @@ -425,17 +423,12 @@ public class DFSAdmin extends FsShell { public int restoreFaileStorage(String arg) throws IOException { int exitCode = -1; - if (!(fs instanceof DistributedFileSystem)) { - System.err.println("FileSystem is " + fs.getUri()); - return exitCode; - } - if(!arg.equals("check") && !arg.equals("true") && !arg.equals("false")) { System.err.println("restoreFailedStorage valid args are true|false|check"); return exitCode; } - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); Boolean res = dfs.restoreFailedStorage(arg); System.out.println("restoreFailedStorage is set to " + res); exitCode = 0; @@ -452,12 +445,7 @@ public class DFSAdmin extends FsShell { public int refreshNodes() throws IOException { int exitCode = -1; - if (!(fs instanceof DistributedFileSystem)) { - System.err.println("FileSystem is " + fs.getUri()); - return exitCode; - } - - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); dfs.refreshNodes(); exitCode = 0; @@ -611,18 +599,10 @@ public class DFSAdmin extends FsShell { * @exception IOException */ public int finalizeUpgrade() throws IOException { - int exitCode = -1; - - if (!(fs instanceof DistributedFileSystem)) { - System.out.println("FileSystem is " + fs.getUri()); - return exitCode; - } - - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); dfs.finalizeUpgrade(); - exitCode = 0; - - return exitCode; + + return 0; } /** @@ -633,10 +613,7 @@ public class DFSAdmin extends FsShell { * @exception IOException */ public int upgradeProgress(String[] argv, int idx) throws IOException { - if (!(fs instanceof DistributedFileSystem)) { - System.out.println("FileSystem is " + fs.getUri()); - return -1; - } + if (idx != argv.length - 1) { printUsage("-upgradeProgress"); return -1; @@ -654,7 +631,7 @@ public class DFSAdmin extends FsShell { return -1; } - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); UpgradeStatusReport status = dfs.distributedUpgradeProgress(action); String statusText = (status == null ? "There are no upgrades in progress." : @@ -673,7 +650,7 @@ public class DFSAdmin extends FsShell { */ public int metaSave(String[] argv, int idx) throws IOException { String pathname = argv[idx]; - DistributedFileSystem dfs = (DistributedFileSystem) fs; + DistributedFileSystem dfs = getDFS(); dfs.metaSave(pathname); System.out.println("Created file " + pathname + " on server " + dfs.getUri()); @@ -688,8 +665,7 @@ public class DFSAdmin extends FsShell { * @throws IOException If an error while getting datanode report */ public int printTopology() throws IOException { - if (fs instanceof DistributedFileSystem) { - DistributedFileSystem dfs = (DistributedFileSystem)fs; + DistributedFileSystem dfs = getDFS(); DFSClient client = dfs.getClient(); DatanodeInfo[] report = client.datanodeReport(DatanodeReportType.ALL); @@ -724,7 +700,6 @@ public class DFSAdmin extends FsShell { System.out.println(); } - } return 0; } @@ -1009,13 +984,13 @@ public class DFSAdmin extends FsShell { } else if ("-metasave".equals(cmd)) { exitCode = metaSave(argv, i); } else if (ClearQuotaCommand.matches(cmd)) { - exitCode = new ClearQuotaCommand(argv, i, fs).runAll(); + exitCode = new ClearQuotaCommand(argv, i, getDFS()).runAll(); } else if (SetQuotaCommand.matches(cmd)) { - exitCode = new SetQuotaCommand(argv, i, fs).runAll(); + exitCode = new SetQuotaCommand(argv, i, getDFS()).runAll(); } else if (ClearSpaceQuotaCommand.matches(cmd)) { - exitCode = new ClearSpaceQuotaCommand(argv, i, fs).runAll(); + exitCode = new ClearSpaceQuotaCommand(argv, i, getDFS()).runAll(); } else if (SetSpaceQuotaCommand.matches(cmd)) { - exitCode = new SetSpaceQuotaCommand(argv, i, fs).runAll(); + exitCode = new SetSpaceQuotaCommand(argv, i, getDFS()).runAll(); } else if ("-refreshServiceAcl".equals(cmd)) { exitCode = refreshServiceAcl(); } else if ("-refreshUserToGroupsMappings".equals(cmd)) { Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java?rev=1092524&r1=1092523&r2=1092524&view=diff ============================================================================== --- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java (original) +++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSShell.java Thu Apr 14 21:35:17 2011 @@ -47,6 +47,7 @@ import org.apache.hadoop.fs.shell.Count; import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.FSDataset; +import org.apache.hadoop.hdfs.tools.DFSAdmin; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.StringUtils; @@ -1285,4 +1286,18 @@ public class TestDFSShell extends TestCa System.out.println("results:\n" + results); return results; } + + /** + * default setting is file:// which is not a DFS + * so DFSAdmin should throw and catch InvalidArgumentException + * and return -1 exit code. + * @throws Exception + */ + public void testInvalidShell() throws Exception { + Configuration conf = new Configuration(); // default FS (non-DFS) + DFSAdmin admin = new DFSAdmin(); + admin.setConf(conf); + int res = admin.run(new String[] {"-refreshNodes"}); + assertEquals("expected to fail -1", res , -1); + } }