You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/02/22 01:50:52 UTC

[1/2] git commit: Replaced static non-PODs with pointers and removed dead code.

Repository: mesos
Updated Branches:
  refs/heads/master 4cbad36f5 -> c1cb7d39e


Replaced static non-PODs with pointers and removed dead code.

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


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

Branch: refs/heads/master
Commit: ae5a6d57f20c1ad986e3f56099571e5ee33820e7
Parents: 4cbad36
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Fri Feb 21 16:31:42 2014 -0800
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Fri Feb 21 16:39:11 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/logging.hpp |   1 +
 3rdparty/libprocess/include/process/time.hpp    |   7 +-
 .../libprocess/include/process/timeseries.hpp   |   4 +-
 3rdparty/libprocess/src/process.cpp             |  19 ++-
 3rdparty/libprocess/src/synchronized.cpp        |  66 ----------
 3rdparty/libprocess/src/tests/time_tests.cpp    |  20 +--
 3rdparty/libprocess/src/timer.cpp               |  57 ---------
 3rdparty/libprocess/src/timer.hpp               | 125 -------------------
 8 files changed, 26 insertions(+), 273 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/include/process/logging.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/logging.hpp b/3rdparty/libprocess/include/process/logging.hpp
index f4fb619..0882266 100644
--- a/3rdparty/libprocess/include/process/logging.hpp
+++ b/3rdparty/libprocess/include/process/logging.hpp
@@ -101,6 +101,7 @@ private:
     }
   }
 
+  // TODO(dhamon): Convert to static function.
   static const std::string TOGGLE_HELP;
 
   Timeout timeout;

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/include/process/time.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/time.hpp b/3rdparty/libprocess/include/process/time.hpp
index 26cec3d..bd31211 100644
--- a/3rdparty/libprocess/include/process/time.hpp
+++ b/3rdparty/libprocess/include/process/time.hpp
@@ -18,8 +18,8 @@ public:
   // empty values.
   Time() : sinceEpoch(Duration::zero()) {}
 
-  static Time EPOCH;
-  static Time MAX;
+  static Time epoch();
+  static Time max();
 
   static Try<Time> create(double seconds);
 
@@ -74,6 +74,9 @@ private:
   Time(const Duration& _sinceEpoch) : sinceEpoch(_sinceEpoch) {}
 };
 
