|
46 | 46 | import org.apache.hadoop.yarn.api.records.ExecutionType; |
47 | 47 | import org.apache.hadoop.yarn.api.records.NodeId; |
48 | 48 | import org.apache.hadoop.yarn.api.records.NodeState; |
| 49 | +import org.apache.hadoop.yarn.api.records.Priority; |
49 | 50 | import org.apache.hadoop.yarn.api.records.Resource; |
50 | 51 | import org.apache.hadoop.yarn.api.records.ResourceOption; |
51 | 52 | import org.apache.hadoop.yarn.api.records.ResourceUtilization; |
52 | 53 | import org.apache.hadoop.yarn.event.EventHandler; |
53 | 54 | import org.apache.hadoop.yarn.event.InlineDispatcher; |
| 55 | +import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; |
| 56 | +import org.apache.hadoop.yarn.server.api.protocolrecords.NMContainerStatus; |
54 | 57 | import org.apache.hadoop.yarn.server.api.protocolrecords.NodeHeartbeatResponse; |
55 | 58 | import org.apache.hadoop.yarn.server.api.records.NodeHealthStatus; |
56 | 59 | import org.apache.hadoop.yarn.server.api.records.NodeStatus; |
@@ -251,6 +254,14 @@ private static ContainerStatus getMockContainerStatus( |
251 | 254 | return containerStatus; |
252 | 255 | } |
253 | 256 |
|
| 257 | + private static NMContainerStatus createNMContainerStatus( |
| 258 | + final ContainerId containerId, final ExecutionType executionType, |
| 259 | + final ContainerState containerState, final Resource capability) { |
| 260 | + return NMContainerStatus.newInstance(containerId, 0, containerState, |
| 261 | + capability, "", 0, Priority.newInstance(0), 0, |
| 262 | + CommonNodeLabelsManager.NO_LABEL, executionType, -1); |
| 263 | + } |
| 264 | + |
254 | 265 | @Test (timeout = 5000) |
255 | 266 | public void testExpiredContainer() { |
256 | 267 | NodeStatus mockNodeStatus = createMockNodeStatus(); |
@@ -375,6 +386,68 @@ public void testContainerUpdate() throws InterruptedException{ |
375 | 386 | .getContainerId()); |
376 | 387 | } |
377 | 388 |
|
| 389 | + /** |
| 390 | + * Tests that allocated resources are counted correctly on new nodes |
| 391 | + * that are added to the cluster. |
| 392 | + */ |
| 393 | + @Test |
| 394 | + public void testAddWithAllocatedContainers() { |
| 395 | + NodeStatus mockNodeStatus = createMockNodeStatus(); |
| 396 | + RMNodeImpl node = getNewNode(); |
| 397 | + ApplicationId app0 = BuilderUtils.newApplicationId(0, 0); |
| 398 | + |
| 399 | + // Independently computed expected allocated resource to verify against |
| 400 | + final Resource expectedResource = Resource.newInstance(Resources.none()); |
| 401 | + |
| 402 | + // Guaranteed containers |
| 403 | + final ContainerId newContainerId = BuilderUtils.newContainerId( |
| 404 | + BuilderUtils.newApplicationAttemptId(app0, 0), 0); |
| 405 | + final Resource newContainerCapability = |
| 406 | + Resource.newInstance(100, 1); |
| 407 | + Resources.addTo(expectedResource, newContainerCapability); |
| 408 | + final NMContainerStatus newContainerStatus = createNMContainerStatus( |
| 409 | + newContainerId, ExecutionType.GUARANTEED, |
| 410 | + ContainerState.NEW, newContainerCapability); |
| 411 | + |
| 412 | + final ContainerId runningContainerId = BuilderUtils.newContainerId( |
| 413 | + BuilderUtils.newApplicationAttemptId(app0, 0), 1); |
| 414 | + final Resource runningContainerCapability = |
| 415 | + Resource.newInstance(200, 2); |
| 416 | + Resources.addTo(expectedResource, runningContainerCapability); |
| 417 | + final NMContainerStatus runningContainerStatus = createNMContainerStatus( |
| 418 | + runningContainerId, ExecutionType.GUARANTEED, |
| 419 | + ContainerState.RUNNING, runningContainerCapability); |
| 420 | + |
| 421 | + // Opportunistic containers |
| 422 | + final ContainerId newOppContainerId = BuilderUtils.newContainerId( |
| 423 | + BuilderUtils.newApplicationAttemptId(app0, 0), 2); |
| 424 | + final Resource newOppContainerCapability = |
| 425 | + Resource.newInstance(300, 3); |
| 426 | + Resources.addTo(expectedResource, newOppContainerCapability); |
| 427 | + final NMContainerStatus newOppContainerStatus = createNMContainerStatus( |
| 428 | + newOppContainerId, ExecutionType.OPPORTUNISTIC, |
| 429 | + ContainerState.NEW, newOppContainerCapability); |
| 430 | + |
| 431 | + final ContainerId runningOppContainerId = BuilderUtils.newContainerId( |
| 432 | + BuilderUtils.newApplicationAttemptId(app0, 0), 3); |
| 433 | + final Resource runningOppContainerCapability = |
| 434 | + Resource.newInstance(400, 4); |
| 435 | + Resources.addTo(expectedResource, runningOppContainerCapability); |
| 436 | + final NMContainerStatus runningOppContainerStatus = createNMContainerStatus( |
| 437 | + runningOppContainerId, ExecutionType.OPPORTUNISTIC, |
| 438 | + ContainerState.RUNNING, runningOppContainerCapability); |
| 439 | + |
| 440 | + node.handle(new RMNodeStartedEvent(node.getNodeID(), |
| 441 | + Arrays.asList(newContainerStatus, runningContainerStatus, |
| 442 | + newOppContainerStatus, runningOppContainerStatus), |
| 443 | + null, mockNodeStatus)); |
| 444 | + Assert.assertEquals(NodeState.RUNNING, node.getState()); |
| 445 | + Assert.assertNotNull(nodesListManagerEvent); |
| 446 | + Assert.assertEquals(NodesListManagerEventType.NODE_USABLE, |
| 447 | + nodesListManagerEvent.getType()); |
| 448 | + Assert.assertEquals(expectedResource, node.getAllocatedContainerResource()); |
| 449 | + } |
| 450 | + |
378 | 451 | /** |
379 | 452 | * Tests that allocated container resources are counted correctly in |
380 | 453 | * {@link org.apache.hadoop.yarn.server.resourcemanager.rmnode.RMNode} |
|
0 commit comments