Implemented `LIST_FILES` call in v1 master API.

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


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

Branch: refs/heads/master
Commit: 2238ccf50211bd4b9606979f9cce8560dace1bf3
Parents: 74edde6
Author: Abhishek Dasgupta <a10gu...@linux.vnet.ibm.com>
Authored: Thu Jul 7 10:52:15 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Thu Jul 7 11:05:43 2016 -0700

----------------------------------------------------------------------
 include/mesos/master/master.proto    |  4 ++-
 include/mesos/v1/master/master.proto |  4 ++-
 src/master/http.cpp                  | 52 +++++++++++++++++++++++++++++--
 src/master/master.hpp                |  5 +++
 4 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2238ccf5/include/mesos/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/master/master.proto 
b/include/mesos/master/master.proto
index 236a286..d82b245 100644
--- a/include/mesos/master/master.proto
+++ b/include/mesos/master/master.proto
@@ -108,6 +108,7 @@ message Call {
     required DurationInfo duration = 2;
   }
 
+  // Provides the file listing for a directory.
   message ListFiles {
     required string path = 1;
   }
@@ -261,8 +262,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 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/2238ccf5/include/mesos/v1/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/master/master.proto 
b/include/mesos/v1/master/master.proto
index 55eb2d8..711a664 100644
--- a/include/mesos/v1/master/master.proto
+++ b/include/mesos/v1/master/master.proto
@@ -108,6 +108,7 @@ message Call {
     required DurationInfo duration = 2;
   }
 
+  // Provides the file listing for a directory.
   message ListFiles {
     required string path = 1;
   }
@@ -262,8 +263,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 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/2238ccf5/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index bff1fd5..8b7e917 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -517,7 +517,7 @@ Future<Response> Master::Http::api(
       return setLoggingLevel(call, principal, acceptType);
 
     case mesos::master::Call::LIST_FILES:
-      return NotImplemented();
+      return listFiles(call, principal, acceptType);
 
     case mesos::master::Call::READ_FILE:
       return NotImplemented();
@@ -3237,6 +3237,54 @@ Future<Response> Master::Http::roles(
 }
 
 
+Future<Response> Master::Http::listFiles(
+    const mesos::master::Call& call,
+    const Option<string>& principal,
+    ContentType contentType) const
+{
+  CHECK_EQ(mesos::master::Call::LIST_FILES, call.type());
+
+  const string& path = call.list_files().path();
+
+  return master->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::master::Response response;
+      response.set_type(mesos::master::Response::LIST_FILES);
+
+      mesos::master::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));
+    });
+}
+
+
 // This duplicates the functionality offered by `roles()`. This was necessary
 // as the JSON object returned by `roles()` was not specified in a formal way
 // i.e. via a corresponding protobuf object and would have been very hard to
@@ -4229,7 +4277,7 @@ Future<Response> Master::Http::maintenanceStatus(
 
   return _getMaintenanceStatus()
     .then([request](const mesos::maintenance::ClusterStatus& status)
-            -> Response {
+      -> Response {
       return OK(JSON::protobuf(status), request.url.query.get("jsonp"));
     });
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/2238ccf5/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 60efd22..845f2f6 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1425,6 +1425,11 @@ private:
         const Option<std::string>& principal,
         ContentType contentType) const;
 
+    process::Future<process::http::Response> listFiles(
+        const mesos::master::Call& call,
+        const Option<std::string>& principal,
+        ContentType contentType) const;
+
     process::Future<process::http::Response> getLeadingMaster(
         const mesos::master::Call& call,
         const Option<std::string>& principal,

Reply via email to