YARN-382. SchedulerUtils improve way normalizeRequest sets the resource capabilities (Zhijie Shen via bikas)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1463653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bikas Saha 2013-04-02 18:07:07 +00:00
parent 9c26c28c87
commit d40b154d27
5 changed files with 18 additions and 27 deletions

View File

@ -176,6 +176,9 @@ Release 2.0.5-beta - UNRELEASED
YARN-516. Fix failure in TestContainerLocalizer caused by HADOOP-9357. YARN-516. Fix failure in TestContainerLocalizer caused by HADOOP-9357.
(Andrew Wang via vinodkv) (Andrew Wang via vinodkv)
YARN-382. SchedulerUtils improve way normalizeRequest sets the resource
capabilities. (Zhijie Shen via bikas)
Release 2.0.4-alpha - UNRELEASED Release 2.0.4-alpha - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -771,6 +771,11 @@ public class RMAppAttemptImpl implements RMAppAttempt, Recoverable {
// Set the masterContainer // Set the masterContainer
appAttempt.setMasterContainer(amContainerAllocation.getContainers().get( appAttempt.setMasterContainer(amContainerAllocation.getContainers().get(
0)); 0));
// Updating CLC's resource is no longer necessary once YARN-486 is
// completed, because nothing from Container to CLC will be copied into
// CLC then.
appAttempt.getSubmissionContext().getAMContainerSpec().setResource(
appAttempt.getMasterContainer().getResource());
RMStateStore store = appAttempt.rmContext.getStateStore(); RMStateStore store = appAttempt.rmContext.getStateStore();
appAttempt.storeAttempt(store); appAttempt.storeAttempt(store);

View File

@ -108,8 +108,7 @@ public class SchedulerUtils {
Resource normalized = Resource normalized =
Resources.normalize( Resources.normalize(
resourceCalculator, ask.getCapability(), minimumResource); resourceCalculator, ask.getCapability(), minimumResource);
ask.getCapability().setMemory(normalized.getMemory()); ask.setCapability(normalized);
ask.getCapability().setVirtualCores(normalized.getVirtualCores());
} }
} }

View File

