Added definitions of container rootfs directories. Review: https://reviews.apache.org/r/37722
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c0910886 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c0910886 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c0910886 Branch: refs/heads/master Commit: c0910886549364058025718703aab5ccaa0c4087 Parents: dee1912 Author: Jiang Yan Xu <y...@jxu.me> Authored: Mon Aug 24 11:05:20 2015 -0700 Committer: Jiang Yan Xu <y...@jxu.me> Committed: Tue Aug 25 17:06:31 2015 -0700 ---------------------------------------------------------------------- include/mesos/type_utils.hpp | 8 ++++++ .../containerizer/provisioners/appc/paths.cpp | 19 +++++++++++++ .../containerizer/provisioners/appc/paths.hpp | 28 +++++++++++++++++++- src/slave/paths.cpp | 11 ++++++++ src/slave/paths.hpp | 16 ++++++++--- src/tests/paths_tests.cpp | 11 ++++++++ 6 files changed, 89 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/include/mesos/type_utils.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp index dafe1df..92a0b46 100644 --- a/include/mesos/type_utils.hpp +++ b/include/mesos/type_utils.hpp @@ -395,6 +395,14 @@ inline std::ostream& operator<<( } +inline std::ostream& operator<<( + std::ostream& stream, + const Image::Type& imageType) +{ + return stream << Image::Type_Name(imageType); +} + + template <typename T> inline std::ostream& operator<<( std::ostream& stream, http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/src/slave/containerizer/provisioners/appc/paths.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/provisioners/appc/paths.cpp b/src/slave/containerizer/provisioners/appc/paths.cpp index a244d9a..3113c84 100644 --- a/src/slave/containerizer/provisioners/appc/paths.cpp +++ b/src/slave/containerizer/provisioners/appc/paths.cpp @@ -19,6 +19,7 @@ #include <stout/path.hpp> #include "slave/containerizer/provisioners/appc/paths.hpp" +#include "slave/paths.hpp" using std::string; @@ -73,6 +74,24 @@ string getImageManifestPath(const std::string& imagePath) return path::join(imagePath, "manifest"); } + +string getContainerRootfsDir( + const string& rootDir, + const Image::Type& imageType, + const ContainerID& containerId, + const string& backend, + const string& imageId) +{ + return path::join( + slave::paths::getProvisionerDir(rootDir, imageType), + "containers", + containerId.value(), + "backends", + backend, + "rootfses", + imageId); +} + } // namespace paths { } // namespace appc { } // namespace slave { http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/src/slave/containerizer/provisioners/appc/paths.hpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/provisioners/appc/paths.hpp b/src/slave/containerizer/provisioners/appc/paths.hpp index e358051..41e3bf7 100644 --- a/src/slave/containerizer/provisioners/appc/paths.hpp +++ b/src/slave/containerizer/provisioners/appc/paths.hpp @@ -32,7 +32,7 @@ namespace paths { // The appc store file system layout is as follows: // -// <root> ('--appc_store_dir' flag) +// <store_dir> ('--appc_store_dir' flag) // |--staging (contains temp directories for staging downloads) // | // |--images (stores validated images) @@ -45,6 +45,24 @@ namespace paths { // externally managed) but implemented to illustrate the need for a // separate 'images' directory. Complete the layout diagram when the // staging directory is utilized by the provisioner. +// +// The appc provisioner rootfs directory is as follows: +// <work_dir> ('--work_dir' flag) +// |-- provisioners +// |-- APPC (see definition in src/slave/paths.hpp) +// |-- containers +// |-- <container_id> +// |-- backends +// |-- <backend> (copy, bind, etc.) +// |-- rootfses +// |-- <image_id> (the rootfs) +// +// NOTE: Each container could have multiple image types, therefore there +// can be the same <container_id> directory under other provisioners e.g., +// <work_dir>/provisioners/DOCKER, etc. Under each provisioner + container +// there can be multiple backends due to the change of backend flags. For +// appc, under each backend a rootfs is identified by the 'image_id' of +// the topmost filesystem layer. std::string getStagingDir(const std::string& storeDir); @@ -72,6 +90,14 @@ std::string getImageManifestPath( std::string getImageManifestPath(const std::string& imagePath); + +std::string getContainerRootfsDir( + const std::string& rootDir, + const Image::Type& imageType, + const ContainerID& containerId, + const std::string& backend, + const std::string& imageId); + } // namespace paths { } // namespace appc { } // namespace slave { http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/src/slave/paths.cpp ---------------------------------------------------------------------- diff --git a/src/slave/paths.cpp b/src/slave/paths.cpp index 0741616..f5697fb 100644 --- a/src/slave/paths.cpp +++ b/src/slave/paths.cpp @@ -446,6 +446,17 @@ string createSlaveDirectory( return directory; } + +string getProvisionerDir( + const string& rootDir, + const Image::Type& imageType) +{ + return path::join( + rootDir, + "provisioners", + stringify(imageType)); +} + } // namespace paths { } // namespace slave { } // namespace internal { http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/src/slave/paths.hpp ---------------------------------------------------------------------- diff --git a/src/slave/paths.hpp b/src/slave/paths.hpp index dbb1f68..35b0439 100644 --- a/src/slave/paths.hpp +++ b/src/slave/paths.hpp @@ -45,6 +45,8 @@ namespace paths { // This includes things like persistent volumes and dynamic // reservations. // +// (5) For provisioning root filesystems for containers. +// // The file system layout is as follows: // // root ('--work_dir' flag) @@ -85,9 +87,11 @@ namespace paths { // |-- resources // | |-- resources.info // |-- volumes -// |-- roles -// |-- <role> -// |-- <persistence_id> (persistent volume) +// | |-- roles +// | |-- <role> +// | |-- <persistence_id> (persistent volume) +// |-- provisioners +// |-- <image_type> (as defined in Image::Type) const char LATEST_SYMLINK[] = "latest"; @@ -270,6 +274,12 @@ std::string createSlaveDirectory( const std::string& rootDir, const SlaveID& slaveId); + +// Contents of the provisioner directory are managed by the provisioner itself. +std::string getProvisionerDir( + const std::string& rootDir, + const Image::Type& imageType); + } // namespace paths { } // namespace slave { } // namespace internal { http://git-wip-us.apache.org/repos/asf/mesos/blob/c0910886/src/tests/paths_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/paths_tests.cpp b/src/tests/paths_tests.cpp index 9b71796..1ccc5c7 100644 --- a/src/tests/paths_tests.cpp +++ b/src/tests/paths_tests.cpp @@ -55,6 +55,8 @@ public: Try<string> path = os::mkdtemp(); CHECK_SOME(path) << "Failed to mkdtemp"; rootDir = path.get(); + + imageType = Image::APPC; } virtual void TearDown() @@ -71,6 +73,7 @@ protected: string role; string persistenceId; string rootDir; + Image::Type imageType; }; @@ -215,6 +218,14 @@ TEST_F(PathsTest, PersistentVolume) EXPECT_EQ(dir, paths::getPersistentVolumePath(rootDir, role, persistenceId)); } + +TEST_F(PathsTest, ProvisionerDir) +{ + string dir = path::join(rootDir, "provisioners", "APPC"); + + EXPECT_EQ(dir, paths::getProvisionerDir(rootDir, imageType)); +} + } // namespace paths { } // namespace slave { } // namespace internal {