You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/12/07 05:36:39 UTC

mesos git commit: Waited for the domain socket file in IOSwitchboard::connect.

Repository: mesos
Updated Branches:
  refs/heads/master e8fe8bb6d -> 9da19f5cc


Waited for the domain socket file in IOSwitchboard::connect.

Do not try to connect to the domain socket until the socket file has
been created by the server.

Review: https://reviews.apache.org/r/54472


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9da19f5c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9da19f5c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9da19f5c

Branch: refs/heads/master
Commit: 9da19f5cc7a527a69a29a2d76c16cde8775c1b67
Parents: e8fe8bb
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Dec 6 21:19:32 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Dec 6 21:30:57 2016 -0800

----------------------------------------------------------------------
 .../containerizer/mesos/io/switchboard.cpp      | 37 +++++++++---
 .../containerizer/io_switchboard_tests.cpp      | 61 ++++++++++++++++++++
 2 files changed, 91 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9da19f5c/src/slave/containerizer/mesos/io/switchboard.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/io/switchboard.cpp b/src/slave/containerizer/mesos/io/switchboard.cpp
index c54d64e..4452d5a 100644
--- a/src/slave/containerizer/mesos/io/switchboard.cpp
+++ b/src/slave/containerizer/mesos/io/switchboard.cpp
@@ -29,10 +29,12 @@
 #include <process/future.hpp>
 #include <process/http.hpp>
 #include <process/io.hpp>
+#include <process/limiter.hpp>
 #include <process/loop.hpp>
 #include <process/owned.hpp>
 #include <process/process.hpp>
 #include <process/reap.hpp>
+#include <process/shared.hpp>
 #include <process/subprocess.hpp>
 
 #include <stout/hashmap.hpp>
@@ -74,10 +76,13 @@ using std::string;
 using process::ErrnoFailure;
 using process::Failure;
 using process::Future;
+using process::loop;
 using process::Owned;
 using process::PID;
 using process::Process;
 using process::Promise;
+using process::RateLimiter;
+using process::Shared;
 using process::Subprocess;
 
 using std::list;
@@ -613,9 +618,8 @@ Future<http::Connection> IOSwitchboard::connect(
     return Failure("Not supported in local mode");
   }
 
-  if (!flags.io_switchboard_enable_server) {
-    return Failure("Support for running an io switchboard"
-                   " server was disabled by the agent");
+  if (!infos.contains(containerId)) {
+    return Failure("IO switchboard server was disabled for this container");
   }
 
   // Get the io switchboard address from the `containerId`.
@@ -629,12 +633,31 @@ Future<http::Connection> IOSwitchboard::connect(
 
   if (!address.isSome()) {
     return Failure("Failed to get the io switchboard address"
-                   " " + (address.isError()
-                          ? address.error()
-                          : "No address found"));
+                   ": " + (address.isError() ? address.error() : "Not found"));
   }
 
-  return http::connect(address.get());
+  // Wait for the server to create the domain socket file.
+  Shared<RateLimiter> limiter(new RateLimiter(1, Milliseconds(10)));
+
+  return loop(
+      self(),
+      [=]() {
+        return limiter->acquire();
+      },
+      [=](const Nothing&) {
+        return infos.contains(containerId) && !os::exists(address->path());
+      })
+    .then(defer(self(), [=]() -> Future<http::Connection> {
+      if (!infos.contains(containerId)) {
+        return Failure("Container has or is being destroyed");
+      }
+
+      // TODO(jieyu): We might still get a connection refused error
+      // here because the server might not have started listening on
+      // the socket yet. Consider retrying if 'http::connect' failed
+      // with ECONNREFUSED.
+      return http::connect(address.get());
+    }));
 #endif // __WINDOWS__
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/9da19f5c/src/tests/containerizer/io_switchboard_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/io_switchboard_tests.cpp b/src/tests/containerizer/io_switchboard_tests.cpp
index 851a101..43f1ad6 100644
--- a/src/tests/containerizer/io_switchboard_tests.cpp
+++ b/src/tests/containerizer/io_switchboard_tests.cpp
@@ -455,6 +455,67 @@ class IOSwitchboardTest
   : public ContainerizerTest<slave::MesosContainerizer> {};
 
 
+TEST_F(IOSwitchboardTest, ContainerAttach)
+{
+  slave::Flags flags = CreateSlaveFlags();
+  flags.launcher = "posix";
+  flags.isolation = "posix/cpu";
+  flags.io_switchboard_enable_server = true;
+
+  Fetcher fetcher;
+
+  Try<MesosContainerizer*> create = MesosContainerizer::create(
+      flags,
+      false,
+      &fetcher);
+
+  ASSERT_SOME(create);
+
+  Owned<MesosContainerizer> containerizer(create.get());
+
+  SlaveState state;
+  state.id = SlaveID();
+
+  AWAIT_READY(containerizer->recover(state));
+
+  ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+
+  Try<string> directory = environment->mkdtemp();
+  ASSERT_SOME(directory);
+
+  ExecutorInfo executorInfo = createExecutorInfo(
+      "executor",
+      "sleep 1000",
+      "cpus:1");
+
+  Future<bool> launch = containerizer->launch(
+      containerId,
+      None(),
+      executorInfo,
+      directory.get(),
+      None(),
+      SlaveID(),
+      map<string, string>(),
+      true); // TODO(benh): Ever want to test not checkpointing?
+
+  AWAIT_ASSERT_TRUE(launch);
+
+  Future<http::Connection> connection = containerizer->attach(containerId);
+  AWAIT_READY(connection);
+
+  Future<Option<ContainerTermination>> wait = containerizer->wait(containerId);
+
+  Future<bool> destroy = containerizer->destroy(containerId);
+  AWAIT_READY(destroy);
+
+  AWAIT_READY(wait);
+  ASSERT_SOME(wait.get());
+  ASSERT_TRUE(wait.get()->has_status());
+  EXPECT_WTERMSIG_EQ(SIGKILL, wait.get()->status());
+}
+
+
 // The test verifies the output redirection of the container with TTY
 // allocated for the container.
 TEST_F(IOSwitchboardTest, OutputRedirectionWithTTY)