@ -202,9 +202,10 @@ public class TestRMAppAttemptTransitions {
submissionContext = mock(ApplicationSubmissionContext.class); submissionContext = mock(ApplicationSubmissionContext.class);
when(submissionContext.getUser()).thenReturn(user); when(submissionContext.getUser()).thenReturn(user);
when(submissionContext.getQueue()).thenReturn(queue); when(submissionContext.getQueue()).thenReturn(queue);
ContainerLaunchContext amContainerSpec = mock(ContainerLaunchContext.class); Resource resource = BuilderUtils.newResource(1536, 1);
Resource resource = mock(Resource.class); ContainerLaunchContext amContainerSpec =
when(amContainerSpec.getResource()).thenReturn(resource); BuilderUtils.newContainerLaunchContext(null, user, resource, null, null,
null, null, null, null);
when(submissionContext.getAMContainerSpec()).thenReturn(amContainerSpec); when(submissionContext.getAMContainerSpec()).thenReturn(amContainerSpec);
unmanagedAM = false; unmanagedAM = false;
@ -469,8 +470,10 @@ public class TestRMAppAttemptTransitions {
// Mock the allocation of AM container // Mock the allocation of AM container
Container container = mock(Container.class); Container container = mock(Container.class);
Resource resource = BuilderUtils.newResource(2048, 1);
when(container.getId()).thenReturn( when(container.getId()).thenReturn(
BuilderUtils.newContainerId(applicationAttempt.getAppAttemptId(), 1)); BuilderUtils.newContainerId(applicationAttempt.getAppAttemptId(), 1));
when(container.getResource()).thenReturn(resource);
Allocation allocation = mock(Allocation.class); Allocation allocation = mock(Allocation.class);
when(allocation.getContainers()). when(allocation.getContainers()).
thenReturn(Collections.singletonList(container)); thenReturn(Collections.singletonList(container));
@ -491,6 +494,9 @@ public class TestRMAppAttemptTransitions {
applicationAttempt.handle( applicationAttempt.handle(
new RMAppAttemptStoredEvent( new RMAppAttemptStoredEvent(
applicationAttempt.getAppAttemptId(), null)); applicationAttempt.getAppAttemptId(), null));
assertEquals(resource,
applicationAttempt.getSubmissionContext()
.getAMContainerSpec().getResource());
testAppAttemptAllocatedState(container); testAppAttemptAllocatedState(container);

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.yarn.server.resourcemanager.scheduler; package org.apache.hadoop.yarn.server.resourcemanager.scheduler;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.api.records.ResourceRequest; import org.apache.hadoop.yarn.api.records.ResourceRequest;
@ -43,35 +42,23 @@ public class TestSchedulerUtils {
// case negative memory // case negative memory
ask.setCapability(Resources.createResource(-1024)); ask.setCapability(Resources.createResource(-1024));
Resource before = ask.getCapability();
SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource); SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource);
Resource after = ask.getCapability();
assertEquals(minMemory, ask.getCapability().getMemory()); assertEquals(minMemory, ask.getCapability().getMemory());
assertTrue(before == after);
// case zero memory // case zero memory
ask.setCapability(Resources.createResource(0)); ask.setCapability(Resources.createResource(0));
before = ask.getCapability();
SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource); SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource);
after = ask.getCapability();
assertEquals(minMemory, ask.getCapability().getMemory()); assertEquals(minMemory, ask.getCapability().getMemory());
assertTrue(before == after);
// case memory is a multiple of minMemory // case memory is a multiple of minMemory
ask.setCapability(Resources.createResource(2 * minMemory)); ask.setCapability(Resources.createResource(2 * minMemory));
before = ask.getCapability();
SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource); SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource);
after = ask.getCapability();
assertEquals(2 * minMemory, ask.getCapability().getMemory()); assertEquals(2 * minMemory, ask.getCapability().getMemory());
assertTrue(before == after);
// case memory is not a multiple of minMemory // case memory is not a multiple of minMemory
ask.setCapability(Resources.createResource(minMemory + 10)); ask.setCapability(Resources.createResource(minMemory + 10));
before = ask.getCapability();
SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource); SchedulerUtils.normalizeRequest(ask, resourceCalculator, null, minResource);
after = ask.getCapability();
assertEquals(2 * minMemory, ask.getCapability().getMemory()); assertEquals(2 * minMemory, ask.getCapability().getMemory());
assertTrue(before == after);
} }
@ -86,33 +73,24 @@ public class TestSchedulerUtils {
// case negative memory/vcores // case negative memory/vcores
ask.setCapability(Resources.createResource(-1024, -1)); ask.setCapability(Resources.createResource(-1024, -1));
Resource before = ask.getCapability();
SchedulerUtils.normalizeRequest( SchedulerUtils.normalizeRequest(
ask, resourceCalculator, clusterResource, minResource); ask, resourceCalculator, clusterResource, minResource);
Resource after = ask.getCapability();
assertEquals(minResource, ask.getCapability()); assertEquals(minResource, ask.getCapability());
assertTrue(before == after);
// case zero memory/vcores // case zero memory/vcores
ask.setCapability(Resources.createResource(0, 0)); ask.setCapability(Resources.createResource(0, 0));
before = ask.getCapability();
SchedulerUtils.normalizeRequest( SchedulerUtils.normalizeRequest(
ask, resourceCalculator, clusterResource, minResource); ask, resourceCalculator, clusterResource, minResource);
after = ask.getCapability();
assertEquals(minResource, ask.getCapability()); assertEquals(minResource, ask.getCapability());
assertEquals(1, ask.getCapability().getVirtualCores()); assertEquals(1, ask.getCapability().getVirtualCores());
assertEquals(1024, ask.getCapability().getMemory()); assertEquals(1024, ask.getCapability().getMemory());
assertTrue(before == after);
// case non-zero memory & zero cores // case non-zero memory & zero cores
ask.setCapability(Resources.createResource(1536, 0)); ask.setCapability(Resources.createResource(1536, 0));
before = ask.getCapability();
SchedulerUtils.normalizeRequest( SchedulerUtils.normalizeRequest(
ask, resourceCalculator, clusterResource, minResource); ask, resourceCalculator, clusterResource, minResource);
after = ask.getCapability();
assertEquals(Resources.createResource(2048, 1), ask.getCapability()); assertEquals(Resources.createResource(2048, 1), ask.getCapability());
assertEquals(1, ask.getCapability().getVirtualCores()); assertEquals(1, ask.getCapability().getVirtualCores());
assertEquals(2048, ask.getCapability().getMemory()); assertEquals(2048, ask.getCapability().getMemory());
assertTrue(before == after);
} }
} }