Loading src/common/api/admire_types.hpp +26 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,7 @@ private: struct node { node(); explicit node(std::string hostname); explicit node(const ADM_node_t& srv); node(const node&) noexcept; Loading @@ -154,6 +155,12 @@ struct node { std::string hostname() const; // The implementation for this must be deferred until // after the declaration of the PIMPL class template <class Archive> void serialize(Archive& ar); private: class impl; std::unique_ptr<impl> m_pimpl; Loading Loading @@ -339,18 +346,27 @@ struct adhoc_storage { }; struct resources { resources() = default; explicit resources(std::vector<admire::node> nodes); explicit resources(ADM_adhoc_resources_t res); std::vector<admire::node> nodes() const; template <typename Archive> void serialize(Archive&& ar) { ar& m_nodes; } private: std::vector<admire::node> m_nodes; }; struct ctx { ctx() = default; ctx(execution_mode exec_mode, access_type access_type, adhoc_storage::resources resources, std::uint32_t walltime, bool should_flush); Loading @@ -368,6 +384,16 @@ struct adhoc_storage { bool should_flush() const; template <class Archive> void serialize(Archive&& ar) { ar& m_exec_mode; ar& m_access_type; ar& m_resources; ar& m_walltime; ar& m_should_flush; } private: execution_mode m_exec_mode; enum access_type m_access_type; Loading src/common/api/types.cpp +42 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <logger/logger.hpp> #include <net/proto/rpc_types.h> #include <net/serialization.hpp> #include <utility> #include <utils/ctype_ptr.hpp> #include <cstdarg> Loading Loading @@ -1117,6 +1118,7 @@ server::address() const { class node::impl { public: impl() = default; explicit impl(std::string hostname) : m_hostname(std::move(hostname)) {} std::string Loading @@ -1124,10 +1126,24 @@ public: return m_hostname; } template <class Archive> void load(Archive& ar) { ar(SCORD_SERIALIZATION_NVP(m_hostname)); } template <class Archive> void save(Archive& ar) const { ar(SCORD_SERIALIZATION_NVP(m_hostname)); } private: std::string m_hostname; }; node::node() = default; node::node(std::string hostname) : m_pimpl(std::make_unique<node::impl>(std::move(hostname))) {} Loading @@ -1154,6 +1170,32 @@ node::hostname() const { return m_pimpl->hostname(); } // since the PIMPL class is fully defined at this point, we can now // define the serialization function template <class Archive> inline void node::serialize(Archive& ar) { ar(SCORD_SERIALIZATION_NVP(m_pimpl)); } // we must also explicitly instantiate our template functions for // serialization in the desired archives template void node::impl::save<scord::network::serialization::output_archive>( scord::network::serialization::output_archive&) const; template void node::impl::load<scord::network::serialization::input_archive>( scord::network::serialization::input_archive&); template void node::serialize<scord::network::serialization::output_archive>( scord::network::serialization::output_archive&); template void node::serialize<scord::network::serialization::input_archive>( scord::network::serialization::input_archive&); class job::impl { public: Loading src/common/net/CMakeLists.txt +2 −2 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ add_library(_rpc_client STATIC) target_sources( _rpc_client INTERFACE endpoint.hpp client.hpp request.hpp INTERFACE endpoint.hpp client.hpp request.hpp serialization.hpp PRIVATE endpoint.cpp client.cpp ) Loading @@ -35,7 +35,7 @@ set_property(TARGET _rpc_client PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(_rpc_server STATIC) target_sources( _rpc_server INTERFACE server.hpp request.hpp INTERFACE server.hpp request.hpp serialization.hpp PRIVATE server.cpp ) Loading src/common/net/request.hpp +31 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,37 @@ private: admire::error_code m_error_code; }; template <typename Value> class response_with_value : public generic_response { public: constexpr response_with_value() noexcept = default; constexpr response_with_value(std::uint64_t op_id, admire::error_code ec, std::optional<Value> value) noexcept : generic_response(op_id, ec), m_value(std::move(value)) {} constexpr auto value() const noexcept { return m_value.value(); } constexpr auto has_value() const noexcept { return m_value.has_value(); } template <typename Archive> constexpr void serialize(Archive&& ar) { ar(cereal::base_class<generic_response>(this), m_value); } private: std::optional<Value> m_value; }; using response_with_id = response_with_value<std::uint64_t>; } // namespace scord::network Loading src/common/net/serialization.hpp 0 → 100644 +45 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2021-2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of scord. * * scord 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. * * scord 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 GNU General Public License * along with scord. If not, see <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #ifndef SCORD_SERIALIZATION_HPP #define SCORD_SERIALIZATION_HPP #include <cereal/cereal.hpp> #include <cereal/types/optional.hpp> #include <cereal/types/memory.hpp> #include <thallium/serialization/proc_input_archive.hpp> #include <thallium/serialization/proc_output_archive.hpp> #include <thallium/serialization/stl/string.hpp> #include <thallium/serialization/stl/vector.hpp> namespace scord::network::serialization { #define SCORD_SERIALIZATION_NVP CEREAL_NVP using input_archive = thallium::proc_input_archive<>; using output_archive = thallium::proc_output_archive<>; } // namespace scord::network::serialization #endif // SCORD_SERIALIZATION_HPP Loading
src/common/api/admire_types.hpp +26 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,7 @@ private: struct node { node(); explicit node(std::string hostname); explicit node(const ADM_node_t& srv); node(const node&) noexcept; Loading @@ -154,6 +155,12 @@ struct node { std::string hostname() const; // The implementation for this must be deferred until // after the declaration of the PIMPL class template <class Archive> void serialize(Archive& ar); private: class impl; std::unique_ptr<impl> m_pimpl; Loading Loading @@ -339,18 +346,27 @@ struct adhoc_storage { }; struct resources { resources() = default; explicit resources(std::vector<admire::node> nodes); explicit resources(ADM_adhoc_resources_t res); std::vector<admire::node> nodes() const; template <typename Archive> void serialize(Archive&& ar) { ar& m_nodes; } private: std::vector<admire::node> m_nodes; }; struct ctx { ctx() = default; ctx(execution_mode exec_mode, access_type access_type, adhoc_storage::resources resources, std::uint32_t walltime, bool should_flush); Loading @@ -368,6 +384,16 @@ struct adhoc_storage { bool should_flush() const; template <class Archive> void serialize(Archive&& ar) { ar& m_exec_mode; ar& m_access_type; ar& m_resources; ar& m_walltime; ar& m_should_flush; } private: execution_mode m_exec_mode; enum access_type m_access_type; Loading
src/common/api/types.cpp +42 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include <logger/logger.hpp> #include <net/proto/rpc_types.h> #include <net/serialization.hpp> #include <utility> #include <utils/ctype_ptr.hpp> #include <cstdarg> Loading Loading @@ -1117,6 +1118,7 @@ server::address() const { class node::impl { public: impl() = default; explicit impl(std::string hostname) : m_hostname(std::move(hostname)) {} std::string Loading @@ -1124,10 +1126,24 @@ public: return m_hostname; } template <class Archive> void load(Archive& ar) { ar(SCORD_SERIALIZATION_NVP(m_hostname)); } template <class Archive> void save(Archive& ar) const { ar(SCORD_SERIALIZATION_NVP(m_hostname)); } private: std::string m_hostname; }; node::node() = default; node::node(std::string hostname) : m_pimpl(std::make_unique<node::impl>(std::move(hostname))) {} Loading @@ -1154,6 +1170,32 @@ node::hostname() const { return m_pimpl->hostname(); } // since the PIMPL class is fully defined at this point, we can now // define the serialization function template <class Archive> inline void node::serialize(Archive& ar) { ar(SCORD_SERIALIZATION_NVP(m_pimpl)); } // we must also explicitly instantiate our template functions for // serialization in the desired archives template void node::impl::save<scord::network::serialization::output_archive>( scord::network::serialization::output_archive&) const; template void node::impl::load<scord::network::serialization::input_archive>( scord::network::serialization::input_archive&); template void node::serialize<scord::network::serialization::output_archive>( scord::network::serialization::output_archive&); template void node::serialize<scord::network::serialization::input_archive>( scord::network::serialization::input_archive&); class job::impl { public: Loading
src/common/net/CMakeLists.txt +2 −2 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ add_library(_rpc_client STATIC) target_sources( _rpc_client INTERFACE endpoint.hpp client.hpp request.hpp INTERFACE endpoint.hpp client.hpp request.hpp serialization.hpp PRIVATE endpoint.cpp client.cpp ) Loading @@ -35,7 +35,7 @@ set_property(TARGET _rpc_client PROPERTY POSITION_INDEPENDENT_CODE ON) add_library(_rpc_server STATIC) target_sources( _rpc_server INTERFACE server.hpp request.hpp INTERFACE server.hpp request.hpp serialization.hpp PRIVATE server.cpp ) Loading
src/common/net/request.hpp +31 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,37 @@ private: admire::error_code m_error_code; }; template <typename Value> class response_with_value : public generic_response { public: constexpr response_with_value() noexcept = default; constexpr response_with_value(std::uint64_t op_id, admire::error_code ec, std::optional<Value> value) noexcept : generic_response(op_id, ec), m_value(std::move(value)) {} constexpr auto value() const noexcept { return m_value.value(); } constexpr auto has_value() const noexcept { return m_value.has_value(); } template <typename Archive> constexpr void serialize(Archive&& ar) { ar(cereal::base_class<generic_response>(this), m_value); } private: std::optional<Value> m_value; }; using response_with_id = response_with_value<std::uint64_t>; } // namespace scord::network Loading
src/common/net/serialization.hpp 0 → 100644 +45 −0 Original line number Diff line number Diff line /****************************************************************************** * Copyright 2021-2023, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). * * This file is part of scord. * * scord 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. * * scord 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 GNU General Public License * along with scord. If not, see <https://www.gnu.org/licenses/>. * * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ #ifndef SCORD_SERIALIZATION_HPP #define SCORD_SERIALIZATION_HPP #include <cereal/cereal.hpp> #include <cereal/types/optional.hpp> #include <cereal/types/memory.hpp> #include <thallium/serialization/proc_input_archive.hpp> #include <thallium/serialization/proc_output_archive.hpp> #include <thallium/serialization/stl/string.hpp> #include <thallium/serialization/stl/vector.hpp> namespace scord::network::serialization { #define SCORD_SERIALIZATION_NVP CEREAL_NVP using input_archive = thallium::proc_input_archive<>; using output_archive = thallium::proc_output_archive<>; } // namespace scord::network::serialization #endif // SCORD_SERIALIZATION_HPP