You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/12/29 20:20:32 UTC

[2/5] mesos git commit: Add default ContainerLogger implementation: SandboxContainerLogger.

Add default ContainerLogger implementation: SandboxContainerLogger.

This implementation mirrors how executor/task stdout/stderr is
currently saved to plain files.

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


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

Branch: refs/heads/master
Commit: d37f5a470c12249fbdb525d9ff1b3cb9eb1125f2
Parents: a29dd66
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Tue Dec 29 10:45:55 2015 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Tue Dec 29 10:49:16 2015 -0800

----------------------------------------------------------------------
 src/slave/container_loggers/sandbox.cpp | 131 +++++++++++++++++++++++++++
 src/slave/container_loggers/sandbox.hpp |  79 ++++++++++++++++
 2 files changed, 210 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d37f5a47/src/slave/container_loggers/sandbox.cpp
----------------------------------------------------------------------
diff --git a/src/slave/container_loggers/sandbox.cpp b/src/slave/container_loggers/sandbox.cpp
new file mode 100644
index 0000000..1b954d6
--- /dev/null
+++ b/src/slave/container_loggers/sandbox.cpp
@@ -0,0 +1,131 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <mesos/mesos.hpp>
+
+#include <mesos/slave/container_logger.hpp>
+
+#include <process/dispatch.hpp>
+#include <process/future.hpp>
+#include <process/owned.hpp>
+#include <process/process.hpp>
+#include <process/subprocess.hpp>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/path.hpp>
+
+#include "slave/container_loggers/sandbox.hpp"
+
+using namespace process;
+
+using mesos::slave::ContainerLogger;
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+using SubprocessInfo = ContainerLogger::SubprocessInfo;
+
+
+class SandboxContainerLoggerProcess :
+  public Process<SandboxContainerLoggerProcess>
+{
+public:
+  Future<Nothing> recover(
+      const ExecutorInfo& executorInfo,
+      const std::string& sandboxDirectory)
+  {
+    return Nothing();
+  }
+
+  process::Future<ContainerLogger::SubprocessInfo> prepare(
+      const ExecutorInfo& executorInfo,
+      const std::string& sandboxDirectory)
+  {
+    ContainerLogger::SubprocessInfo info;
+
+    info.out = SubprocessInfo::IO::PATH(path::join(sandboxDirectory, "stdout"));
+    info.err = SubprocessInfo::IO::PATH(path::join(sandboxDirectory, "stderr"));
+
+    return info;
+  }
+};
+
+
+SandboxContainerLogger::~SandboxContainerLogger()
+{
+  if (process.get() != NULL) {
+    terminate(process.get());
+    wait(process.get());
+  }
+}
+
+
+Try<Nothing> SandboxContainerLogger::initialize()
+{
+  if (process.get() != NULL) {
+    return Error("Sandbox container logger has already been initialized");
+  }
+
+  process.reset(new SandboxContainerLoggerProcess());
+  spawn(process.get());
+
+  return Nothing();
+}
+
+
+Future<Nothing> SandboxContainerLogger::recover(
+    const ExecutorInfo& executorInfo,
+    const std::string& sandboxDirectory)
+{
+  if (process.get() == NULL) {
+    return Failure("Sandbox container logger is not initialized");
+  }
+
+  return dispatch(
+      process.get(),
+      &SandboxContainerLoggerProcess::recover,
+      executorInfo,
+      sandboxDirectory);
+}
+
+
+Future<ContainerLogger::SubprocessInfo>
+SandboxContainerLogger::prepare(
+    const ExecutorInfo& executorInfo,
+    const std::string& sandboxDirectory)
+{
+  if (process.get() == NULL) {
+    return Failure("Sandbox container logger is not initialized");
+  }
+
+  return dispatch(
+      process.get(),
+      &SandboxContainerLoggerProcess::prepare,
+      executorInfo,
+      sandboxDirectory);
+}
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/d37f5a47/src/slave/container_loggers/sandbox.hpp
----------------------------------------------------------------------
diff --git a/src/slave/container_loggers/sandbox.hpp b/src/slave/container_loggers/sandbox.hpp
new file mode 100644
index 0000000..17bb1d9
--- /dev/null
+++ b/src/slave/container_loggers/sandbox.hpp
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __SLAVE_CONTAINER_LOGGERS_SANDBOX_HPP__
+#define __SLAVE_CONTAINER_LOGGERS_SANDBOX_HPP__
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <mesos/mesos.hpp>
+
+#include <mesos/slave/container_logger.hpp>
+
+#include <process/future.hpp>
+#include <process/owned.hpp>
+#include <process/subprocess.hpp>
+
+#include <stout/try.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+// Forward declaration.
+class SandboxContainerLoggerProcess;
+
+
+// The default container logger.
+//
+// Executors and tasks launched through this container logger will have their
+// stdout and stderr piped to the files "stdout" and "stderr", respectively, in
+// the sandbox.  These logs are accessible via the agent's `/files` endpoint.
+class SandboxContainerLogger : public mesos::slave::ContainerLogger
+{
+public:
+  virtual ~SandboxContainerLogger();
+
+  virtual Try<Nothing> initialize();
+
+  // This is a noop.  The agent recovery process already exposes all files
+  // in a recovered executor's sandbox.
+  virtual process::Future<Nothing> recover(
+      const ExecutorInfo& executorInfo,
+      const std::string& sandboxDirectory);
+
+  // Tells the subprocess to redirect the executor/task's stdout and stderr
+  // to separate "stdout" and "stderr" files in the sandbox.
+  // The `path`, `argv`, and `environment` are not changed.
+  virtual process::Future<mesos::slave::ContainerLogger::SubprocessInfo>
+  prepare(
+      const ExecutorInfo& executorInfo,
+      const std::string& sandboxDirectory);
+
+protected:
+  process::Owned<SandboxContainerLoggerProcess> process;
+};
+
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __SLAVE_CONTAINER_LOGGERS_SANDBOX_HPP__