YARN-5725. Test uncaught exception in TestContainersMonitorResourceChange.testContainersResourceChange

when setting IP and host (Contributed by Miklos Szegedi via Daniel Templeton)
This commit is contained in:
Daniel Templeton 2016-11-28 15:16:43 -08:00
parent a2b1ff0257
commit 62b42ef5dd
2 changed files with 36 additions and 16 deletions

View File

@ -536,15 +536,21 @@ private void initializeProcessTrees(
} }
Container container = context.getContainers().get(containerId); Container container = context.getContainers().get(containerId);
String[] ipAndHost = containerExecutor.getIpAndHost(container);
if (ipAndHost != null && ipAndHost[0] != null if (container != null) {
&& ipAndHost[1] != null) { String[] ipAndHost = containerExecutor.getIpAndHost(container);
container.setIpAndHost(ipAndHost);
LOG.info(containerId + "'s ip = " + ipAndHost[0] if ((ipAndHost != null) && (ipAndHost[0] != null) &&
+ ", and hostname = " + ipAndHost[1]); (ipAndHost[1] != null)) {
container.setIpAndHost(ipAndHost);
LOG.info(containerId + "'s ip = " + ipAndHost[0]
+ ", and hostname = " + ipAndHost[1]);
} else {
LOG.info("Can not get both ip and hostname: "
+ Arrays.toString(ipAndHost));
}
} else { } else {
LOG.info("Can not get both ip and hostname: " + Arrays LOG.info(containerId + " is missing. Not setting ip and hostname");
.toString(ipAndHost));
} }
} }
} }
@ -683,11 +689,15 @@ private void reportResourceUsage(ContainerId containerId,
long currentPmemUsage, float cpuUsagePercentPerCore) { long currentPmemUsage, float cpuUsagePercentPerCore) {
ContainerImpl container = ContainerImpl container =
(ContainerImpl) context.getContainers().get(containerId); (ContainerImpl) context.getContainers().get(containerId);
NMTimelinePublisher nmMetricsPublisher = if (container != null) {
container.getNMTimelinePublisher(); NMTimelinePublisher nmMetricsPublisher =
if (nmMetricsPublisher != null) { container.getNMTimelinePublisher();
nmMetricsPublisher.reportContainerResourceUsage(container, if (nmMetricsPublisher != null) {
currentPmemUsage, cpuUsagePercentPerCore); nmMetricsPublisher.reportContainerResourceUsage(container,
currentPmemUsage, cpuUsagePercentPerCore);
}
} else {
LOG.info(containerId + " does not exist to report");
} }
} }

View File

@ -21,6 +21,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -37,6 +38,7 @@
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEvent;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEventType; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerEventType;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitorImpl.ProcessTreeInfo; import org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitorImpl.ProcessTreeInfo;
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerLivenessContext; import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerLivenessContext;
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerSignalContext; import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerSignalContext;
@ -64,6 +66,7 @@ public class TestContainersMonitorResourceChange {
private AsyncDispatcher dispatcher; private AsyncDispatcher dispatcher;
private Context context; private Context context;
private MockContainerEventHandler containerEventHandler; private MockContainerEventHandler containerEventHandler;
private ConcurrentMap<ContainerId, Container> containerMap;
static final int WAIT_MS_PER_LOOP = 20; // 20 milli seconds static final int WAIT_MS_PER_LOOP = 20; // 20 milli seconds
@ -131,8 +134,10 @@ public void setup() {
executor = new MockExecutor(); executor = new MockExecutor();
dispatcher = new AsyncDispatcher(); dispatcher = new AsyncDispatcher();
context = Mockito.mock(Context.class); context = Mockito.mock(Context.class);
Mockito.doReturn(new ConcurrentSkipListMap<ContainerId, Container>()) containerMap = new ConcurrentSkipListMap<>();
.when(context).getContainers(); Container container = Mockito.mock(ContainerImpl.class);
containerMap.put(getContainerId(1), container);
Mockito.doReturn(containerMap).when(context).getContainers();
conf = new Configuration(); conf = new Configuration();
conf.set( conf.set(
YarnConfiguration.NM_CONTAINER_MON_RESOURCE_CALCULATOR, YarnConfiguration.NM_CONTAINER_MON_RESOURCE_CALCULATOR,
@ -181,7 +186,12 @@ public void testContainersResourceChange() throws Exception {
getContainerId(1)).getProcessTree(); getContainerId(1)).getProcessTree();
mockTree.setRssMemorySize(2500L); mockTree.setRssMemorySize(2500L);
// verify that this container is killed // verify that this container is killed
Thread.sleep(200); for (int waitMs = 0; waitMs < 5000; waitMs += 50) {
if (containerEventHandler.isContainerKilled(getContainerId(1))) {
break;
}
Thread.sleep(50);
}
assertTrue(containerEventHandler assertTrue(containerEventHandler
.isContainerKilled(getContainerId(1))); .isContainerKilled(getContainerId(1)));
// create container 2 // create container 2