YARN-5024. TestContainerResourceUsage#testUsageAfterAMRestartWithMultipleContainers random failure. Contributed by Bibin A Chundatt
(cherry picked from commit 28bd63e92b
)
This commit is contained in:
parent
396d222d7a
commit
b9567b89b9
|
@ -309,7 +309,7 @@ public class TestContainerResourceUsage {
|
||||||
nm.nodeHeartbeat(am0.getApplicationAttemptId(),
|
nm.nodeHeartbeat(am0.getApplicationAttemptId(),
|
||||||
amContainerId.getContainerId(), ContainerState.COMPLETE);
|
amContainerId.getContainerId(), ContainerState.COMPLETE);
|
||||||
rm.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.FAILED);
|
rm.waitForState(am0.getApplicationAttemptId(), RMAppAttemptState.FAILED);
|
||||||
|
rm.drainEvents();
|
||||||
long memorySeconds = 0;
|
long memorySeconds = 0;
|
||||||
long vcoreSeconds = 0;
|
long vcoreSeconds = 0;
|
||||||
|
|
||||||
|
@ -332,6 +332,7 @@ public class TestContainerResourceUsage {
|
||||||
// If keepRunningContainers is false, all live containers should now
|
// If keepRunningContainers is false, all live containers should now
|
||||||
// be completed. Calculate the resource usage metrics for all of them.
|
// be completed. Calculate the resource usage metrics for all of them.
|
||||||
for (RMContainer c : rmContainers) {
|
for (RMContainer c : rmContainers) {
|
||||||
|
waitforContainerCompletion(rm, nm, amContainerId, c);
|
||||||
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
|
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
|
||||||
memorySeconds += ru.getMemorySeconds();
|
memorySeconds += ru.getMemorySeconds();
|
||||||
vcoreSeconds += ru.getVcoreSeconds();
|
vcoreSeconds += ru.getVcoreSeconds();
|
||||||
|
@ -346,13 +347,11 @@ public class TestContainerResourceUsage {
|
||||||
Assert.assertFalse(attempt2.getAppAttemptId()
|
Assert.assertFalse(attempt2.getAppAttemptId()
|
||||||
.equals(am0.getApplicationAttemptId()));
|
.equals(am0.getApplicationAttemptId()));
|
||||||
|
|
||||||
// launch the new AM
|
rm.waitForState(attempt2.getAppAttemptId(), RMAppAttemptState.SCHEDULED);
|
||||||
//TODO explore a better way than sleeping for a while (YARN-4929)
|
|
||||||
Thread.sleep(1000);
|
|
||||||
nm.nodeHeartbeat(true);
|
nm.nodeHeartbeat(true);
|
||||||
MockAM am1 = rm.sendAMLaunched(attempt2.getAppAttemptId());
|
MockAM am1 = rm.sendAMLaunched(attempt2.getAppAttemptId());
|
||||||
am1.registerAppAttempt();
|
am1.registerAppAttempt();
|
||||||
|
rm.waitForState(am1.getApplicationAttemptId(), RMAppAttemptState.RUNNING);
|
||||||
// allocate NUM_CONTAINERS containers
|
// allocate NUM_CONTAINERS containers
|
||||||
am1.allocate("127.0.0.1", 1024, NUM_CONTAINERS,
|
am1.allocate("127.0.0.1", 1024, NUM_CONTAINERS,
|
||||||
new ArrayList<ContainerId>());
|
new ArrayList<ContainerId>());
|
||||||
|
@ -385,6 +384,7 @@ public class TestContainerResourceUsage {
|
||||||
|
|
||||||
// Calculate container usage metrics for second attempt.
|
// Calculate container usage metrics for second attempt.
|
||||||
for (RMContainer c : rmContainers) {
|
for (RMContainer c : rmContainers) {
|
||||||
|
waitforContainerCompletion(rm, nm, amContainerId, c);
|
||||||
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
|
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
|
||||||
memorySeconds += ru.getMemorySeconds();
|
memorySeconds += ru.getMemorySeconds();
|
||||||
vcoreSeconds += ru.getVcoreSeconds();
|
vcoreSeconds += ru.getVcoreSeconds();
|
||||||
|
@ -401,6 +401,20 @@ public class TestContainerResourceUsage {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void waitforContainerCompletion(MockRM rm, MockNM nm,
|
||||||
|
ContainerId amContainerId, RMContainer container) throws Exception {
|
||||||
|
ContainerId containerId = container.getContainerId();
|
||||||
|
if (null != rm.scheduler.getRMContainer(containerId)) {
|
||||||
|
if (containerId.equals(amContainerId)) {
|
||||||
|
rm.waitForState(nm, containerId, RMContainerState.COMPLETED);
|
||||||
|
} else {
|
||||||
|
rm.waitForState(nm, containerId, RMContainerState.KILLED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rm.drainEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AggregateAppResourceUsage calculateContainerResourceMetrics(
|
private AggregateAppResourceUsage calculateContainerResourceMetrics(
|
||||||
RMContainer rmContainer) {
|
RMContainer rmContainer) {
|
||||||
Resource resource = rmContainer.getContainer().getResource();
|
Resource resource = rmContainer.getContainer().getResource();
|
||||||
|
|
Loading…
Reference in New Issue