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 bo...@apache.org on 2011/04/14 23:24:58 UTC
svn commit: r1092519 - in /hadoop/common/trunk: CHANGES.txt
src/java/org/apache/hadoop/fs/FsShell.java
src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java
Author: boryas
Date: Thu Apr 14 21:24:58 2011
New Revision: 1092519
URL: http://svn.apache.org/viewvc?rev=1092519&view=rev
Log:
HADOOP-7207. fs member of FSShell is not really needed
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java
Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1092519&r1=1092518&r2=1092519&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Thu Apr 14 21:24:58 2011
@@ -137,6 +137,8 @@ Trunk (unreleased changes)
HADOOP-7216. Add FsCommand.runAll() with deprecated annotation for the
transition of Command base class improvement. (Daryn Sharp via szetszwo)
+ HADOOP-7207. fs member of FSShell is not really needed (boryas)
+
Release 0.22.0 - Unreleased
INCOMPATIBLE CHANGES
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java?rev=1092519&r1=1092518&r2=1092519&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FsShell.java Thu Apr 14 21:24:58 2011
@@ -60,7 +60,7 @@ public class FsShell extends Configured
static final Log LOG = LogFactory.getLog(FsShell.class);
- protected FileSystem fs;
+ private FileSystem fs;
private Trash trash;
protected CommandFactory commandFactory;
@@ -92,14 +92,22 @@ public class FsShell extends Configured
commandFactory = new CommandFactory();
}
- protected void init() throws IOException {
- getConf().setQuietMode(true);
- if (this.fs == null) {
- this.fs = FileSystem.get(getConf());
- }
+ protected FileSystem getFS() throws IOException {
+ if(fs == null)
+ fs = FileSystem.get(getConf());
+
+ return fs;
+ }
+
+ protected Trash getTrash() throws IOException {
if (this.trash == null) {
this.trash = new Trash(getConf());
}
+ return this.trash;
+ }
+
+ protected void init() throws IOException {
+ getConf().setQuietMode(true);
}
@@ -510,11 +518,12 @@ public class FsShell extends Configured
System.out.flush();
boolean printWarning = false;
- FileStatus status = fs.getFileStatus(f);
+ FileSystem pFS = f.getFileSystem(getConf());
+ FileStatus status = pFS.getFileStatus(f);
long len = status.getLen();
for(boolean done = false; !done; ) {
- BlockLocation[] locations = fs.getFileBlockLocations(status, 0, len);
+ BlockLocation[] locations = pFS.getFileBlockLocations(status, 0, len);
int i = 0;
for(; i < locations.length &&
locations[i].getHosts().length == rep; i++)
@@ -1087,7 +1096,8 @@ public class FsShell extends Configured
//
if (argv.length > 3) {
Path dst = new Path(dest);
- if (!fs.isDirectory(dst)) {
+ FileSystem pFS = dst.getFileSystem(conf);
+ if (!pFS.isDirectory(dst)) {
throw new IOException("When copying multiple files, "
+ "destination " + dest + " should be a directory.");
}
@@ -1199,15 +1209,15 @@ public class FsShell extends Configured
}
private void expunge() throws IOException {
- trash.expunge();
- trash.checkpoint();
+ getTrash().expunge();
+ getTrash().checkpoint();
}
/**
* Returns the Trash object associated with this shell.
*/
- public Path getCurrentTrashDir() {
- return trash.getCurrentTrashDir();
+ public Path getCurrentTrashDir() throws IOException {
+ return getTrash().getCurrentTrashDir();
}
/**
Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java?rev=1092519&r1=1092518&r2=1092519&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFsShellReturnCode.java Thu Apr 14 21:24:58 2011
@@ -274,6 +274,37 @@ public class TestFsShellReturnCode {
}
}
+ @Test
+ public void testInvalidDefautlFS() throws Exception {
+ // if default fs doesn't exist or is invalid, but the path provided in
+ // arguments is valid - fsshell should work
+ FsShell shell = new FsShell();
+ Configuration conf = new Configuration();
+ FsConfig.setDefaultFS(conf, "hhhh://doesnotexist/");
+ shell.setConf(conf);
+ String [] args = new String[2];
+ args[0] = "-ls";
+ args[1] = "file:///"; // this is valid, so command should run
+ int res = shell.run(args);
+ System.out.println("res =" + res);
+ shell.setConf(conf);
+ final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ final PrintStream out = new PrintStream(bytes);
+ final PrintStream oldErr = System.err;
+ System.setErr(out);
+ final String results;
+ try {
+ int run = shell.run(args);
+ results = bytes.toString();
+ LOG.info("result=" + results);
+ assertTrue("Return code should be 0", run == 0);
+ } finally {
+ IOUtils.closeStream(out);
+ System.setErr(oldErr);
+ }
+
+ }
+
static class LocalFileSystemExtn extends RawLocalFileSystem {
private String username;