|
| 1 | +/* |
| 2 | + * LSST Data Management System |
| 3 | + * |
| 4 | + * This product includes software developed by the |
| 5 | + * LSST Project (http://www.lsst.org/). |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the LSST License Statement and |
| 18 | + * the GNU General Public License along with this program. If not, |
| 19 | + * see <http://www.lsstcorp.org/LegalNotices/>. |
| 20 | + */ |
| 21 | +#ifndef LSST_QSERV_REPLICA_POSTEVENTQSERVCZARMGTREQUEST_H |
| 22 | +#define LSST_QSERV_REPLICA_POSTEVENTQSERVCZARMGTREQUEST_H |
| 23 | + |
| 24 | +// System headers |
| 25 | +#include <list> |
| 26 | +#include <memory> |
| 27 | +#include <string> |
| 28 | +#include <utility> |
| 29 | + |
| 30 | +// Third party headers |
| 31 | +#include "nlohmann/json.hpp" |
| 32 | + |
| 33 | +// Qserv headers |
| 34 | +#include "cconfig/DataManagementEvent.h" |
| 35 | +#include "replica/qserv/QservCzarMgtRequest.h" |
| 36 | + |
| 37 | +namespace lsst::qserv::replica { |
| 38 | +class ServiceProvider; |
| 39 | +} // namespace lsst::qserv::replica |
| 40 | + |
| 41 | +// This header declarations |
| 42 | +namespace lsst::qserv::replica { |
| 43 | + |
| 44 | +/** |
| 45 | + * Class PostEventQservCzarMgtRequest implements a request for posting the data |
| 46 | + * management events to the Qserv Czar. |
| 47 | + */ |
| 48 | +class PostEventQservCzarMgtRequest : public QservCzarMgtRequest { |
| 49 | +public: |
| 50 | + typedef std::shared_ptr<PostEventQservCzarMgtRequest> Ptr; |
| 51 | + |
| 52 | + /// The function type for notifications on the completion of the request |
| 53 | + typedef std::function<void(Ptr)> CallbackType; |
| 54 | + |
| 55 | + PostEventQservCzarMgtRequest() = delete; |
| 56 | + PostEventQservCzarMgtRequest(PostEventQservCzarMgtRequest const&) = delete; |
| 57 | + PostEventQservCzarMgtRequest& operator=(PostEventQservCzarMgtRequest const&) = delete; |
| 58 | + |
| 59 | + virtual ~PostEventQservCzarMgtRequest() override = default; |
| 60 | + |
| 61 | + /** |
| 62 | + * Static factory method is needed to prevent issues with the lifespan |
| 63 | + * and memory management of instances created otherwise (as values or via |
| 64 | + * low-level pointers). |
| 65 | + * |
| 66 | + * @param serviceProvider A reference to a provider of services for accessing |
| 67 | + * Configuration, saving the request's persistent state to the database. |
| 68 | + * @param czarName The name of a Czar to send the request to. |
| 69 | + * @param event The management event to be posted to the Czar. |
| 70 | + * @param onFinish (optional) callback function to be called upon request completion. |
| 71 | + * @return A pointer to the created object. |
| 72 | + */ |
| 73 | + static Ptr create(ServiceProvider::Ptr const& serviceProvider, std::string const& czarName, |
| 74 | + cconfig::DataManagementEvent const& event, CallbackType const& onFinish = nullptr); |
| 75 | + |
| 76 | + /// @see QservMgtRequest::extendedPersistentState() |
| 77 | + std::list<std::pair<std::string, std::string>> extendedPersistentState() const override; |
| 78 | + |
| 79 | +protected: |
| 80 | + /// @see QservMgtRequest::createHttpReqImpl() |
| 81 | + virtual void createHttpReqImpl(replica::Lock const& lock) override; |
| 82 | + |
| 83 | + /// @see QservMgtRequest::notify |
| 84 | + virtual void notify(replica::Lock const& lock) override; |
| 85 | + |
| 86 | +private: |
| 87 | + /// @see PostEventQservCzarMgtRequest::create() |
| 88 | + PostEventQservCzarMgtRequest(ServiceProvider::Ptr const& serviceProvider, std::string const& czarName, |
| 89 | + cconfig::DataManagementEvent const& event, CallbackType const& onFinish); |
| 90 | + |
| 91 | + // Input parameters |
| 92 | + |
| 93 | + cconfig::DataManagementEvent const _event; ///< The management event to be posted to the Czar. |
| 94 | + CallbackType _onFinish; ///< The callback function is reset when the request finishes. |
| 95 | +}; |
| 96 | + |
| 97 | +} // namespace lsst::qserv::replica |
| 98 | + |
| 99 | +#endif // LSST_QSERV_REPLICA_POSTEVENTQSERVCZARMGTREQUEST_H |
0 commit comments