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/09/30 21:10:30 UTC
[5/6] mesos git commit: Extended buildPath to support more modes.
Extended buildPath to support more modes.
Review: https://reviews.apache.org/r/52415
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/45381916
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/45381916
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/45381916
Branch: refs/heads/master
Commit: 453819161cd0c2b938144a2f9554a0be81798d67
Parents: a80021d
Author: Jie Yu <yu...@gmail.com>
Authored: Thu Sep 29 21:49:32 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Sep 30 14:04:35 2016 -0700
----------------------------------------------------------------------
src/Makefile.am | 1 +
.../containerizer/mesos/linux_launcher.cpp | 9 +-
src/slave/containerizer/mesos/paths.cpp | 35 +++++--
src/slave/containerizer/mesos/paths.hpp | 25 ++++-
.../mesos_containerizer_paths_tests.cpp | 100 +++++++++++++++++++
5 files changed, 152 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/45381916/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index f093000..63559e2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2162,6 +2162,7 @@ mesos_tests_SOURCES = \
tests/containerizer/memory_isolator_tests.cpp \
tests/containerizer/memory_test_helper.cpp \
tests/containerizer/mesos_containerizer_tests.cpp \
+ tests/containerizer/mesos_containerizer_paths_tests.cpp \
tests/containerizer/provisioner_appc_tests.cpp \
tests/containerizer/provisioner_backend_tests.cpp \
tests/containerizer/provisioner_docker_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/45381916/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 1bce077..bf5c8aa 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -581,13 +581,10 @@ string LinuxLauncherProcess::cgroup(const ContainerID& containerId)
{
return path::join(
flags.cgroups_root,
- strings::remove(
- strings::trim(
- containerizer::paths::buildPath(containerId, CGROUP_SEPARATOR),
- strings::PREFIX,
- "/"),
+ containerizer::paths::buildPath(
+ containerId,
CGROUP_SEPARATOR,
- strings::PREFIX));
+ containerizer::paths::JOIN));
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/45381916/src/slave/containerizer/mesos/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/paths.cpp b/src/slave/containerizer/mesos/paths.cpp
index 6c6b4dc..c34bd33 100644
--- a/src/slave/containerizer/mesos/paths.cpp
+++ b/src/slave/containerizer/mesos/paths.cpp
@@ -32,15 +32,36 @@ namespace paths {
string buildPath(
const ContainerID& containerId,
- const string& prefix)
+ const string& separator,
+ const Mode& mode)
{
if (!containerId.has_parent()) {
- return path::join(prefix, containerId.value());
+ switch (mode) {
+ case PREFIX: return path::join(separator, containerId.value());
+ case SUFFIX: return path::join(containerId.value(), separator);
+ case JOIN: return containerId.value();
+ default: UNREACHABLE();
+ }
} else {
- return path::join(
- buildPath(containerId.parent(), prefix),
- prefix,
- containerId.value());
+ switch (mode) {
+ case PREFIX:
+ return path::join(
+ buildPath(containerId.parent(), separator, PREFIX),
+ separator,
+ containerId.value());
+ case SUFFIX:
+ return path::join(
+ buildPath(containerId.parent(), separator, SUFFIX),
+ containerId.value(),
+ separator);
+ case JOIN:
+ return path::join(
+ buildPath(containerId.parent(), separator, JOIN),
+ separator,
+ containerId.value());
+ default:
+ UNREACHABLE();
+ }
}
}
@@ -51,7 +72,7 @@ string getRuntimePath(
{
return path::join(
runtimeDir,
- buildPath(containerId, CONTAINER_DIRECTORY));
+ buildPath(containerId, CONTAINER_DIRECTORY, PREFIX));
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/45381916/src/slave/containerizer/mesos/paths.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/paths.hpp b/src/slave/containerizer/mesos/paths.hpp
index 1051c21..349ee00 100644
--- a/src/slave/containerizer/mesos/paths.hpp
+++ b/src/slave/containerizer/mesos/paths.hpp
@@ -17,7 +17,13 @@
#ifndef __MESOS_CONTAINERIZER_PATHS_HPP__
#define __MESOS_CONTAINERIZER_PATHS_HPP__
+#include <sys/types.h>
+
#include <string>
+#include <vector>
+
+#include <stout/result.hpp>
+#include <stout/try.hpp>
#include <mesos/mesos.hpp>
@@ -32,17 +38,26 @@ constexpr char STATUS_FILE[] = "status";
constexpr char CONTAINER_DIRECTORY[] = "containers";
+enum Mode
+{
+ PREFIX,
+ SUFFIX,
+ JOIN,
+};
+
// Returns a path representation of a ContainerID that can be used for
// creating cgroups or writing to the filesystem. A ContainerID can
// represent a nested container (i.e, it has a parent ContainerID) and
// the path representation includes all of the parents as directories
-// in the path. The `prefix` parameter is prepended to each
-// ContainerID as we build the path. For example, given two
-// containers, one with ID 'a9dd' and one nested within 'a9dd' with ID
-// '4e3a' and a prefix of 'foo' we'd get: 'foo/a9dd/foo/4e3a').
+// in the path. Depending on the 'mode', the result can be the
+// following for a nested container 'xxx.yyy':
+// 1) mode == PREFIX: '<separator>/xxx/<separator>/yyy'
+// 2) mode == SUFFIX: 'xxx/<separator>/yyy/<separator>'
+// 3) mode == JOIN: 'xxx/<separator>/yyy'
std::string buildPath(
const ContainerID& containerId,
- const std::string& prefix = "");
+ const std::string& separator,
+ const Mode& mode);
// The containerizer uses the runtime directory (flag 'runtime_dir')
http://git-wip-us.apache.org/repos/asf/mesos/blob/45381916/src/tests/containerizer/mesos_containerizer_paths_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/mesos_containerizer_paths_tests.cpp b/src/tests/containerizer/mesos_containerizer_paths_tests.cpp
new file mode 100644
index 0000000..1f35703
--- /dev/null
+++ b/src/tests/containerizer/mesos_containerizer_paths_tests.cpp
@@ -0,0 +1,100 @@
+// 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 <string>
+
+#include <gtest/gtest.h>
+
+#include <stout/path.hpp>
+
+#include "slave/containerizer/mesos/paths.hpp"
+
+using std::string;
+
+using mesos::internal::slave::containerizer::paths::buildPath;
+using mesos::internal::slave::containerizer::paths::JOIN;
+using mesos::internal::slave::containerizer::paths::PREFIX;
+using mesos::internal::slave::containerizer::paths::SUFFIX;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+TEST(MesosContainerizerPathsTest, BuildPathPrefixMode)
+{
+ ContainerID parent;
+ parent.set_value("parent");
+
+ ContainerID child;
+ child.set_value("child");
+ child.mutable_parent()->CopyFrom(parent);
+
+ const string separator = "separator";
+
+ EXPECT_EQ(
+ buildPath(parent, separator, PREFIX),
+ path::join(separator, parent.value()));
+
+ EXPECT_EQ(
+ buildPath(child, separator, PREFIX),
+ path::join(separator, parent.value(), separator, child.value()));
+}
+
+
+TEST(MesosContainerizerPathsTest, BuildPathSuffixMode)
+{
+ ContainerID parent;
+ parent.set_value("parent");
+
+ ContainerID child;
+ child.set_value("child");
+ child.mutable_parent()->CopyFrom(parent);
+
+ const string separator = "separator";
+
+ EXPECT_EQ(
+ buildPath(parent, separator, SUFFIX),
+ path::join(parent.value(), separator));
+
+ EXPECT_EQ(
+ buildPath(child, separator, SUFFIX),
+ path::join(parent.value(), separator, child.value(), separator));
+}
+
+
+TEST(MesosContainerizerPathsTest, BuildPathJoinMode)
+{
+ ContainerID parent;
+ parent.set_value("parent");
+
+ ContainerID child;
+ child.set_value("child");
+ child.mutable_parent()->CopyFrom(parent);
+
+ const string separator = "separator";
+
+ EXPECT_EQ(
+ buildPath(parent, separator, JOIN),
+ parent.value());
+
+ EXPECT_EQ(
+ buildPath(child, separator, JOIN),
+ path::join(parent.value(), separator, child.value()));
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {