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/04 19:44:34 UTC

[1/3] mesos git commit: Implemented file volume support in mesos containerizer.

Repository: mesos
Updated Branches:
  refs/heads/master 5e42b96c9 -> 750ada63c


Implemented file volume support in mesos containerizer.

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


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

Branch: refs/heads/master
Commit: d227300199f3c8a5c4ec938d61b53afaec52444d
Parents: 5e42b96
Author: Gilbert Song <so...@gmail.com>
Authored: Mon Jul 4 12:44:14 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 4 12:44:14 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/filesystem/linux.cpp        | 59 ++++++++++++++++----
 1 file changed, 48 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d2273001/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
index adacde1..1f1ec0c 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
@@ -392,7 +392,9 @@ Try<string> LinuxFilesystemIsolatorProcess::script(
       // TODO(idownes): Consider setting ownership and mode.
     }
 
-    // Determine the target of the mount.
+    // Determine the target of the mount. The mount target
+    // is determined by 'container_path'. It can be either
+    // a directory, or the path of a file.
     string target;
 
     if (strings::startsWith(volume.container_path(), "/")) {
@@ -401,11 +403,29 @@ Try<string> LinuxFilesystemIsolatorProcess::script(
             containerConfig.rootfs(),
             volume.container_path());
 
-        Try<Nothing> mkdir = os::mkdir(target);
-        if (mkdir.isError()) {
-          return Error(
-              "Failed to create the target of the mount at '" +
-              target + "': " + mkdir.error());
+        if (os::stat::isfile(source)) {
+          // The file volume case.
+          Try<Nothing> mkdir = os::mkdir(Path(target).dirname());
+          if (mkdir.isError()) {
+            return Error(
+                "Failed to create directory '" +
+                Path(target).dirname() + "' "
+                "for the target mount file: " + mkdir.error());
+          }
+
+          Try<Nothing> touch = os::touch(target);
+          if (touch.isError()) {
+            return Error(
+                "Failed to create the target mount file at '" +
+                target + "': " + touch.error());
+          }
+        } else {
+          Try<Nothing> mkdir = os::mkdir(target);
+          if (mkdir.isError()) {
+            return Error(
+                "Failed to create the target of the mount at '" +
+                target + "': " + mkdir.error());
+          }
         }
       } else {
         target = volume.container_path();
@@ -444,11 +464,28 @@ Try<string> LinuxFilesystemIsolatorProcess::script(
           containerConfig.directory(),
           volume.container_path());
 
-      Try<Nothing> mkdir = os::mkdir(mountPoint);
-      if (mkdir.isError()) {
-        return Error(
-            "Failed to create the target of the mount at '" +
-            mountPoint + "': " + mkdir.error());
+      if (os::stat::isfile(source)) {
+        // The file volume case.
+        Try<Nothing> mkdir = os::mkdir(Path(mountPoint).dirname());
+        if (mkdir.isError()) {
+          return Error(
+              "Failed to create the target mount file directory at '" +
+              Path(mountPoint).dirname() + "': " + mkdir.error());
+        }
+
+        Try<Nothing> touch = os::touch(mountPoint);
+        if (touch.isError()) {
+          return Error(
+              "Failed to create the target mount file at '" +
+              target + "': " + touch.error());
+        }
+      } else {
+        Try<Nothing> mkdir = os::mkdir(mountPoint);
+        if (mkdir.isError()) {
+          return Error(
+              "Failed to create the target of the mount at '" +
+              mountPoint + "': " + mkdir.error());
+        }
       }
     }
 


[3/3] mesos git commit: Added test for file volume from host sandbox mountpoint.

Posted by ji...@apache.org.
Added test for file volume from host sandbox mountpoint.

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


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

Branch: refs/heads/master
Commit: 750ada63cacece03bba7d23bb498892c56fbd699
Parents: f6e2d1e
Author: Gilbert Song <so...@gmail.com>
Authored: Mon Jul 4 12:44:21 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 4 12:44:21 2016 -0700

----------------------------------------------------------------------
 .../containerizer/filesystem_isolator_tests.cpp | 52 ++++++++++++++++++++
 1 file changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/750ada63/src/tests/containerizer/filesystem_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp
index 82e5cae..4d852ad 100644
--- a/src/tests/containerizer/filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/filesystem_isolator_tests.cpp
@@ -1010,6 +1010,58 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHostSandboxMountPoint)
 }
 
 
