Implemented `LIST_FILES` call in v1 agent API. Review: https://reviews.apache.org/r/49447/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6600ebe5 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6600ebe5 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6600ebe5 Branch: refs/heads/master Commit: 6600ebe5697240a2df9ed68d3e4456d2168e9150 Parents: 2238ccf Author: Abhishek Dasgupta <a10gu...@linux.vnet.ibm.com> Authored: Thu Jul 7 10:52:19 2016 -0700 Committer: Anand Mazumdar <an...@apache.org> Committed: Thu Jul 7 11:06:16 2016 -0700 ---------------------------------------------------------------------- include/mesos/agent/agent.proto | 6 ++-- include/mesos/v1/agent/agent.proto | 6 ++-- src/slave/http.cpp | 51 ++++++++++++++++++++++++++++++++- src/slave/slave.hpp | 5 ++++ 4 files changed, 63 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/6600ebe5/include/mesos/agent/agent.proto ---------------------------------------------------------------------- diff --git a/include/mesos/agent/agent.proto b/include/mesos/agent/agent.proto index 538d12f..ef07b1f 100644 --- a/include/mesos/agent/agent.proto +++ b/include/mesos/agent/agent.proto @@ -72,6 +72,7 @@ message Call { required DurationInfo duration = 2; } + // Provides the file listing for a directory. message ListFiles { required string path = 1; } @@ -140,8 +141,9 @@ message Response { required uint32 level = 1; } + // Contains the file listing(similar to `ls -l`) for a directory. message ListFiles { - repeated string files = 1; + repeated FileInfo file_infos = 1; } message GetFileContents { @@ -179,4 +181,4 @@ message Response { optional GetFileContents get_file_contents = 8; optional GetState get_state = 9; optional GetContainers get_containers = 10; -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/mesos/blob/6600ebe5/include/mesos/v1/agent/agent.proto ---------------------------------------------------------------------- diff --git a/include/mesos/v1/agent/agent.proto b/include/mesos/v1/agent/agent.proto index 48f1517..8f84508 100644 --- a/include/mesos/v1/agent/agent.proto +++ b/include/mesos/v1/agent/agent.proto @@ -72,6 +72,7 @@ message Call { required DurationInfo duration = 2; } + // Provides the file listing for a directory. message ListFiles { required string path = 1; } @@ -140,8 +141,9 @@ message Response { required uint32 level = 1; } + // Contains the file listing(similar to `ls -l`) for a directory. message ListFiles { - repeated string files = 1; + repeated FileInfo file_infos = 1; } message GetFileContents { @@ -179,4 +181,4 @@ message Response { optional GetFileContents get_file_contents = 8; optional GetState get_state = 9; optional GetContainers get_containers = 10; -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/mesos/blob/6600ebe5/src/slave/http.cpp ---------------------------------------------------------------------- diff --git a/src/slave/http.cpp b/src/slave/http.cpp index ef2d510..86803fe 100644 --- a/src/slave/http.cpp +++ b/src/slave/http.cpp @@ -78,6 +78,7 @@ using process::TLDR; using process::http::Accepted; using process::http::BadRequest; using process::http::Forbidden; +using process::http::NotFound; using process::http::InternalServerError; using process::http::MethodNotAllowed; using process::http::NotAcceptable; @@ -378,7 +379,7 @@ Future<Response> Slave::Http::api( return setLoggingLevel(call, principal, acceptType); case agent::Call::LIST_FILES: - return NotImplemented(); + return listFiles(call, principal, acceptType); case agent::Call::READ_FILE: return NotImplemented(); @@ -734,6 +735,54 @@ Future<Response> Slave::Http::setLoggingLevel( } +Future<Response> Slave::Http::listFiles( + const mesos::agent::Call& call, + const Option<string>& principal, + ContentType contentType) const +{ + CHECK_EQ(mesos::agent::Call::LIST_FILES, call.type()); + + const string& path = call.list_files().path(); + + return slave->files->browse(path, principal) + .then([contentType](const Try<list<FileInfo>, FilesError>& result) + -> Future<Response> { + if (result.isError()) { + const FilesError& error = result.error(); + + switch (error.type) { + case FilesError::Type::INVALID: + return BadRequest(error.message); + + case FilesError::Type::UNAUTHORIZED: + return Forbidden(error.message); + + case FilesError::Type::NOT_FOUND: + return NotFound(error.message); + + case FilesError::Type::UNKNOWN: + return InternalServerError(error.message); + } + + UNREACHABLE(); + } + + mesos::agent::Response response; + response.set_type(mesos::agent::Response::LIST_FILES); + + mesos::agent::Response::ListFiles* listFiles = + response.mutable_list_files(); + + foreach (const FileInfo& fileInfo, result.get()) { + listFiles->add_file_infos()->CopyFrom(fileInfo); + } + + return OK(serialize(contentType, evolve(response)), + stringify(contentType)); + }); +} + + string Slave::Http::STATE_HELP() { return HELP( TLDR( http://git-wip-us.apache.org/repos/asf/mesos/blob/6600ebe5/src/slave/slave.hpp ---------------------------------------------------------------------- diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp index 6a82c36..a8952f0 100644 --- a/src/slave/slave.hpp +++ b/src/slave/slave.hpp @@ -534,6 +534,11 @@ private: const Option<std::string>& principal, ContentType contentType) const; + process::Future<process::http::Response> listFiles( + const mesos::agent::Call& call, + const Option<std::string>& principal, + ContentType contentType) const; + process::Future<process::http::Response> getContainers( const mesos::agent::Call& call, const Option<std::string>& principal,