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 2016/07/14 17:00:29 UTC
[2/2] mesos git commit: Added stubs for the unified cgroups isolator.
Added stubs for the unified cgroups isolator.
Review: https://reviews.apache.org/r/49813/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/38bc6d3f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/38bc6d3f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/38bc6d3f
Branch: refs/heads/master
Commit: 38bc6d3f1c1230bcd4583eb19e0a68907b4b0858
Parents: c3ede84
Author: haosdent huang <ha...@gmail.com>
Authored: Thu Jul 14 10:00:18 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Jul 14 10:00:18 2016 -0700
----------------------------------------------------------------------
src/CMakeLists.txt | 2 +
src/Makefile.am | 4 +
.../mesos/isolators/cgroups/cgroups.cpp | 117 ++++++++++++++
.../mesos/isolators/cgroups/cgroups.hpp | 122 ++++++++++++++
.../mesos/isolators/cgroups/subsystem.cpp | 103 ++++++++++++
.../mesos/isolators/cgroups/subsystem.hpp | 159 +++++++++++++++++++
6 files changed, 507 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9d8a8ba..4402142 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -159,11 +159,13 @@ set(LINUX_SRC
linux/systemd.cpp
slave/containerizer/mesos/linux_launcher.cpp
slave/containerizer/mesos/isolators/appc/runtime.cpp
+ slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
slave/containerizer/mesos/isolators/cgroups/cpushare.cpp
slave/containerizer/mesos/isolators/cgroups/devices.cpp
slave/containerizer/mesos/isolators/cgroups/mem.cpp
slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
slave/containerizer/mesos/isolators/cgroups/perf_event.cpp
+ slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
slave/containerizer/mesos/isolators/docker/runtime.cpp
slave/containerizer/mesos/isolators/docker/volume/driver.cpp
slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d798d6..cc83525 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1045,11 +1045,13 @@ MESOS_LINUX_FILES = \
linux/systemd.cpp \
slave/containerizer/mesos/linux_launcher.cpp \
slave/containerizer/mesos/isolators/appc/runtime.cpp \
+ slave/containerizer/mesos/isolators/cgroups/cgroups.cpp \
slave/containerizer/mesos/isolators/cgroups/cpushare.cpp \
slave/containerizer/mesos/isolators/cgroups/devices.cpp \
slave/containerizer/mesos/isolators/cgroups/mem.cpp \
slave/containerizer/mesos/isolators/cgroups/net_cls.cpp \
slave/containerizer/mesos/isolators/cgroups/perf_event.cpp \
+ slave/containerizer/mesos/isolators/cgroups/subsystem.cpp \
slave/containerizer/mesos/isolators/docker/runtime.cpp \
slave/containerizer/mesos/isolators/docker/volume/isolator.cpp \
slave/containerizer/mesos/isolators/filesystem/linux.cpp \
@@ -1074,12 +1076,14 @@ MESOS_LINUX_FILES += \
linux/systemd.hpp \
slave/containerizer/mesos/linux_launcher.hpp \
slave/containerizer/mesos/isolators/appc/runtime.hpp \
+ slave/containerizer/mesos/isolators/cgroups/cgroups.hpp \
slave/containerizer/mesos/isolators/cgroups/constants.hpp \
slave/containerizer/mesos/isolators/cgroups/cpushare.hpp \
slave/containerizer/mesos/isolators/cgroups/devices.hpp \
slave/containerizer/mesos/isolators/cgroups/mem.hpp \
slave/containerizer/mesos/isolators/cgroups/net_cls.hpp \
slave/containerizer/mesos/isolators/cgroups/perf_event.hpp \
+ slave/containerizer/mesos/isolators/cgroups/subsystem.hpp \
slave/containerizer/mesos/isolators/docker/runtime.hpp \
slave/containerizer/mesos/isolators/docker/volume/isolator.hpp \
slave/containerizer/mesos/isolators/filesystem/linux.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/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
new file mode 100644
index 0000000..4a9f55b
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -0,0 +1,117 @@
+// 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 <stout/error.hpp>
+
+#include "slave/containerizer/mesos/isolators/cgroups/cgroups.hpp"
+
+using mesos::slave::ContainerConfig;
+using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerLimitation;
+using mesos::slave::ContainerState;
+using mesos::slave::Isolator;
+
+using process::Failure;
+using process::Future;
+using process::Owned;
+
+using std::list;
+using std::string;
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+CgroupsIsolatorProcess::CgroupsIsolatorProcess(
+ const Flags& _flags,
+ const hashmap<string, string>& _hierarchies,
+ const multihashmap<string, Owned<Subsystem>>& _subsystems)
+ : flags(_flags),
+ hierarchies(_hierarchies),
+ subsystems(_subsystems) {}
+
+
+CgroupsIsolatorProcess::~CgroupsIsolatorProcess() {}
+
+
+Try<Isolator*> CgroupsIsolatorProcess::create(const Flags& flags)
+{
+ return Error("Not implemented.");
+}
+
+
+Future<Nothing> CgroupsIsolatorProcess::recover(
+ const list<ContainerState>& states,
+ const hashset<ContainerID>& orphans)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Option<ContainerLaunchInfo>> CgroupsIsolatorProcess::prepare(
+ const ContainerID& containerId,
+ const ContainerConfig& containerConfig)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> CgroupsIsolatorProcess::isolate(
+ const ContainerID& containerId,
+ pid_t pid)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<ContainerLimitation> CgroupsIsolatorProcess::watch(
+ const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> CgroupsIsolatorProcess::update(
+ const ContainerID& containerId,
+ const Resources& resources)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<ResourceStatistics> CgroupsIsolatorProcess::usage(
+ const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<ContainerStatus> CgroupsIsolatorProcess::status(
+ const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> CgroupsIsolatorProcess::cleanup(
+ const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/src/slave/containerizer/mesos/isolators/cgroups/cgroups.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.hpp b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.hpp
new file mode 100644
index 0000000..c57baec
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.hpp
@@ -0,0 +1,122 @@
+// 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 __CGROUPS_ISOLATOR_HPP__
+#define __CGROUPS_ISOLATOR_HPP__
+
+#include <string>
+
+#include <mesos/resources.hpp>
+
+#include <process/future.hpp>
+#include <process/owned.hpp>
+
+#include <stout/hashmap.hpp>
+#include <stout/hashset.hpp>
+#include <stout/multihashmap.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+#include "slave/flags.hpp"
+
+#include "slave/containerizer/mesos/isolator.hpp"
+
+#include "slave/containerizer/mesos/isolators/cgroups/subsystem.hpp"
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+// This isolator manages all cgroups subsystems for containers, and delegate
+// most operations on cgroups subsystem to specific `Subsystem` class.
+class CgroupsIsolatorProcess : public MesosIsolatorProcess
+{
+public:
+ static Try<mesos::slave::Isolator*> create(const Flags& flags);
+
+ virtual ~CgroupsIsolatorProcess();
+
+ virtual process::Future<Nothing> recover(
+ const std::list<mesos::slave::ContainerState>& states,
+ const hashset<ContainerID>& orphans);
+
+ virtual process::Future<Option<mesos::slave::ContainerLaunchInfo>> prepare(
+ const ContainerID& containerId,
+ const mesos::slave::ContainerConfig& containerConfig);
+
+ virtual process::Future<Nothing> isolate(
+ const ContainerID& containerId,
+ pid_t pid);
+
+ virtual process::Future<mesos::slave::ContainerLimitation> watch(
+ const ContainerID& containerId);
+
+ virtual process::Future<Nothing> update(
+ const ContainerID& containerId,
+ const Resources& resources);
+
+ virtual process::Future<ResourceStatistics> usage(
+ const ContainerID& containerId);
+
+ virtual process::Future<ContainerStatus> status(
+ const ContainerID& containerId);
+
+ virtual process::Future<Nothing> cleanup(
+ const ContainerID& containerId);
+
+private:
+ CgroupsIsolatorProcess(
+ const Flags& _flags,
+ const hashmap<std::string, std::string>& _hierarchies,
+ const multihashmap<std::string, process::Owned<Subsystem>>& _subsystems);
+
+ struct Info {
+ Info(const ContainerID& _containerId, const std::string& _cgroup)
+ : containerId(_containerId), cgroup(_cgroup) {}
+
+ const ContainerID containerId;
+ const std::string cgroup;
+
+ // This promise will complete if a container is impacted by a resource
+ // limitation and should be terminated.
+ process::Promise<mesos::slave::ContainerLimitation> limitation;
+ };
+
+ const Flags flags;
+
+ // Map from subsystem name to hierarchy path.
+ hashmap<std::string, std::string> hierarchies;
+
+ // We map hierarchy path and `Subsytem` in subsystems. Same hierarchy may
+ // map to multiple Subsystems. For example, our cgroups hierarchies may
+ // mount like below in the machine:
+ // /cgroup/cpu,cpuacct -> cpu
+ // /cgroup/cpu,cpuacct -> cpuacct
+ // /cgroup/memory -> memory
+ // As we see, subsystem 'cpu' and 'cpuacct' are co-mounted at
+ // '/cgroup/cpu,cpuacct'.
+ multihashmap<std::string, process::Owned<Subsystem>> subsystems;
+
+ // Store cgroups associated information for containers.
+ hashmap<ContainerID, process::Owned<Info>> infos;
+};
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __CGROUPS_ISOLATOR_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
new file mode 100644
index 0000000..64fca3c
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
@@ -0,0 +1,103 @@
+// 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 <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+#include "slave/containerizer/mesos/isolators/cgroups/cgroups.hpp"
+#include "slave/containerizer/mesos/isolators/cgroups/subsystem.hpp"
+
+using mesos::slave::ContainerLimitation;
+
+using process::Failure;
+using process::Future;
+using process::Owned;
+using process::PID;
+
+using std::string;
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+Try<Owned<Subsystem>> Subsystem::create(
+ const Flags& _flags,
+ const string& _name,
+ const string& _hierarchy)
+{
+ return Error("Not implemented.");
+}
+
+
+Subsystem::Subsystem(
+ const Flags& _flags,
+ const string& _hierarchy)
+ : flags(_flags),
+ hierarchy(_hierarchy) {}
+
+
+Subsystem::~Subsystem()
+{
+}
+
+
+Future<Nothing> Subsystem::recover(const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> Subsystem::prepare(const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> Subsystem::isolate(const ContainerID& containerId, pid_t pid)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> Subsystem::update(
+ const ContainerID& containerId,
+ const Resources& resources)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<ResourceStatistics> Subsystem::usage(const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<ContainerStatus> Subsystem::status(const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+
+Future<Nothing> Subsystem::cleanup(const ContainerID& containerId)
+{
+ return Failure("Not implemented.");
+}
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/38bc6d3f/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
new file mode 100644
index 0000000..f677da3
--- /dev/null
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
@@ -0,0 +1,159 @@
+// 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 __CGROUPS_ISOLATOR_SUBSYSTEM_HPP__
+#define __CGROUPS_ISOLATOR_SUBSYSTEM_HPP__
+
+#include <string>
+
+#include <mesos/resources.hpp>
+
+#include <mesos/slave/isolator.hpp>
+
+#include <process/future.hpp>
+#include <process/owned.hpp>
+
+#include <stout/lambda.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+#include "slave/flags.hpp"
+
+namespace mesos {
+namespace internal {
+namespace slave {
+
+// Forward declarations.
+class CgroupsIsolatorProcess;
+
+
+/**
+ * An abstraction for cgroups subsystem.
+ */
+class Subsystem : public process::Process<Subsystem>
+{
+public:
+ /**
+ * Attempts to create a specific `Subsystem` object that will contain specific
+ * information associated with container.
+ *
+ * @param flags `Flags` used to launch the agent.
+ * @param name The name of cgroups subsystem.
+ * @param hierarchy The hierarchy path of cgroups subsystem.
+ * @return A specific `Subsystem` object or an error if `create` fails.
+ */
+ static Try<process::Owned<Subsystem>> create(
+ const Flags& _flags,
+ const std::string& _name,
+ const std::string& _hierarchy);
+
+ virtual ~Subsystem();
+
+ /**
+ * The cgroups subsystem name of this `Subsystem` object.
+ *
+ * @return The cgroups subsystem name.
+ */
+ virtual std::string name() const = 0;
+
+ /**
+ * Recover the cgroups subsystem for the associated container.
+ *
+ * @param containerId The target containerId.
+ * @return Nothing or an error if `recover` fails.
+ */
+ virtual process::Future<Nothing> recover(const ContainerID& containerId);
+
+ /**
+ * Prepare the cgroups subsystem for the associated container.
+ *
+ * @param containerId The target containerId.
+ * @return Nothing or an error if `prepare` fails.
+ */
+ virtual process::Future<Nothing> prepare(const ContainerID& containerId);
+
+ /**
+ * Isolate the associated container to cgroups subsystem.
+ *
+ * @param containerId The target containerId.
+ * @param pid The process id of container.
+ * @return Nothing or an error if `isolate` fails.
+ */
+ virtual process::Future<Nothing> isolate(
+ const ContainerID& containerId,
+ pid_t pid);
+
+ /**
+ * Update resources allocated to the associated container in this cgroups
+ * subsystem.
+ *
+ * @param containerId The target containerId.
+ * @param resources The resources need to update.
+ * @return Nothing or an error if `update` fails.
+ */
+ virtual process::Future<Nothing> update(
+ const ContainerID& containerId,
+ const Resources& resources);
+
+ /**
+ * Gather resource usage statistics of the cgroups subsystem for the
+ * associated container.
+ *
+ * @param containerId The target containerId.
+ * @return The resource usage statistics or an error if gather statistics
+ * fails.
+ */
+ virtual process::Future<ResourceStatistics> usage(
+ const ContainerID& containerId);
+
+ /**
+ * Get the run-time status of cgroups subsystem specific properties associated
+ * with the container.
+ *
+ * @param containerId The target containerId.
+ * @return The container status or an error if get fails.
+ */
+ virtual process::Future<ContainerStatus> status(
+ const ContainerID& containerId);
+
+ /**
+ * Clean up the cgroups subsystem for the associated container. It will be
+ * called when destruction to ensure everyting be cleanup.
+ *
+ * @param containerId The target containerId.
+ * @return Nothing or an error if `cleanup` fails.
+ */
+ virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+
+protected:
+ Subsystem(const Flags& _flags, const std::string& _hierarchy);
+
+ /**
+ * `Flags` used to launch the agent.
+ */
+ const Flags flags;
+
+ /**
+ * The hierarchy path of cgroups subsystem.
+ */
+ const std::string hierarchy;
+};
+
+} // namespace slave {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __CGROUPS_ISOLATOR_SUBSYSTEM_HPP__