From 52fe4e6be94e96dc214dac66a36718ceedf53f42 Mon Sep 17 00:00:00 2001 From: Jason Darrell Lowe Date: Tue, 18 Jun 2013 20:25:00 +0000 Subject: [PATCH] MAPREDUCE-5316. job -list-attempt-ids command does not handle illegal task-state. Contributed by Ashwin Shankar git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1494285 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 30 +++++++++++++++++++ .../apache/hadoop/mapreduce/tools/CLI.java | 21 ++++++------- .../hadoop/mapreduce/tools/TestCLI.java | 18 +++++++++-- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 5de6fa51c1c..b5c53d0dee4 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -137,6 +137,33 @@ Trunk (Unreleased) MAPREDUCE-5191. TestQueue#testQueue fails with timeout on Windows. (Ivan Mitic via hitesh) +Release 2.3.0 - UNRELEASED + + INCOMPATIBLE CHANGES + + NEW FEATURES + + IMPROVEMENTS + + OPTIMIZATIONS + + BUG FIXES + + MAPREDUCE-5316. job -list-attempt-ids command does not handle illegal + task-state (Ashwin Shankar via jlowe) + +Release 2.2.0 - UNRELEASED + + INCOMPATIBLE CHANGES + + NEW FEATURES + + IMPROVEMENTS + + OPTIMIZATIONS + + BUG FIXES + Release 2.1.0-beta - UNRELEASED INCOMPATIBLE CHANGES @@ -1149,6 +1176,9 @@ Release 0.23.9 - UNRELEASED MAPREDUCE-4019. -list-attempt-ids is not working (Ashwin Shankar, Devaraj K, and B Anil Kumar via jlowe) + MAPREDUCE-5316. job -list-attempt-ids command does not handle illegal + task-state (Ashwin Shankar via jlowe) + Release 0.23.8 - 2013-06-05 INCOMPATIBLE CHANGES 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 0d6a68ae331..4a1398b0c33 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 @@ -223,7 +223,12 @@ public class CLI extends Configured implements Tool { taskState = argv[3]; displayTasks = true; if (!taskTypes.contains(taskType.toUpperCase())) { - System.out.println("Error: Invalid task-type: "+taskType); + System.out.println("Error: Invalid task-type: " + taskType); + displayUsage(cmd); + return exitCode; + } + if (!taskStates.contains(taskState.toLowerCase())) { + System.out.println("Error: Invalid task-state: " + taskState); displayUsage(cmd); return exitCode; } @@ -572,19 +577,15 @@ public class CLI extends Configured implements Tool { protected void displayTasks(Job job, String type, String state) throws IOException, InterruptedException { - if (!taskStates.contains(state)) { - throw new java.lang.IllegalArgumentException("Invalid state: " + state + - ". Valid states for task are: pending, running, completed, failed, killed."); - } TaskReport[] reports=null; reports = job.getTaskReports(TaskType.valueOf(type.toUpperCase())); for (TaskReport report : reports) { TIPStatus status = report.getCurrentStatus(); - if ((state.equals("pending") && status ==TIPStatus.PENDING) || - (state.equals("running") && status ==TIPStatus.RUNNING) || - (state.equals("completed") && status == TIPStatus.COMPLETE) || - (state.equals("failed") && status == TIPStatus.FAILED) || - (state.equals("killed") && status == TIPStatus.KILLED)) { + if ((state.equalsIgnoreCase("pending") && status ==TIPStatus.PENDING) || + (state.equalsIgnoreCase("running") && status ==TIPStatus.RUNNING) || + (state.equalsIgnoreCase("completed") && status == TIPStatus.COMPLETE) || + (state.equalsIgnoreCase("failed") && status == TIPStatus.FAILED) || + (state.equalsIgnoreCase("killed") && status == TIPStatus.KILLED)) { printTaskAttempts(report); } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java index 8693defd1a2..0060e8579b7 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/tools/TestCLI.java @@ -58,13 +58,19 @@ public class TestCLI { int retCode_REDUCE = cli.run(new String[] { "-list-attempt-ids", jobIdStr, "REDUCE", "running" }); + int retCode_completed = cli.run(new String[] { "-list-attempt-ids", + jobIdStr, "REDUCE", "completed" }); + assertEquals("MAP is a valid input,exit code should be 0", 0, retCode_MAP); assertEquals("map is a valid input,exit code should be 0", 0, retCode_map); assertEquals("REDUCE is a valid input,exit code should be 0", 0, retCode_REDUCE); + assertEquals( + "REDUCE and completed are a valid inputs to -list-attempt-ids,exit code should be 0", + 0, retCode_completed); verify(job, times(2)).getTaskReports(TaskType.MAP); - verify(job, times(1)).getTaskReports(TaskType.REDUCE); + verify(job, times(2)).getTaskReports(TaskType.REDUCE); } @Test @@ -79,13 +85,19 @@ public class TestCLI { int retCode_JOB_SETUP = cli.run(new String[] { "-list-attempt-ids", jobIdStr, "JOB_SETUP", "running" }); + int retCode_JOB_CLEANUP = cli.run(new String[] { "-list-attempt-ids", jobIdStr, "JOB_CLEANUP", "running" }); - assertEquals("JOB_SETUP is a invalid input,exit code should be -1", -1, + int retCode_invalidTaskState = cli.run(new String[] { "-list-attempt-ids", + jobIdStr, "REDUCE", "complete" }); + + assertEquals("JOB_SETUP is an invalid input,exit code should be -1", -1, retCode_JOB_SETUP); - assertEquals("JOB_CLEANUP is a invalid input,exit code should be -1", -1, + assertEquals("JOB_CLEANUP is an invalid input,exit code should be -1", -1, retCode_JOB_CLEANUP); + assertEquals("complete is an invalid input,exit code should be -1", -1, + retCode_invalidTaskState); }