You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/07/02 00:11:57 UTC
[1/4] git commit: Removed bin/mesos-build-env.sh.in in favor of just
putting flags in the bin/mesos-master.sh.in, bin/mesos-slave.sh.in,
and bin/mesos-local.sh.in scripts since some binaries require different flags
and they will fail on startup if they t
Updated Branches:
refs/heads/master d681af1d6 -> 977f698d3
Removed bin/mesos-build-env.sh.in in favor of just putting flags in
the bin/mesos-master.sh.in, bin/mesos-slave.sh.in, and
bin/mesos-local.sh.in scripts since some binaries require different
flags and they will fail on startup if they try and load an unknown
flag.
Review: https://reviews.apache.org/r/12118
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/5c784f49
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/5c784f49
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/5c784f49
Branch: refs/heads/master
Commit: 5c784f49b544c9389b43c6afeda9aeafa63deb31
Parents: d681af1
Author: Benjamin Hindman <be...@twitter.com>
Authored: Fri Jun 7 18:10:14 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Mon Jul 1 17:18:54 2013 -0400
----------------------------------------------------------------------
README | 12 ++++++------
bin/mesos-build-env.sh.in | 26 --------------------------
bin/mesos-local.sh.in | 6 +++++-
bin/mesos-master.sh.in | 4 +++-
bin/mesos-slave.sh.in | 6 +++++-
bin/mesos-tests.sh.in | 8 ++++++--
configure.ac | 1 -
7 files changed, 25 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/README
----------------------------------------------------------------------
diff --git a/README b/README
index f0f8aa9..ec417c1 100644
--- a/README
+++ b/README
@@ -77,12 +77,12 @@ directory if any).
Running Mesos before Installing
===============================
-After running 'make' but before running 'make install' you can run any
-of the binaries but certain environment variables must be set up first
-(see [build]/bin/mesos-build-env.sh.in). It's advisable to run the
-binaries by using the wrapper scripts provided in [build]/bin. Note
-that these scripts also have a GDB variant that starts the binaries in
-GDB when you want to debug.
+After running 'make' but before running 'make install' we've provided
+scripts for running mesos-master, mesos-slave, mesos-local, and
+mesos-tests that first set some environment variables (see
+[build]/bin/mesos-*.sh). Note that these scripts also have a GDB
+variant ([build]/bin/gdb-mesos-*.sh) that starts the binaries in GDB
+when you want to debug.
Examples and Tests
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/bin/mesos-build-env.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-build-env.sh.in b/bin/mesos-build-env.sh.in
deleted file mode 100644
index f2bbe42..0000000
--- a/bin/mesos-build-env.sh.in
+++ /dev/null
@@ -1,26 +0,0 @@
-# This file is meant to be sourced.
-
-# 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.
-
-# It sets environment variables so Mesos will search for uninstalled
-# dependencies (such as the WebUI) rather than looking in installed locations.
-
-MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
-MESOS_LAUNCHER_DIR=@abs_top_builddir@/src
-
-export MESOS_WEBUI_DIR
-export MESOS_LAUNCHER_DIR
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/bin/mesos-local.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-local.sh.in b/bin/mesos-local.sh.in
index 2ac6789..4910cc9 100644
--- a/bin/mesos-local.sh.in
+++ b/bin/mesos-local.sh.in
@@ -19,6 +19,10 @@
# This is a wrapper for running mesos-local before it is installed
# that first sets up environment variables as appropriate.
-. @abs_top_builddir@/bin/mesos-build-env.sh
+MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
+MESOS_LAUNCHER_DIR=@abs_top_builddir@/src
+
+export MESOS_WEBUI_DIR
+export MESOS_LAUNCHER_DIR
@abs_top_builddir@/src/mesos-local "${@}"
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/bin/mesos-master.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-master.sh.in b/bin/mesos-master.sh.in
index fa9f139..51118f3 100644
--- a/bin/mesos-master.sh.in
+++ b/bin/mesos-master.sh.in
@@ -19,6 +19,8 @@
# This is a wrapper for running mesos-master before it is installed
# that first sets up environment variables as appropriate.
-. @abs_top_builddir@/bin/mesos-build-env.sh
+MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
+
+export MESOS_WEBUI_DIR
exec @abs_top_builddir@/src/mesos-master "${@}"
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/bin/mesos-slave.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-slave.sh.in b/bin/mesos-slave.sh.in
index 0384bcb..1877ef5 100644
--- a/bin/mesos-slave.sh.in
+++ b/bin/mesos-slave.sh.in
@@ -19,6 +19,10 @@
# This is a wrapper for running mesos-slave before it is installed
# that first sets up environment variables as appropriate.
-. @abs_top_builddir@/bin/mesos-build-env.sh
+MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
+MESOS_LAUNCHER_DIR=@abs_top_builddir@/src
+
+export MESOS_WEBUI_DIR
+export MESOS_LAUNCHER_DIR
@abs_top_builddir@/src/mesos-slave "${@}"
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/bin/mesos-tests.sh.in
----------------------------------------------------------------------
diff --git a/bin/mesos-tests.sh.in b/bin/mesos-tests.sh.in
index 8d19556..f234035 100644
--- a/bin/mesos-tests.sh.in
+++ b/bin/mesos-tests.sh.in
@@ -16,9 +16,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# This is a wrapper for running mesos-master before it is installed
+# This is a wrapper for running mesos-tests from the build directory
# that first sets up environment variables as appropriate.
-. @abs_top_builddir@/bin/mesos-build-env.sh
+MESOS_WEBUI_DIR=@abs_top_srcdir@/src/webui
+MESOS_LAUNCHER_DIR=@abs_top_builddir@/src
+
+export MESOS_WEBUI_DIR
+export MESOS_LAUNCHER_DIR
exec @abs_top_builddir@/src/mesos-tests "${@}"
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/5c784f49/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index fbe22e5..eca96a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,7 +83,6 @@ AC_CONFIG_FILES([jenkins/Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([3rdparty/Makefile])
-AC_CONFIG_FILES([bin/mesos-build-env.sh])
AC_CONFIG_FILES([bin/mesos-local.sh], [chmod +x bin/mesos-local.sh])
AC_CONFIG_FILES([bin/mesos-master.sh], [chmod +x bin/mesos-master.sh])
AC_CONFIG_FILES([bin/mesos-slave.sh], [chmod +x bin/mesos-slave.sh])
[3/4] git commit: Added help pages to libprocess.
Posted by be...@apache.org.
Added help pages to libprocess.
Review: https://reviews.apache.org/r/11710
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/0c38dabd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/0c38dabd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/0c38dabd
Branch: refs/heads/master
Commit: 0c38dabd7fa778d75f108b5dc824b572dcc5e88d
Parents: 663ebd0
Author: Benjamin Hindman <be...@twitter.com>
Authored: Thu Jun 6 23:23:21 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Mon Jul 1 18:10:27 2013 -0400
----------------------------------------------------------------------
3rdparty/libprocess/Makefile.am | 1 +
3rdparty/libprocess/include/process/help.hpp | 297 +++++++++++++++++++
3rdparty/libprocess/include/process/logging.hpp | 4 +-
3rdparty/libprocess/include/process/process.hpp | 14 +-
.../libprocess/include/process/profiler.hpp | 7 +-
3rdparty/libprocess/src/process.cpp | 72 +++++
3rdparty/libprocess/src/statistics.cpp | 34 ++-
3rdparty/libprocess/src/tests/http_tests.cpp | 5 +-
8 files changed, 418 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am
index 2819734..a13ea70 100644
--- a/3rdparty/libprocess/Makefile.am
+++ b/3rdparty/libprocess/Makefile.am
@@ -72,6 +72,7 @@ libprocess_la_SOURCES += \
$(top_srcdir)/include/process/gc.hpp \
$(top_srcdir)/include/process/gmock.hpp \
$(top_srcdir)/include/process/gtest.hpp \
+ $(top_srcdir)/include/process/help.hpp \
$(top_srcdir)/include/process/http.hpp \
$(top_srcdir)/include/process/id.hpp \
$(top_srcdir)/include/process/io.hpp \
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/include/process/help.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/help.hpp b/3rdparty/libprocess/include/process/help.hpp
new file mode 100644
index 0000000..65b0590
--- /dev/null
+++ b/3rdparty/libprocess/include/process/help.hpp
@@ -0,0 +1,297 @@
+#ifndef __PROCESS_HELP_HPP__
+#define __PROCESS_HELP_HPP__
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <process/future.hpp>
+#include <process/http.hpp>
+#include <process/process.hpp>
+
+#include <stout/foreach.hpp>
+#include <stout/json.hpp>
+#include <stout/option.hpp>
+#include <stout/preprocessor.hpp>
+#include <stout/stringify.hpp>
+#include <stout/strings.hpp>
+
+namespace process {
+
+// Constructs a Markdown based help "page" for a route with the
+// following template:
+//
+// ### TL;DR; ###
+// tldr
+//
+// ### USAGE ###
+// usage
+//
+// ### DESCRIPTION ###
+// description
+//
+// references
+//
+// See the 'TLDR', 'USAGE', 'DESCRIPTION', and 'REFERENCES' helpers
+// below to more easily construct your help pages.
+inline std::string HELP(
+ std::string tldr,
+ std::string usage,
+ std::string description,
+ const Option<std::string>& references = None())
+{
+ // Make sure 'tldr', 'usage', and 'description' end with a newline.
+ if (!strings::endsWith(tldr, "\n")) {
+ tldr += "\n";
+ }
+
+ if (!strings::endsWith(usage, "\n")) {
+ usage += "\n";
+ }
+
+ if (!strings::endsWith(description, "\n")) {
+ description += "\n";
+ }
+
+ // Construct the help string.
+ std::string help =
+ "### TL;DR; ###\n" +
+ tldr +
+ "\n" +
+ "### USAGE ###\n" +
+ usage +
+ "\n" +
+ "### DESCRIPTION ###\n" +
+ description;
+
+ if (references.isSome()) {
+ help += "\n";
+ help += references.get();
+ }
+
+ return help;
+}
+
+
+// Helper for single-line TL;DR; that adds a newline.
+inline std::string TLDR(const std::string& tldr)
+{
+ return tldr + "\n";
+}
+
+
+// Helper for single-line usage that puts it in a blockquote as code
+// and adds a newline.
+inline std::string USAGE(const std::string& usage)
+{
+ return "> " + usage + "\n";
+}
+
+
+// Helpers for adding newlines to each line of a multi-line
+// description or references.
+#define LINE_TEMPLATE(Z, N, DATA) + CAT(line, N) + "\n"
+#define TEMPLATE(Z, N, DATA) \
+ inline std::string DESCRIPTION( \
+ ENUM_PARAMS(N, const std::string& line)) \
+ { \
+ return \
+ "" \
+ REPEAT_FROM_TO(0, N, LINE_TEMPLATE, _); \
+ } \
+ \
+ \
+ inline std::string REFERENCES( \
+ ENUM_PARAMS(N, const std::string& line)) \
+ { \
+ return \
+ "" \
+ REPEAT_FROM_TO(0, N, LINE_TEMPLATE, _); \
+ }
+
+ REPEAT_FROM_TO(1, 201, TEMPLATE, _) // Lines 1 -> 200.
+#undef TEMPLATE
+#undef LINE_TEMPLATE
+
+
+// Help process for serving /help, /help/id, and /help/id/name (see
+// Help::help below for more information).
+class Help : public Process<Help>
+{
+public:
+ Help() : ProcessBase("help") {}
+
+ // Adds 'help' for the route 'name' of the process with the
+ // specified 'id' (i.e., 'http://ip:port/id/name'). It's expected
+ // that 'help' is written using Markdown. When serving help to a
+ // browser the Markdown will be rendered into HTML while a tool like
+ // 'curl' or 'http' will just be given the Markdown directly (thus
+ // making it easy to get help without opening a browser).
+ // NOTE: There is no need to dispatch this directly; this gets
+ // automagically dispatched by 'ProcessBase::route'.
+ void add(const std::string& id,
+ const std::string& name,
+ const Option<std::string>& help)
+ {
+ if (id != "help") { // TODO(benh): Enable help for help.
+ if (help.isSome()) {
+ helps[id][name] = help.get();
+ } else {
+ helps[id][name] = "## No help page for `/" + id + name + "`\n";
+ }
+ route("/" + id, "Help for " + id, &Help::help);
+ }
+ }
+
+protected:
+ virtual void initialize()
+ {
+ route("/", None(), &Help::help);
+ }
+
+private:
+ // Handles the following:
+ //
+ // (1) http://ip:port/help
+ // (2) http://ip:port/help/id
+ // (3) http://ip:port/help/id/name
+ //
+ // Where 'id' and 'name' are replaced with a process ID and route
+ // name respectively. (1) provides a "table of contents" for all
+ // available processes while (2) provides a "table of contents" for
+ // all endpoints associated with a particular process and (3)
+ // provides the help associated with a particular endpoint of a
+ // process.
+ Future<http::Response> help(const http::Request& request)
+ {
+ // Split the path by '/'.
+ std::vector<std::string> tokens = strings::tokenize(request.path, "/");
+
+ Option<std::string> id = None();
+ Option<std::string> name = None();
+
+ if (tokens.size() > 3) {
+ return http::BadRequest("Malformed URL, expecting '/help/id/name/'\n");
+ } else if (tokens.size() == 3) {
+ id = tokens[1];
+ name = tokens[2];
+ } else if (tokens.size() > 1) {
+ id = tokens[1];
+ }
+
+ std::string document;
+ std::string references;
+
+ if (id.isNone()) { // http://ip:port/help
+ document += "## HELP\n";
+ foreachkey (const std::string& id, helps) {
+ document += "> [/" + id + "][" + id + "]\n";
+ references += "[" + id + "]: /help/" + id + "\n";
+ }
+ } else if (name.isNone()) { // http://ip:port/help/id
+ if (helps.count(id.get()) == 0) {
+ return http::BadRequest(
+ "No help available for '/" + id.get() + "'.\n");
+ }
+
+ document += "## `/" + id.get() + "` ##\n";
+ foreachkey (const std::string& name, helps[id.get()]) {
+ const std::string& path = id.get() + name;
+ document += "> [/" + path + "][" + path + "]\n";
+ references += "[" + path + "]: /help/" + path + "\n";
+ }
+ } else { // http://ip:port/help/id/name
+ if (helps.count(id.get()) == 0) {
+ return http::BadRequest(
+ "No help available for '/" + id.get() + "'.\n");
+ } else if (helps[id.get()].count("/" + name.get()) == 0) {
+ return http::BadRequest(
+ "No help available for '/" + id.get() + "/" + name.get() + "'.\n");
+ }
+
+ document += helps[id.get()]["/" + name.get()];
+ }
+
+ // Final Markdown is 'document' followed by the 'references'.
+ std::string markdown = document + "\n" + references;
+
+ // Just send the Markdown if we aren't speaking to a browser. For
+ // now we only check for the 'curl' or 'http' utilities.
+ Option<std::string> agent = request.headers.get("User-Agent");
+
+ if (agent.isSome() &&
+ (strings::startsWith(agent.get(), "curl") ||
+ strings::startsWith(agent.get(), "HTTPie"))) {
+ http::Response response = http::OK(markdown);
+ response.headers["Content-Type"] = "text/x-markdown";
+ return response;
+ }
+
+ // Need to JSONify the markdown for embedding into JavaScript.
+ markdown = stringify(JSON::String(markdown));
+
+ // URL for jQuery.
+ const std::string jquery =
+ "https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js";
+
+ // Assuming client has Internet access, provide some JavaScript to
+ // render the Markdown into some aesthetically pleasing HTML. ;)
+ // This currently uses GitHub to render the Markdown instead of
+ // doing it client-side in the browser (e.g., using something like
+ // 'showdown.js').
+ return http::OK(
+ "<html>"
+ "<head>"
+ "<title>Help</title>"
+ "<script src=\"" + jquery + "\"></script>"
+ "<script>"
+ " function loaded() {"
+ " var markdown = " + markdown + ";"
+ " if (typeof $ === 'undefined') {"
+ " document.body.innerHTML = '<pre>' + markdown + '</pre>';"
+ " } else {"
+ " var data = { text: markdown, mode: 'gfm' };"
+ " $.ajax({"
+ " type: 'POST',"
+ " url: 'https://api.github.com/markdown',"
+ " data: JSON.stringify(data),"
+ " success: function(data) {"
+ " document.body.innerHTML = data;"
+ " }"
+ " });"
+ " }"
+ " }"
+ "</script>"
+ "<style>"
+ "body {"
+ " font-family: Helvetica, arial, sans-serif;"
+ " font-size: 14px;"
+ " line-height: 1.6;"
+ " padding-top: 10px;"
+ " padding-bottom: 10px;"
+ " background-color: white;"
+ " padding: 30px;"
+ "}"
+ "blockquote {"
+ " border-left: 5px solid #dddddd;"
+ " padding: 0 10px;"
+ " color: #777777;"
+ " margin: 0 0 20px;"
+ "}"
+ "a {"
+ " color: #0088cc;"
+ " text-decoration: none;"
+ "}"
+ "</style>"
+ "</head>"
+ "<body onload=\"loaded()\">"
+ "</body>"
+ "</html>");
+ }
+
+ std::map<std::string, std::map<std::string, std::string> > helps;
+};
+
+} // namespace process {
+
+#endif // __PROCESS_HELP_HPP__
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/include/process/logging.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/logging.hpp b/3rdparty/libprocess/include/process/logging.hpp
index cba2fd4..f4fb619 100644
--- a/3rdparty/libprocess/include/process/logging.hpp
+++ b/3rdparty/libprocess/include/process/logging.hpp
@@ -36,7 +36,7 @@ public:
protected:
virtual void initialize()
{
- route("/toggle", &This::toggle);
+ route("/toggle", TOGGLE_HELP, &This::toggle);
}
private:
@@ -101,6 +101,8 @@ private:
}
}
+ static const std::string TOGGLE_HELP;
+
Timeout timeout;
const int32_t original; // Original value of FLAGS_v.
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/include/process/process.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/process.hpp b/3rdparty/libprocess/include/process/process.hpp
index e70b4f7..df7e143 100644
--- a/3rdparty/libprocess/include/process/process.hpp
+++ b/3rdparty/libprocess/include/process/process.hpp
@@ -18,6 +18,7 @@
#include <process/pid.hpp>
#include <stout/duration.hpp>
+#include <stout/option.hpp>
#include <stout/thread.hpp>
namespace process {
@@ -126,18 +127,13 @@ protected:
// Setup a handler for an HTTP request.
bool route(
const std::string& name,
- const HttpRequestHandler& handler)
- {
- if (name.find('/') != 0) {
- return false;
- }
- handlers.http[name.substr(1)] = handler;
- return true;
- }
+ const Option<std::string>& help,
+ const HttpRequestHandler& handler);
template <typename T>
bool route(
const std::string& name,
+ const Option<std::string>& help,
Future<http::Response> (T::*method)(const http::Request&))
{
// Note that we use dynamic_cast here so a process can use
@@ -146,7 +142,7 @@ protected:
HttpRequestHandler handler =
std::tr1::bind(method, dynamic_cast<T*>(this),
std::tr1::placeholders::_1);
- return route(name, handler);
+ return route(name, help, handler);
}
// Provide the static asset(s) at the specified _absolute_ path for
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/include/process/profiler.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/profiler.hpp b/3rdparty/libprocess/include/process/profiler.hpp
index 64cf622..c886d7e 100644
--- a/3rdparty/libprocess/include/process/profiler.hpp
+++ b/3rdparty/libprocess/include/process/profiler.hpp
@@ -30,11 +30,14 @@ public:
protected:
virtual void initialize()
{
- route("/start", &Profiler::start);
- route("/stop", &Profiler::stop);
+ route("/start", START_HELP, &Profiler::start);
+ route("/stop", STOP_HELP, &Profiler::stop);
}
private:
+ static const std::string START_HELP;
+ static const std::string STOP_HELP;
+
// HTTP endpoints.
// Starts the profiler. There are no request parameters.
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 3ffe0b5..3bd7015 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -53,6 +53,7 @@
#include <process/filter.hpp>
#include <process/future.hpp>
#include <process/gc.hpp>
+#include <process/help.hpp>
#include <process/id.hpp>
#include <process/io.hpp>
#include <process/logging.hpp>
@@ -411,6 +412,56 @@ private:
};
+// Help strings.
+const string Logging::TOGGLE_HELP = HELP(
+ TLDR(
+ "Sets the logging verbosity level for a specified duration."),
+ USAGE(
+ "/logging/toggle?level=VALUE&duration=VALUE"),
+ DESCRIPTION(
+ "The libprocess library uses [glog][glog] for logging. The library",
+ "only uses verbose logging which means nothing will be output unless",
+ "the verbosity level is set (by default it's 0, libprocess uses"
+ "levels 1, 2, and 3).",
+ "",
+ "**NOTE:** If your application uses glog this will also affect",
+ "your verbose logging.",
+ "",
+ "Required query parameters:",
+ "",
+ "> level=VALUE Verbosity level (e.g., 1, 2, 3)",
+ "> duration=VALUE Duration to keep verbosity level",
+ "> toggled (e.g., 10secs, 15mins, etc.)"),
+ REFERENCES(
+ "[glog]: https://code.google.com/p/google-glog"));
+
+
+const string Profiler::START_HELP = HELP(
+ TLDR(
+ "Starts profiling ..."),
+ USAGE(
+ "/profiler/start..."),
+ DESCRIPTION(
+ "...",
+ "",
+ "Query parameters:",
+ "",
+ "> param=VALUE Some description here"));
+
+
+const string Profiler::STOP_HELP = HELP(
+ TLDR(
+ "Stops profiling ..."),
+ USAGE(
+ "/profiler/stop..."),
+ DESCRIPTION(
+ "...",
+ "",
+ "Query parameters:",
+ "",
+ "> param=VALUE Some description here"));
+
+
// Unique id that can be assigned to each process.
static uint32_t __id__ = 0;
@@ -472,6 +523,9 @@ static synchronizable(filterer) = SYNCHRONIZED_INITIALIZER_RECURSIVE;
// Global garbage collector.
PID<GarbageCollector> gc;
+// Global help.
+PID<Help> help;
+
// Per thread process pointer.
ThreadLocal<ProcessBase>* _process_ = new ThreadLocal<ProcessBase>();
@@ -1400,6 +1454,9 @@ void initialize(const string& delegate)
// Create global garbage collector process.
gc = spawn(new GarbageCollector());
+ // Create global help process.
+ help = spawn(new Help(), true);
+
// Create the global logging process.
spawn(new Logging(), true);
@@ -3036,6 +3093,21 @@ UPID ProcessBase::link(const UPID& to)
}
+bool ProcessBase::route(
+ const string& name,
+ const Option<string>& help_,
+ const HttpRequestHandler& handler)
+{
+ if (name.find('/') != 0) {
+ return false;
+ }
+ handlers.http[name.substr(1)] = handler;
+ dispatch(help, &Help::add, pid.id, name, help_);
+ return true;
+}
+
+
+
UPID spawn(ProcessBase* process, bool manage)
{
process::initialize();
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/src/statistics.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/statistics.cpp b/3rdparty/libprocess/src/statistics.cpp
index d8f5ad1..d4ba9f1 100644
--- a/3rdparty/libprocess/src/statistics.cpp
+++ b/3rdparty/libprocess/src/statistics.cpp
@@ -11,6 +11,7 @@
#include <process/delay.hpp>
#include <process/dispatch.hpp>
#include <process/future.hpp>
+#include <process/help.hpp>
#include <process/http.hpp>
#include <process/process.hpp>
#include <process/statistics.hpp>
@@ -101,14 +102,17 @@ public:
protected:
virtual void initialize()
{
- route("/snapshot.json", &StatisticsProcess::snapshot);
- route("/series.json", &StatisticsProcess::series);
+ route("/snapshot.json", SNAPSHOT_HELP, &StatisticsProcess::snapshot);
+ route("/series.json", SERIES_HELP, &StatisticsProcess::series);
// Schedule the first truncation.
delay(STATISTICS_TRUNCATION_INTERVAL, self(), &StatisticsProcess::truncate);
}
private:
+ static const string SNAPSHOT_HELP;
+ static const string SERIES_HELP;
+
// Removes values for the specified statistic that occurred outside
// the time series window.
// NOTE: We always ensure there is at least 1 value left for a statistic,
@@ -140,6 +144,32 @@ private:
};
+const string StatisticsProcess::SERIES_HELP = HELP(
+ TLDR(
+ "Provides the time series for ..."),
+ USAGE(
+ "/statistics/series.json..."),
+ DESCRIPTION(
+ "...",
+ "",
+ "Query parameters:",
+ "",
+ "> param=VALUE Some description here"));
+
+
+const string StatisticsProcess::SNAPSHOT_HELP = HELP(
+ TLDR(
+ "Provides a snapshot of the current statistics ..."),
+ USAGE(
+ "/statistics/snapshot.json..."),
+ DESCRIPTION(
+ "...",
+ "",
+ "Query parameters:",
+ "",
+ "> param=VALUE Some description here"));
+
+
Try<Nothing> StatisticsProcess::meter(
const string& context,
const string& name,
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/0c38dabd/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index f677267..89a9105 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -14,6 +14,7 @@
#include <process/io.hpp>
#include <stout/gtest.hpp>
+#include <stout/none.hpp>
#include <stout/nothing.hpp>
#include <stout/os.hpp>
@@ -32,8 +33,8 @@ class HttpProcess : public Process<HttpProcess>
public:
HttpProcess()
{
- route("/body", &HttpProcess::body);
- route("/pipe", &HttpProcess::pipe);
+ route("/body", None(), &HttpProcess::body);
+ route("/pipe", None(), &HttpProcess::pipe);
}
MOCK_METHOD1(body, Future<http::Response>(const http::Request&));
[4/4] git commit: Updated routes in Mesos to provide help.
Posted by be...@apache.org.
Updated routes in Mesos to provide help.
Review: https://reviews.apache.org/r/12120
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/977f698d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/977f698d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/977f698d
Branch: refs/heads/master
Commit: 977f698d3d0be7fb4fb004652d224a833760aa69
Parents: 0c38dab
Author: Benjamin Hindman <be...@twitter.com>
Authored: Fri Jun 7 18:20:14 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Mon Jul 1 18:10:27 2013 -0400
----------------------------------------------------------------------
src/files/files.cpp | 8 ++++----
src/master/master.cpp | 8 ++++----
src/slave/monitor.hpp | 5 +++--
src/slave/slave.cpp | 6 +++---
4 files changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/977f698d/src/files/files.cpp
----------------------------------------------------------------------
diff --git a/src/files/files.cpp b/src/files/files.cpp
index 00591a2..c609505 100644
--- a/src/files/files.cpp
+++ b/src/files/files.cpp
@@ -104,10 +104,10 @@ FilesProcess::FilesProcess()
void FilesProcess::initialize()
{
- route("/browse.json", &FilesProcess::browse);
- route("/read.json", &FilesProcess::read);
- route("/download.json", &FilesProcess::download);
- route("/debug.json", &FilesProcess::debug);
+ route("/browse.json", None(), &FilesProcess::browse);
+ route("/read.json", None(), &FilesProcess::read);
+ route("/download.json", None(), &FilesProcess::download);
+ route("/debug.json", None(), &FilesProcess::debug);
}
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/977f698d/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index cf95101..61dbecd 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -357,10 +357,10 @@ void Master::initialize()
&ExitedExecutorMessage::status);
// Setup HTTP routes.
- route("/redirect", bind(&Http::redirect, http, params::_1));
- route("/vars", bind(&Http::vars, http, params::_1));
- route("/stats.json", bind(&Http::stats, http, params::_1));
- route("/state.json", bind(&Http::state, http, params::_1));
+ route("/redirect", None(), bind(&Http::redirect, http, params::_1));
+ route("/vars", None(), bind(&Http::vars, http, params::_1));
+ route("/stats.json", None(), bind(&Http::stats, http, params::_1));
+ route("/state.json", None(), bind(&Http::state, http, params::_1));
// Provide HTTP assets from a "webui" directory. This is either
// specified via flags (which is necessary for running out of the
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/977f698d/src/slave/monitor.hpp
----------------------------------------------------------------------
diff --git a/src/slave/monitor.hpp b/src/slave/monitor.hpp
index e5fdcbd..52568ad 100644
--- a/src/slave/monitor.hpp
+++ b/src/slave/monitor.hpp
@@ -28,6 +28,7 @@
#include <stout/duration.hpp>
#include <stout/hashmap.hpp>
#include <stout/nothing.hpp>
+#include <stout/option.hpp>
#include <stout/try.hpp>
#include "common/type_utils.hpp"
@@ -102,8 +103,8 @@ public:
protected:
virtual void initialize()
{
- route("/statistics.json", &ResourceMonitorProcess::statisticsJSON);
- route("/usage.json", &ResourceMonitorProcess::usage);
+ route("/statistics.json", None(), &ResourceMonitorProcess::statisticsJSON);
+ route("/usage.json", None(), &ResourceMonitorProcess::usage);
}
private:
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/977f698d/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 7271097..9a2c671 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -354,9 +354,9 @@ void Slave::initialize()
install("PING", &Slave::ping);
// Setup HTTP routes.
- route("/vars", bind(&Http::vars, http, params::_1));
- route("/stats.json", bind(&Http::stats, http, params::_1));
- route("/state.json", bind(&Http::state, http, params::_1));
+ route("/vars", None(), bind(&Http::vars, http, params::_1));
+ route("/stats.json", None(), bind(&Http::stats, http, params::_1));
+ route("/state.json", None(), bind(&Http::state, http, params::_1));
if (flags.log_dir.isSome()) {
Try<string> log = logging::getLogFile(google::INFO);
[2/4] git commit: Moved master/slave HTTP route handlers into inner
class.
Posted by be...@apache.org.
Moved master/slave HTTP route handlers into inner class.
Review: https://reviews.apache.org/r/12119
Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/663ebd02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/663ebd02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/663ebd02
Branch: refs/heads/master
Commit: 663ebd02010a9b755215f6565883fe9ea1136645
Parents: 5c784f4
Author: Benjamin Hindman <be...@twitter.com>
Authored: Fri Jun 7 18:17:54 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Mon Jul 1 18:10:25 2013 -0400
----------------------------------------------------------------------
src/Makefile.am | 4 +--
src/master/http.cpp | 24 +++--------------
src/master/http.hpp | 65 ----------------------------------------------
src/master/master.cpp | 12 +++++----
src/master/master.hpp | 47 +++++++++++++++++++--------------
src/slave/http.cpp | 20 +++-----------
src/slave/http.hpp | 61 -------------------------------------------
src/slave/slave.cpp | 9 ++++---
src/slave/slave.hpp | 33 +++++++++++++----------
9 files changed, 68 insertions(+), 207 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 9337435..5d6f309 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -223,10 +223,10 @@ libmesos_no_3rdparty_la_SOURCES += common/attributes.hpp \
logging/flags.hpp logging/logging.hpp \
master/allocator.hpp \
master/constants.hpp master/drf_sorter.hpp master/flags.hpp \
- master/hierarchical_allocator_process.hpp master/http.hpp \
+ master/hierarchical_allocator_process.hpp \
master/master.hpp master/sorter.hpp \
messages/messages.hpp slave/constants.hpp \
- slave/flags.hpp slave/gc.hpp slave/monitor.hpp slave/http.hpp \
+ slave/flags.hpp slave/gc.hpp slave/monitor.hpp \
slave/isolator.hpp \
slave/cgroups_isolator.hpp \
slave/paths.hpp slave/state.hpp \
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 47471d6..4317bfc 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -39,7 +39,6 @@
#include "logging/logging.hpp"
-#include "master/http.hpp"
#include "master/master.hpp"
namespace mesos {
@@ -63,7 +62,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)
{
@@ -211,11 +209,7 @@ JSON::Object model(const Slave& slave)
}
-namespace http {
-
-Future<Response> vars(
- const Master& master,
- const Request& request)
+Future<Response> Master::Http::vars(const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -236,9 +230,7 @@ Future<Response> vars(
return OK(out.str(), request.query.get("jsonp"));
}
-Future<Response> redirect(
- const Master& master,
- const Request& request)
+Future<Response> Master::Http::redirect(const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -255,11 +247,7 @@ Future<Response> redirect(
}
-namespace json {
-
-Future<Response> stats(
- const Master& master,
- const Request& request)
+Future<Response> Master::Http::stats(const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -307,9 +295,7 @@ Future<Response> stats(
}
-Future<Response> state(
- const Master& master,
- const Request& request)
+Future<Response> Master::Http::state(const Request& request)
{
VLOG(1) << "HTTP request for '" << request.path << "'";
@@ -378,8 +364,6 @@ Future<Response> state(
return OK(object, request.query.get("jsonp"));
}
-} // namespace json {
-} // namespace http {
} // namespace master {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/master/http.hpp
----------------------------------------------------------------------
diff --git a/src/master/http.hpp b/src/master/http.hpp
deleted file mode 100644
index 9eb0a31..0000000
--- a/src/master/http.hpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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 __MASTER_HTTP_HPP__
-#define __MASTER_HTTP_HPP__
-
-#include <process/future.hpp>
-#include <process/http.hpp>
-
-namespace mesos {
-namespace internal {
-namespace master {
-
-// Forward declaration (necessary to break circular dependency).
-class Master;
-
-namespace http {
-
-// Returns current vars in "key value\n" format (keys do not contain
-// spaces, values may contain spaces but are ended by a newline).
-process::Future<process::http::Response> vars(
- const Master& master,
- const process::http::Request& request);
-
-// Redirects immediately to the current leader. If there's no leader, this
-// redirects to the master.
-process::Future<process::http::Response> redirect(
- const Master& master,
- const process::http::Request& request);
-
-namespace json {
-
-// Returns current statistics of the master.
-process::Future<process::http::Response> stats(
- const Master& master,
- const process::http::Request& request);
-
-
-// Returns current state of the cluster that the master knows about.
-process::Future<process::http::Response> state(
- const Master& master,
- const process::http::Request& request);
-
-} // namespace json {
-} // namespace http {
-} // namespace master {
-} // namespace internal {
-} // namespace mesos {
-
-#endif // __MASTER_HTTP_HPP__
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 695fb93..cf95101 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -188,6 +188,7 @@ private:
Master::Master(Allocator* _allocator, Files* _files)
: ProcessBase("master"),
+ http(*this),
flags(),
allocator(_allocator),
files(_files),
@@ -196,6 +197,7 @@ Master::Master(Allocator* _allocator, Files* _files)
Master::Master(Allocator* _allocator, Files* _files, const Flags& _flags)
: ProcessBase("master"),
+ http(*this),
flags(_flags),
allocator(_allocator),
files(_files),
@@ -354,11 +356,11 @@ void Master::initialize()
&ExitedExecutorMessage::executor_id,
&ExitedExecutorMessage::status);
- // Setup HTTP request handlers.
- route("/redirect", bind(&http::redirect, cref(*this), params::_1));
- route("/vars", bind(&http::vars, cref(*this), params::_1));
- route("/stats.json", bind(&http::json::stats, cref(*this), params::_1));
- route("/state.json", bind(&http::json::state, cref(*this), params::_1));
+ // Setup HTTP routes.
+ route("/redirect", bind(&Http::redirect, http, params::_1));
+ route("/vars", bind(&Http::vars, http, params::_1));
+ route("/stats.json", bind(&Http::stats, http, params::_1));
+ route("/state.json", bind(&Http::state, http, params::_1));
// Provide HTTP assets from a "webui" directory. This is either
// specified via flags (which is necessary for running out of the
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 86c5232..edbc3f8 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -45,7 +45,6 @@
#include "master/constants.hpp"
#include "master/flags.hpp"
-#include "master/http.hpp"
#include "messages/messages.hpp"
@@ -191,30 +190,38 @@ protected:
SlaveID newSlaveId();
private:
- Master(const Master&); // No copying.
- Master& operator = (const Master&); // No assigning.
+ // Inner class used to namespace HTTP route handlers (see
+ // master/http.cpp for implementations).
+ class Http
+ {
+ public:
+ Http(const Master& _master) : master(_master) {}
- friend struct SlaveRegistrar;
- friend struct SlaveReregistrar;
+ // /master/vars
+ process::Future<process::http::Response> vars(
+ const process::http::Request& request);
+
+ // /master/redirect
+ process::Future<process::http::Response> redirect(
+ const process::http::Request& request);
- // HTTP handlers, friends of the master in order to access state,
- // they get invoked from within the master so there is no need to
- // use synchronization mechanisms to protect state.
- friend Future<process::http::Response> http::vars(
- const Master& master,
- const process::http::Request& request);
+ // /master/stats.json
+ process::Future<process::http::Response> stats(
+ const process::http::Request& request);
- friend Future<process::http::Response> http::redirect(
- const Master& master,
- const process::http::Request& request);
+ // /master/state.json
+ process::Future<process::http::Response> state(
+ const process::http::Request& request);
- friend Future<process::http::Response> http::json::stats(
- const Master& master,
- const process::http::Request& request);
+ private:
+ const Master& master;
+ } http;
- friend Future<process::http::Response> http::json::state(
- const Master& master,
- const process::http::Request& request);
+ Master(const Master&); // No copying.
+ Master& operator = (const Master&); // No assigning.
+
+ friend struct SlaveRegistrar;
+ friend struct SlaveReregistrar;
const Flags flags;
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index e362c30..582b3a2 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -52,11 +52,9 @@ using std::map;
using std::string;
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)
{
@@ -247,11 +245,7 @@ JSON::Object model(const Framework& framework)
}
-namespace http {
-
-Future<Response> vars(
- const Slave& slave,
- const Request& request)
+Future<Response> Slave::Http::vars(const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -273,11 +267,7 @@ Future<Response> vars(
}
-namespace json {
-
-Future<Response> stats(
- const Slave& slave,
- const Request& request)
+Future<Response> Slave::Http::stats(const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -297,9 +287,7 @@ Future<Response> stats(
}
-Future<Response> state(
- const Slave& slave,
- const Request& request)
+Future<Response> Slave::Http::state(const Request& request)
{
LOG(INFO) << "HTTP request for '" << request.path << "'";
@@ -345,8 +333,6 @@ Future<Response> state(
return OK(object, request.query.get("jsonp"));
}
-} // namespace json {
-} // namespace http {
} // namespace slave {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/slave/http.hpp
----------------------------------------------------------------------
diff --git a/src/slave/http.hpp b/src/slave/http.hpp
deleted file mode 100644
index 9801470..0000000
--- a/src/slave/http.hpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 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 __SLAVE_HTTP_HPP__
-#define __SLAVE_HTTP_HPP__
-
-#include <process/future.hpp>
-#include <process/http.hpp>
-
-
-namespace mesos {
-namespace internal {
-namespace slave {
-
-// Forward declaration (necessary to break circular dependency).
-class Slave;
-
-namespace http {
-
-// Returns current vars in "key value\n" format (keys do not contain
-// spaces, values may contain spaces but are ended by a newline).
-process::Future<process::http::Response> vars(
- const Slave& slave,
- const process::http::Request& request);
-
-
-namespace json {
-
-// Returns current statistics of the slave.
-process::Future<process::http::Response> stats(
- const Slave& slave,
- const process::http::Request& request);
-
-
-// Returns current state of the cluster that the slave knows about.
-process::Future<process::http::Response> state(
- const Slave& slave,
- const process::http::Request& request);
-
-} // namespace json {
-} // namespace http {
-} // namespace slave {
-} // namespace internal {
-} // namespace mesos {
-
-#endif // __SLAVE_HTTP_HPP__
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 1752689..7271097 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -82,6 +82,7 @@ Slave::Slave(const slave::Flags& _flags,
Files* _files)
: ProcessBase(ID::generate("slave")),
state(RECOVERING),
+ http(*this),
flags(_flags),
local(_local),
completedFrameworks(MAX_COMPLETED_FRAMEWORKS),
@@ -352,10 +353,10 @@ void Slave::initialize()
// Install the ping message handler.
install("PING", &Slave::ping);
- // Setup some HTTP routes.
- route("/vars", bind(&http::vars, cref(*this), params::_1));
- route("/stats.json", bind(&http::json::stats, cref(*this), params::_1));
- route("/state.json", bind(&http::json::state, cref(*this), params::_1));
+ // Setup HTTP routes.
+ route("/vars", bind(&Http::vars, http, params::_1));
+ route("/stats.json", bind(&Http::stats, http, params::_1));
+ route("/state.json", bind(&Http::state, http, params::_1));
if (flags.log_dir.isSome()) {
Try<string> log = logging::getLogFile(google::INFO);
http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/663ebd02/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 1fca208..c679447 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -43,7 +43,6 @@
#include "slave/constants.hpp"
#include "slave/flags.hpp"
#include "slave/gc.hpp"
-#include "slave/http.hpp"
#include "slave/isolator.hpp"
#include "slave/monitor.hpp"
#include "slave/paths.hpp"
@@ -252,27 +251,35 @@ protected:
void remove(Framework* framework);
private:
- Slave(const Slave&); // No copying.
- Slave& operator = (const Slave&); // No assigning.
-
- // HTTP handlers, friends of the slave in order to access state,
- // they get invoked from within the slave so there is no need to
- // use synchronization mechanisms to protect state.
- friend Future<process::http::Response> http::vars(
- const Slave& slave,
+ // Inner class used to namespace HTTP route handlers (see
+ // slave/http.cpp for implementations).
+ class Http
+ {
+ public:
+ Http(const Slave& _slave) : slave(_slave) {}
+
+ // /slave/vars
+ process::Future<process::http::Response> vars(
const process::http::Request& request);
- friend Future<process::http::Response> http::json::stats(
- const Slave& slave,
+ // /slave/stats.json
+ process::Future<process::http::Response> stats(
const process::http::Request& request);
- friend Future<process::http::Response> http::json::state(
- const Slave& slave,
+ // /slave/state.json
+ process::Future<process::http::Response> state(
const process::http::Request& request);
+ private:
+ const Slave& slave;
+ } http;
+
friend class Framework;
friend class Executor;
+ Slave(const Slave&); // No copying.
+ Slave& operator = (const Slave&); // No assigning.
+
const Flags flags;
bool local;