You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/07/07 18:19:59 UTC
[03/11] mesos git commit: Added a helper function for JSON:Object to
FileInfo protobuf conversion.
Added a helper function for JSON:Object to FileInfo protobuf conversion.
Review: https://reviews.apache.org/r/49444/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4d26eadd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4d26eadd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4d26eadd
Branch: refs/heads/master
Commit: 4d26eaddab60d883ff8fc7de040dd2b8eaf87ab2
Parents: e36e71a
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Thu Jul 7 10:52:05 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Thu Jul 7 11:02:36 2016 -0700
----------------------------------------------------------------------
src/common/http.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
src/common/http.hpp | 1 +
2 files changed, 63 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4d26eadd/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index dfe44da..d73170d 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -32,11 +32,14 @@
#include <process/http.hpp>
#include <process/pid.hpp>
+#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/protobuf.hpp>
#include <stout/stringify.hpp>
#include <stout/unreachable.hpp>
+#include <stout/os/permissions.hpp>
+
#include "common/http.hpp"
#include "messages/messages.hpp"
@@ -387,6 +390,65 @@ JSON::Object model(const ExecutorInfo& executorInfo)
}
+// Returns JSON representation of a FileInfo protobuf message.
+// Example JSON:
+// {
+// 'path': '\/some\/file',
+// 'mode': '-rwxrwxrwx',
+// 'nlink': 5,
+// 'uid': 'bmahler',
+// 'gid': 'employee',
+// 'size': 4096, // Bytes.
+// 'mtime': 1348258116, // Unix timestamp.
+// }
+JSON::Object model(const FileInfo& fileInfo)
+{
+ JSON::Object file;
+ file.values["path"] = fileInfo.path();
+ file.values["nlink"] = fileInfo.nlink();
+ file.values["size"] = fileInfo.size();
+ file.values["mtime"] = Nanoseconds(fileInfo.mtime().nanoseconds()).secs();
+
+ char filetype;
+ if (S_ISREG(fileInfo.mode())) {
+ filetype = '-';
+ } else if (S_ISDIR(fileInfo.mode())) {
+ filetype = 'd';
+ } else if (S_ISCHR(fileInfo.mode())) {
+ filetype = 'c';
+ } else if (S_ISBLK(fileInfo.mode())) {
+ filetype = 'b';
+ } else if (S_ISFIFO(fileInfo.mode())) {
+ filetype = 'p';
+ } else if (S_ISLNK(fileInfo.mode())) {
+ filetype = 'l';
+ } else if (S_ISSOCK(fileInfo.mode())) {
+ filetype = 's';
+ } else {
+ filetype = '-';
+ }
+
+ struct os::Permissions permissions(fileInfo.mode());
+
+ file.values["mode"] = strings::format(
+ "%c%c%c%c%c%c%c%c%c%c",
+ filetype,
+ permissions.owner.r ? 'r' : '-',
+ permissions.owner.w ? 'w' : '-',
+ permissions.owner.x ? 'x' : '-',
+ permissions.group.r ? 'r' : '-',
+ permissions.group.w ? 'w' : '-',
+ permissions.group.x ? 'x' : '-',
+ permissions.others.r ? 'r' : '-',
+ permissions.others.w ? 'w' : '-',
+ permissions.others.x ? 'x' : '-').get();
+
+ file.values["uid"] = fileInfo.uid();
+ file.values["gid"] = fileInfo.gid();
+
+ return file;
+}
+
} // namespace internal {
void json(JSON::ObjectWriter* writer, const Attributes& attributes)
http://git-wip-us.apache.org/repos/asf/mesos/blob/4d26eadd/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index ca44b11..2dfa789 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -87,6 +87,7 @@ JSON::Object model(const CommandInfo& command);
JSON::Object model(const ExecutorInfo& executorInfo);
JSON::Array model(const Labels& labels);
JSON::Object model(const Task& task);
+JSON::Object model(const FileInfo& fileInfo);
void json(JSON::ObjectWriter* writer, const Task& task);