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 2014/06/18 19:19:56 UTC

[2/2] git commit: Updated mesos to use the new Subprocess API.

Updated mesos to use the new Subprocess API.

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


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

Branch: refs/heads/master
Commit: 83fcc8ca15e8b9d19a511d64c99ec908acd7082a
Parents: 9657fe0
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Jun 17 16:31:23 2014 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Jun 18 10:19:23 2014 -0700

----------------------------------------------------------------------
 src/launcher/launcher.cpp                        | 12 +++++++++---
 src/linux/perf.cpp                               | 15 ++++++++++-----
 .../containerizer/external_containerizer.cpp     | 19 +++++++++++--------
 src/slave/containerizer/mesos_containerizer.cpp  | 12 +++++++++---
 src/tests/slave_tests.cpp                        |  7 ++++++-
 5 files changed, 45 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/83fcc8ca/src/launcher/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/launcher.cpp b/src/launcher/launcher.cpp
index 1d352b6..5585aad 100644
--- a/src/launcher/launcher.cpp
+++ b/src/launcher/launcher.cpp
@@ -206,13 +206,19 @@ process::Future<Option<int> > Operation::launch(
   // Prepare the command: 'mesos-launcher <operation_name> ...'.
   string command = strings::join(" ", realpath.get(), name());
 
-  Try<Subprocess> s = subprocess(command, environment);
+  Try<Subprocess> s = subprocess(
+      command,
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
+      environment);
+
   if (s.isError()) {
     return Failure("Launch subprocess failed: " + s.error());
   }
 
-  io::redirect(s.get().out(), stdout);
-  io::redirect(s.get().err(), stderr);
+  io::redirect(s.get().out().get(), stdout);
+  io::redirect(s.get().err().get(), stderr);
 
   return s.get().status();
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/83fcc8ca/src/linux/perf.cpp
----------------------------------------------------------------------
diff --git a/src/linux/perf.cpp b/src/linux/perf.cpp
index bc31db5..fc5acf4 100644
--- a/src/linux/perf.cpp
+++ b/src/linux/perf.cpp
@@ -157,7 +157,12 @@ protected:
 private:
   void sample()
   {
-    Try<Subprocess> _perf = subprocess(command);
+    Try<Subprocess> _perf = subprocess(
+        command,
+        Subprocess::PIPE(),
+        Subprocess::PIPE(),
+        Subprocess::PIPE());
+
     if (_perf.isError()) {
       promise.fail("Failed to launch perf process: " + _perf.error());
       terminate(self());
@@ -165,7 +170,7 @@ private:
     }
     perf = _perf.get();
 
-    Try<Nothing> nonblock = os::nonblock(perf.get().out());
+    Try<Nothing> nonblock = os::nonblock(perf.get().out().get());
     if (nonblock.isError()) {
       promise.fail("Failed to set nonblock on stdout for perf process: " +
                     nonblock.error());
@@ -173,7 +178,7 @@ private:
       return;
     }
 
-    nonblock = os::nonblock(perf.get().err());
+    nonblock = os::nonblock(perf.get().err().get());
     if (nonblock.isError()) {
       promise.fail("Failed to set nonblock on stderr for perf process: " +
                     nonblock.error());
@@ -184,8 +189,8 @@ private:
     // Start reading from stdout and stderr now. We don't use stderr
     // but must read from it to avoid the subprocess blocking on the
     // pipe.
-    output.push_back(process::io::read(perf.get().out()));
-    output.push_back(process::io::read(perf.get().err()));
+    output.push_back(process::io::read(perf.get().out().get()));
+    output.push_back(process::io::read(perf.get().err().get()));
 
     // Wait for the process to exit.
     perf.get().status()

http://git-wip-us.apache.org/repos/asf/mesos/blob/83fcc8ca/src/slave/containerizer/external_containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/external_containerizer.cpp b/src/slave/containerizer/external_containerizer.cpp
index b5d0c4c..923046c 100644
--- a/src/slave/containerizer/external_containerizer.cpp
+++ b/src/slave/containerizer/external_containerizer.cpp
@@ -626,7 +626,7 @@ Future<containerizer::Termination> ExternalContainerizerProcess::_wait(
     &::protobuf::read<containerizer::Termination>;
 
   Future<Result<containerizer::Termination> > future = async(
-      read, invoked.get().out(), false, false);
+      read, invoked.get().out().get(), false, false);
 
   // Await both, a protobuf Message from the subprocess as well as
   // its exit.
@@ -817,7 +817,7 @@ Future<ResourceStatistics> ExternalContainerizerProcess::_usage(
     &::protobuf::read<ResourceStatistics>;
 
   Future<Result<ResourceStatistics> > future = async(
-      read, invoked.get().out(), false, false);
+      read, invoked.get().out().get(), false, false);
 
   // Await both, a protobuf Message from the subprocess as well as
   // its exit.
@@ -955,7 +955,7 @@ Future<hashset<ContainerID> > ExternalContainerizerProcess::containers()
     &::protobuf::read<containerizer::Containers>;
 
   Future<Result<containerizer::Containers> > future = async(
-      read, invoked.get().out(), false, false);
+      read, invoked.get().out().get(), false, false);
 
   // Await both, a protobuf Message from the subprocess as well as
   // its exit.
@@ -1116,6 +1116,9 @@ Try<Subprocess> ExternalContainerizerProcess::invoke(
   // the child-context.
   Try<Subprocess> external = process::subprocess(
       execute,
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
       environment,
       lambda::bind(&setup, sandbox.isSome() ? sandbox.get().directory
                                             : string()));
@@ -1128,11 +1131,11 @@ Try<Subprocess> ExternalContainerizerProcess::invoke(
   // Sync parent and child process to make sure we have done the
   // setsid within the child context before continuing.
   int sync;
-  while (::read(external.get().out(), &sync, sizeof(sync)) == -1 &&
+  while (::read(external.get().out().get(), &sync, sizeof(sync)) == -1 &&
          errno == EINTR);
 
   // Set stderr into non-blocking mode.
-  Try<Nothing> nonblock = os::nonblock(external.get().err());
+  Try<Nothing> nonblock = os::nonblock(external.get().err().get());
   if (nonblock.isError()) {
     return Error("Failed to accept nonblock: " + nonblock.error());
   }
@@ -1170,14 +1173,14 @@ Try<Subprocess> ExternalContainerizerProcess::invoke(
 
   // TODO(tillt): Consider adding an overload to io::redirect
   // that accepts a file path as 'to' for further reducing code.
-  io::redirect(external.get().err(), err.get());
+  io::redirect(external.get().err().get(), err.get());
 
   // Redirect does 'dup' the file descriptor, hence we can close the
   // original now.
   os::close(err.get());
 
   VLOG(2) << "Subprocess pid: " << external.get().pid() << ", "
-          << "output pipe: " << external.get().out();
+          << "output pipe: " << external.get().out().get();
 
   return external;
 }
@@ -1196,7 +1199,7 @@ Try<Subprocess> ExternalContainerizerProcess::invoke(
 
   // Transmit protobuf data via stdout towards the external
   // containerizer. Each message is prefixed by its total size.
-  Try<Nothing> write = ::protobuf::write(external.get().in(), message);
+  Try<Nothing> write = ::protobuf::write(external.get().in().get(), message);
   if (write.isError()) {
     return Error("Failed to write protobuf to pipe: " + write.error());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/83fcc8ca/src/slave/containerizer/mesos_containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos_containerizer.cpp b/src/slave/containerizer/mesos_containerizer.cpp
index 4d97d49..e5c159d 100644
--- a/src/slave/containerizer/mesos_containerizer.cpp
+++ b/src/slave/containerizer/mesos_containerizer.cpp
@@ -658,7 +658,13 @@ Future<Nothing> MesosContainerizerProcess::fetch(
   LOG(INFO) << "Fetching URIs for container '" << containerId
             << "' using command '" << command << "'";
 
-  Try<Subprocess> fetcher = subprocess(command, environment);
+  Try<Subprocess> fetcher = subprocess(
+      command,
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
+      Subprocess::PIPE(),
+      environment);
+
   if (fetcher.isError()) {
     return Failure("Failed to execute mesos-fetcher: " + fetcher.error());
   }
@@ -693,7 +699,7 @@ Future<Nothing> MesosContainerizerProcess::fetch(
 
   // Redirect takes care of nonblocking and close-on-exec for the
   // supplied file descriptors.
-  io::redirect(fetcher.get().out(), out.get());
+  io::redirect(fetcher.get().out().get(), out.get());
 
   // Redirect does 'dup' the file descriptor, hence we can close the
   // original now.
@@ -722,7 +728,7 @@ Future<Nothing> MesosContainerizerProcess::fetch(
     }
   }
 
-  io::redirect(fetcher.get().err(), err.get());
+  io::redirect(fetcher.get().err().get(), err.get());
 
   os::close(err.get());
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/83fcc8ca/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index 9178e01..9dc4046 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -346,7 +346,12 @@ TEST_F(SlaveTest, MesosExecutorWithOverride)
     .WillOnce(FutureArg<1>(&status2));
 
   Try<process::Subprocess> executor =
-    process::subprocess(executorCommand, environment);
+    process::subprocess(
+        executorCommand,
+        process::Subprocess::PIPE(),
+        process::Subprocess::PIPE(),
+        process::Subprocess::PIPE(),
+        environment);
 
   ASSERT_SOME(executor);