瀏覽代碼

YARN-9072. Send exit command to terminate docker exec on connection close. Contributed by Eric Yang

Billie Rinaldi 6 年之前
父節點
當前提交
c5c73182e5

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerShellWebSocket.java

@@ -113,6 +113,7 @@ public class ContainerShellWebSocket {
           .fromString(cId));
       if (!checkAuthorization(session, container)) {
         session.close(1008, "Forbidden");
+        return;
       }
       LOG.info(session.getRemoteAddress().getHostString() + " connected!");
       LOG.info(
@@ -135,6 +136,9 @@ public class ContainerShellWebSocket {
   public void onClose(Session session, int status, String reason) {
     try {
       LOG.info(session.getRemoteAddress().getHostString() + " closed!");
+      String exit = "exit\r\n";
+      pair.out.write(exit.getBytes(Charset.forName("UTF-8")));
+      pair.out.flush();
       pair.in.close();
       pair.out.close();
     } catch (IOException e) {

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/webapp/TestNMWebTerminal.java

@@ -48,7 +48,7 @@ import com.sun.jersey.api.client.WebResource.Builder;
 public class TestNMWebTerminal {
   private static final File TESTROOTDIR = new File("target",
       TestNMWebServer.class.getSimpleName());
-  private static File TESTLOGDIR = new File("target",
+  private static final File TESTLOGDIR = new File("target",
       TestNMWebServer.class.getSimpleName() + "LogDir");
   private NodeHealthCheckerService healthChecker;
   private WebServer server;