You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2019/07/18 16:19:12 UTC

[mesos] 04/07: Added `LauncherTracker` for tracking calls of launcher methods.

This is an automated email from the ASF dual-hosted git repository.

gilbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 5e01feb96874c0f7327ada82c39165900610c1b4
Author: Andrei Budnik <ab...@mesosphere.com>
AuthorDate: Thu Jul 18 09:10:44 2019 -0700

    Added `LauncherTracker` for tracking calls of launcher methods.
    
    This patch adds a new `LauncherTracker` class that proxies
    calls to the real `Launcher` and keeps track of returned futures
    by employing `PendingFutureTracker` class.
    
    Review: https://reviews.apache.org/r/70890/
---
 src/CMakeLists.txt                                 |   1 +
 src/Makefile.am                                    |   2 +
 src/slave/containerizer/mesos/launcher_tracker.cpp | 109 +++++++++++++++++++++
 src/slave/containerizer/mesos/launcher_tracker.hpp |  63 ++++++++++++
 4 files changed, 175 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c4d32df..99402cb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -173,6 +173,7 @@ set(AGENT_SRC
   slave/containerizer/mesos/isolator_tracker.cpp
   slave/containerizer/mesos/launch.cpp
   slave/containerizer/mesos/launcher.cpp
+  slave/containerizer/mesos/launcher_tracker.cpp
   slave/containerizer/mesos/mount.cpp
   slave/containerizer/mesos/paths.cpp
   slave/containerizer/mesos/io/switchboard.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 395b9f7..80ae6c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1254,6 +1254,8 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   slave/containerizer/mesos/launch.hpp					\
   slave/containerizer/mesos/launcher.cpp				\
   slave/containerizer/mesos/launcher.hpp				\
+  slave/containerizer/mesos/launcher_tracker.cpp			\
+  slave/containerizer/mesos/launcher_tracker.hpp			\
   slave/containerizer/mesos/mount.cpp					\
   slave/containerizer/mesos/mount.hpp					\
   slave/containerizer/mesos/paths.cpp					\
diff --git a/src/slave/containerizer/mesos/launcher_tracker.cpp b/src/slave/containerizer/mesos/launcher_tracker.cpp
new file mode 100644
index 0000000..4434e57
--- /dev/null
+++ b/src/slave/containerizer/mesos/launcher_tracker.cpp
@@ -0,0 +1,109 @@
+// 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 <process/async.hpp>
+
+#include "common/future_tracker.hpp"
+
+#include "slave/constants.hpp"
+
+#include "slave/containerizer/mesos/launcher_tracker.hpp"
+
+using std::map;
+using std::string;
+using std::vector;
+
+using process::Future;
+using process::Promise;
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+LauncherTracker::LauncherTracker(
+    const process::Owned<Launcher>& _launcher, PendingFutureTracker* _tracker)
+  : launcher(_launcher), tracker(_tracker)
+{}
+
+
+Future<hashset<ContainerID>> LauncherTracker::recover(
+    const vector<mesos::slave::ContainerState>& states)
+{
+  return tracker->track(
+      launcher->recover(states),
+      "launcher::recover",
+      COMPONENT_NAME_CONTAINERIZER);
+}
+
+
+Try<pid_t> LauncherTracker::fork(
+    const ContainerID& containerId,
+    const string& path,
+    const vector<string>& argv,
+    const mesos::slave::ContainerIO& containerIO,
+    const flags::FlagsBase* flags,
+    const Option<map<string, string>>& environment,
+    const Option<int>& enterNamespaces,
+    const Option<int>& cloneNamespaces,
+    const vector<int_fd>& whitelistFds)
+{
+  Promise<Try<pid_t>> promise;
+
+  tracker->track(
+      promise.future(),
+      "launcher::fork",
+      COMPONENT_NAME_CONTAINERIZER,
+      {{"containerId", stringify(containerId)},
+       {"path", path}});
+
+  Try<pid_t> forked = launcher->fork(
+      containerId,
+      path,
+      argv,
+      containerIO,
+      flags,
+      environment,
+      enterNamespaces,
+      cloneNamespaces,
+      whitelistFds);
+
+  promise.set(forked);
+  return forked;
+}
+
+
+Future<Nothing> LauncherTracker::destroy(const ContainerID& containerId)
+{
+  return tracker->track(
+      launcher->destroy(containerId),
+      "launcher::destroy",
+      COMPONENT_NAME_CONTAINERIZER,
+      {{"containerId", stringify(containerId)}});
+}
+
+
+Future<ContainerStatus> LauncherTracker::status(const ContainerID& containerId)
+{
+  return tracker->track(
+      launcher->status(containerId),
+      "launcher::status",
+      COMPONENT_NAME_CONTAINERIZER,
+      {{"containerId", stringify(containerId)}});
+}
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
diff --git a/src/slave/containerizer/mesos/launcher_tracker.hpp b/src/slave/containerizer/mesos/launcher_tracker.hpp
new file mode 100644
index 0000000..999f6be
--- /dev/null
+++ b/src/slave/containerizer/mesos/launcher_tracker.hpp
@@ -0,0 +1,63 @@
+// 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 __LAUNCHER_TRACKER_HPP__
+#define __LAUNCHER_TRACKER_HPP__
+
+#include <process/owned.hpp>
+
+#include "slave/containerizer/mesos/launcher.hpp"
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+class LauncherTracker : public Launcher
+{
+public:
+  LauncherTracker(
+      const process::Owned<Launcher>& _launcher,
+      PendingFutureTracker* _tracker);
+
+  process::Future<hashset<ContainerID>> recover(
+      const std::vector<mesos::slave::ContainerState>& states) override;
+
+  Try<pid_t> fork(
+      const ContainerID& containerId,
+      const std::string& path,
+      const std::vector<std::string>& argv,
+      const mesos::slave::ContainerIO& containerIO,
+      const flags::FlagsBase* flags,
+      const Option<std::map<std::string, std::string>>& environment,
+      const Option<int>& enterNamespaces,
+      const Option<int>& cloneNamespaces,
+      const std::vector<int_fd>& whitelistFds) override;
+
+  process::Future<Nothing> destroy(const ContainerID& containerId) override;
+
+  process::Future<ContainerStatus> status(
+      const ContainerID& containerId) override;
+
+private:
+  process::Owned<Launcher> launcher;
+  PendingFutureTracker* tracker;
+};
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __LAUNCHER_TRACKER_HPP__