Skip to content

Commit

Permalink
Extended Controller's REST API to report database activities
Browse files Browse the repository at this point in the history
Incremented the version number of the REST API.
  • Loading branch information
iagaponenko committed Aug 3, 2023
1 parent b301b80 commit 17c39bf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/admin/python/lsst/qserv/admin/replicationInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(
self.repl_ctrl = urlparse(repl_ctrl_uri)
self.auth_key = auth_key
self.admin_auth_key = admin_auth_key
self.repl_api_version = 23
self.repl_api_version = 24
_log.debug(f"ReplicationInterface %s", self.repl_ctrl)

def version(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/replica/HttpMetaModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using json = nlohmann::json;

namespace lsst::qserv::replica {

unsigned int const HttpMetaModule::version = 23;
unsigned int const HttpMetaModule::version = 24;

void HttpMetaModule::process(ServiceProvider::Ptr const& serviceProvider, string const& context,
qhttp::Request::Ptr const& req, qhttp::Response::Ptr const& resp,
Expand Down
13 changes: 8 additions & 5 deletions src/replica/HttpProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,15 @@ void HttpProcessor::registerServices() {
"WORKERS");
});
httpServer()->addHandler("GET", "/replication/qserv/worker/status/:worker",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
HttpQservMonitorModule::process(self->controller(), self->name(),
self->_processorConfig, req, resp, "WORKER");
});
httpServer()->addHandler("GET", "/replication/qserv/worker/db/:worker",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
HttpQservMonitorModule::process(self->controller(), self->name(),
self->_processorConfig, req, resp,
"SELECT-WORKER-BY-NAME");
"WORKER-DB");
});
httpServer()->addHandler("GET", "/replication/qserv/master/query",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
Expand All @@ -248,14 +253,12 @@ void HttpProcessor::registerServices() {
httpServer()->addHandler("GET", "/replication/qserv/master/query/:id",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
HttpQservMonitorModule::process(self->controller(), self->name(),
self->_processorConfig, req, resp,
"SELECT-QUERY-BY-ID");
self->_processorConfig, req, resp, "QUERY");
});
httpServer()->addHandler("GET", "/replication/qserv/css/shared-scan",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
HttpQservMonitorModule::process(self->controller(), self->name(),
self->_processorConfig, req, resp,
"CSS-SHARED-SCAN");
self->_processorConfig, req, resp, "CSS");
});
httpServer()->addHandler("GET", "/replication/sql/table/schema/:database/:table",
[self](qhttp::Request::Ptr const req, qhttp::Response::Ptr const resp) {
Expand Down
41 changes: 36 additions & 5 deletions src/replica/HttpQservMonitorModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "replica/Configuration.h"
#include "replica/ConfigDatabase.h"
#include "replica/DatabaseServices.h"
#include "replica/HttpExceptions.h"
#include "replica/QservMgtServices.h"
#include "replica/QservStatusJob.h"
#include "replica/ServiceProvider.h"
Expand Down Expand Up @@ -136,14 +137,16 @@ HttpQservMonitorModule::HttpQservMonitorModule(Controller::Ptr const& controller
json HttpQservMonitorModule::executeImpl(string const& subModuleName) {
if (subModuleName == "WORKERS")
return _workers();
else if (subModuleName == "SELECT-WORKER-BY-NAME")
else if (subModuleName == "WORKER")
return _worker();
else if (subModuleName == "WORKER-DB")
return _workerDb();
else if (subModuleName == "QUERIES")
return _userQueries();
else if (subModuleName == "SELECT-QUERY-BY-ID")
else if (subModuleName == "QUERY")
return _userQuery();
else if (subModuleName == "CSS-SHARED-SCAN")
return _cssSharedScan();
else if (subModuleName == "CSS")
return _css();
throw invalid_argument(context() + "::" + string(__func__) + " unsupported sub-module: '" +
subModuleName + "'");
}
Expand Down Expand Up @@ -216,6 +219,34 @@ json HttpQservMonitorModule::_worker() {
return result;
}

json HttpQservMonitorModule::_workerDb() {
debug(__func__);
checkApiVersion(__func__, 24);

auto const worker = params().at("worker");
unsigned int const timeoutSec = query().optionalUInt("timeout_sec", workerResponseTimeoutSec());
wbase::TaskSelector const taskSelector = _translateTaskSelector(__func__);

debug(__func__, "worker=" + worker);
debug(__func__, "timeout_sec=" + to_string(timeoutSec));

string const noParentJobId;
GetDbStatusQservMgtRequest::CallbackType const onFinish = nullptr;

auto const request = controller()->serviceProvider()->qservMgtServices()->databaseStatus(
worker, noParentJobId, onFinish, timeoutSec);
request->wait();

if (request->extendedState() != QservMgtRequest::ExtendedState::SUCCESS) {
string const msg = "database operation failed, error: " +
QservMgtRequest::state2string(request->extendedState());
throw HttpError(__func__, msg);
}
json result = json::object();
result["status"] = request->info();
return result;
}

wbase::TaskSelector HttpQservMonitorModule::_translateTaskSelector(string const& func) const {
wbase::TaskSelector selector;
selector.includeTasks = query().optionalUInt("include_tasks", 0) != 0;
Expand Down Expand Up @@ -535,7 +566,7 @@ json HttpQservMonitorModule::_getQueries(json const& workerInfo) const {
return result;
}

json HttpQservMonitorModule::_cssSharedScan() {
json HttpQservMonitorModule::_css() {
debug(__func__);
checkApiVersion(__func__, 12);

Expand Down
21 changes: 14 additions & 7 deletions src/replica/HttpQservMonitorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ class HttpQservMonitorModule : public HttpModule {
/**
* Supported values for parameter 'subModuleName':
*
* WORKERS for many workers (possible selected by various criteria)
* SELECT-WORKER-BY-NAME for a specific worker
* QUERIES for many queries (selected by various criteria)
* SELECT-QUERY-BY-ID for a specific query
* CSS-SHARED-SCAN get CSS configurations of the shared scan for all tables
* WORKERS get the status info of many workers (possible selected by various criteria)
* WORKER get the status info of a specific worker
* WORKER-DB get the database status of a specific worker
* QUERIES get user query info (queries selected by various criteria)
* QUERY get user query info for a specific query
* CSS get CSS configurations (the shared scan settings, etc.)
*
* @throws std::invalid_argument for unknown values of parameter 'subModuleName'
*/
Expand Down Expand Up @@ -94,6 +95,12 @@ class HttpQservMonitorModule : public HttpModule {
*/
nlohmann::json _worker();

/**
* Process a request for extracting various status info on the database
* service for select Qserv worker.
*/
nlohmann::json _workerDb();

/**
* Process a request for extracting a status on select user queries
* launched at Qserv.
Expand Down Expand Up @@ -161,8 +168,8 @@ class HttpQservMonitorModule : public HttpModule {
*/
nlohmann::json _getQueries(nlohmann::json const& workerInfo) const;

/// @return The shared scan parameters of all partitioned tables (CSS)
nlohmann::json _cssSharedScan();
/// @return The CSS info (shared scan parameters of all partitioned tables, etc.)
nlohmann::json _css();

/**
* @param chunks collection of chunks numbers to be expanded
Expand Down

0 comments on commit 17c39bf

Please sign in to comment.