From 4167275e89e8cc48077706c53e36d400664e744e Mon Sep 17 00:00:00 2001 From: bibinchundatt Date: Mon, 22 Oct 2018 15:59:14 +0530 Subject: [PATCH] MAPREDUCE-7151. RMContainerAllocator#handleJobPriorityChange expects application_priority always. Contributed by Bilwa S T. (cherry picked from commit 74a5e683fe65ee624a094de77940a42777ed7a26) --- .../mapreduce/v2/app/rm/RMContainerAllocator.java | 14 ++++++++------ .../v2/app/rm/TestRMContainerAllocator.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java index 9d030b84e98..e459cb52f05 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/rm/RMContainerAllocator.java @@ -1020,12 +1020,14 @@ public class RMContainerAllocator extends RMContainerRequestor } } - private void handleJobPriorityChange(AllocateResponse response) { - Priority priorityFromResponse = Priority.newInstance(response - .getApplicationPriority().getPriority()); - - // Update the job priority to Job directly. - getJob().setJobPriority(priorityFromResponse); + void handleJobPriorityChange(AllocateResponse response) { + Priority applicationPriority = response.getApplicationPriority(); + if (null != applicationPriority) { + Priority priorityFromResponse = Priority + .newInstance(applicationPriority.getPriority()); + // Update the job priority to Job directly. + getJob().setJobPriority(priorityFromResponse); + } } @Private diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java index 427e6ea228f..ad00bd651bd 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/rm/TestRMContainerAllocator.java @@ -2160,6 +2160,20 @@ public class TestRMContainerAllocator { } } + @Test + public void testIfApplicationPriorityIsNotSet() { + Job mockJob = mock(Job.class); + RMCommunicator communicator = mock(RMCommunicator.class); + ClientService service = mock(ClientService.class); + AppContext context = mock(AppContext.class); + AMPreemptionPolicy policy = mock(AMPreemptionPolicy.class); + when(communicator.getJob()).thenReturn(mockJob); + RMContainerAllocator allocator = new RMContainerAllocator(service, context, + policy); + AllocateResponse response = Records.newRecord(AllocateResponse.class); + allocator.handleJobPriorityChange(response); + } + @Test public void testReduceScheduling() throws Exception { int totalMaps = 10;