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 um...@apache.org on 2012/03/09 19:48:36 UTC
svn commit: r1298976 - in
/hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt
src/main/java/org/apache/hadoop/fs/shell/Command.java
src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java
Author: umamahesh
Date: Fri Mar 9 18:48:35 2012
New Revision: 1298976
URL: http://svn.apache.org/viewvc?rev=1298976&view=rev
Log:
HADOOP-8146. FsShell commands cannot be interrupted. Contributed by Daryn Shar
Modified:
hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java
hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1298976&r1=1298975&r2=1298976&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Fri Mar 9 18:48:35 2012
@@ -59,6 +59,9 @@ Trunk (unreleased changes)
BUG FIXES
+ HADOOP-8146. FsShell commands cannot be interrupted
+ (Daryn Sharp via Uma Maheswara Rao G)
+
HADOOP-8018. Hudson auto test for HDFS has started throwing javadoc
(Jon Eagles via bobby)
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java?rev=1298976&r1=1298975&r2=1298976&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java Fri Mar 9 18:48:35 2012
@@ -19,6 +19,7 @@ package org.apache.hadoop.fs.shell;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -152,6 +153,9 @@ abstract public class Command extends Co
}
processOptions(args);
processRawArguments(args);
+ } catch (CommandInterruptException e) {
+ displayError("Interrupted");
+ return 130;
} catch (IOException e) {
displayError(e);
}
@@ -349,6 +353,10 @@ abstract public class Command extends Co
public void displayError(Exception e) {
// build up a list of exceptions that occurred
exceptions.add(e);
+ // use runtime so it rips up through the stack and exits out
+ if (e instanceof InterruptedIOException) {
+ throw new CommandInterruptException();
+ }
String errorMessage = e.getLocalizedMessage();
if (errorMessage == null) {
@@ -454,4 +462,7 @@ abstract public class Command extends Co
}
return value;
}
+
+ @SuppressWarnings("serial")
+ static class CommandInterruptException extends RuntimeException {}
}
Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java?rev=1298976&r1=1298975&r2=1298976&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellReturnCode.java Fri Mar 9 18:48:35 2012
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTru
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.util.Collections;
import java.util.HashMap;
@@ -33,6 +34,9 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ftpserver.command.impl.STAT;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.shell.CommandFactory;
+import org.apache.hadoop.fs.shell.FsCommand;
+import org.apache.hadoop.fs.shell.PathData;
import org.apache.hadoop.io.IOUtils;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
import org.junit.BeforeClass;
@@ -331,6 +335,33 @@ public class TestFsShellReturnCode {
}
+ @Test
+ public void testInterrupt() throws Exception {
+ MyFsShell shell = new MyFsShell();
+ shell.setConf(new Configuration());
+ final Path d = new Path(TEST_ROOT_DIR, "testInterrupt");
+ final Path f1 = new Path(d, "f1");
+ final Path f2 = new Path(d, "f2");
+ assertTrue(fileSys.mkdirs(d));
+ writeFile(fileSys, f1);
+ assertTrue(fileSys.isFile(f1));
+ writeFile(fileSys, f2);
+ assertTrue(fileSys.isFile(f2));
+
+ int exitCode = shell.run(
+ new String[]{ "-testInterrupt", f1.toString(), f2.toString() });
+ // processing a file throws an interrupt, it should blow on first file
+ assertEquals(1, InterruptCommand.processed);
+ assertEquals(130, exitCode);
+
+ exitCode = shell.run(
+ new String[]{ "-testInterrupt", d.toString() });
+ // processing a file throws an interrupt, it should blow on file
+ // after descent into dir
+ assertEquals(2, InterruptCommand.processed);
+ assertEquals(130, exitCode);
+ }
+
static class LocalFileSystemExtn extends LocalFileSystem {
public LocalFileSystemExtn() {
super(new RawLocalFileSystemExtn());
@@ -379,4 +410,27 @@ public class TestFsShellReturnCode {
return stat;
}
}
+
+ static class MyFsShell extends FsShell {
+ protected void registerCommands(CommandFactory factory) {
+ factory.addClass(InterruptCommand.class, "-testInterrupt");
+ }
+ }
+
+ static class InterruptCommand extends FsCommand {
+ static int processed = 0;
+ InterruptCommand() {
+ processed = 0;
+ setRecursive(true);
+ }
+ @Override
+ protected void processPath(PathData item) throws IOException {
+ System.out.println("processing: "+item);
+ processed++;
+ if (item.stat.isFile()) {
+ System.out.println("throw interrupt");
+ throw new InterruptedIOException();
+ }
+ }
+ }
}