+inline Time Time::epoch() { return Time(Duration::zero()); }
+inline Time Time::max() { return Time(Duration::max()); }
+
 
 // Outputs the time in RFC 3339 Format.
 inline std::ostream& operator << (std::ostream& stream, const Time& time)

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/include/process/timeseries.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/timeseries.hpp b/3rdparty/libprocess/include/process/timeseries.hpp
index b368b9b..dbb2c7a 100644
--- a/3rdparty/libprocess/include/process/timeseries.hpp
+++ b/3rdparty/libprocess/include/process/timeseries.hpp
@@ -86,10 +86,10 @@ struct TimeSeries
     }
 
     typename std::map<Time, T>::const_iterator lower = values.lower_bound(
-        start.isSome() ? start.get() : Time::EPOCH);
+        start.isSome() ? start.get() : Time::epoch());
 
     typename std::map<Time, T>::const_iterator upper = values.upper_bound(
-        stop.isSome() ? stop.get() : Time::MAX);
+        stop.isSome() ? stop.get() : Time::max());
 
     std::vector<Value> values;
     while (lower != upper) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 69898b7..f3ec750 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -136,12 +136,12 @@ namespace ID {
 
 string generate(const string& prefix)
 {
-  static map<string, int> prefixes;
+  static map<string, int>* prefixes = new map<string, int>();
   static synchronizable(prefixes) = SYNCHRONIZED_INITIALIZER;
 
   int id;
   synchronized (prefixes) {
-    int& _id = prefixes[prefix];
+    int& _id = (*prefixes)[prefix];
     _id += 1;
     id = _id;
   }
@@ -561,8 +561,7 @@ static synchronizable(watchers) = SYNCHRONIZED_INITIALIZER;
 // We store the timers in a map of lists indexed by the timeout of the
 // timer so that we can have two timers that have the same timeout. We
 // exploit that the map is SORTED!
-static map<Time, list<Timer> >* timeouts =
-  new map<Time, list<Timer> >();
+static map<Time, list<Timer> >* timeouts = new map<Time, list<Timer> >();
 static synchronizable(timeouts) = SYNCHRONIZED_INITIALIZER_RECURSIVE;
 
 // For supporting Clock::settle(), true if timers have been removed
@@ -605,8 +604,10 @@ namespace clock {
 
 map<ProcessBase*, Time>* currents = new map<ProcessBase*, Time>();
 
-Time initial = Time::EPOCH;
-Time current = Time::EPOCH;
+// TODO(dhamon): These static non-POD instances should be replaced by pointers
+// or functions.
+Time initial = Time::epoch();
+Time current = Time::epoch();
 
 Duration advanced = Duration::zero();
 
@@ -615,12 +616,6 @@ bool paused = false;
 } // namespace clock {
 
 
-Time Time::EPOCH = Time(Duration::zero());
-
-
-Time Time::MAX = Time(Duration::max());
-
-
 Time Clock::now()
 {
   return now(__process__);

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/src/synchronized.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/synchronized.cpp b/3rdparty/libprocess/src/synchronized.cpp
deleted file mode 100644
index 79b0849..0000000
--- a/3rdparty/libprocess/src/synchronized.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-#include "synchronized.hpp"
-
-using std::string;
-
-
-static string s1;
-static synchronizable(s1);
-
-static string s2;
-static synchronizable(s2) = SYNCHRONIZED_INITIALIZER;
-
-static string s3;
-static synchronizable(s3) = SYNCHRONIZED_INITIALIZER_RECURSIVE;
-
-
-void bar()
-{
-  synchronized(s3) {
-
-  }
-}
-
-
-void foo()
-{
-  synchronized(s3) {
-    bar();
-  }
-}
-
-
-class Foo
-{
-public:
-  Foo()
-  {
-    synchronizer(s) = SYNCHRONIZED_INITIALIZER_RECURSIVE;
-  }
-
-  void foo()
-  {
-    synchronized(s) {
-      synchronized(s) {
-
-      }
-    }
-  }
-  
-private:
-  string s;
-  synchronizable(s);
-};
-
-
-int main(int argc, char **argv)
-{
-  synchronizer(s1) = SYNCHRONIZED_INITIALIZER_RECURSIVE;
-  //synchronizer(s2) = SYNCHRONIZED_INITIALIZER;
-
-  //foo();
-
-  Foo f;
-  f.foo();
-
-  return 0;
-}

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/src/tests/time_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/time_tests.cpp b/3rdparty/libprocess/src/tests/time_tests.cpp
index a25827e..be31418 100644
--- a/3rdparty/libprocess/src/tests/time_tests.cpp
+++ b/3rdparty/libprocess/src/tests/time_tests.cpp
@@ -14,17 +14,18 @@ using namespace process;
 
 TEST(TimeTest, Arithmetic)
 {
-  Time t = Time::EPOCH + Weeks(1000);
+  Time t = Time::epoch() + Weeks(1000);
   t -= Weeks(1);
-  EXPECT_EQ(Time::EPOCH + Weeks(999), t);
+  EXPECT_EQ(Time::epoch() + Weeks(999), t);
 
   t += Weeks(2);
-  EXPECT_EQ(Time::EPOCH + Weeks(1001), t);
+  EXPECT_EQ(Time::epoch() + Weeks(1001), t);
 
-  EXPECT_EQ(t, Time::EPOCH + Weeks(1000) + Weeks(1));
-  EXPECT_EQ(t, Time::EPOCH + Weeks(1002) - Weeks(1));
+  EXPECT_EQ(t, Time::epoch() + Weeks(1000) + Weeks(1));
+  EXPECT_EQ(t, Time::epoch() + Weeks(1002) - Weeks(1));
 
-  EXPECT_EQ(Weeks(1), (Time::EPOCH + Weeks(1000)) - (Time::EPOCH + Weeks(999)));
+  EXPECT_EQ(Weeks(1),
+            (Time::epoch() + Weeks(1000)) - (Time::epoch() + Weeks(999)));
 }
 
 
@@ -38,9 +39,10 @@ TEST(TimeTest, Now)
 
 TEST(TimeTest, Output)
 {
-  EXPECT_EQ("1989-03-02 00:00:00+00:00", stringify(Time::EPOCH + Weeks(1000)));
+  EXPECT_EQ("1989-03-02 00:00:00+00:00",
+            stringify(Time::epoch() + Weeks(1000)));
   EXPECT_EQ("1989-03-02 00:00:00.000000001+00:00",
-            stringify(Time::EPOCH + Weeks(1000) + Nanoseconds(1)));
+            stringify(Time::epoch() + Weeks(1000) + Nanoseconds(1)));
   EXPECT_EQ("1989-03-02 00:00:00.000001000+00:00",
-            stringify(Time::EPOCH + Weeks(1000) + Microseconds(1)));
+            stringify(Time::epoch() + Weeks(1000) + Microseconds(1)));
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/src/timer.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/timer.cpp b/3rdparty/libprocess/src/timer.cpp
deleted file mode 100644
index aa1ee1b..0000000
--- a/3rdparty/libprocess/src/timer.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <process/timeout.hpp>
-#include <process/timer.hpp>
-
-#include <stout/lambda.hpp>
-
-namespace process {
-
-class TimerProcess : public Process<TimerProcess>
-{
-public:
-  TimerProcess(double _secs,
-               const UPID& _pid,
-               lambda::function<void(ProcessBase*)>* _dispatcher)
-    : secs(_secs), pid(_pid), dispatcher(_dispatcher) {}
-
-protected:
-  virtual void operator () ()
-  {
-    if (receive(secs) == TIMEOUT) {
-      internal::dispatch(pid, dispatcher);
-    } else {
-      delete dispatcher;
-    }
-  }
-
-private:
-  const double secs;
-  const UPID pid;
-  lambda::function<void(ProcessBase*)>* dispatcher;
-};
-
-
-static void dispatch()
-
-
-Timer::Timer(double secs,
-             const UPID& pid,
-             lambda::function<void(ProcessBase*)>* dispatcher)
-{
-  timer = spawn(new TimerProcess(secs, pid, dispatcher), true);
-}
-
-
-Timer::~Timer()
-{
-  // NOTE: Do not terminate the timer! Some users will simply ignore
-  // saving the timer because they never want to cancel, thus
-  // we can not terminate it here!
-}
-
-
-void Timer::cancel()
-{
-  timeouts::cancel(timeout);
-}
-
-} // namespace process {

http://git-wip-us.apache.org/repos/asf/mesos/blob/ae5a6d57/3rdparty/libprocess/src/timer.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/timer.hpp b/3rdparty/libprocess/src/timer.hpp
deleted file mode 100644
index 443b5a0..0000000
--- a/3rdparty/libprocess/src/timer.hpp
+++ /dev/null
@@ -1,125 +0,0 @@
-#ifndef TIMER_HPP
-#define TIMER_HPP
-
-#include <ctime>
-#include <iostream>
-#include <iomanip>
-
-class timer
-{
-  friend std::ostream& operator<<(std::ostream& os, timer& t);
-
-private:
-  bool running;
-  clock_t start_clock;
-  time_t start_time;
-  double acc_time;
-
-  double elapsed_time();
-
-public:
-  // 'running' is initially false.  A timer needs to be explicitly started
-  // using 'start' or 'restart'
-  timer() : running(false), start_clock(0), start_time(0), acc_time(0) { }
-
-  void start(const char* msg = 0);
-  void restart(const char* msg = 0);
-  void stop(const char* msg = 0);
-  void check(const char* msg = 0);
-
-}; // class timer
-
-//===========================================================================
-// Return the total time that the timer has been in the "running"
-// state since it was first "started" or last "restarted".  For
-// "short" time periods (less than an hour), the actual cpu time
-// used is reported instead of the elapsed time.
-
-inline double timer::elapsed_time()
-{
-  time_t acc_sec = time(0) - start_time;
-  if (acc_sec < 3600)
-    return (clock() - start_clock) / (1.0 * CLOCKS_PER_SEC);
-  else
-    return (1.0 * acc_sec);
-
-} // timer::elapsed_time
-
-//===========================================================================
-// Start a timer.  If it is already running, let it continue running.
-// Print an optional message.
-
-inline void timer::start(const char* msg)
-{
-  // Print an optional message, something like "Starting timer t";
-  if (msg) std::cout << msg << std::endl;
-
-  // Return immediately if the timer is already running
-  if (running) return;
-
-  // Set timer status to running and set the start time
-  running = true;
-  start_clock = clock();
-  start_time = time(0);
-
-} // timer::start
-
-//===========================================================================
-// Turn the timer off and start it again from 0.  Print an optional message.
-
-inline void timer::restart(const char* msg)
-{
-  // Print an optional message, something like "Restarting timer t";
-  if (msg) std::cout << msg << std::endl;
-
-  // Set timer status to running, reset accumulated time, and set start time
-  running = true;
-  acc_time = 0;
-  start_clock = clock();
-  start_time = time(0);
-
-} // timer::restart
-
-//===========================================================================
-// Stop the timer and print an optional message.
-
-inline void timer::stop(const char* msg)
-{
-  // Print an optional message, something like "Stopping timer t";
-  if (msg) std::cout << msg << std::endl;
-
-  // Compute accumulated running time and set timer status to not running
-  if (running) acc_time += elapsed_time();
-  running = false;
-
-} // timer::stop
-
-//===========================================================================
-// Print out an optional message followed by the current timer timing.
-
-inline void timer::check(const char* msg)
-{
-  // Print an optional message, something like "Checking timer t";
-  if (msg) std::cout << msg << " : ";
-
-  std::cout << "Elapsed time [" << std::setiosflags(std::ios::fixed)
-            << std::setprecision(2)
-            << acc_time + (running ? elapsed_time() : 0) << "] seconds\n";
-
-} // timer::check
-
-//===========================================================================
-// Allow timers to be printed to ostreams using the syntax 'os << t'
-// for an ostream 'os' and a timer 't'.  For example, "cout << t" will
-// print out the total amount of time 't' has been "running".
-
-inline std::ostream& operator<<(std::ostream& os, timer& t)
-{
-  os << std::setprecision(2) << std::setiosflags(std::ios::fixed)
-     << t.acc_time + (t.running ? t.elapsed_time() : 0);
-  return os;
-}
-
-//===========================================================================
-
-#endif /* TIMER_HPP */


[2/2] git commit: Updated resource model reporting to sum across multiple roles.

Posted by bm...@apache.org.
Updated resource model reporting to sum across multiple roles.

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


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

Branch: refs/heads/master
Commit: c1cb7d39e2f1e48738b669f266c09a14738ae82b
Parents: ae5a6d5
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Fri Feb 21 16:41:28 2014 -0800
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Fri Feb 21 16:41:28 2014 -0800

----------------------------------------------------------------------
 src/Makefile.am     |   2 +
 src/common/http.cpp | 119 +++++++++++++++++++++++++++++++++++++++++++++++
 src/common/http.hpp |  39 ++++++++++++++++
 src/master/http.cpp |  99 +++------------------------------------
 src/slave/http.cpp  |  76 +++---------------------------
 5 files changed, 173 insertions(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index f1ceab3..61d832b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,6 +186,7 @@ libmesos_no_3rdparty_la_SOURCES =					\
 	slave/status_update_manager.cpp					\
 	exec/exec.cpp							\
 	common/lock.cpp							\
+	common/http.cpp							\
 	common/date_utils.cpp						\
 	common/resources.cpp						\
 	common/attributes.cpp						\
@@ -221,6 +222,7 @@ endif
 libmesos_no_3rdparty_la_SOURCES += common/attributes.hpp		\
 	common/build.hpp common/date_utils.hpp common/factory.hpp	\
 	common/protobuf_utils.hpp					\
+	common/http.hpp							\
 	common/lock.hpp							\
 	common/type_utils.hpp common/thread.hpp				\
 	examples/utils.hpp files/files.hpp				\

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
new file mode 100644
index 0000000..e81a7ad
--- /dev/null
+++ b/src/common/http.cpp
@@ -0,0 +1,119 @@
+#include "common/http.hpp"
+
+#include <map>
+#include <string>
+
+#include <glog/logging.h>
+
+#include <stout/foreach.hpp>
+#include <stout/stringify.hpp>
+
+#include "common/attributes.hpp"
+
+#include "messages/messages.hpp"
+
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
+using std::map;
+using std::string;
+
+namespace mesos {
+namespace internal {
+
+// TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
+// it becomes available).
+
+JSON::Object model(const Resources& resources)
+{
+  JSON::Object object;
+  object.values["cpus"] = 0;
+  object.values["mem"] = 0;
+  object.values["disk"] = 0;
+
+  const Option<double>& cpus = resources.cpus();
+  if (cpus.isSome()) {
+    object.values["cpus"] = cpus.get();
+  }
+
+  const Option<Bytes>& mem = resources.mem();
+  if (mem.isSome()) {
+    object.values["mem"] = mem.get().megabytes();
+  }
+
+  const Option<Bytes>& disk = resources.disk();
+  if (disk.isSome()) {
+    object.values["disk"] = disk.get().megabytes();
+  }
+
+  const Option<Value::Ranges>& ports = resources.ports();
+  if (ports.isSome()) {
+    object.values["ports"] = stringify(ports.get());
+  }
+
+  return object;
+}
+
+
+JSON::Object model(const Attributes& attributes)
+{
+  JSON::Object object;
+
+  foreach (const Attribute& attribute, attributes) {
+    switch (attribute.type()) {
+      case Value::SCALAR:
+        object.values[attribute.name()] = attribute.scalar().value();
+        break;
+      case Value::RANGES:
+        object.values[attribute.name()] = stringify(attribute.ranges());
+        break;
+      case Value::SET:
+        object.values[attribute.name()] = stringify(attribute.set());
+        break;
+      case Value::TEXT:
+        object.values[attribute.name()] = attribute.text().value();
+        break;
+      default:
+        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
+        break;
+    }
+  }
+
+  return object;
+}
+
+
+// Returns a JSON object modeled on a TaskStatus.
+JSON::Object model(const TaskStatus& status)
+{
+  JSON::Object object;
+  object.values["state"] = TaskState_Name(status.state());
+  object.values["timestamp"] = status.timestamp();
+
+  return object;
+}
+
+
+// TODO(bmahler): Expose the executor name / source.
+JSON::Object model(const Task& task)
+{
+  JSON::Object object;
+  object.values["id"] = task.task_id().value();
+  object.values["name"] = task.name();
+  object.values["framework_id"] = task.framework_id().value();
+  object.values["executor_id"] = task.executor_id().value();
+  object.values["slave_id"] = task.slave_id().value();
+  object.values["state"] = TaskState_Name(task.state());
+  object.values["resources"] = model(task.resources());
+
+  JSON::Array array;
+  foreach (const TaskStatus& status, task.statuses()) {
+    array.values.push_back(model(status));
+  }
+  object.values["statuses"] = array;
+
+  return object;
+}
+
+}  // namespace internal {
+}  // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
new file mode 100644
index 0000000..717bbe9
--- /dev/null
+++ b/src/common/http.hpp
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __COMMON_HTTP_HPP__
+#define __COMMON_HTTP_HPP__
+
+#include <stout/json.hpp>
+
+namespace mesos {
+class Resources;
+
+namespace internal {
+class Attributes;
+class Task;
+
+JSON::Object model(const Resources& resources);
+JSON::Object model(const Attributes& attributes);
+JSON::Object model(const Task& task);
+
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __COMMON_HTTP_HPP__
+

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index c941274..6654cac 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -24,9 +24,6 @@
 
 #include <boost/array.hpp>
 
-#include <mesos/mesos.hpp>
-#include <mesos/resources.hpp>
-
 #include <process/help.hpp>
 
 #include <stout/foreach.hpp>
@@ -40,17 +37,23 @@
 
 #include "common/attributes.hpp"
 #include "common/build.hpp"
-#include "common/type_utils.hpp"
+#include "common/http.hpp"
 #include "common/protobuf_utils.hpp"
+#include "common/type_utils.hpp"
 
 #include "logging/logging.hpp"
 
 #include "master/master.hpp"
 
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
 namespace mesos {
 namespace internal {
 namespace master {
 
+using mesos::internal::model;
+
 using process::Future;
 using process::HELP;
 using process::TLDR;
@@ -71,93 +74,6 @@ using std::vector;
 // TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
 // it becomes available).
 
-// Returns a JSON object modeled on a Resources.
-JSON::Object model(const Resources& resources)
-{
-  JSON::Object object;
-
-  foreach (const Resource& resource, resources) {
-    switch (resource.type()) {
-      case Value::SCALAR:
-        object.values[resource.name()] = resource.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[resource.name()] = stringify(resource.ranges());
-        break;
-      case Value::SET:
-        object.values[resource.name()] = stringify(resource.set());
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << resource.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-JSON::Object model(const Attributes& attributes)
-{
-  JSON::Object object;
-
-  foreach (const Attribute& attribute, attributes) {
-    switch (attribute.type()) {
-      case Value::SCALAR:
-        object.values[attribute.name()] = attribute.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[attribute.name()] = stringify(attribute.ranges());
-        break;
-      case Value::SET:
-        object.values[attribute.name()] = stringify(attribute.set());
-        break;
-      case Value::TEXT:
-        object.values[attribute.name()] = attribute.text().value();
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-// Returns a JSON object modeled on a TaskStatus.
-JSON::Object model(const TaskStatus& status)
-{
-  JSON::Object object;
-  object.values["state"] = TaskState_Name(status.state());
-  object.values["timestamp"] = status.timestamp();
-
-  return object;
-}
-
-
-// Returns a JSON object modeled on a Task.
-// TODO(bmahler): Expose the executor name / source.
-JSON::Object model(const Task& task)
-{
-  JSON::Object object;
-  object.values["id"] = task.task_id().value();
-  object.values["name"] = task.name();
-  object.values["framework_id"] = task.framework_id().value();
-  object.values["executor_id"] = task.executor_id().value();
-  object.values["slave_id"] = task.slave_id().value();
-  object.values["state"] = TaskState_Name(task.state());
-  object.values["resources"] = model(task.resources());
-
-  JSON::Array array;
-  foreach (const TaskStatus& status, task.statuses()) {
-    array.values.push_back(model(status));
-  }
-  object.values["statuses"] = array;
-
-  return object;
-}
-
 
 // Returns a JSON object modeled on an Offer.
 JSON::Object model(const Offer& offer)
@@ -395,7 +311,6 @@ const string Master::Http::REDIRECT_HELP = HELP(
         "this will attempt to redirect to the private IP address."));
 
 
-
 Future<Response> Master::Http::redirect(const Request& request)
 {
   LOG(INFO) << "HTTP request for '" << request.path << "'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/c1cb7d39/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 7c4cfba..7ed9abe 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -21,9 +21,6 @@
 #include <string>
 #include <vector>
 
-#include <mesos/mesos.hpp>
-#include <mesos/resources.hpp>
-
 #include <process/help.hpp>
 #include <process/owned.hpp>
 
@@ -36,14 +33,20 @@
 
 #include "common/attributes.hpp"
 #include "common/build.hpp"
+#include "common/http.hpp"
 #include "common/type_utils.hpp"
 
+#include "mesos/mesos.hpp"
+#include "mesos/resources.hpp"
+
 #include "slave/slave.hpp"
 
 namespace mesos {
 namespace internal {
 namespace slave {
 
+using mesos::internal::model;
+
 using process::Future;
 using process::HELP;
 using process::Owned;
@@ -61,59 +64,6 @@ using std::vector;
 // TODO(bmahler): Kill these in favor of automatic Proto->JSON Conversion (when
 // in becomes available).
 
-// Returns a JSON object modeled on a Resources.
-JSON::Object model(const Resources& resources)
-{
-  JSON::Object object;
-
-  foreach (const Resource& resource, resources) {
-    switch (resource.type()) {
-      case Value::SCALAR:
-        object.values[resource.name()] = resource.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[resource.name()] = stringify(resource.ranges());
-        break;
-      case Value::SET:
-        object.values[resource.name()] = stringify(resource.set());
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << resource.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
-
-JSON::Object model(const Attributes& attributes)
-{
-  JSON::Object object;
-
-  foreach (const Attribute& attribute, attributes) {
-    switch (attribute.type()) {
-      case Value::SCALAR:
-        object.values[attribute.name()] = attribute.scalar().value();
-        break;
-      case Value::RANGES:
-        object.values[attribute.name()] = stringify(attribute.ranges());
-        break;
-      case Value::SET:
-        object.values[attribute.name()] = stringify(attribute.set());
-        break;
-      case Value::TEXT:
-        object.values[attribute.name()] = attribute.text().value();
-        break;
-      default:
-        LOG(FATAL) << "Unexpected Value type: " << attribute.type();
-        break;
-    }
-  }
-
-  return object;
-}
-
 
 JSON::Object model(const CommandInfo& command)
 {
@@ -161,20 +111,6 @@ JSON::Object model(const ExecutorInfo& executorInfo)
 }
 
 
-JSON::Object model(const Task& task)
-{
-  JSON::Object object;
-  object.values["id"] = task.task_id().value();
-  object.values["name"] = task.name();
-  object.values["executor_id"] = task.executor_id().value();
-  object.values["framework_id"] = task.framework_id().value();
-  object.values["slave_id"] = task.slave_id().value();
-  object.values["state"] = TaskState_Name(task.state());
-  object.values["resources"] = model(task.resources());
-  return object;
-}
-
-
 JSON::Object model(const TaskInfo& task)
 {
   JSON::Object object;