HADOOP-7207. fs member of FSShell is not really needed
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1092519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7f30939885
commit
6e74a3592c
|
@ -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
|
||||
|
|
|
@ -60,7 +60,7 @@ public class FsShell extends Configured implements Tool {
|
|||
|
||||
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 implements Tool {
|
|||
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 implements Tool {
|
|||
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 implements Tool {
|
|||
//
|
||||
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 implements Tool {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue