Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <webserver.h>
Classes | |
class | UrlHandler |
Public Types | |
typedef std::map< std::string, std::string > | ArgumentMap |
typedef boost::function< void(const ArgumentMap &args, rapidjson::Document *json)> | UrlCallback |
Public Member Functions | |
Webserver (const int port) | |
Using this constructor, the webserver will bind to all available interfaces. More... | |
Webserver () | |
Uses FLAGS_webserver_{port, interface}. More... | |
~Webserver () | |
Status | Start () |
void | Stop () |
Stops the webserver synchronously. More... | |
void | RegisterUrlCallback (const std::string &path, const std::string &template_filename, const UrlCallback &callback, bool is_on_nav_bar=true) |
Only one callback may be registered per URL. More... | |
const TNetworkAddress & | http_address () |
bool | IsSecure () const |
True if serving all traffic over SSL, false otherwise. More... | |
Static Public Attributes | |
static const char * | ENABLE_RAW_JSON_KEY = "__raw__" |
Private Types | |
typedef std::map< std::string, UrlHandler > | UrlHandlerMap |
Private Member Functions | |
int | BeginRequestCallback (struct sq_connection *connection, struct sq_request_info *request_info) |
Dispatch point for all incoming requests. Returns squeasel success code. More... | |
void | RootHandler (const ArgumentMap &args, rapidjson::Document *document) |
Registered to handle "/", populates document with various system-wide information. More... | |
void | ErrorHandler (const ArgumentMap &args, rapidjson::Document *document) |
Called when an error is encountered, e.g. when a handler for a URI cannot be found. More... | |
void | BuildArgumentMap (const std::string &args, ArgumentMap *output) |
void | GetCommonJson (rapidjson::Document *document) |
Static Private Member Functions | |
static int | LogMessageCallbackStatic (const struct sq_connection *connection, const char *message) |
Squeasel callback for log events. Returns squeasel success code. More... | |
static int | BeginRequestCallbackStatic (struct sq_connection *connection) |
Private Attributes | |
boost::shared_mutex | url_handlers_lock_ |
Lock guarding the path_handlers_ map. More... | |
UrlHandlerMap | url_handlers_ |
TNetworkAddress | http_address_ |
The address of the interface on which to run this webserver. More... | |
struct sq_context * | context_ |
Handle to Squeasel context; owned and freed by Squeasel internally. More... | |
UrlHandler | error_handler_ |
Catch-all handler for error messages. More... | |
Wrapper class for the Squeasel web server library. Clients may register callback methods which produce Json documents which are rendered via a template file to either HTML or text.
Definition at line 34 of file webserver.h.
typedef std::map<std::string, std::string> impala::Webserver::ArgumentMap |
Definition at line 36 of file webserver.h.
typedef boost::function<void (const ArgumentMap& args, rapidjson::Document* json)> impala::Webserver::UrlCallback |
Definition at line 38 of file webserver.h.
|
private |
Map of path to a UrlHandler containing a list of handlers for that path. More than one handler may register itself with a path so that many components may contribute to a single page.
Definition at line 138 of file webserver.h.
impala::Webserver::Webserver | ( | const int | port | ) |
Using this constructor, the webserver will bind to all available interfaces.
Definition at line 145 of file webserver.cc.
References http_address_, and impala::MakeNetworkAddress().
impala::Webserver::Webserver | ( | ) |
Uses FLAGS_webserver_{port, interface}.
Definition at line 136 of file webserver.cc.
References http_address_, and impala::MakeNetworkAddress().
impala::Webserver::~Webserver | ( | ) |
Definition at line 152 of file webserver.cc.
References Stop().
|
private |
Dispatch point for all incoming requests. Returns squeasel success code.
Definition at line 329 of file webserver.cc.
References BuildArgumentMap(), impala::BuildHeaderString(), impala::Webserver::UrlHandler::callback(), DOC_FOLDER, DOC_FOLDER_LEN, impala::MonotonicStopWatch::ElapsedTime(), ENABLE_RAW_JSON_KEY, error_handler_, ERROR_KEY, GetCommonJson(), impala::HTML, impala::NOT_FOUND, NOT_PROCESSED, impala::OK, impala::PLAIN, impala::PrettyPrinter::Print(), PROCESSING_COMPLETE, impala::MonotonicStopWatch::Start(), impala::Webserver::UrlHandler::template_filename(), url_handlers_, and url_handlers_lock_.
Referenced by BeginRequestCallbackStatic().
|
staticprivate |
Squeasel callback for HTTP request events. Static so that it can act as a function pointer, and then call the next method. Returns squeasel success code.
Definition at line 323 of file webserver.cc.
References BeginRequestCallback().
Referenced by Start().
|
private |
Builds a map of argument name to argument value from a typical URL argument string (that is, "key1=value1&key2=value2.."). If no value is given for a key, it is entered into the map as (key, "").
Definition at line 181 of file webserver.cc.
References impala::UrlDecode().
Referenced by BeginRequestCallback().
|
private |
Called when an error is encountered, e.g. when a handler for a URI cannot be found.
Definition at line 173 of file webserver.cc.
References ERROR_KEY.
|
private |
Adds a common object to document with common data that every webpage might want to read (e.g. the names of links to write to the navbar).
Definition at line 295 of file webserver.cc.
References COMMON_JSON_KEY, and url_handlers_.
Referenced by BeginRequestCallback().
|
inline |
Definition at line 72 of file webserver.h.
References http_address_.
bool impala::Webserver::IsSecure | ( | ) | const |
True if serving all traffic over SSL, false otherwise.
Definition at line 199 of file webserver.cc.
Referenced by Start().
|
staticprivate |
Squeasel callback for log events. Returns squeasel success code.
Definition at line 315 of file webserver.cc.
References PROCESSING_COMPLETE.
Referenced by Start().
void impala::Webserver::RegisterUrlCallback | ( | const std::string & | path, |
const std::string & | template_filename, | ||
const UrlCallback & | callback, | ||
bool | is_on_nav_bar = true |
||
) |
Only one callback may be registered per URL.
Register a callback for a Url that produces a json document that will be rendered with the template at 'template_filename'. The URL 'path' should not include the http://hostname/ prefix. If is_on_nav_bar is true, the page will appear in the standard navigation bar rendered on all pages.The path of the template file is relative to the webserver's document root.
Definition at line 412 of file webserver.cc.
References url_handlers_, and url_handlers_lock_.
Referenced by impala::AddDefaultUrlCallbacks(), impala::AddPprofUrlCallbacks(), impala::MetricGroup::Init(), impala::InitRpcEventTracing(), impala::CatalogServer::RegisterWebpages(), impala::Statestore::RegisterWebpages(), impala::ImpalaServer::RegisterWebserverCallbacks(), Start(), impala::ThreadMgr::StartInstrumentation(), and TEST().
|
private |
Registered to handle "/", populates document with various system-wide information.
Definition at line 156 of file webserver.cc.
References impala_udf::DebugString(), impala::OsInfo::DebugString(), impala::MemInfo::DebugString(), impala::DiskInfo::DebugString(), impala::CpuInfo::DebugString(), and impala::GetVersionString().
Referenced by Start().
Status impala::Webserver::Start | ( | ) |
Starts a webserver on the port passed to the constructor. The webserver runs in a separate thread, so this call is non-blocking.
Definition at line 203 of file webserver.cc.
References BeginRequestCallbackStatic(), context_, http_address_, IsSecure(), LogMessageCallbackStatic(), impala::Status::OK, RegisterUrlCallback(), and RootHandler().
Referenced by TEST().
void impala::Webserver::Stop | ( | ) |
Stops the webserver synchronously.
Definition at line 288 of file webserver.cc.
References context_.
Referenced by ~Webserver().
|
private |
Handle to Squeasel context; owned and freed by Squeasel internally.
Definition at line 145 of file webserver.h.
|
static |
Any callback may add a member to their Json output with key ENABLE_RAW_JSON_KEY; this causes the result of the template rendering process to be sent to the browser as text, not HTML.
Definition at line 43 of file webserver.h.
Referenced by BeginRequestCallback(), and JsonCallback().
|
private |
Catch-all handler for error messages.
Definition at line 148 of file webserver.h.
Referenced by BeginRequestCallback().
|
private |
The address of the interface on which to run this webserver.
Definition at line 142 of file webserver.h.
Referenced by http_address(), Start(), and Webserver().
|
private |
Definition at line 139 of file webserver.h.
Referenced by BeginRequestCallback(), GetCommonJson(), and RegisterUrlCallback().
|
private |
Lock guarding the path_handlers_ map.
Definition at line 133 of file webserver.h.
Referenced by BeginRequestCallback(), and RegisterUrlCallback().