diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 11e37eb4a0..1c4926f245 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -49,6 +49,8 @@ Trunk (unreleased changes) Move the support for multiple protocols to lower layer so that Writable, PB and Avro can all use it (Sanjay) + MAPREDUCE-2944. Improve checking of input for JobClient.displayTasks() (XieXianshan via harsh) + BUG FIXES MAPREDUCE-3349. Log rack-name in JobHistory for unsuccessful tasks. (Devaraj K and Amar Kamat via amarrk) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java index fa3d799fe7..be9981a592 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/JobClient.java @@ -723,6 +723,8 @@ public TaskReport[] getReduceTaskReports(String jobId) throws IOException { * @param type the type of the task (map/reduce/setup/cleanup) * @param state the state of the task * (pending/running/completed/failed/killed) + * @throws IOException when there is an error communicating with the master + * @throws IllegalArgumentException if an invalid type/state is passed */ public void displayTasks(final JobID jobId, String type, String state) throws IOException { diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java index f7ac9c40a6..c42456aafc 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/tools/CLI.java @@ -20,6 +20,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.HashSet; +import java.util.Arrays; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -56,6 +59,10 @@ public class CLI extends Configured implements Tool { private static final Log LOG = LogFactory.getLog(CLI.class); protected Cluster cluster; + private final Set taskTypes = new HashSet( + Arrays.asList("map", "reduce", "setup", "cleanup")); + private final Set taskStates = new HashSet( + Arrays.asList("pending", "running", "completed", "failed", "killed")); public CLI() { } @@ -545,9 +552,21 @@ private void printTaskAttempts(TaskReport report) { * @param type the type of the task (map/reduce/setup/cleanup) * @param state the state of the task * (pending/running/completed/failed/killed) + * @throws IOException when there is an error communicating with the master + * @throws InterruptedException + * @throws IllegalArgumentException if an invalid type/state is passed */ protected void displayTasks(Job job, String type, String state) throws IOException, InterruptedException { + if (!taskTypes.contains(type)) { + throw new IllegalArgumentException("Invalid type: " + type + + ". Valid types for task are: map, reduce, setup, cleanup."); + } + if (!taskStates.contains(state)) { + throw new java.lang.IllegalArgumentException("Invalid state: " + state + + ". Valid states for task are: pending, running, completed, failed, killed."); + } + TaskReport[] reports = job.getTaskReports(TaskType.valueOf(type)); for (TaskReport report : reports) { TIPStatus status = report.getCurrentStatus();