You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/02/28 03:45:01 UTC
[1/2] mesos git commit: Required jsonifying of generic protobuf to be
explicit opt-in [stout].
Repository: mesos
Updated Branches:
refs/heads/master dd903d0d9 -> b91a740fb
Required jsonifying of generic protobuf to be explicit opt-in [stout].
Review: https://reviews.apache.org/r/43938/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/19945044
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/19945044
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/19945044
Branch: refs/heads/master
Commit: 19945044e46b8512df5cd08469941b4d4da429a7
Parents: dd903d0
Author: Michael Park <mp...@apache.org>
Authored: Sat Feb 27 18:12:00 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Sat Feb 27 18:16:25 2016 -0800
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/protobuf.hpp | 20 ++++++++++++++++----
.../stout/include/stout/representation.hpp | 2 ++
.../3rdparty/stout/tests/protobuf_tests.cpp | 12 +++++++++---
3 files changed, 27 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/19945044/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index eb5502c..eb4ac8c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -39,6 +39,7 @@
#include <stout/jsonify.hpp>
#include <stout/none.hpp>
#include <stout/nothing.hpp>
+#include <stout/representation.hpp>
#include <stout/result.hpp>
#include <stout/stringify.hpp>
#include <stout/try.hpp>
@@ -620,13 +621,23 @@ Try<T> parse(const JSON::Value& value)
namespace JSON {
+// The representation of generic protobuf => JSON,
+// e.g., `jsonify(JSON::Protobuf(message))`.
+struct Protobuf : Representation<google::protobuf::Message>
+{
+ using Representation<google::protobuf::Message>::Representation;
+};
+
+
// `json` function for protobuf messages. Refer to `jsonify.hpp` for details.
// TODO(mpark): This currently uses the default value for optional fields with
// a default that are not set, but we may want to revisit this decision.
-inline void json(ObjectWriter* writer, const google::protobuf::Message& message)
+inline void json(ObjectWriter* writer, const Protobuf& protobuf)
{
using google::protobuf::FieldDescriptor;
+ const google::protobuf::Message& message = protobuf;
+
const google::protobuf::Descriptor* descriptor = message.GetDescriptor();
const google::protobuf::Reflection* reflection = message.GetReflection();
@@ -688,8 +699,8 @@ inline void json(ObjectWriter* writer, const google::protobuf::Message& message)
reflection->GetRepeatedDouble(message, field, i));
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
- writer->element(
- reflection->GetRepeatedMessage(message, field, i));
+ writer->element(Protobuf(
+ reflection->GetRepeatedMessage(message, field, i)));
break;
case FieldDescriptor::CPPTYPE_ENUM:
writer->element(
@@ -731,7 +742,8 @@ inline void json(ObjectWriter* writer, const google::protobuf::Message& message)
writer->field(field->name(), reflection->GetDouble(message, field));
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
- writer->field(field->name(), reflection->GetMessage(message, field));
+ writer->field(
+ field->name(), Protobuf(reflection->GetMessage(message, field)));
break;
case FieldDescriptor::CPPTYPE_ENUM:
writer->field(
http://git-wip-us.apache.org/repos/asf/mesos/blob/19945044/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
index 22f70f7..d1fedcb 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/representation.hpp
@@ -75,6 +75,8 @@ struct Representation : std::reference_wrapper<const T>
// not inherit the base class' constructors.
using std::reference_wrapper<const T>::reference_wrapper;
+ explicit Representation(const T& t) : std::reference_wrapper<const T>(t) {}
+
// Disallow rebinding.
Representation& operator=(const Representation&) = delete;
Representation& operator=(Representation&&) = delete;
http://git-wip-us.apache.org/repos/asf/mesos/blob/19945044/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
index 8dd9cfd..932007b 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
@@ -498,7 +498,7 @@ TEST(ProtobufTest, Jsonify)
"}",
" ");
- EXPECT_EQ(expected, string(jsonify(message)));
+ EXPECT_EQ(expected, string(jsonify(JSON::Protobuf(message))));
}
@@ -533,7 +533,13 @@ TEST(ProtobufTest, JsonifyArray)
arrayMessage.add_values()->CopyFrom(message1);
arrayMessage.add_values()->CopyFrom(message2);
- EXPECT_EQ(expected, string(jsonify(arrayMessage.values())));
+ string actual = jsonify([&arrayMessage](JSON::ArrayWriter* writer) {
+ foreach (const tests::SimpleMessage& message, arrayMessage.values()) {
+ writer->element(JSON::Protobuf(message));
+ }
+ });
+
+ EXPECT_EQ(expected, actual);
}
@@ -592,5 +598,5 @@ TEST(ProtobufTest, JsonifyLargeIntegers)
" ");
// Check JSON -> String.
- EXPECT_EQ(expected, string(jsonify(message)));
+ EXPECT_EQ(expected, string(jsonify(JSON::Protobuf(message))));
}
[2/2] mesos git commit: Required jsonifying of generic protobuf to be
explicit opt-in [mesos].
Posted by mp...@apache.org.
Required jsonifying of generic protobuf to be explicit opt-in [mesos].
Review: https://reviews.apache.org/r/43939/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b91a740f
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b91a740f
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b91a740f
Branch: refs/heads/master
Commit: b91a740fb3c6deca4b8f1ab6a7d83decf144b5fb
Parents: 1994504
Author: Michael Park <mp...@apache.org>
Authored: Sat Feb 27 18:12:13 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Sat Feb 27 18:16:28 2016 -0800
----------------------------------------------------------------------
src/common/http.cpp | 18 ++++++++++++------
src/master/http.cpp | 4 ++--
2 files changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b91a740f/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index f8a0441..be8538f 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -417,11 +417,11 @@ void json(JSON::ObjectWriter* writer, const Task& task)
}
if (task.has_discovery()) {
- writer->field("discovery", task.discovery());
+ writer->field("discovery", JSON::Protobuf(task.discovery()));
}
if (task.has_container()) {
- writer->field("container", task.container());
+ writer->field("container", JSON::Protobuf(task.container()));
}
}
@@ -463,7 +463,7 @@ void json(JSON::ObjectWriter* writer, const CommandInfo& command)
writer->field("argv", command.arguments());
if (command.has_environment()) {
- writer->field("environment", command.environment());
+ writer->field("environment", JSON::Protobuf(command.environment()));
}
writer->field("uris", [&command](JSON::ArrayWriter* writer) {
@@ -484,7 +484,7 @@ void json(JSON::ObjectWriter* writer, const ContainerStatus& status)
}
if (status.has_cgroup_info()) {
- writer->field("cgroup_info", status.cgroup_info());
+ writer->field("cgroup_info", JSON::Protobuf(status.cgroup_info()));
}
}
@@ -501,7 +501,9 @@ void json(JSON::ObjectWriter* writer, const ExecutorInfo& executorInfo)
void json(JSON::ArrayWriter* writer, const Labels& labels)
{
- json(writer, labels.labels());
+ foreach (const Label& label, labels.labels()) {
+ writer->element(JSON::Protobuf(label));
+ }
}
@@ -520,7 +522,11 @@ void json(JSON::ObjectWriter* writer, const NetworkInfo& info)
}
if (info.ip_addresses().size() > 0) {
- writer->field("ip_addresses", info.ip_addresses());
+ writer->field("ip_addresses", [&info](JSON::ArrayWriter* writer) {
+ foreach (const NetworkInfo::IPAddress& ipAddress, info.ip_addresses()) {
+ writer->element(JSON::Protobuf(ipAddress));
+ }
+ });
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/b91a740f/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index f3ce1aa..22f52f4 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -255,11 +255,11 @@ void json(JSON::ObjectWriter* writer, const Full<Framework>& full)
}
if (taskInfo.has_discovery()) {
- writer->field("discovery", taskInfo.discovery());
+ writer->field("discovery", JSON::Protobuf(taskInfo.discovery()));
}
if (taskInfo.has_container()) {
- writer->field("container", taskInfo.container());
+ writer->field("container", JSON::Protobuf(taskInfo.container()));
}
});
}