Added `Event::Update` and `v1::scheduler::TaskStatus` ostream operators.

This operators make gtest print a human-readable representation of the
protos on test failures.

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


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

Branch: refs/heads/master
Commit: 29d1e4e1a1b894da78c2033f1932b282ee794f4b
Parents: 103d6e0
Author: Gaston Kleiman <gas...@mesosphere.io>
Authored: Wed Feb 14 14:34:50 2018 +0800
Committer: Qian Zhang <zhq527...@gmail.com>
Committed: Wed Feb 14 20:34:56 2018 +0800

----------------------------------------------------------------------
 include/mesos/v1/mesos.hpp               |  3 +++
 include/mesos/v1/scheduler/scheduler.hpp | 10 ++++++++
 src/v1/mesos.cpp                         | 37 +++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/29d1e4e1/include/mesos/v1/mesos.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.hpp b/include/mesos/v1/mesos.hpp
index d4c354a..f16568e 100644
--- a/include/mesos/v1/mesos.hpp
+++ b/include/mesos/v1/mesos.hpp
@@ -395,6 +395,9 @@ std::ostream& operator<<(
     const ResourceProviderInfo& resourceProviderInfo);
 
 
+std::ostream& operator<<(std::ostream& stream, const TaskStatus& status);
+
+
 std::ostream& operator<<(std::ostream& stream, const AgentID& agentId);
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/29d1e4e1/include/mesos/v1/scheduler/scheduler.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/scheduler/scheduler.hpp 
b/include/mesos/v1/scheduler/scheduler.hpp
index 2fdd8f2..ab94462 100644
--- a/include/mesos/v1/scheduler/scheduler.hpp
+++ b/include/mesos/v1/scheduler/scheduler.hpp
@@ -19,6 +19,8 @@
 
 #include <ostream>
 
+#include <mesos/v1/mesos.hpp>
+
 // ONLY USEFUL AFTER RUNNING PROTOC.
 #include <mesos/v1/scheduler/scheduler.pb.h>
 
@@ -37,6 +39,14 @@ inline std::ostream& operator<<(std::ostream& stream, const 
Event::Type& type)
   return stream << Event::Type_Name(type);
 }
 
+
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const Event::Update& update)
+{
+  return stream << update.status();
+}
+
 } // namespace scheduler {
 } // namespace v1 {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/29d1e4e1/src/v1/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/v1/mesos.cpp b/src/v1/mesos.cpp
index 8abeae0..576f367 100644
--- a/src/v1/mesos.cpp
+++ b/src/v1/mesos.cpp
@@ -17,6 +17,7 @@
 #include <ostream>
 
 #include <stout/protobuf.hpp>
+#include <stout/uuid.hpp>
 
 #include <mesos/v1/attributes.hpp>
 #include <mesos/v1/mesos.hpp>
@@ -600,6 +601,42 @@ ostream& operator<<(ostream& stream, const RLimitInfo& 
limits)
 }
 
 
+ostream& operator<<(ostream& stream, const TaskStatus& status)
+{
+  stream << status.state();
+
+  if (status.has_uuid()) {
+    stream << " (Status UUID: "
+           << stringify(id::UUID::fromBytes(status.uuid()).get()) << ")";
+  }
+
+  if (status.has_source()) {
+    stream << " Source: " << TaskStatus::Source_Name(status.source());
+  }
+
+  if (status.has_reason()) {
+    stream << " Reason: " << TaskStatus::Reason_Name(status.reason());
+  }
+
+  if (status.has_message()) {
+    stream << " Message: '" << status.message() << "'";
+  }
+
+  stream << " for task '" << status.task_id() << "'";
+
+  if (status.has_agent_id()) {
+    stream << " on agent: " << status.agent_id() << "";
+  }
+
+  if (status.has_healthy()) {
+    stream << " in health state "
+           << (status.healthy() ? "healthy" : "unhealthy");
+  }
+
+  return stream;
+}
+
+
 ostream& operator<<(ostream& stream, const AgentID& agentId)
 {
   return stream << agentId.value();

Reply via email to