+// This test verifies that a file volume with an absolute host path
+// and a relative container path is properly mounted in the container's
+// mount namespace. The mount point will be created in the sandbox.
+TEST_F(LinuxFilesystemIsolatorTest, ROOT_FileVolumeFromHostSandboxMountPoint)
+{
+  slave::Flags flags = CreateSlaveFlags();
+
+  ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+
+  Try<Owned<MesosContainerizer>> containerizer = createContainerizer(
+      flags,
+      {{"test_image", path::join(os::getcwd(), "test_image")}});
+
+  ASSERT_SOME(containerizer);
+
+  ExecutorInfo executor = CREATE_EXECUTOR_INFO(
+      "test_executor",
+      "test -f mountpoint/file.txt");
+
+  const string file = path::join(os::getcwd(), "file");
+  ASSERT_SOME(os::touch(file));
+
+  executor.mutable_container()->CopyFrom(createContainerInfo(
+      "test_image",
+      {createVolumeFromHostPath("mountpoint/file.txt", file, Volume::RW)}));
+
+  const string directory = path::join(os::getcwd(), "sandbox");
+  ASSERT_SOME(os::mkdir(directory));
+
+  Future<bool> launch = containerizer.get()->launch(
+      containerId,
+      executor,
+      directory,
+      None(),
+      SlaveID(),
+      PID<Slave>(),
+      false);
+
+  AWAIT_READY_FOR(launch, Seconds(60));
+
+  Future<containerizer::Termination> wait =
+    containerizer.get()->wait(containerId);
+
+  AWAIT_READY(wait);
+
+  // Check the executor exited correctly.
+  EXPECT_TRUE(wait.get().has_status());
+  EXPECT_EQ(0, wait.get().status());
+}
+
+
 // This test verifies that persistent volumes are properly mounted in
 // the container's root filesystem.
 TEST_F(LinuxFilesystemIsolatorTest, ROOT_PersistentVolumeWithRootFilesystem)


[2/3] mesos git commit: Added test for file volume from host.

Posted by ji...@apache.org.
Added test for file volume from host.

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


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

Branch: refs/heads/master
Commit: f6e2d1e7ecc61bbd1ebe1b77313e848df1a2f1d2
Parents: d227300
Author: Gilbert Song <so...@gmail.com>
Authored: Mon Jul 4 12:44:18 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Jul 4 12:44:18 2016 -0700

----------------------------------------------------------------------
 .../containerizer/filesystem_isolator_tests.cpp | 52 ++++++++++++++++++++
 1 file changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f6e2d1e7/src/tests/containerizer/filesystem_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp
index fd23519..82e5cae 100644
--- a/src/tests/containerizer/filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/filesystem_isolator_tests.cpp
@@ -906,6 +906,58 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHost)
 }
 
 
+// This test verifies that a file volume with an absolute host
+// path as well as an absolute container path is properly mounted
+// in the container's mount namespace.
+TEST_F(LinuxFilesystemIsolatorTest, ROOT_FileVolumeFromHost)
+{
+  slave::Flags flags = CreateSlaveFlags();
+
+  ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+
+  Try<Owned<MesosContainerizer>> containerizer = createContainerizer(
+      flags,
+      {{"test_image", path::join(os::getcwd(), "test_image")}});
+
+  ASSERT_SOME(containerizer);
+
+  ExecutorInfo executor = CREATE_EXECUTOR_INFO(
+      "test_executor",
+      "test -f /tmp/test/file.txt");
+
+  const string file = path::join(os::getcwd(), "file");
+  ASSERT_SOME(os::touch(file));
+
+  executor.mutable_container()->CopyFrom(createContainerInfo(
+      "test_image",
+      {createVolumeFromHostPath("/tmp/test/file.txt", file, Volume::RW)}));
+
+  const string directory = path::join(os::getcwd(), "sandbox");
+  ASSERT_SOME(os::mkdir(directory));
+
+  Future<bool> launch = containerizer.get()->launch(
+      containerId,
+      executor,
+      directory,
+      None(),
+      SlaveID(),
+      PID<Slave>(),
+      false);
+
+  AWAIT_READY_FOR(launch, Seconds(60));
+
+  Future<containerizer::Termination> wait =
+    containerizer.get()->wait(containerId);
+
+  AWAIT_READY(wait);
+
+  // Check the executor exited correctly.
+  EXPECT_TRUE(wait.get().has_status());
+  EXPECT_EQ(0, wait.get().status());
+}
+
+
 // This test verifies that a volume with an absolute host path and a
 // relative container path is properly mounted in the container's
 // mount namespace. The mount point will be created in the sandbox.