summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-03-29 18:00:48 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-03-30 13:22:33 -0400
commit165f6ec707de7ec1e4e3f37e60c317221f6a26d0 (patch)
treee2604536cb91841e2b77cf09b3af71629e9140cc
parent4d17fceb1d3ec9e231a601066944aed51b702b45 (diff)
downloadmongo-165f6ec707de7ec1e4e3f37e60c317221f6a26d0.tar.gz
SERVER-23429 Get rid of Command::htmlHelp and _webCommands
-rw-r--r--src/mongo/db/commands.cpp78
-rw-r--r--src/mongo/db/commands.h17
-rw-r--r--src/mongo/db/dbwebserver.cpp136
3 files changed, 104 insertions, 127 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 82f533d629e..dff5e6f91a1 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -60,7 +60,6 @@ using std::stringstream;
using logger::LogComponent;
Command::CommandMap* Command::_commandsByBestName;
-Command::CommandMap* Command::_webCommands;
Command::CommandMap* Command::_commands;
Counter64 Command::unknownCommands;
@@ -124,76 +123,9 @@ ResourcePattern Command::parseResourcePattern(const std::string& dbname,
return ResourcePattern::forExactNamespace(NamespaceString(ns));
}
-void Command::htmlHelp(stringstream& ss) const {
- string helpStr;
- {
- stringstream h;
- help(h);
- helpStr = h.str();
- }
- ss << "\n<tr><td>";
- bool web = _webCommands->find(getName()) != _webCommands->end();
- if (web)
- ss << "<a href=\"/" << getName() << "?text=1\">";
- ss << getName();
- if (web)
- ss << "</a>";
- ss << "</td>\n";
- ss << "<td>";
- ss << "UNUSED ";
- if (slaveOk())
- ss << "S ";
- if (adminOnly())
- ss << "A";
- ss << "</td>";
- ss << "<td>";
- if (helpStr != "no help defined") {
- const char* p = helpStr.c_str();
- while (*p) {
- if (*p == '<') {
- ss << "&lt;";
- p++;
- continue;
- } else if (*p == '{')
- ss << "<code>";
- else if (*p == '}') {
- ss << "}</code>";
- p++;
- continue;
- }
- if (strncmp(p, "http:", 5) == 0) {
- ss << "<a href=\"";
- const char* q = p;
- while (*q && *q != ' ' && *q != '\n')
- ss << *q++;
- ss << "\">";
- q = p;
- if (str::startsWith(q, "http://www.mongodb.org/display/"))
- q += 31;
- while (*q && *q != ' ' && *q != '\n') {
- ss << (*q == '+' ? ' ' : *q);
- q++;
- if (*q == '#')
- while (*q && *q != ' ' && *q != '\n')
- q++;
- }
- ss << "</a>";
- p = q;
- continue;
- }
- if (*p == '\n')
- ss << "<br>";
- else
- ss << *p;
- p++;
- }
- }
- ss << "</td>";
- ss << "</tr>\n";
-}
-
-Command::Command(StringData name, bool web, StringData oldName)
+Command::Command(StringData name, bool webUI, StringData oldName)
: _name(name.toString()),
+ _webUI(webUI),
_commandsExecutedMetric("commands." + _name + ".total", &_commandsExecuted),
_commandsFailedMetric("commands." + _name + ".failed", &_commandsFailed) {
// register ourself.
@@ -207,12 +139,6 @@ Command::Command(StringData name, bool web, StringData oldName)
c = this;
(*_commandsByBestName)[name] = this;
- if (web) {
- if (_webCommands == 0)
- _webCommands = new CommandMap();
- (*_webCommands)[name] = this;
- }
-
if (!oldName.empty())
(*_commands)[oldName.toString()] = this;
}
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 5d26450a01d..f04f453b24e 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -96,6 +96,13 @@ public:
return _name;
}
+ /**
+ * Returns whether this command is visible in the Web UI.
+ */
+ bool isWebUI() const {
+ return _webUI;
+ }
+
// Return the namespace for the command. If the first field in 'cmdObj' is of type
// mongo::String, then that field is interpreted as the collection name, and is
// appended to 'dbname' after a '.' character. If the first field is not of type
@@ -139,8 +146,6 @@ public:
return false;
}
- void htmlHelp(std::stringstream&) const;
-
/* Like adminOnly, but even stricter: we must either be authenticated for admin db,
or, if running without auth, on the local interface. Used for things which
are so major that remote invocation may not make sense (e.g., shutdownServer).
@@ -266,7 +271,6 @@ protected:
static CommandMap* _commands;
static CommandMap* _commandsByBestName;
- static CommandMap* _webCommands;
// Counters for how many times this command has been executed and failed
Counter64 _commandsExecuted;
@@ -277,10 +281,6 @@ public:
return _commandsByBestName;
}
- static const CommandMap* webCommands() {
- return _webCommands;
- }
-
// Counter for unknown commands
static Counter64 unknownCommands;
@@ -444,6 +444,9 @@ private:
// The full name of the command
const std::string _name;
+ // Whether the command is available in the web UI
+ const bool _webUI;
+
// Pointers to hold the metrics tree references
ServerStatusMetricField<Counter64> _commandsExecutedMetric;
ServerStatusMetricField<Counter64> _commandsFailedMetric;
diff --git a/src/mongo/db/dbwebserver.cpp b/src/mongo/db/dbwebserver.cpp
index bee10b95a5b..b7a856ef167 100644
--- a/src/mongo/db/dbwebserver.cpp
+++ b/src/mongo/db/dbwebserver.cpp
@@ -35,7 +35,6 @@
#include "mongo/db/dbwebserver.h"
-#include <boost/date_time/posix_time/posix_time.hpp>
#include <pcrecpp.h>
#include "mongo/base/init.h"
@@ -63,7 +62,6 @@
#include "mongo/util/ramlog.h"
#include "mongo/util/version.h"
-
namespace mongo {
using std::map;
@@ -84,19 +82,77 @@ void doUnlockedStuff(stringstream& ss) {
ss << "</pre>";
}
-
bool prisort(const Prioritizable* a, const Prioritizable* b) {
return a->priority() < b->priority();
}
-
-struct Timing {
- Timing() {
- start = timeLocked = 0;
+void htmlHelp(Command* command, stringstream& ss) {
+ string helpStr;
+ {
+ stringstream h;
+ command->help(h);
+ helpStr = h.str();
}
- unsigned long long start, timeLocked;
-};
+ ss << "\n<tr><td>";
+ if (command->isWebUI())
+ ss << "<a href=\"/" << command->getName() << "?text=1\">";
+ ss << command->getName();
+ if (command->isWebUI())
+ ss << "</a>";
+ ss << "</td>\n";
+ ss << "<td>";
+ ss << "UNUSED ";
+ if (command->slaveOk())
+ ss << "S ";
+ if (command->adminOnly())
+ ss << "A";
+ ss << "</td>";
+ ss << "<td>";
+ if (helpStr != "no help defined") {
+ const char* p = helpStr.c_str();
+ while (*p) {
+ if (*p == '<') {
+ ss << "&lt;";
+ p++;
+ continue;
+ } else if (*p == '{')
+ ss << "<code>";
+ else if (*p == '}') {
+ ss << "}</code>";
+ p++;
+ continue;
+ }
+ if (strncmp(p, "http:", 5) == 0) {
+ ss << "<a href=\"";
+ const char* q = p;
+ while (*q && *q != ' ' && *q != '\n')
+ ss << *q++;
+ ss << "\">";
+ q = p;
+ if (str::startsWith(q, "http://www.mongodb.org/display/"))
+ q += 31;
+ while (*q && *q != ' ' && *q != '\n') {
+ ss << (*q == '+' ? ' ' : *q);
+ q++;
+ if (*q == '#')
+ while (*q && *q != ' ' && *q != '\n')
+ q++;
+ }
+ ss << "</a>";
+ p = q;
+ continue;
+ }
+ if (*p == '\n')
+ ss << "<br>";
+ else
+ ss << *p;
+ p++;
+ }
+ }
+ ss << "</td>";
+ ss << "</tr>\n";
+}
class LogPlugin : public WebStatusPlugin {
public:
@@ -112,7 +168,6 @@ public:
RamLog* _log;
};
-
class FavIconHandler : public DbWebHandler {
public:
FavIconHandler() : DbWebHandler("favicon.ico", 0, false) {}
@@ -132,7 +187,6 @@ public:
} faviconHandler;
-
class StatusHandler : public DbWebHandler {
public:
StatusHandler() : DbWebHandler("_status", 1, false) {}
@@ -188,7 +242,6 @@ public:
} statusHandler;
-
class CommandListHandler : public DbWebHandler {
public:
CommandListHandler() : DbWebHandler("_commands", 1, true) {}
@@ -217,7 +270,7 @@ public:
ss << table();
ss << "<tr><th>Command</th><th>Attributes</th><th>Help</th></tr>\n";
for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
- i->second->htmlHelp(ss);
+ htmlHelp(i->second, ss);
}
ss << _table() << _end();
@@ -225,7 +278,6 @@ public:
}
} commandListHandler;
-
class CommandsHandler : public DbWebHandler {
public:
CommandsHandler() : DbWebHandler("DUMMY COMMANDS", 2, true) {}
@@ -236,16 +288,13 @@ public:
return true;
}
- Command* _cmd(const string& cmd) const {
- const Command::CommandMap* m = Command::webCommands();
- if (!m)
- return 0;
-
- Command::CommandMap::const_iterator i = m->find(cmd);
- if (i == m->end())
- return 0;
+ Command* _cmd(const string& cmdName) const {
+ Command* cmd = Command::findCommand(cmdName);
+ if (cmd->isWebUI()) {
+ return cmd;
+ }
- return i->second;
+ return nullptr;
}
virtual bool handles(const string& url) const {
@@ -398,29 +447,28 @@ void DbWebServer::doRequest(const char* rq,
ss << "<p><a href=\"/_commands\">List all commands</a> | \n";
ss << "<a href=\"/_replSet\">Replica set status</a></p>\n";
- {
- const Command::CommandMap* m = Command::webCommands();
- if (m) {
- ss << a("",
- "These read-only context-less commands can be executed from the web "
- "interface. Results are json format, unless ?text=1 is appended in which "
- "case the result is output as text for easier human viewing",
- "Commands") << ": ";
-
- for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
- stringstream h;
- i->second->help(h);
-
- const string help = h.str();
- ss << "<a href=\"/" << i->first << "?text=1\"";
- if (help != "no help defined") {
- ss << " title=\"" << help << '"';
- }
+ ss << a("",
+ "These read-only context-less commands can be executed from the web "
+ "interface. Results are json format, unless ?text=1 is appended in which "
+ "case the result is output as text for easier human viewing",
+ "Commands") << ": ";
- ss << ">" << i->first << "</a> ";
- }
- ss << '\n';
+ auto m = Command::commandsByBestName();
+
+ for (Command::CommandMap::const_iterator i = m->begin(); i != m->end(); ++i) {
+ if (!i->second->isWebUI())
+ continue;
+
+ stringstream h;
+ i->second->help(h);
+
+ const string help = h.str();
+ ss << "<a href=\"/" << i->first << "?text=1\"";
+ if (help != "no help defined") {
+ ss << " title=\"" << help << '"';
}
+
+ ss << ">" << i->first << "</a> ";
}
ss << '\n';