YARN-5607. Document TestContainerResourceUsage#waitForContainerCompletion. Contributed by Susheel Gupta

This commit is contained in:
Szilard Nemeth 2023-01-25 15:13:24 +01:00
parent 8eda456d37
commit 29f2230cb6
2 changed files with 27 additions and 16 deletions

View File

@ -1011,6 +1011,31 @@ public void waitForAppRemovedFromScheduler(ApplicationId appId)
LOG.info("app is removed from scheduler, " + appId);
}
/**
* Wait until a container has reached a completion state.
* The timeout is 20 seconds.
* @param nm A mock nodemanager
* @param rm A mock resourcemanager
* @param amContainerId The id of an am container
* @param container A container
* @throws Exception
* if interrupted while waiting for the completion transition
* or an unexpected error while MockNM is hearbeating.
*/
public static 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 void drainEventsImplicitly() {
if (!disableDrainEventsImplicitly) {
drainEvents();

View File

@ -348,7 +348,7 @@ private void amRestartTests(boolean keepRunningContainers)
// If keepRunningContainers is false, all live containers should now
// be completed. Calculate the resource usage metrics for all of them.
for (RMContainer c : rmContainers) {
waitforContainerCompletion(rm, nm, amContainerId, c);
MockRM.waitForContainerCompletion(rm, nm, amContainerId, c);
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
memorySeconds += ru.getMemorySeconds();
vcoreSeconds += ru.getVcoreSeconds();
@ -400,7 +400,7 @@ private void amRestartTests(boolean keepRunningContainers)
// Calculate container usage metrics for second attempt.
for (RMContainer c : rmContainers) {
waitforContainerCompletion(rm, nm, amContainerId, c);
MockRM.waitForContainerCompletion(rm, nm, amContainerId, c);
AggregateAppResourceUsage ru = calculateContainerResourceMetrics(c);
memorySeconds += ru.getMemorySeconds();
vcoreSeconds += ru.getVcoreSeconds();
@ -417,20 +417,6 @@ private void amRestartTests(boolean keepRunningContainers)
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(
RMContainer rmContainer) {
Resource resource = rmContainer.getContainer().getResource();