Windows: Added support for `fetcher.cpp`. Review: https://reviews.apache.org/r/47472/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/db26fdad Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/db26fdad Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/db26fdad Branch: refs/heads/master Commit: db26fdadbf3bfd135c4ef5ee491f0ee34dfc7791 Parents: e182780 Author: Alex Clemmer <[email protected]> Authored: Mon May 30 21:03:36 2016 -0700 Committer: Joris Van Remoortere <[email protected]> Committed: Mon May 30 21:06:28 2016 -0700 ---------------------------------------------------------------------- src/slave/containerizer/fetcher.cpp | 45 ++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/db26fdad/src/slave/containerizer/fetcher.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp index 176d886..12f64ae 100644 --- a/src/slave/containerizer/fetcher.cpp +++ b/src/slave/containerizer/fetcher.cpp @@ -24,7 +24,12 @@ #include <stout/net.hpp> #include <stout/path.hpp> +#ifdef __WINDOWS__ +#include <stout/windows.hpp> +#endif // __WINDOWS__ +#include <stout/os/find.hpp> +#include <stout/os/killtree.hpp> #include <stout/os/read.hpp> #include "hdfs/hdfs.hpp" @@ -206,11 +211,18 @@ Result<string> Fetcher::uriToLocalPath( fileUri = true; } - if (fileUri && !strings::startsWith(path, "/")) { - return Error("File URI only supports absolute paths"); - } + const bool isRelativePath = +#ifndef __WINDOWS__ + !strings::startsWith(path, "/"); +#else + static_cast<bool>(::PathIsRelative(path.c_str())); +#endif // __WINDOWS__ + + if (isRelativePath) { + if (fileUri) { + return Error("File URI only supports absolute paths"); + } - if (path.find_first_of("/") != 0) { if (frameworksHome.isNone() || frameworksHome.get().empty()) { return Error("A relative path was passed for the resource but the " "Mesos framework home was not specified. " @@ -305,6 +317,9 @@ static Try<Bytes> fetchSize( return size.get(); } + // TODO(hausdorff): (MESOS-5460) Explore adding support for fetching from + // HDFS. +#ifndef __WINDOWS__ Try<Owned<HDFS>> hdfs = HDFS::create(); if (hdfs.isError()) { return Error("Failed to create HDFS client: " + hdfs.error()); @@ -319,6 +334,9 @@ static Try<Bytes> fetchSize( } return size.get(); +#else + return Error("Windows currently does not support fetching files from HDFS"); +#endif // __WINDOWS__ } @@ -354,6 +372,8 @@ Future<Nothing> FetcherProcess::fetch( cacheDirectory = path::join(cacheDirectory, commandUser.get()); } +// `os::chown` is not supported on Windows. +#ifndef __WINDOWS__ if (commandUser.isSome()) { // First assure that we are working for a valid user. // TODO(bernd-mesos): This should be asynchronous. @@ -364,6 +384,7 @@ Future<Nothing> FetcherProcess::fetch( " with error: " + chown.error()); } } +#endif // __WINDOWS__ // For each URI we determine if we should use the cache and if so we // try and either get the cache entry or create a cache entry. If @@ -561,7 +582,11 @@ Future<Nothing> FetcherProcess::__fetch( } return future; // Always propagate the failure! - })) + }) + // Call to `operator` here forces the conversion on MSVC. This is implicit + // on clang an gcc. + .operator std::function<process::Future<Nothing>( + const process::Future<Nothing> &)>()) .then(defer(self(), [=]() { foreachvalue (const Option<shared_ptr<Cache::Entry>>& entry, entries) { if (entry.isSome()) { @@ -732,9 +757,9 @@ Future<Nothing> FetcherProcess::run( return Failure("Failed to create 'stdout' file: " + out.error()); } - string stderr = path::join(info.sandbox_directory(), "stderr"); + string _stderr = path::join(info.sandbox_directory(), "stderr"); Try<int> err = os::open( - stderr, + _stderr, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); @@ -743,6 +768,9 @@ Future<Nothing> FetcherProcess::run( return Failure("Failed to create 'stderr' file: " + err.error()); } +// NOTE: `os::chown` is not supported on Windows. The flag that gets passed in +// here is conditionally compiled out on Windows. +#ifndef __WINDOWS__ if (user.isSome()) { // This is a recursive chown that both checks if we have a valid user // and also chowns the files we just opened. @@ -756,6 +784,7 @@ Future<Nothing> FetcherProcess::run( "' with error: " + chown.error()); } } +#endif // __WINDOWS__ string fetcherPath = path::join(flags.launcher_dir, "mesos-fetcher"); Result<string> realpath = os::realpath(fetcherPath); @@ -830,7 +859,7 @@ Future<Nothing> FetcherProcess::run( .onFailed(defer(self(), [=](const string&) { // To aid debugging what went wrong when attempting to fetch, grab the // fetcher's local log output from the sandbox and log it here. - Try<string> text = os::read(stderr); + Try<string> text = os::read(_stderr); if (text.isSome()) { LOG(WARNING) << "Begin fetcher log (stderr in sandbox) for container " << containerId << " from running command: " << command
