diff --git a/src/replica/AddReplicaQservHttpMgtRequest.cc b/src/replica/AddReplicaQservHttpMgtRequest.cc
deleted file mode 100644
index 6201d1a44..000000000
--- a/src/replica/AddReplicaQservHttpMgtRequest.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/AddReplicaQservHttpMgtRequest.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace nlohmann;
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.AddReplicaQservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-AddReplicaQservHttpMgtRequest::Ptr AddReplicaQservHttpMgtRequest::create(
- shared_ptr const& serviceProvider, string const& worker, unsigned int chunk,
- vector const& databases, AddReplicaQservHttpMgtRequest::CallbackType const& onFinish) {
- return AddReplicaQservHttpMgtRequest::Ptr(
- new AddReplicaQservHttpMgtRequest(serviceProvider, worker, chunk, databases, onFinish));
-}
-
-AddReplicaQservHttpMgtRequest::AddReplicaQservHttpMgtRequest(
- shared_ptr const& serviceProvider, string const& worker, unsigned int chunk,
- vector const& databases, AddReplicaQservHttpMgtRequest::CallbackType const& onFinish)
- : QservHttpMgtRequest(serviceProvider, "QSERV_ADD_REPLICA", worker),
- _chunk(chunk),
- _databases(databases),
- _onFinish(onFinish) {}
-
-list> AddReplicaQservHttpMgtRequest::extendedPersistentState() const {
- list> result;
- result.emplace_back("chunk", to_string(chunk()));
- for (auto&& database : databases()) {
- result.emplace_back("database", database);
- }
- return result;
-}
-
-void AddReplicaQservHttpMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
- string const method = "POST";
- string const target = "/replica";
- json const data = json::object({{"chunk", _chunk}, {"databases", _databases}});
- createHttpReq(lock, method, target, data);
-}
-
-void AddReplicaQservHttpMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__);
- notifyDefaultImpl(lock, _onFinish);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/AddReplicaQservHttpMgtRequest.h b/src/replica/AddReplicaQservHttpMgtRequest.h
deleted file mode 100644
index 9e3293639..000000000
--- a/src/replica/AddReplicaQservHttpMgtRequest.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_ADDREPLICAQSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_ADDREPLICAQSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-#include
-#include
-#include
-
-// Third party headers
-#include "nlohmann/json.hpp"
-
-// Qserv headers
-#include "replica/QservHttpMgtRequest.h"
-
-namespace lsst::qserv::replica {
-class ServiceProvider;
-} // namespace lsst::qserv::replica
-
-// This header declarations
-
-namespace lsst::qserv::replica {
-
-/**
- * Class AddReplicaQservHttpMgtRequest implements a request notifying Qserv workers
- * on new chunks added to the database.
- */
-class AddReplicaQservHttpMgtRequest : public QservHttpMgtRequest {
-public:
- typedef std::shared_ptr Ptr;
-
- /// The function type for notifications on the completion of the request
- typedef std::function CallbackType;
-
- AddReplicaQservHttpMgtRequest() = delete;
- AddReplicaQservHttpMgtRequest(AddReplicaQservHttpMgtRequest const&) = delete;
- AddReplicaQservHttpMgtRequest& operator=(AddReplicaQservHttpMgtRequest const&) = delete;
-
- virtual ~AddReplicaQservHttpMgtRequest() final = default;
-
- /**
- * Static factory method is needed to prevent issues with the lifespan
- * and memory management of instances created otherwise (as values or via
- * low-level pointers).
- *
- * @param serviceProvider A reference to a provider of services for accessing
- * Configuration, saving the request's persistent state to the database.
- * @param worker The name of a worker to send the request to.
- * @param chunk The chunk number.
- * @param databases The names of databases.
- * @param onFinish (optional) callback function to be called upon request completion.
- * @return A pointer to the created object.
- */
- static Ptr create(std::shared_ptr const& serviceProvider, std::string const& worker,
- unsigned int chunk, std::vector const& databases,
- CallbackType const& onFinish = nullptr);
-
- /// @return the chunk number
- unsigned int chunk() const { return _chunk; }
-
- /// @return names of databases
- std::vector const& databases() const { return _databases; }
-
- /// @see QservHttpMgtRequest::extendedPersistentState()
- virtual std::list> extendedPersistentState() const final;
-
-protected:
- /// @see QservHttpMgtRequest::createHttpReqImpl
- virtual void createHttpReqImpl(replica::Lock const& lock) final;
-
- /// @see QservHttpMgtRequest::notify
- virtual void notify(replica::Lock const& lock) final;
-
-private:
- /// @see AddReplicaQservHttpMgtRequest::create()
- AddReplicaQservHttpMgtRequest(std::shared_ptr const& serviceProvider,
- std::string const& worker, unsigned int chunk,
- std::vector const& databases, CallbackType const& onFinish);
-
- // Input parameters
-
- unsigned int const _chunk;
- std::vector const _databases;
- CallbackType _onFinish; ///< The callback is reset when the request finishes.
-};
-
-} // namespace lsst::qserv::replica
-
-#endif // LSST_QSERV_REPLICA_ADDREPLICAQSERVHTTPMGTREQUEST_H
diff --git a/src/replica/AddReplicaQservMgtRequest.cc b/src/replica/AddReplicaQservMgtRequest.cc
index e85d9264e..24edcf156 100644
--- a/src/replica/AddReplicaQservMgtRequest.cc
+++ b/src/replica/AddReplicaQservMgtRequest.cc
@@ -22,19 +22,10 @@
// Class header
#include "replica/AddReplicaQservMgtRequest.h"
-// Third party headers
-#include "XrdSsi/XrdSsiProvider.hh"
-#include "XrdSsi/XrdSsiService.hh"
-
-// Qserv headers
-#include "global/ResourceUnit.h"
-#include "proto/worker.pb.h"
-#include "replica/Configuration.h"
-#include "replica/ServiceProvider.h"
-
// LSST headers
#include "lsst/log/Log.h"
+using namespace nlohmann;
using namespace std;
namespace {
@@ -46,21 +37,20 @@ LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.AddReplicaQservMgtRequest");
namespace lsst::qserv::replica {
AddReplicaQservMgtRequest::Ptr AddReplicaQservMgtRequest::create(
- ServiceProvider::Ptr const& serviceProvider, string const& worker, unsigned int chunk,
+ shared_ptr const& serviceProvider, string const& worker, unsigned int chunk,
vector const& databases, AddReplicaQservMgtRequest::CallbackType const& onFinish) {
return AddReplicaQservMgtRequest::Ptr(
new AddReplicaQservMgtRequest(serviceProvider, worker, chunk, databases, onFinish));
}
-AddReplicaQservMgtRequest::AddReplicaQservMgtRequest(ServiceProvider::Ptr const& serviceProvider,
+AddReplicaQservMgtRequest::AddReplicaQservMgtRequest(shared_ptr const& serviceProvider,
string const& worker, unsigned int chunk,
vector const& databases,
AddReplicaQservMgtRequest::CallbackType const& onFinish)
: QservMgtRequest(serviceProvider, "QSERV_ADD_REPLICA", worker),
_chunk(chunk),
_databases(databases),
- _onFinish(onFinish),
- _qservRequest(nullptr) {}
+ _onFinish(onFinish) {}
list> AddReplicaQservMgtRequest::extendedPersistentState() const {
list> result;
@@ -71,52 +61,15 @@ list> AddReplicaQservMgtRequest::extendedPersistentState()
return result;
}
-void AddReplicaQservMgtRequest::startImpl(replica::Lock const& lock) {
- auto const request = shared_from_base();
-
- _qservRequest = xrdreq::AddChunkGroupQservRequest::create(
- chunk(), databases(), [request](proto::WorkerCommandStatus::Code code, string const& error) {
- if (request->state() == State::FINISHED) return;
- replica::Lock lock(request->_mtx, request->context() + string(__func__) + "[callback]");
- if (request->state() == State::FINISHED) return;
-
- switch (code) {
- case proto::WorkerCommandStatus::SUCCESS:
- request->finish(lock, QservMgtRequest::ExtendedState::SUCCESS);
- break;
- case proto::WorkerCommandStatus::INVALID:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_BAD, error);
- break;
- case proto::WorkerCommandStatus::IN_USE:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_CHUNK_IN_USE, error);
- break;
- case proto::WorkerCommandStatus::ERROR:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_ERROR, error);
- break;
- default:
- throw logic_error("AddReplicaQservMgtRequest::" + string(__func__) +
- " unhandled request completion code: " +
- proto::WorkerCommandStatus_Code_Name(code));
- }
- });
- XrdSsiResource resource(ResourceUnit::makeWorkerPath(worker()));
- service()->ProcessRequest(*_qservRequest, resource);
-}
-
-void AddReplicaQservMgtRequest::finishImpl(replica::Lock const& lock) {
- switch (extendedState()) {
- case ExtendedState::CANCELLED:
- case ExtendedState::TIMEOUT_EXPIRED:
- if (_qservRequest) _qservRequest->cancel();
- break;
- default:
- break;
- }
+void AddReplicaQservMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
+ string const method = "POST";
+ string const target = "/replica";
+ json const data = json::object({{"chunk", _chunk}, {"databases", _databases}});
+ createHttpReq(lock, method, target, data);
}
void AddReplicaQservMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_DEBUG, context() << __func__);
-
+ LOGS(_log, LOG_LVL_TRACE, context() << __func__);
notifyDefaultImpl(lock, _onFinish);
}
diff --git a/src/replica/AddReplicaQservMgtRequest.h b/src/replica/AddReplicaQservMgtRequest.h
index ba1c3b550..7672d8d5a 100644
--- a/src/replica/AddReplicaQservMgtRequest.h
+++ b/src/replica/AddReplicaQservMgtRequest.h
@@ -22,14 +22,21 @@
#define LSST_QSERV_REPLICA_ADDREPLICAQSERVMGTREQUEST_H
// System headers
+#include
#include
#include
#include
+#include
+
+// Third party headers
+#include "nlohmann/json.hpp"
// Qserv headers
#include "replica/QservMgtRequest.h"
-#include "replica/ServiceProvider.h"
-#include "xrdreq/ChunkGroupQservRequest.h"
+
+namespace lsst::qserv::replica {
+class ServiceProvider;
+} // namespace lsst::qserv::replica
// This header declarations
@@ -50,7 +57,7 @@ class AddReplicaQservMgtRequest : public QservMgtRequest {
AddReplicaQservMgtRequest(AddReplicaQservMgtRequest const&) = delete;
AddReplicaQservMgtRequest& operator=(AddReplicaQservMgtRequest const&) = delete;
- ~AddReplicaQservMgtRequest() final = default;
+ virtual ~AddReplicaQservMgtRequest() final = default;
/**
* Static factory method is needed to prevent issues with the lifespan
@@ -65,7 +72,7 @@ class AddReplicaQservMgtRequest : public QservMgtRequest {
* @param onFinish (optional) callback function to be called upon request completion.
* @return A pointer to the created object.
*/
- static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
+ static Ptr create(std::shared_ptr const& serviceProvider, std::string const& worker,
unsigned int chunk, std::vector const& databases,
CallbackType const& onFinish = nullptr);
@@ -76,32 +83,26 @@ class AddReplicaQservMgtRequest : public QservMgtRequest {
std::vector const& databases() const { return _databases; }
/// @see QservMgtRequest::extendedPersistentState()
- std::list> extendedPersistentState() const final;
+ virtual std::list> extendedPersistentState() const final;
protected:
- /// @see QservMgtRequest::startImpl
- void startImpl(replica::Lock const& lock) final;
-
- /// @see QservMgtRequest::finishImpl
- void finishImpl(replica::Lock const& lock) final;
+ /// @see QservMgtRequest::createHttpReqImpl
+ virtual void createHttpReqImpl(replica::Lock const& lock) final;
/// @see QservMgtRequest::notify
- void notify(replica::Lock const& lock) final;
+ virtual void notify(replica::Lock const& lock) final;
private:
/// @see AddReplicaQservMgtRequest::create()
- AddReplicaQservMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- unsigned int chunk, std::vector const& databases,
- CallbackType const& onFinish);
+ AddReplicaQservMgtRequest(std::shared_ptr const& serviceProvider,
+ std::string const& worker, unsigned int chunk,
+ std::vector const& databases, CallbackType const& onFinish);
// Input parameters
unsigned int const _chunk;
std::vector const _databases;
- CallbackType _onFinish; /// @note is reset when the request finishes
-
- /// A request to the remote services
- xrdreq::AddChunkGroupQservRequest::Ptr _qservRequest;
+ CallbackType _onFinish; ///< The callback is reset when the request finishes.
};
} // namespace lsst::qserv::replica
diff --git a/src/replica/CMakeLists.txt b/src/replica/CMakeLists.txt
index 10b1b1bdf..991dc2015 100644
--- a/src/replica/CMakeLists.txt
+++ b/src/replica/CMakeLists.txt
@@ -11,7 +11,6 @@ target_sources(replica PRIVATE
${REPLICA_PB_HDRS}
AbortTransactionApp.cc
AbortTransactionJob.cc
- AddReplicaQservHttpMgtRequest.cc
AddReplicaQservMgtRequest.cc
AdminApp.cc
Application.cc
@@ -74,13 +73,9 @@ target_sources(replica PRIVATE
FindRequest.cc
FixUpApp.cc
FixUpJob.cc
- GetReplicasQservHttpMgtRequest.cc
GetReplicasQservMgtRequest.cc
- GetDbStatusQservHttpMgtRequest.cc
GetDbStatusQservMgtRequest.cc
- GetConfigQservHttpMgtRequest.cc
GetConfigQservMgtRequest.cc
- GetStatusQservHttpMgtRequest.cc
GetStatusQservMgtRequest.cc
HealthMonitorTask.cc
HttpAsyncReqApp.cc
@@ -135,7 +130,6 @@ target_sources(replica PRIVATE
PurgeJob.cc
QhttpTestApp.cc
QservGetReplicasJob.cc
- QservHttpMgtRequest.cc
QservMgtRequest.cc
QservMgtServices.cc
QservStatusJob.cc
@@ -149,7 +143,6 @@ target_sources(replica PRIVATE
RegistryHttpSvc.cc
RegistryHttpSvcMod.cc
RegistryWorkers.cc
- RemoveReplicaQservHttpMgtRequest.cc
RemoveReplicaQservMgtRequest.cc
ReplicaInfo.cc
ReplicateApp.cc
@@ -163,7 +156,6 @@ target_sources(replica PRIVATE
ServiceManagementRequest.cc
ServiceManagementRequestBase.cc
ServiceProvider.cc
- SetReplicasQservHttpMgtRequest.cc
SetReplicasQservMgtRequest.cc
SqlAlterTablesJob.cc
SqlAlterTablesRequest.cc
@@ -210,7 +202,6 @@ target_sources(replica PRIVATE
SuccessRateGenerator.cc
SyncApp.cc
Task.cc
- TestEchoQservHttpMgtRequest.cc
TestEchoQservMgtRequest.cc
TransactionContrib.cc
TransactionsApp.cc
diff --git a/src/replica/GetConfigQservHttpMgtRequest.cc b/src/replica/GetConfigQservHttpMgtRequest.cc
deleted file mode 100644
index 6f4c5140e..000000000
--- a/src/replica/GetConfigQservHttpMgtRequest.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/GetConfigQservHttpMgtRequest.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetConfigQservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-shared_ptr GetConfigQservHttpMgtRequest::create(
- shared_ptr const& serviceProvider, string const& worker,
- GetConfigQservHttpMgtRequest::CallbackType const& onFinish) {
- return shared_ptr(
- new GetConfigQservHttpMgtRequest(serviceProvider, worker, onFinish));
-}
-
-GetConfigQservHttpMgtRequest::GetConfigQservHttpMgtRequest(
- shared_ptr const& serviceProvider, string const& worker,
- GetConfigQservHttpMgtRequest::CallbackType const& onFinish)
- : QservHttpMgtRequest(serviceProvider, "QSERV_GET_DATABASE_STATUS", worker), _onFinish(onFinish) {}
-
-void GetConfigQservHttpMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
- string const service = "/config";
- createHttpReq(lock, service);
-}
-
-void GetConfigQservHttpMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__);
- notifyDefaultImpl(lock, _onFinish);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/GetConfigQservHttpMgtRequest.h b/src/replica/GetConfigQservHttpMgtRequest.h
deleted file mode 100644
index b40902ae7..000000000
--- a/src/replica/GetConfigQservHttpMgtRequest.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_GETCONFIGQSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_GETCONFIGQSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-
-// Qserv headers
-#include "replica/QservHttpMgtRequest.h"
-
-namespace lsst::qserv::replica {
-class ServiceProvider;
-} // namespace lsst::qserv::replica
-
-// This header declarations
-namespace lsst::qserv::replica {
-
-/**
- * Class GetConfigQservHttpMgtRequest is a request for obtaining various info
- * on the database service of the Qserv worker.
- */
-class GetConfigQservHttpMgtRequest : public QservHttpMgtRequest {
-public:
- /// The function type for notifications on the completion of the request
- typedef std::function const&)> CallbackType;
-
- GetConfigQservHttpMgtRequest() = delete;
- GetConfigQservHttpMgtRequest(GetConfigQservHttpMgtRequest const&) = delete;
- GetConfigQservHttpMgtRequest& operator=(GetConfigQservHttpMgtRequest const&) = delete;
-
- virtual ~GetConfigQservHttpMgtRequest() final = default;
-
- /**
- * Static factory method is needed to prevent issues with the lifespan
- * and memory management of instances created otherwise (as values or via
- * low-level pointers).
- * @param serviceProvider A reference to a provider of services for accessing
- * Configuration, saving the request's persistent state to the database.
- * @param worker The name of a worker to send the request to.
- * @param onFinish (optional) callback function to be called upon request completion.
- * @return A pointer to the created object.
- */
- static std::shared_ptr create(
- std::shared_ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish = nullptr);
-
-protected:
- /// @see QservHttpMgtRequest::createHttpReqImpl()
- virtual void createHttpReqImpl(replica::Lock const& lock) final;
-
- /// @see QservHttpMgtRequest::notify()
- virtual void notify(replica::Lock const& lock) final;
-
-private:
- /// @see GetConfigQservHttpMgtRequest::create()
- GetConfigQservHttpMgtRequest(std::shared_ptr const& serviceProvider,
- std::string const& worker, CallbackType const& onFinish);
-
- // Input parameters
-
- CallbackType _onFinish; ///< This callback is reset after finishing the request.
-};
-
-} // namespace lsst::qserv::replica
-
-#endif // LSST_QSERV_REPLICA_GETCONFIGQSERVHTTPMGTREQUEST_H
diff --git a/src/replica/GetConfigQservMgtRequest.cc b/src/replica/GetConfigQservMgtRequest.cc
index 7f06ead05..1c43deb02 100644
--- a/src/replica/GetConfigQservMgtRequest.cc
+++ b/src/replica/GetConfigQservMgtRequest.cc
@@ -22,23 +22,9 @@
// Class header
#include "replica/GetConfigQservMgtRequest.h"
-// System headers
-#include
-#include
-
-// Third party headers
-#include "XrdSsi/XrdSsiProvider.hh"
-#include "XrdSsi/XrdSsiService.hh"
-
-// Qserv headers
-#include "global/ResourceUnit.h"
-#include "proto/worker.pb.h"
-#include "replica/ServiceProvider.h"
-
// LSST headers
#include "lsst/log/Log.h"
-using namespace nlohmann;
using namespace std;
namespace {
@@ -49,65 +35,21 @@ LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetConfigQservMgtRequest");
namespace lsst::qserv::replica {
-GetConfigQservMgtRequest::Ptr GetConfigQservMgtRequest::create(
- ServiceProvider::Ptr const& serviceProvider, string const& worker,
+shared_ptr GetConfigQservMgtRequest::create(
+ shared_ptr const& serviceProvider, string const& worker,
GetConfigQservMgtRequest::CallbackType const& onFinish) {
- return GetConfigQservMgtRequest::Ptr(new GetConfigQservMgtRequest(serviceProvider, worker, onFinish));
+ return shared_ptr(
+ new GetConfigQservMgtRequest(serviceProvider, worker, onFinish));
}
-GetConfigQservMgtRequest::GetConfigQservMgtRequest(ServiceProvider::Ptr const& serviceProvider,
+GetConfigQservMgtRequest::GetConfigQservMgtRequest(shared_ptr const& serviceProvider,
string const& worker,
GetConfigQservMgtRequest::CallbackType const& onFinish)
: QservMgtRequest(serviceProvider, "QSERV_GET_DATABASE_STATUS", worker), _onFinish(onFinish) {}
-json const& GetConfigQservMgtRequest::info() const {
- if (!((state() == State::FINISHED) && (extendedState() == ExtendedState::SUCCESS))) {
- throw logic_error("GetConfigQservMgtRequest::" + string(__func__) +
- " no info available in state: " + state2string(state(), extendedState()));
- }
- return _info;
-}
-
-void GetConfigQservMgtRequest::startImpl(replica::Lock const& lock) {
- auto const request = shared_from_base();
- _qservRequest = xrdreq::GetConfigQservRequest::create([request](proto::WorkerCommandStatus::Code code,
- string const& error, string const& info) {
- if (request->state() == State::FINISHED) return;
- replica::Lock const lock(request->_mtx, request->context() + string(__func__) + "[callback]");
- if (request->state() == State::FINISHED) return;
-
- switch (code) {
- case proto::WorkerCommandStatus::SUCCESS:
- try {
- request->_setInfo(lock, info);
- request->finish(lock, QservMgtRequest::ExtendedState::SUCCESS);
- } catch (exception const& ex) {
- string const msg = "failed to parse worker response, ex: " + string(ex.what());
- LOGS(_log, LOG_LVL_ERROR, "GetConfigQservMgtRequest::" << __func__ << " " << msg);
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_BAD_RESPONSE, msg);
- }
- break;
- case proto::WorkerCommandStatus::ERROR:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_ERROR, error);
- break;
- default:
- throw logic_error("GetConfigQservMgtRequest::" + string(__func__) +
- " unhandled server status: " + proto::WorkerCommandStatus_Code_Name(code));
- }
- });
- XrdSsiResource resource(ResourceUnit::makeWorkerPath(worker()));
- service()->ProcessRequest(*_qservRequest, resource);
-}
-
-void GetConfigQservMgtRequest::finishImpl(replica::Lock const& lock) {
- switch (extendedState()) {
- case ExtendedState::CANCELLED:
- case ExtendedState::TIMEOUT_EXPIRED:
- if (_qservRequest) _qservRequest->cancel();
- break;
- default:
- break;
- }
+void GetConfigQservMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
+ string const service = "/config";
+ createHttpReq(lock, service);
}
void GetConfigQservMgtRequest::notify(replica::Lock const& lock) {
@@ -115,8 +57,4 @@ void GetConfigQservMgtRequest::notify(replica::Lock const& lock) {
notifyDefaultImpl(lock, _onFinish);
}
-void GetConfigQservMgtRequest::_setInfo(replica::Lock const& lock, string const& info) {
- _info = json::parse(info);
-}
-
} // namespace lsst::qserv::replica
diff --git a/src/replica/GetConfigQservMgtRequest.h b/src/replica/GetConfigQservMgtRequest.h
index fc75dd038..6877b723b 100644
--- a/src/replica/GetConfigQservMgtRequest.h
+++ b/src/replica/GetConfigQservMgtRequest.h
@@ -25,20 +25,19 @@
#include
#include
-// Third party headers
-#include "nlohmann/json.hpp"
-
// Qserv headers
#include "replica/QservMgtRequest.h"
-#include "replica/ServiceProvider.h"
-#include "xrdreq/GetConfigQservRequest.h"
+
+namespace lsst::qserv::replica {
+class ServiceProvider;
+} // namespace lsst::qserv::replica
// This header declarations
namespace lsst::qserv::replica {
/**
- * Class GetConfigQservMgtRequest is a request for obtaining configuration
- * parameters of the Qserv worker.
+ * Class GetConfigQservMgtRequest is a request for obtaining various info
+ * on the database service of the Qserv worker.
*/
class GetConfigQservMgtRequest : public QservMgtRequest {
public:
@@ -51,7 +50,7 @@ class GetConfigQservMgtRequest : public QservMgtRequest {
GetConfigQservMgtRequest(GetConfigQservMgtRequest const&) = delete;
GetConfigQservMgtRequest& operator=(GetConfigQservMgtRequest const&) = delete;
- virtual ~GetConfigQservMgtRequest() = default;
+ virtual ~GetConfigQservMgtRequest() final = default;
/**
* Static factory method is needed to prevent issues with the lifespan
@@ -63,48 +62,25 @@ class GetConfigQservMgtRequest : public QservMgtRequest {
* @param onFinish (optional) callback function to be called upon request completion.
* @return A pointer to the created object.
*/
- static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish = nullptr);
-
- /**
- * @return The info object returned back by the worker.
- * @note The method will throw exception std::logic_error if called before
- * the request finishes or if it's finished with any status but SUCCESS.
- */
- nlohmann::json const& info() const;
+ static std::shared_ptr create(
+ std::shared_ptr const& serviceProvider, std::string const& worker,
+ CallbackType const& onFinish = nullptr);
protected:
- /// @see QservMgtRequest::startImpl()
- virtual void startImpl(replica::Lock const& lock);
-
- /// @see QservMgtRequest::finishImpl()
- virtual void finishImpl(replica::Lock const& lock);
+ /// @see QservMgtRequest::createHttpReqImpl()
+ virtual void createHttpReqImpl(replica::Lock const& lock) final;
/// @see QservMgtRequest::notify()
- virtual void notify(replica::Lock const& lock);
+ virtual void notify(replica::Lock const& lock) final;
private:
/// @see GetConfigQservMgtRequest::create()
- GetConfigQservMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish);
-
- /**
- * Carry over results of the request into a local storage.
- * @param lock A lock on QservMgtRequest::_mtx must be acquired by a caller of the method.
- * @param info The data string returned by a worker.
- */
- void _setInfo(replica::Lock const& lock, std::string const& info);
+ GetConfigQservMgtRequest(std::shared_ptr const& serviceProvider,
+ std::string const& worker, CallbackType const& onFinish);
// Input parameters
- std::string const _data;
- CallbackType _onFinish; ///< this object is reset after finishing the request
-
- /// A request to the remote services
- xrdreq::GetConfigQservRequest::Ptr _qservRequest;
-
- /// The info object returned by the Qserv worker
- nlohmann::json _info;
+ CallbackType _onFinish; ///< This callback is reset after finishing the request.
};
} // namespace lsst::qserv::replica
diff --git a/src/replica/GetDbStatusQservHttpMgtRequest.cc b/src/replica/GetDbStatusQservHttpMgtRequest.cc
deleted file mode 100644
index 075de27fd..000000000
--- a/src/replica/GetDbStatusQservHttpMgtRequest.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/GetDbStatusQservHttpMgtRequest.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetDbStatusQservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-shared_ptr GetDbStatusQservHttpMgtRequest::create(
- shared_ptr const& serviceProvider, string const& worker,
- GetDbStatusQservHttpMgtRequest::CallbackType const& onFinish) {
- return shared_ptr(
- new GetDbStatusQservHttpMgtRequest(serviceProvider, worker, onFinish));
-}
-
-GetDbStatusQservHttpMgtRequest::GetDbStatusQservHttpMgtRequest(
- shared_ptr const& serviceProvider, string const& worker,
- GetDbStatusQservHttpMgtRequest::CallbackType const& onFinish)
- : QservHttpMgtRequest(serviceProvider, "QSERV_GET_DATABASE_STATUS", worker), _onFinish(onFinish) {}
-
-void GetDbStatusQservHttpMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
- string const service = "/mysql";
- createHttpReq(lock, service);
-}
-
-void GetDbStatusQservHttpMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__);
- notifyDefaultImpl(lock, _onFinish);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/GetDbStatusQservHttpMgtRequest.h b/src/replica/GetDbStatusQservHttpMgtRequest.h
deleted file mode 100644
index 0ffabc96e..000000000
--- a/src/replica/GetDbStatusQservHttpMgtRequest.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_GETDBSTATUSQSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_GETDBSTATUSQSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-
-// Qserv headers
-#include "replica/QservHttpMgtRequest.h"
-
-namespace lsst::qserv::replica {
-class ServiceProvider;
-} // namespace lsst::qserv::replica
-
-// This header declarations
-namespace lsst::qserv::replica {
-
-/**
- * Class GetDbStatusQservHttpMgtRequest is a request for obtaining various info
- * on the database service of the Qserv worker.
- */
-class GetDbStatusQservHttpMgtRequest : public QservHttpMgtRequest {
-public:
- typedef std::shared_ptr Ptr;
-
- /// The function type for notifications on the completion of the request
- typedef std::function CallbackType;
-
- GetDbStatusQservHttpMgtRequest() = delete;
- GetDbStatusQservHttpMgtRequest(GetDbStatusQservHttpMgtRequest const&) = delete;
- GetDbStatusQservHttpMgtRequest& operator=(GetDbStatusQservHttpMgtRequest const&) = delete;
-
- virtual ~GetDbStatusQservHttpMgtRequest() final = default;
-
- /**
- * Static factory method is needed to prevent issues with the lifespan
- * and memory management of instances created otherwise (as values or via
- * low-level pointers).
- * @param serviceProvider A reference to a provider of services for accessing
- * Configuration, saving the request's persistent state to the database.
- * @param worker The name of a worker to send the request to.
- * @param onFinish (optional) callback function to be called upon request completion.
- * @return A pointer to the created object.
- */
- static std::shared_ptr create(
- std::shared_ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish = nullptr);
-
-protected:
- /// @see QservHttpMgtRequest::createHttpReqImpl()
- virtual void createHttpReqImpl(replica::Lock const& lock) final;
-
- /// @see QservHttpMgtRequest::notify()
- virtual void notify(replica::Lock const& lock) final;
-
-private:
- /// @see GetDbStatusQservHttpMgtRequest::create()
- GetDbStatusQservHttpMgtRequest(std::shared_ptr const& serviceProvider,
- std::string const& worker, CallbackType const& onFinish);
-
- // Input parameters
-
- CallbackType _onFinish; ///< This callback is reset after finishing the request.
-};
-
-} // namespace lsst::qserv::replica
-
-#endif // LSST_QSERV_REPLICA_GETDBSTATUSQSERVHTTPMGTREQUEST_H
diff --git a/src/replica/GetDbStatusQservMgtRequest.cc b/src/replica/GetDbStatusQservMgtRequest.cc
index c1e89bd52..ee6987ea7 100644
--- a/src/replica/GetDbStatusQservMgtRequest.cc
+++ b/src/replica/GetDbStatusQservMgtRequest.cc
@@ -22,23 +22,9 @@
// Class header
#include "replica/GetDbStatusQservMgtRequest.h"
-// System headers
-#include
-#include
-
-// Third party headers
-#include "XrdSsi/XrdSsiProvider.hh"
-#include "XrdSsi/XrdSsiService.hh"
-
-// Qserv headers
-#include "global/ResourceUnit.h"
-#include "proto/worker.pb.h"
-#include "replica/ServiceProvider.h"
-
// LSST headers
#include "lsst/log/Log.h"
-using namespace nlohmann;
using namespace std;
namespace {
@@ -49,71 +35,21 @@ LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetDbStatusQservMgtRequest");
namespace lsst::qserv::replica {
-GetDbStatusQservMgtRequest::Ptr GetDbStatusQservMgtRequest::create(
- ServiceProvider::Ptr const& serviceProvider, string const& worker,
+shared_ptr GetDbStatusQservMgtRequest::create(
+ shared_ptr const& serviceProvider, string const& worker,
GetDbStatusQservMgtRequest::CallbackType const& onFinish) {
- return GetDbStatusQservMgtRequest::Ptr(new GetDbStatusQservMgtRequest(serviceProvider, worker, onFinish));
+ return shared_ptr(
+ new GetDbStatusQservMgtRequest(serviceProvider, worker, onFinish));
}
GetDbStatusQservMgtRequest::GetDbStatusQservMgtRequest(
- ServiceProvider::Ptr const& serviceProvider, string const& worker,
+ shared_ptr const& serviceProvider, string const& worker,
GetDbStatusQservMgtRequest::CallbackType const& onFinish)
: QservMgtRequest(serviceProvider, "QSERV_GET_DATABASE_STATUS", worker), _onFinish(onFinish) {}
-json const& GetDbStatusQservMgtRequest::info() const {
- if (!((state() == State::FINISHED) && (extendedState() == ExtendedState::SUCCESS))) {
- throw logic_error("GetDbStatusQservMgtRequest::" + string(__func__) +
- " no info available in state: " + state2string(state(), extendedState()));
- }
- return _info;
-}
-
-list> GetDbStatusQservMgtRequest::extendedPersistentState() const {
- list> result;
- return result;
-}
-
-void GetDbStatusQservMgtRequest::startImpl(replica::Lock const& lock) {
- auto const request = shared_from_base();
- _qservRequest = xrdreq::GetDbStatusQservRequest::create([request](proto::WorkerCommandStatus::Code code,
- string const& error,
- string const& info) {
- if (request->state() == State::FINISHED) return;
- replica::Lock const lock(request->_mtx, request->context() + string(__func__) + "[callback]");
- if (request->state() == State::FINISHED) return;
-
- switch (code) {
- case proto::WorkerCommandStatus::SUCCESS:
- try {
- request->_setInfo(lock, info);
- request->finish(lock, QservMgtRequest::ExtendedState::SUCCESS);
- } catch (exception const& ex) {
- string const msg = "failed to parse worker response, ex: " + string(ex.what());
- LOGS(_log, LOG_LVL_ERROR, "GetDbStatusQservMgtRequest::" << __func__ << " " << msg);
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_BAD_RESPONSE, msg);
- }
- break;
- case proto::WorkerCommandStatus::ERROR:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_ERROR, error);
- break;
- default:
- throw logic_error("GetDbStatusQservMgtRequest::" + string(__func__) +
- " unhandled server status: " + proto::WorkerCommandStatus_Code_Name(code));
- }
- });
- XrdSsiResource resource(ResourceUnit::makeWorkerPath(worker()));
- service()->ProcessRequest(*_qservRequest, resource);
-}
-
-void GetDbStatusQservMgtRequest::finishImpl(replica::Lock const& lock) {
- switch (extendedState()) {
- case ExtendedState::CANCELLED:
- case ExtendedState::TIMEOUT_EXPIRED:
- if (_qservRequest) _qservRequest->cancel();
- break;
- default:
- break;
- }
+void GetDbStatusQservMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
+ string const service = "/mysql";
+ createHttpReq(lock, service);
}
void GetDbStatusQservMgtRequest::notify(replica::Lock const& lock) {
@@ -121,8 +57,4 @@ void GetDbStatusQservMgtRequest::notify(replica::Lock const& lock) {
notifyDefaultImpl(lock, _onFinish);
}
-void GetDbStatusQservMgtRequest::_setInfo(replica::Lock const& lock, string const& info) {
- _info = json::parse(info);
-}
-
} // namespace lsst::qserv::replica
diff --git a/src/replica/GetDbStatusQservMgtRequest.h b/src/replica/GetDbStatusQservMgtRequest.h
index 57a7d8b42..cf9c04fca 100644
--- a/src/replica/GetDbStatusQservMgtRequest.h
+++ b/src/replica/GetDbStatusQservMgtRequest.h
@@ -25,13 +25,12 @@
#include
#include
-// Third party headers
-#include "nlohmann/json.hpp"
-
// Qserv headers
#include "replica/QservMgtRequest.h"
-#include "replica/ServiceProvider.h"
-#include "xrdreq/GetDbStatusQservRequest.h"
+
+namespace lsst::qserv::replica {
+class ServiceProvider;
+} // namespace lsst::qserv::replica
// This header declarations
namespace lsst::qserv::replica {
@@ -51,7 +50,7 @@ class GetDbStatusQservMgtRequest : public QservMgtRequest {
GetDbStatusQservMgtRequest(GetDbStatusQservMgtRequest const&) = delete;
GetDbStatusQservMgtRequest& operator=(GetDbStatusQservMgtRequest const&) = delete;
- ~GetDbStatusQservMgtRequest() final = default;
+ virtual ~GetDbStatusQservMgtRequest() final = default;
/**
* Static factory method is needed to prevent issues with the lifespan
@@ -63,51 +62,25 @@ class GetDbStatusQservMgtRequest : public QservMgtRequest {
* @param onFinish (optional) callback function to be called upon request completion.
* @return A pointer to the created object.
*/
- static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish = nullptr);
-
- /**
- * @return The info object returned back by the worker.
- * @note The method will throw exception std::logic_error if called before
- * the request finishes or if it's finished with any status but SUCCESS.
- */
- nlohmann::json const& info() const;
-
- /// @see QservMgtRequest::extendedPersistentState()
- std::list> extendedPersistentState() const override;
+ static std::shared_ptr create(
+ std::shared_ptr const& serviceProvider, std::string const& worker,
+ CallbackType const& onFinish = nullptr);
protected:
- /// @see QservMgtRequest::startImpl()
- void startImpl(replica::Lock const& lock) final;
-
- /// @see QservMgtRequest::finishImpl()
- void finishImpl(replica::Lock const& lock) final;
+ /// @see QservMgtRequest::createHttpReqImpl()
+ virtual void createHttpReqImpl(replica::Lock const& lock) final;
/// @see QservMgtRequest::notify()
- void notify(replica::Lock const& lock) final;
+ virtual void notify(replica::Lock const& lock) final;
private:
/// @see GetDbStatusQservMgtRequest::create()
- GetDbStatusQservMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- CallbackType const& onFinish);
-
- /**
- * Carry over results of the request into a local storage.
- * @param lock A lock on QservMgtRequest::_mtx must be acquired by a caller of the method.
- * @param info The data string returned by a worker.
- */
- void _setInfo(replica::Lock const& lock, std::string const& info);
+ GetDbStatusQservMgtRequest(std::shared_ptr const& serviceProvider,
+ std::string const& worker, CallbackType const& onFinish);
// Input parameters
- std::string const _data;
- CallbackType _onFinish; ///< this object is reset after finishing the request
-
- /// A request to the remote services
- xrdreq::GetDbStatusQservRequest::Ptr _qservRequest;
-
- /// The info object returned by the Qserv worker
- nlohmann::json _info;
+ CallbackType _onFinish; ///< This callback is reset after finishing the request.
};
} // namespace lsst::qserv::replica
diff --git a/src/replica/GetReplicasQservHttpMgtRequest.cc b/src/replica/GetReplicasQservHttpMgtRequest.cc
deleted file mode 100644
index 01b64bfbe..000000000
--- a/src/replica/GetReplicasQservHttpMgtRequest.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/GetReplicasQservHttpMgtRequest.h"
-
-// System headers
-#include
-#include
-
-// Qserv headers
-#include "replica/Common.h"
-#include "replica/Configuration.h"
-#include "replica/ServiceProvider.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace nlohmann;
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetReplicasQservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-GetReplicasQservHttpMgtRequest::Ptr GetReplicasQservHttpMgtRequest::create(
- ServiceProvider::Ptr const& serviceProvider, string const& worker, string const& databaseFamily,
- bool inUseOnly, GetReplicasQservHttpMgtRequest::CallbackType const& onFinish) {
- return GetReplicasQservHttpMgtRequest::Ptr(
- new GetReplicasQservHttpMgtRequest(serviceProvider, worker, databaseFamily, inUseOnly, onFinish));
-}
-
-GetReplicasQservHttpMgtRequest::GetReplicasQservHttpMgtRequest(
- ServiceProvider::Ptr const& serviceProvider, string const& worker, string const& databaseFamily,
- bool inUseOnly, GetReplicasQservHttpMgtRequest::CallbackType const& onFinish)
- : QservHttpMgtRequest(serviceProvider, "QSERV_GET_REPLICAS", worker),
- _databaseFamily(databaseFamily),
- _inUseOnly(inUseOnly),
- _onFinish(onFinish) {}
-
-QservReplicaCollection const& GetReplicasQservHttpMgtRequest::replicas() const {
- if (!((state() == State::FINISHED) && (extendedState() == ExtendedState::SUCCESS))) {
- throw logic_error("GetReplicasQservHttpMgtRequest::" + string(__func__) +
- " replicas aren't available in state: " + state2string(state(), extendedState()));
- }
- return _replicas;
-}
-
-list> GetReplicasQservHttpMgtRequest::extendedPersistentState() const {
- list> result;
- result.emplace_back("database_family", _databaseFamily);
- result.emplace_back("in_use_only", replica::bool2str(_inUseOnly));
- return result;
-}
-
-void GetReplicasQservHttpMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
- string const service = "/replicas";
- string query = "?in_use_only=" + string(_inUseOnly ? "1" : "0") + "&databases=";
- for (auto&& database : serviceProvider()->config()->databases(_databaseFamily)) {
- query += database + ",";
- }
- createHttpReq(lock, service, query);
-}
-
-QservHttpMgtRequest::ExtendedState GetReplicasQservHttpMgtRequest::dataReady(replica::Lock const& lock,
- json const& data) {
- _replicas.clear();
- for (auto&& [database, chunks] : data.at("replicas").get().items()) {
- for (auto&& chunkEntry : chunks) {
- unsigned int const chunk = chunkEntry.at(0);
- unsigned int const useCount = chunkEntry.at(1);
- _replicas.emplace_back(QservReplica{chunk, database, useCount});
- }
- }
- return QservHttpMgtRequest::ExtendedState::SUCCESS;
-}
-
-void GetReplicasQservHttpMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__);
- notifyDefaultImpl(lock, _onFinish);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/GetReplicasQservHttpMgtRequest.h b/src/replica/GetReplicasQservHttpMgtRequest.h
deleted file mode 100644
index a9cd56fd2..000000000
--- a/src/replica/GetReplicasQservHttpMgtRequest.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_GET_REPLICAS_QSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_GET_REPLICAS_QSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-#include
-#include
-
-// Third party headers
-#include "nlohmann/json.hpp"
-
-// Qserv headers
-#include "replica/QservHttpMgtRequest.h"
-#include "replica/ReplicaInfo.h"
-
-namespace lsst::qserv::replica {
-class ServiceProvider;
-} // namespace lsst::qserv::replica
-
-// This header declarations
-namespace lsst::qserv::replica {
-
-/**
- * Class GetReplicasQservHttpMgtRequest implements a request retrieving a list of
- * replicas known to Qserv workers.
- */
-class GetReplicasQservHttpMgtRequest : public QservHttpMgtRequest {
-public:
- typedef std::shared_ptr Ptr;
-
- /// The function type for notifications on the completion of the request
- typedef std::function CallbackType;
-
- GetReplicasQservHttpMgtRequest() = delete;
- GetReplicasQservHttpMgtRequest(GetReplicasQservHttpMgtRequest const&) = delete;
- GetReplicasQservHttpMgtRequest& operator=(GetReplicasQservHttpMgtRequest const&) = delete;
-
- virtual ~GetReplicasQservHttpMgtRequest() final = default;
-
- /**
- * Static factory method is needed to prevent issues with the lifespan
- * and memory management of instances created otherwise (as values or via
- * low-level pointers).
- *
- * @param serviceProvider A reference to a provider of services for accessing
- * Configuration, saving the request's persistent state to the database.
- * @param worker The name of a worker to send the request to.
- * @param databaseFamily The name of a database family.
- * @param inUseOnly (optional) return replicas which are presently in use.
- * @param onFinish (optional) callback function to be called upon request completion.
- * @return A pointer to the created object.
- */
- static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- std::string const& databaseFamily, bool inUseOnly = false,
- CallbackType const& onFinish = nullptr);
-
- /// @return name of a database family
- std::string const& databaseFamily() const { return _databaseFamily; }
-
- /// @return flag indicating (if set) to report a subset of chunks which are in use
- bool inUseOnly() const { return _inUseOnly; }
-
- /**
- * @return A collection of replicas reported from the corresponding Qserv worker.
- * @throw std::logic_error If called before the request finishes or if it's finished with
- * any status but SUCCESS.
- */
- QservReplicaCollection const& replicas() const;
-
- /// @see QservHttpMgtRequest::extendedPersistentState()
- std::list> extendedPersistentState() const override;
-
-protected:
- /// @see QservHttpMgtRequest::createHttpReqImpl()
- virtual void createHttpReqImpl(replica::Lock const& lock) final;
-
- /// @see QservHttpMgtRequest::dataReady()
- virtual QservHttpMgtRequest::ExtendedState dataReady(replica::Lock const& lock,
- nlohmann::json const& data) final;
-
- /// @see QservHttpMgtRequest::notify
- virtual void notify(replica::Lock const& lock) final;
-
-private:
- /// @see GetReplicasQservHttpMgtRequest::create()
- GetReplicasQservHttpMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- std::string const& databaseFamily, bool inUseOnly,
- CallbackType const& onFinish);
-
- // Input parameters
-
- std::string const _databaseFamily;
- bool const _inUseOnly;
- CallbackType _onFinish; ///< The callback function is reset when the request finishes.
-
- /// A collection of replicas reported by the Qserr worker
- QservReplicaCollection _replicas;
-};
-
-} // namespace lsst::qserv::replica
-
-#endif // LSST_QSERV_REPLICA_GET_REPLICAS_QSERVHTTPMGTREQUEST_H
diff --git a/src/replica/GetReplicasQservMgtRequest.cc b/src/replica/GetReplicasQservMgtRequest.cc
index 57c88e21a..7c2964546 100644
--- a/src/replica/GetReplicasQservMgtRequest.cc
+++ b/src/replica/GetReplicasQservMgtRequest.cc
@@ -26,19 +26,15 @@
#include
#include
-// Third party headers
-#include "XrdSsi/XrdSsiProvider.hh"
-#include "XrdSsi/XrdSsiService.hh"
-
// Qserv headers
-#include "global/ResourceUnit.h"
-#include "proto/worker.pb.h"
+#include "replica/Common.h"
#include "replica/Configuration.h"
#include "replica/ServiceProvider.h"
// LSST headers
#include "lsst/log/Log.h"
+using namespace nlohmann;
using namespace std;
namespace {
@@ -62,11 +58,10 @@ GetReplicasQservMgtRequest::GetReplicasQservMgtRequest(
: QservMgtRequest(serviceProvider, "QSERV_GET_REPLICAS", worker),
_databaseFamily(databaseFamily),
_inUseOnly(inUseOnly),
- _onFinish(onFinish),
- _qservRequest(nullptr) {}
+ _onFinish(onFinish) {}
QservReplicaCollection const& GetReplicasQservMgtRequest::replicas() const {
- if (not((state() == State::FINISHED) and (extendedState() == ExtendedState::SUCCESS))) {
+ if (!((state() == State::FINISHED) && (extendedState() == ExtendedState::SUCCESS))) {
throw logic_error("GetReplicasQservMgtRequest::" + string(__func__) +
" replicas aren't available in state: " + state2string(state(), extendedState()));
}
@@ -75,81 +70,35 @@ QservReplicaCollection const& GetReplicasQservMgtRequest::replicas() const {
list> GetReplicasQservMgtRequest::extendedPersistentState() const {
list> result;
- result.emplace_back("database_family", databaseFamily());
- result.emplace_back("in_use_only", bool2str(inUseOnly()));
+ result.emplace_back("database_family", _databaseFamily);
+ result.emplace_back("in_use_only", replica::bool2str(_inUseOnly));
return result;
}
-void GetReplicasQservMgtRequest::_setReplicas(
- replica::Lock const& lock, xrdreq::GetChunkListQservRequest::ChunkCollection const& collection) {
- // Filter results by databases participating in the family
-
- set databases;
- for (auto&& database : serviceProvider()->config()->databases(databaseFamily())) {
- databases.insert(database);
- }
- _replicas.clear();
- for (auto&& replica : collection) {
- if (databases.count(replica.database)) {
- _replicas.emplace_back(QservReplica{replica.chunk, replica.database, replica.use_count});
- }
+void GetReplicasQservMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
+ string const service = "/replicas";
+ string query = "?in_use_only=" + string(_inUseOnly ? "1" : "0") + "&databases=";
+ for (auto&& database : serviceProvider()->config()->databases(_databaseFamily)) {
+ query += database + ",";
}
+ createHttpReq(lock, service, query);
}
-void GetReplicasQservMgtRequest::startImpl(replica::Lock const& lock) {
- // Check if configuration parameters are valid
-
- if (not serviceProvider()->config()->isKnownDatabaseFamily(databaseFamily())) {
- LOGS(_log, LOG_LVL_ERROR,
- context() << __func__ << " ** MISCONFIGURED ** "
- << " database family: '" << databaseFamily() << "'");
-
- finish(lock, ExtendedState::CONFIG_ERROR);
- return;
- }
-
- // Submit the actual request
-
- auto const request = shared_from_base();
-
- _qservRequest = xrdreq::GetChunkListQservRequest::create(
- inUseOnly(), [request](proto::WorkerCommandStatus::Code code, string const& error,
- xrdreq::GetChunkListQservRequest::ChunkCollection const& collection) {
- if (request->state() == State::FINISHED) return;
- replica::Lock lock(request->_mtx, request->context() + string(__func__) + "[callback]");
- if (request->state() == State::FINISHED) return;
-
- switch (code) {
- case proto::WorkerCommandStatus::SUCCESS:
- request->_setReplicas(lock, collection);
- request->finish(lock, QservMgtRequest::ExtendedState::SUCCESS);
- break;
- case proto::WorkerCommandStatus::ERROR:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_ERROR, error);
- break;
- default:
- throw logic_error(
- "GetReplicasQservMgtRequest::" + string(__func__) +
- " unhandled server status: " + proto::WorkerCommandStatus_Code_Name(code));
- }
- });
- XrdSsiResource resource(ResourceUnit::makeWorkerPath(worker()));
- service()->ProcessRequest(*_qservRequest, resource);
-}
-
-void GetReplicasQservMgtRequest::finishImpl(replica::Lock const& lock) {
- switch (extendedState()) {
- case ExtendedState::CANCELLED:
- case ExtendedState::TIMEOUT_EXPIRED:
- if (_qservRequest) _qservRequest->cancel();
- break;
- default:
- break;
+QservMgtRequest::ExtendedState GetReplicasQservMgtRequest::dataReady(replica::Lock const& lock,
+ json const& data) {
+ _replicas.clear();
+ for (auto&& [database, chunks] : data.at("replicas").get().items()) {
+ for (auto&& chunkEntry : chunks) {
+ unsigned int const chunk = chunkEntry.at(0);
+ unsigned int const useCount = chunkEntry.at(1);
+ _replicas.emplace_back(QservReplica{chunk, database, useCount});
+ }
}
+ return QservMgtRequest::ExtendedState::SUCCESS;
}
void GetReplicasQservMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_DEBUG, context() << __func__);
+ LOGS(_log, LOG_LVL_TRACE, context() << __func__);
notifyDefaultImpl(lock, _onFinish);
}
diff --git a/src/replica/GetReplicasQservMgtRequest.h b/src/replica/GetReplicasQservMgtRequest.h
index 508bf75cc..f98063a13 100644
--- a/src/replica/GetReplicasQservMgtRequest.h
+++ b/src/replica/GetReplicasQservMgtRequest.h
@@ -22,15 +22,21 @@
#define LSST_QSERV_REPLICA_GET_REPLICAS_QSERVMGTREQUEST_H
// System headers
+#include
#include
#include
-#include
+#include
+
+// Third party headers
+#include "nlohmann/json.hpp"
// Qserv headers
#include "replica/QservMgtRequest.h"
#include "replica/ReplicaInfo.h"
-#include "replica/ServiceProvider.h"
-#include "xrdreq/GetChunkListQservRequest.h"
+
+namespace lsst::qserv::replica {
+class ServiceProvider;
+} // namespace lsst::qserv::replica
// This header declarations
namespace lsst::qserv::replica {
@@ -50,7 +56,7 @@ class GetReplicasQservMgtRequest : public QservMgtRequest {
GetReplicasQservMgtRequest(GetReplicasQservMgtRequest const&) = delete;
GetReplicasQservMgtRequest& operator=(GetReplicasQservMgtRequest const&) = delete;
- ~GetReplicasQservMgtRequest() final = default;
+ virtual ~GetReplicasQservMgtRequest() final = default;
/**
* Static factory method is needed to prevent issues with the lifespan
@@ -86,14 +92,15 @@ class GetReplicasQservMgtRequest : public QservMgtRequest {
std::list> extendedPersistentState() const override;
protected:
- /// @see QservMgtRequest::startImpl
- void startImpl(replica::Lock const& lock) final;
+ /// @see QservMgtRequest::createHttpReqImpl()
+ virtual void createHttpReqImpl(replica::Lock const& lock) final;
- /// @see QservMgtRequest::finishImpl
- void finishImpl(replica::Lock const& lock) final;
+ /// @see QservMgtRequest::dataReady()
+ virtual QservMgtRequest::ExtendedState dataReady(replica::Lock const& lock,
+ nlohmann::json const& data) final;
/// @see QservMgtRequest::notify
- void notify(replica::Lock const& lock) final;
+ virtual void notify(replica::Lock const& lock) final;
private:
/// @see GetReplicasQservMgtRequest::create()
@@ -101,24 +108,11 @@ class GetReplicasQservMgtRequest : public QservMgtRequest {
std::string const& databaseFamily, bool inUseOnly,
CallbackType const& onFinish);
- /**
- * Carry over results of the request into a local collection. Filter results
- * by databases participating in the family.
- *
- * @param lock A lock on QservMgtRequest::_mtx must be acquired before calling this method
- * @param collection The input collection of replicas.
- */
- void _setReplicas(replica::Lock const& lock,
- xrdreq::GetChunkListQservRequest::ChunkCollection const& collection);
-
// Input parameters
std::string const _databaseFamily;
bool const _inUseOnly;
- CallbackType _onFinish; /// @note is reset when the request finishes
-
- /// A request to the remote services
- xrdreq::GetChunkListQservRequest::Ptr _qservRequest;
+ CallbackType _onFinish; ///< The callback function is reset when the request finishes.
/// A collection of replicas reported by the Qserr worker
QservReplicaCollection _replicas;
diff --git a/src/replica/GetStatusQservHttpMgtRequest.cc b/src/replica/GetStatusQservHttpMgtRequest.cc
deleted file mode 100644
index 9d83c184f..000000000
--- a/src/replica/GetStatusQservHttpMgtRequest.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/GetStatusQservHttpMgtRequest.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetStatusQservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-shared_ptr GetStatusQservHttpMgtRequest::create(
- shared_ptr const& serviceProvider, string const& worker,
- wbase::TaskSelector const& taskSelector, GetStatusQservHttpMgtRequest::CallbackType const& onFinish) {
- return shared_ptr(
- new GetStatusQservHttpMgtRequest(serviceProvider, worker, taskSelector, onFinish));
-}
-
-GetStatusQservHttpMgtRequest::GetStatusQservHttpMgtRequest(
- shared_ptr const& serviceProvider, string const& worker,
- wbase::TaskSelector const& taskSelector, GetStatusQservHttpMgtRequest::CallbackType const& onFinish)
- : QservHttpMgtRequest(serviceProvider, "QSERV_GET_STATUS", worker),
- _taskSelector(taskSelector),
- _onFinish(onFinish) {}
-
-void GetStatusQservHttpMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
- string const service = "/status";
- string const query = wbase::taskSelectorToHttpQuery(_taskSelector);
- createHttpReq(lock, service, query);
-}
-
-void GetStatusQservHttpMgtRequest::notify(replica::Lock const& lock) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__);
- notifyDefaultImpl(lock, _onFinish);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/GetStatusQservHttpMgtRequest.h b/src/replica/GetStatusQservHttpMgtRequest.h
deleted file mode 100644
index c88c36f00..000000000
--- a/src/replica/GetStatusQservHttpMgtRequest.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_GETSTATUSQSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_GETSTATUSQSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-
-// Qserv headers
-#include "replica/QservHttpMgtRequest.h"
-#include "wbase/TaskState.h"
-
-namespace lsst::qserv::replica {
-class ServiceProvider;
-} // namespace lsst::qserv::replica
-
-// This header declarations
-namespace lsst::qserv::replica {
-
-/**
- * Class GetStatusQservHttpMgtRequest is a request for obtaining various info
- * (status, counters, monitoring) reported the Qserv workers.
- */
-class GetStatusQservHttpMgtRequest : public QservHttpMgtRequest {
-public:
- typedef std::shared_ptr Ptr;
-
- /// The function type for notifications on the completion of the request
- typedef std::function CallbackType;
-
- GetStatusQservHttpMgtRequest() = delete;
- GetStatusQservHttpMgtRequest(GetStatusQservHttpMgtRequest const&) = delete;
- GetStatusQservHttpMgtRequest& operator=(GetStatusQservHttpMgtRequest const&) = delete;
-
- virtual ~GetStatusQservHttpMgtRequest() final = default;
-
- /**
- * Static factory method is needed to prevent issues with the lifespan
- * and memory management of instances created otherwise (as values or via
- * low-level pointers).
- * @param serviceProvider A reference to a provider of services for accessing
- * Configuration, saving the request's persistent state to the database.
- * @param worker The name of a worker to send the request to.
- * @param taskSelector (optional) task selection criterias
- * @param onFinish (optional) callback function to be called upon request completion.
- * @return A pointer to the created object.
- */
- static std::shared_ptr create(
- std::shared_ptr const& serviceProvider, std::string const& worker,
- wbase::TaskSelector const& taskSelector = wbase::TaskSelector(),
- CallbackType const& onFinish = nullptr);
-
-protected:
- /// @see QservHttpMgtRequest::createHttpReqImpl()
- virtual void createHttpReqImpl(replica::Lock const& lock) final;
-
- /// @see QservHttpMgtRequest::notify()
- virtual void notify(replica::Lock const& lock) final;
-
-private:
- /// @see GetStatusQservHttpMgtRequest::create()
- GetStatusQservHttpMgtRequest(std::shared_ptr const& serviceProvider,
- std::string const& worker, wbase::TaskSelector const& taskSelector,
- CallbackType const& onFinish);
-
- // Input parameters
-
- wbase::TaskSelector const _taskSelector;
- CallbackType _onFinish; ///< This callback is reset after finishing the request.
-};
-
-} // namespace lsst::qserv::replica
-
-#endif // LSST_QSERV_REPLICA_GETSTATUSQSERVHTTPMGTREQUEST_H
diff --git a/src/replica/GetStatusQservMgtRequest.cc b/src/replica/GetStatusQservMgtRequest.cc
index 06a3bec11..2bc546455 100644
--- a/src/replica/GetStatusQservMgtRequest.cc
+++ b/src/replica/GetStatusQservMgtRequest.cc
@@ -22,24 +22,9 @@
// Class header
#include "replica/GetStatusQservMgtRequest.h"
-// System headers
-#include
-#include
-
-// Third party headers
-#include "XrdSsi/XrdSsiProvider.hh"
-#include "XrdSsi/XrdSsiService.hh"
-
-// Qserv headers
-#include "global/ResourceUnit.h"
-#include "proto/worker.pb.h"
-#include "replica/Configuration.h"
-#include "replica/ServiceProvider.h"
-
// LSST headers
#include "lsst/log/Log.h"
-using namespace nlohmann;
using namespace std;
namespace {
@@ -50,14 +35,14 @@ LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.GetStatusQservMgtRequest");
namespace lsst::qserv::replica {
-GetStatusQservMgtRequest::Ptr GetStatusQservMgtRequest::create(
- ServiceProvider::Ptr const& serviceProvider, string const& worker,
+shared_ptr GetStatusQservMgtRequest::create(
+ shared_ptr const& serviceProvider, string const& worker,
wbase::TaskSelector const& taskSelector, GetStatusQservMgtRequest::CallbackType const& onFinish) {
- return GetStatusQservMgtRequest::Ptr(
+ return shared_ptr(
new GetStatusQservMgtRequest(serviceProvider, worker, taskSelector, onFinish));
}
-GetStatusQservMgtRequest::GetStatusQservMgtRequest(ServiceProvider::Ptr const& serviceProvider,
+GetStatusQservMgtRequest::GetStatusQservMgtRequest(shared_ptr const& serviceProvider,
string const& worker,
wbase::TaskSelector const& taskSelector,
GetStatusQservMgtRequest::CallbackType const& onFinish)
@@ -65,62 +50,10 @@ GetStatusQservMgtRequest::GetStatusQservMgtRequest(ServiceProvider::Ptr const& s
_taskSelector(taskSelector),
_onFinish(onFinish) {}
-json const& GetStatusQservMgtRequest::info() const {
- if (not((state() == State::FINISHED) and (extendedState() == ExtendedState::SUCCESS))) {
- throw logic_error("GetStatusQservMgtRequest::" + string(__func__) +
- " no info available in state: " + state2string(state(), extendedState()));
- }
- return _info;
-}
-
-list> GetStatusQservMgtRequest::extendedPersistentState() const {
- list> result;
- return result;
-}
-
-void GetStatusQservMgtRequest::startImpl(replica::Lock const& lock) {
- auto const request = shared_from_base();
- _qservRequest = xrdreq::GetStatusQservRequest::create(
- _taskSelector,
- [request](proto::WorkerCommandStatus::Code code, string const& error, string const& info) {
- if (request->state() == State::FINISHED) return;
- replica::Lock const lock(request->_mtx, request->context() + string(__func__) + "[callback]");
- if (request->state() == State::FINISHED) return;
-
- switch (code) {
- case proto::WorkerCommandStatus::SUCCESS:
- try {
- request->_setInfo(lock, info);
- request->finish(lock, QservMgtRequest::ExtendedState::SUCCESS);
- } catch (exception const& ex) {
- string const msg = "failed to parse worker response, ex: " + string(ex.what());
- LOGS(_log, LOG_LVL_ERROR,
- "GetStatusQservMgtRequest::" << __func__ << " " << msg);
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_BAD_RESPONSE, msg);
- }
- break;
- case proto::WorkerCommandStatus::ERROR:
- request->finish(lock, QservMgtRequest::ExtendedState::SERVER_ERROR, error);
- break;
- default:
- throw logic_error(
- "GetStatusQservMgtRequest::" + string(__func__) +
- " unhandled server status: " + proto::WorkerCommandStatus_Code_Name(code));
- }
- });
- XrdSsiResource resource(ResourceUnit::makeWorkerPath(worker()));
- service()->ProcessRequest(*_qservRequest, resource);
-}
-
-void GetStatusQservMgtRequest::finishImpl(replica::Lock const& lock) {
- switch (extendedState()) {
- case ExtendedState::CANCELLED:
- case ExtendedState::TIMEOUT_EXPIRED:
- if (_qservRequest) _qservRequest->cancel();
- break;
- default:
- break;
- }
+void GetStatusQservMgtRequest::createHttpReqImpl(replica::Lock const& lock) {
+ string const service = "/status";
+ string const query = wbase::taskSelectorToHttpQuery(_taskSelector);
+ createHttpReq(lock, service, query);
}
void GetStatusQservMgtRequest::notify(replica::Lock const& lock) {
@@ -128,8 +61,4 @@ void GetStatusQservMgtRequest::notify(replica::Lock const& lock) {
notifyDefaultImpl(lock, _onFinish);
}
-void GetStatusQservMgtRequest::_setInfo(replica::Lock const& lock, string const& info) {
- _info = json::parse(info);
-}
-
} // namespace lsst::qserv::replica
diff --git a/src/replica/GetStatusQservMgtRequest.h b/src/replica/GetStatusQservMgtRequest.h
index 4242906d5..05448ea4c 100644
--- a/src/replica/GetStatusQservMgtRequest.h
+++ b/src/replica/GetStatusQservMgtRequest.h
@@ -24,16 +24,14 @@
// System headers
#include
#include
-#include
-
-// Third party headers
-#include "nlohmann/json.hpp"
// Qserv headers
#include "replica/QservMgtRequest.h"
-#include "replica/ServiceProvider.h"
#include "wbase/TaskState.h"
-#include "xrdreq/GetStatusQservRequest.h"
+
+namespace lsst::qserv::replica {
+class ServiceProvider;
+} // namespace lsst::qserv::replica
// This header declarations
namespace lsst::qserv::replica {
@@ -53,7 +51,7 @@ class GetStatusQservMgtRequest : public QservMgtRequest {
GetStatusQservMgtRequest(GetStatusQservMgtRequest const&) = delete;
GetStatusQservMgtRequest& operator=(GetStatusQservMgtRequest const&) = delete;
- ~GetStatusQservMgtRequest() final = default;
+ virtual ~GetStatusQservMgtRequest() final = default;
/**
* Static factory method is needed to prevent issues with the lifespan
@@ -66,53 +64,28 @@ class GetStatusQservMgtRequest : public QservMgtRequest {
* @param onFinish (optional) callback function to be called upon request completion.
* @return A pointer to the created object.
*/
- static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- wbase::TaskSelector const& taskSelector = wbase::TaskSelector(),
- CallbackType const& onFinish = nullptr);
-
- /**
- * @return The info object returned back by the worker.
- * @note The method will throw exception std::logic_error if called before
- * the request finishes or if it's finished with any status but SUCCESS.
- */
- nlohmann::json const& info() const;
-
- /// @see QservMgtRequest::extendedPersistentState()
- std::list> extendedPersistentState() const override;
+ static std::shared_ptr create(
+ std::shared_ptr const& serviceProvider, std::string const& worker,
+ wbase::TaskSelector const& taskSelector = wbase::TaskSelector(),
+ CallbackType const& onFinish = nullptr);
protected:
- /// @see QservMgtRequest::startImpl()
- void startImpl(replica::Lock const& lock) final;
-
- /// @see QservMgtRequest::finishImpl()
- void finishImpl(replica::Lock const& lock) final;
+ /// @see QservMgtRequest::createHttpReqImpl()
+ virtual void createHttpReqImpl(replica::Lock const& lock) final;
/// @see QservMgtRequest::notify()
- void notify(replica::Lock const& lock) final;
+ virtual void notify(replica::Lock const& lock) final;
private:
/// @see GetStatusQservMgtRequest::create()
- GetStatusQservMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& worker,
- wbase::TaskSelector const& taskSelector, CallbackType const& onFinish);
-
- /**
- * Carry over results of the request into a local storage.
- * @param lock A lock on QservMgtRequest::_mtx must be acquired by a caller of the method.
- * @param info The data string returned by a worker.
- */
- void _setInfo(replica::Lock const& lock, std::string const& info);
+ GetStatusQservMgtRequest(std::shared_ptr const& serviceProvider,
+ std::string const& worker, wbase::TaskSelector const& taskSelector,
+ CallbackType const& onFinish);
// Input parameters
- std::string const _data;
wbase::TaskSelector const _taskSelector;
- CallbackType _onFinish; ///< this object is reset after finishing the request
-
- /// A request to the remote services
- xrdreq::GetStatusQservRequest::Ptr _qservRequest;
-
- /// The info object returned by the Qserv worker
- nlohmann::json _info;
+ CallbackType _onFinish; ///< This callback is reset after finishing the request.
};
} // namespace lsst::qserv::replica
diff --git a/src/replica/QservHttpMgtRequest.cc b/src/replica/QservHttpMgtRequest.cc
deleted file mode 100644
index eb2c870ea..000000000
--- a/src/replica/QservHttpMgtRequest.cc
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-
-// Class header
-#include "replica/QservHttpMgtRequest.h"
-
-// System headers
-#include
-#include
-
-// Qserv headers
-#include "http/MetaModule.h"
-#include "replica/Configuration.h"
-#include "replica/Common.h"
-#include "replica/DatabaseServices.h"
-
-// LSST headers
-#include "lsst/log/Log.h"
-
-using namespace nlohmann;
-using namespace std;
-
-namespace {
-
-LOG_LOGGER _log = LOG_GET("lsst.qserv.replica.QservHttpMgtRequest");
-
-} // namespace
-
-namespace lsst::qserv::replica {
-
-atomic QservHttpMgtRequest::_numClassInstances(0);
-
-string QservHttpMgtRequest::state2string(State state) {
- switch (state) {
- case State::CREATED:
- return "CREATED";
- case State::IN_PROGRESS:
- return "IN_PROGRESS";
- case State::FINISHED:
- return "FINISHED";
- }
- throw logic_error("QservHttpMgtRequest::" + string(__func__) + "(State) incomplete implementation");
-}
-
-string QservHttpMgtRequest::state2string(ExtendedState state) {
- switch (state) {
- case ExtendedState::NONE:
- return "NONE";
- case ExtendedState::SUCCESS:
- return "SUCCESS";
- case ExtendedState::CONFIG_ERROR:
- return "CONFIG_ERROR";
- case ExtendedState::BODY_LIMIT_ERROR:
- return "BODY_LIMIT_ERROR";
- case ExtendedState::SERVER_BAD:
- return "SERVER_BAD";
- case ExtendedState::SERVER_CHUNK_IN_USE:
- return "SERVER_CHUNK_IN_USE";
- case ExtendedState::SERVER_ERROR:
- return "SERVER_ERROR";
- case ExtendedState::SERVER_BAD_RESPONSE:
- return "SERVER_BAD_RESPONSE";
- case ExtendedState::TIMEOUT_EXPIRED:
- return "TIMEOUT_EXPIRED";
- case ExtendedState::CANCELLED:
- return "CANCELLED";
- }
- throw logic_error("QservHttpMgtRequest::" + string(__func__) +
- "(ExtendedState) incomplete implementation");
-}
-
-QservHttpMgtRequest::QservHttpMgtRequest(ServiceProvider::Ptr const& serviceProvider, string const& type,
- string const& worker)
- : _serviceProvider(serviceProvider),
- _type(type),
- _id(Generators::uniqueId()),
- _worker(worker),
- _state(State::CREATED),
- _extendedState(ExtendedState::NONE) {
- // This report is used solely for debugging purposes to allow tracking
- // potential memory leaks within applications.
- ++_numClassInstances;
- LOGS(_log, LOG_LVL_TRACE, context() << "constructed instances: " << _numClassInstances);
-}
-
-QservHttpMgtRequest::~QservHttpMgtRequest() {
- --_numClassInstances;
- LOGS(_log, LOG_LVL_TRACE, context() << "destructed instances: " << _numClassInstances);
-}
-
-string QservHttpMgtRequest::state2string() const {
- replica::Lock const lock(_mtx, context() + __func__);
- return state2string(state(), extendedState()) + "::" + serverError(lock);
-}
-
-string QservHttpMgtRequest::serverError() const {
- replica::Lock const lock(_mtx, context() + __func__);
- return serverError(lock);
-}
-
-string QservHttpMgtRequest::serverError(replica::Lock const& lock) const { return _serverError; }
-
-string QservHttpMgtRequest::context() const {
- return id() + " " + type() + " " + state2string(state(), extendedState()) + " ";
-}
-
-Performance QservHttpMgtRequest::performance() const {
- replica::Lock const lock(_mtx, context() + __func__);
- return performance(lock);
-}
-
-Performance QservHttpMgtRequest::performance(replica::Lock const& lock) const { return _performance; }
-
-void QservHttpMgtRequest::start(string const& jobId, unsigned int requestExpirationIvalSec) {
- string const context_ = context() + __func__;
- LOGS(_log, LOG_LVL_TRACE, context_);
-
- replica::Lock const lock(_mtx, context_);
- _assertNotStarted(__func__);
-
- // This needs to be updated to override the default value of the counter
- // which was created upon the object construction.
- _performance.setUpdateStart();
-
- // Check if configuration parameters are valid
- auto const config = _serviceProvider->config();
- if (!config->isKnownWorker(_worker)) {
- LOGS(_log, LOG_LVL_ERROR, context_ << " ** MISCONFIGURED ** unknown worker: '" << _worker << "'.");
- _setState(lock, State::FINISHED, ExtendedState::CONFIG_ERROR);
- notify(lock);
- return;
- }
-
- // Build an association with the corresponding parent job (optional).
- _jobId = jobId;
-
- // Adjust the default value of the expiration ival (if requested) before
- // creating and starting the request.
- unsigned int actualExpirationIvalSec = requestExpirationIvalSec;
- if (0 == actualExpirationIvalSec) {
- actualExpirationIvalSec = config->get("xrootd", "request-timeout-sec");
- }
-
- createHttpReqImpl(lock);
-
- _httpRequest->setExpirationIval(actualExpirationIvalSec);
- _httpRequest->start();
-
- _setState(lock, State::IN_PROGRESS);
-}
-
-void QservHttpMgtRequest::wait() {
- LOGS(_log, LOG_LVL_DEBUG, context() << __func__);
- if (_state == State::FINISHED) return;
- unique_lock onFinishLock(_onFinishMtx);
- _onFinishCv.wait(onFinishLock, [&] { return _finished; });
-}
-
-string const& QservHttpMgtRequest::jobId() const {
- _assertStarted(__func__);
- return _jobId;
-}
-
-json const& QservHttpMgtRequest::info() const {
- if (!((_state == State::FINISHED) && (_extendedState == ExtendedState::SUCCESS))) {
- throw logic_error("QservHttpMgtRequest::" + string(__func__) +
- " no info available in state: " + state2string(_state, _extendedState));
- }
- return _info;
-}
-
-void QservHttpMgtRequest::cancel() {
- _assertStarted(__func__);
- // No HTTP request would be sent if the request creation failed for some
- // reason (like misconfiguration, etc.). Hence, there is nothing to cancel.
- {
- replica::Lock const lock(_mtx, context() + __func__);
- if (_httpRequest == nullptr) return;
- }
- _httpRequest->cancel();
-}
-
-void QservHttpMgtRequest::createHttpReq(replica::Lock const& lock, string const& service,
- string const& query) {
- _assertNotStarted(__func__);
- string const target = service + query + string(query.empty() ? "?" : "&") + "id" + _id +
- "&instance_id=" + _serviceProvider->instanceId() + "&worker=" + _worker +
- "&version=" + to_string(http::MetaModule::version);
- _httpRequest = http::AsyncReq::create(
- _serviceProvider->io_service(),
- [self = shared_from_this()](shared_ptr const&) { self->_processResponse(); },
- "GET", _getHostPortTracker(), target);
-}
-
-void QservHttpMgtRequest::createHttpReq(replica::Lock const& lock, string const& method, string const& target,
- json const& body) {
- _assertNotStarted(__func__);
- json data = body;
- data["id"] = _id;
- data["instance_id"] = _serviceProvider->instanceId();
- data["worker"] = _worker;
- data["auth_key"] = _serviceProvider->authKey();
- data["admin_auth_key"] = _serviceProvider->adminAuthKey();
- data["version"] = http::MetaModule::version;
- unordered_map const headers = {{"Content-Type", "application/json"}};
- _httpRequest = http::AsyncReq::create(
- _serviceProvider->io_service(),
- [self = shared_from_this()](shared_ptr const&) { self->_processResponse(); },
- method, _getHostPortTracker(), target, data.dump(), headers);
-}
-
-void QservHttpMgtRequest::finish(replica::Lock const& lock, ExtendedState extendedState,
- string const& serverError) {
- string const context_ = context() + __func__;
- LOGS(_log, LOG_LVL_DEBUG, context_ << " serverError:" << serverError);
-
- // Set the optional server error state as well.
- // IMPORTANT: this needs to be done before performing the state transition to insure
- // clients will get a consistent view onto the object state.
- _serverError = serverError;
-
- // Set new state to make sure all event handlers will recognize
- // this scenario and avoid making any modifications to the request's state.
- _setState(lock, State::FINISHED, extendedState);
-
- // We have to update the timestamp before invoking a user provided
- // callback on the completion of the operation.
- _performance.setUpdateFinish();
-
- // TODO: temporarily disabled while this class is not supported by
- // the persistent backend.
- //
- // _serviceProvider->databaseServices()->saveState(*this, _performance, _serverError);
-
- notify(lock);
-
- // Unblock threads (if any) waiting on the synchronization call to the method wait().
- _finished = true;
- _onFinishCv.notify_all();
-}
-
-http::AsyncReq::GetHostPort QservHttpMgtRequest::_getHostPortTracker() const {
- return [config = _serviceProvider->config(),
- worker = _worker](http::AsyncReq::HostPort const&) -> http::AsyncReq::HostPort {
- auto const info = config->workerInfo(worker);
- return http::AsyncReq::HostPort{info.qservWorker.host.addr, info.qservWorker.port};
- };
-}
-
-void QservHttpMgtRequest::_processResponse() {
- string const context_ = context() + string(__func__) + " ";
- if (_state == State::FINISHED) return;
- replica::Lock const lock(_mtx, context_);
- if (_state == State::FINISHED) return;
-
- switch (_httpRequest->state()) {
- case http::AsyncReq::State::FINISHED:
- try {
- _info = json::parse(_httpRequest->responseBody());
- if (_info.at("success").get() == 0) {
- string const msg = "worker reported error: " + _info.at("error").get();
- auto extendedState = ExtendedState::SERVER_BAD;
- // Check for optional markers in the optional extended error section that might
- // clarify an actual reason behind the failure.
- if (auto const itr = _info.find("error_ext"); itr != _info.end()) {
- json const errorExt = *itr;
- if (errorExt.contains("in_use")) {
- extendedState = ExtendedState::SERVER_CHUNK_IN_USE;
- } else if (errorExt.contains("invalid_param")) {
- extendedState = ExtendedState::CONFIG_ERROR;
- }
- }
- finish(lock, extendedState, msg);
- } else {
- // Let a subclass do the optional result validation and post processing.
- // Note that the subclass has the final say on the completion status
- // of the request.
- finish(lock, dataReady(lock, _info));
- }
- } catch (exception const& ex) {
- string const msg = "failed to parse/process worker response, ex: " + string(ex.what());
- finish(lock, ExtendedState::SERVER_BAD_RESPONSE, msg);
- }
- break;
- case http::AsyncReq::State::FAILED:
- finish(lock, ExtendedState::SERVER_ERROR,
- _httpRequest->errorMessage() + ", code: " + to_string(_httpRequest->responseCode()));
- break;
- case http::AsyncReq::State::BODY_LIMIT_ERROR:
- finish(lock, ExtendedState::BODY_LIMIT_ERROR,
- _httpRequest->errorMessage() + ", code: " + to_string(_httpRequest->responseCode()));
- break;
- case http::AsyncReq::State::CANCELLED:
- finish(lock, ExtendedState::CANCELLED);
- break;
- case http::AsyncReq::State::EXPIRED:
- finish(lock, ExtendedState::TIMEOUT_EXPIRED);
- break;
- default:
- throw runtime_error(context_ + "unsupported state of the HTTP _httpRequest: " +
- http::AsyncReq::state2str(_httpRequest->state()));
- }
-}
-
-void QservHttpMgtRequest::_assertStarted(string const& func, bool mustBeStarted) const {
- string const context_ = context() + func;
- LOGS(_log, LOG_LVL_TRACE, context_);
- if (mustBeStarted) {
- if (State::CREATED == _state) {
- throw logic_error(context_ + " the request was not started.");
- }
- } else {
- if (State::CREATED != _state) {
- throw logic_error(context_ + " the request was already started.");
- }
- }
-}
-
-void QservHttpMgtRequest::_setState(replica::Lock const& lock, State newState,
- ExtendedState newExtendedState) {
- LOGS(_log, LOG_LVL_TRACE, context() << __func__ << " " << state2string(newState, newExtendedState));
-
- // IMPORTANT: the top-level state is the last to be set when performing
- // the state transition to insure clients will get a consistent view onto
- // the object state.
- {
- unique_lock onFinishLock(_onFinishMtx);
- _extendedState = newExtendedState;
- _state = newState;
- }
-
- // TODO: temporarily disabled while this class is not supported by
- // the persistent backend.
- //
- // _serviceProvider->databaseServices()->saveState(*this, _performance, _serverError);
-}
-
-} // namespace lsst::qserv::replica
diff --git a/src/replica/QservHttpMgtRequest.h b/src/replica/QservHttpMgtRequest.h
deleted file mode 100644
index 5cc1370e8..000000000
--- a/src/replica/QservHttpMgtRequest.h
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * LSST Data Management System
- *
- * This product includes software developed by the
- * LSST Project (http://www.lsst.org/).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the LSST License Statement and
- * the GNU General Public License along with this program. If not,
- * see .
- */
-#ifndef LSST_QSERV_REPLICA_QSERVHTTPMGTREQUEST_H
-#define LSST_QSERV_REPLICA_QSERVHTTPMGTREQUEST_H
-
-// System headers
-#include
-#include
-#include
-#include