Added implementation for containerizer 'attach()' call. Review: https://reviews.apache.org/r/53939
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5e387f43 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5e387f43 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5e387f43 Branch: refs/heads/master Commit: 5e387f431eea5d78e1f0207a80c5154bd45de8fa Parents: 1420cfa Author: Kevin Klues <klue...@gmail.com> Authored: Sun Nov 20 14:41:30 2016 -0800 Committer: Jie Yu <yujie....@gmail.com> Committed: Thu Dec 1 10:11:45 2016 -0800 ---------------------------------------------------------------------- src/slave/containerizer/composing.cpp | 6 ++- src/slave/containerizer/mesos/containerizer.cpp | 6 ++- .../containerizer/mesos/io/switchboard.cpp | 49 ++++++++++++++++++++ .../containerizer/mesos/io/switchboard.hpp | 4 ++ 4 files changed, 63 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5e387f43/src/slave/containerizer/composing.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/composing.cpp b/src/slave/containerizer/composing.cpp index e0818bc..4fb7ba5 100644 --- a/src/slave/containerizer/composing.cpp +++ b/src/slave/containerizer/composing.cpp @@ -566,7 +566,11 @@ Future<bool> ComposingContainerizerProcess::_launch( Future<http::Connection> ComposingContainerizerProcess::attach( const ContainerID& containerId) { - return Failure("Unsupported"); + if (!containers_.contains(containerId)) { + return Failure("Container not found"); + } + + return containers_[containerId]->containerizer->attach(containerId); } http://git-wip-us.apache.org/repos/asf/mesos/blob/5e387f43/src/slave/containerizer/mesos/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp index b594612..a7e2665 100644 --- a/src/slave/containerizer/mesos/containerizer.cpp +++ b/src/slave/containerizer/mesos/containerizer.cpp @@ -1815,7 +1815,11 @@ Future<bool> MesosContainerizerProcess::launch( Future<Connection> MesosContainerizerProcess::attach( const ContainerID& containerId) { - return Failure("Unsupported"); + if (!containers_.contains(containerId)) { + return Failure("Unknown container " + stringify(containerId)); + } + + return ioSwitchboard->connect(containerId); } http://git-wip-us.apache.org/repos/asf/mesos/blob/5e387f43/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 3c031e3..3118d98 100644 --- a/src/slave/containerizer/mesos/io/switchboard.cpp +++ b/src/slave/containerizer/mesos/io/switchboard.cpp @@ -18,10 +18,12 @@ #include <string> #include <vector> +#include <process/address.hpp> #include <process/collect.hpp> #include <process/defer.hpp> #include <process/dispatch.hpp> #include <process/future.hpp> +#include <process/http.hpp> #include <process/io.hpp> #include <process/owned.hpp> @@ -306,6 +308,21 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare( os::close(outfds[0]); os::close(errfds[0]); + // Now that the child has come up, we checkpoint the socket + // address we told it to bind to so we can access it later. + const string path = + containerizer::paths::getContainerIOSwitchboardSocketPath( + flags.runtime_dir, containerId); + + Try<Nothing> checkpointed = slave::state::checkpoint( + path, switchboardFlags.socket_path); + + if (checkpointed.isError()) { + close(fds); + return Failure("Failed to checkpoint container's socket path to" + " '" + path + "': " + checkpointed.error()); + } + // Build an info struct for this container. infos[containerId] = Owned<Info>(new Info( child->pid(), @@ -329,6 +346,38 @@ Future<Option<ContainerLaunchInfo>> IOSwitchboard::_prepare( } +Future<http::Connection> IOSwitchboard::connect( + const ContainerID& containerId) +{ +#ifdef __WINDOWS__ + return Failure("Not supported on Windows"); +#else + if (!flags.io_switchboard_enable_server) { + return Failure("Support for running an io switchboard" + " server was disabled by the agent"); + } + + // Get the io switchboard address from the `containerId`. + // + // NOTE: We explicitly don't want to check for the existence of + // `containerId` in our `infos` struct. Otherwise we wouldn't be + // able to reconnect to the io switchboard after agent restarts. + Result<unix::Address> address = + containerizer::paths::getContainerIOSwitchboardAddress( + flags.runtime_dir, containerId); + + if (!address.isSome()) { + return Failure("Failed to get the io switchboard address" + " " + (address.isError() + ? address.error() + : "No address found")); + } + + return http::connect(address.get()); +#endif // __WINDOWS__ +} + + Future<Nothing> IOSwitchboard::cleanup( const ContainerID& containerId) { http://git-wip-us.apache.org/repos/asf/mesos/blob/5e387f43/src/slave/containerizer/mesos/io/switchboard.hpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/io/switchboard.hpp b/src/slave/containerizer/mesos/io/switchboard.hpp index 679f520..5045dfd 100644 --- a/src/slave/containerizer/mesos/io/switchboard.hpp +++ b/src/slave/containerizer/mesos/io/switchboard.hpp @@ -20,6 +20,7 @@ #include <string> #include <process/future.hpp> +#include <process/http.hpp> #include <process/owned.hpp> #include <process/socket.hpp> @@ -66,6 +67,9 @@ public: virtual process::Future<Nothing> cleanup( const ContainerID& containerId); + process::Future<process::http::Connection> connect( + const ContainerID& containerId); + private: struct Info {