mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject mesos git commit: Implemented `CgroupsIsolatorProcess::create`.
Date Mon, 25 Jul 2016 16:23:52 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 0e76bd018 -> 357abbeb0


Implemented `CgroupsIsolatorProcess::create`.

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


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

Branch: refs/heads/master
Commit: 357abbeb05b60efc1ed033481c4b8bc19386ac1a
Parents: 0e76bd0
Author: haosdent huang <haosdent@gmail.com>
Authored: Mon Jul 25 09:23:41 2016 -0700
Committer: Jie Yu <yujie.jay@gmail.com>
Committed: Mon Jul 25 09:23:41 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/cgroups/cgroups.cpp         | 62 +++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/357abbeb/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
index 4a9f55b..348f105 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -15,6 +15,10 @@
 // limitations under the License.
 
 #include <stout/error.hpp>
+#include <stout/foreach.hpp>
+#include <stout/strings.hpp>
+
+#include "linux/cgroups.hpp"
 
 #include "slave/containerizer/mesos/isolators/cgroups/cgroups.hpp"
 
@@ -49,7 +53,63 @@ CgroupsIsolatorProcess::~CgroupsIsolatorProcess() {}
 
 Try<Isolator*> CgroupsIsolatorProcess::create(const Flags& flags)
 {
-  return Error("Not implemented.");
+  // Subsystem name -> hierarchy path.
+  hashmap<string, string> hierarchies;
+
+  // Hierarchy path -> subsystem object.
+  multihashmap<string, Owned<Subsystem>> subsystems;
+
+  // Multimap: isolator name -> subsystem name.
+  multihashmap<string, string> isolatorMap = {
+  };
+
+  foreach (string isolator, strings::tokenize(flags.isolation, ",")) {
+    if (!strings::startsWith(isolator, "cgroups/")) {
+      // Skip when the isolator is not related to cgroups.
+      continue;
+    }
+
+    isolator = strings::remove(isolator, "cgroups/", strings::Mode::PREFIX);
+
+    // A cgroups isolator name may map to multiple subsystems. We need to
+    // convert the isolator name to its associated subsystems.
+    foreach (const string& subsystemName, isolatorMap.get(isolator)) {
+      if (hierarchies.contains(subsystemName)) {
+        // Skip when the subsystem exists.
+        continue;
+      }
+
+      // Prepare hierarchy if it does not exist.
+      Try<string> hierarchy = cgroups::prepare(
+          flags.cgroups_hierarchy,
+          subsystemName,
+          flags.cgroups_root);
+
+      if (hierarchy.isError()) {
+        return Error(
+            "Failed to prepare hierarchy for the subsystem '" + subsystemName +
+            "': " + hierarchy.error());
+      }
+
+      // Create and load the subsystem.
+      Try<Owned<Subsystem>> subsystem =
+        Subsystem::create(flags, subsystemName, hierarchy.get());
+
+      if (subsystem.isError()) {
+        return Error(
+            "Failed to create subsystem '" + subsystemName + "': " +
+            subsystem.error());
+      }
+
+      subsystems.put(hierarchy.get(), subsystem.get());
+      hierarchies.put(subsystemName, hierarchy.get());
+    }
+  }
+
+  Owned<MesosIsolatorProcess> process(
+      new CgroupsIsolatorProcess(flags, hierarchies, subsystems));
+
+  return new MesosIsolator(process);
 }
 
 


Mime
View raw message