Skip to content

Commit e6a1038

Browse files
committed
YARN-11709. NodeManager should be shut down or blacklisted when it cannot run program /var/lib/yarn-ce/bin/container-executor
1 parent 9209309 commit e6a1038

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutorWithMocks.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import static org.junit.Assert.assertEquals;
2424
import static org.junit.Assert.assertNotEquals;
2525
import static org.junit.Assert.assertTrue;
26-
import static org.junit.Assert.fail;
2726
import static org.mockito.ArgumentMatchers.any;
2827
import static org.mockito.ArgumentMatchers.anyBoolean;
2928
import static org.mockito.Mockito.doAnswer;
29+
import static org.mockito.Mockito.doNothing;
3030
import static org.mockito.Mockito.doThrow;
3131
import static org.mockito.Mockito.mock;
3232
import static org.mockito.Mockito.spy;
@@ -347,7 +347,8 @@ public void testStartLocalizer() throws IOException {
347347

348348
@Test
349349
public void testContainerLaunchError()
350-
throws IOException, ContainerExecutionException, URISyntaxException, IllegalAccessException {
350+
throws IOException, ContainerExecutionException, URISyntaxException, IllegalAccessException,
351+
NoSuchFieldException {
351352

352353
final String[] expecetedMessage = {"badcommand", "Exit code: 24"};
353354
final String[] executor = {
@@ -393,15 +394,10 @@ public Object answer(InvocationOnMock invocationOnMock)
393394
NodeManager nodeManager = new NodeManager();
394395
NodeManager.NMContext nmContext =
395396
nodeManager.createNMContext(null, null, null, false, conf);
396-
try{
397-
Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext");
398-
LceNmContext.setAccessible(true);
399-
LceNmContext.set(mockExec, nmContext);
400-
}catch(NoSuchFieldException e){
401-
fail("Could not find the 'nmContext' field in the LinuxContainerExecution class "
402-
+ "when attempted to set it using reflection.");
403-
};
404-
397+
Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext");
398+
LceNmContext.setAccessible(true);
399+
LceNmContext.set(mockExec, nmContext);
400+
405401
String appSubmitter = "nobody";
406402
String cmd = String
407403
.valueOf(PrivilegedOperation.RunAsUserCommand.LAUNCH_CONTAINER.
@@ -616,15 +612,30 @@ public void testNoExitCodeFromPrivilegedOperation() throws Exception {
616612
LinuxContainerRuntime runtime = new DefaultLinuxContainerRuntime(
617613
spyPrivilegedExecutor);
618614
runtime.initialize(conf, null);
619-
mockExec = new LinuxContainerExecutor(runtime);
620-
mockExec.setConf(conf);
621615
LinuxContainerExecutor lce = new LinuxContainerExecutor(runtime) {
622616
@Override
623617
protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() {
624618
return spyPrivilegedExecutor;
625619
}
626620
};
627621
lce.setConf(conf);
622+
623+
//set the private nmContext field without initing the LinuxContainerExecutor
624+
NodeManager nodeManager = new NodeManager();
625+
NodeManager.NMContext nmContext =
626+
nodeManager.createNMContext(null, null, null, false, conf);
627+
NodeManager.NMContext spyNmContext = spy(nmContext);
628+
629+
//initialize a mock NodeStatusUpdater
630+
NodeStatusUpdaterImpl nodeStatusUpdater = mock(NodeStatusUpdaterImpl.class);
631+
nmContext.setNodeStatusUpdater(nodeStatusUpdater);
632+
//imitate a void method call on the NodeStatusUpdater when setting NM unhealthy.
633+
doNothing().when(nodeStatusUpdater).reportException(any());
634+
635+
Field LceNmContext = LinuxContainerExecutor.class.getDeclaredField("nmContext");
636+
LceNmContext.setAccessible(true);
637+
LceNmContext.set(lce, nmContext);
638+
628639
InetSocketAddress address = InetSocketAddress.createUnresolved(
629640
"localhost", 8040);
630641
Path nmPrivateCTokensPath= new Path("file:///bin/nmPrivateCTokensPath");
@@ -687,6 +698,9 @@ protected PrivilegedOperationExecutor getPrivilegedOperationExecutor() {
687698
assertTrue("Unexpected exception " + e,
688699
e.getMessage().contains("exit code"));
689700
}
701+
702+
//verify that the NM was set unhealthy on PrivilegedOperationException
703+
verify(nodeStatusUpdater, times(1)).reportException( any() );
690704
}
691705

692706
@Test

0 commit comments

Comments
 (0)