From 70df104b3f8dbbbad8a3f956a71b8c37e6ca0953 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Thu, 30 Jun 2022 17:27:40 +0200 Subject: [PATCH] Rename ping RPC to ADM_ping --- .gitlab-ci.yml | 2 +- README.md | 2 +- examples/cxx/{ping.cpp => ADM_ping.cpp} | 20 +++++------ examples/cxx/CMakeLists.txt | 2 +- src/api/admire.cpp | 10 ++++++ src/api/admire.h | 10 ++++++ src/api/admire.hpp | 20 +++++------ src/api/c_wrapper.cpp | 6 ++++ src/api/detail/impl.cpp | 15 ++++++++ src/api/detail/impl.hpp | 3 ++ src/network/engine.hpp | 27 +++++++-------- src/network/rpcs.cpp | 4 +-- src/network/rpcs.hpp | 46 +++++++++---------------- 13 files changed, 96 insertions(+), 71 deletions(-) rename examples/cxx/{ping.cpp => ADM_ping.cpp} (76%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 329a0f0a..87629b4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -46,7 +46,7 @@ rpc: script: - export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:${CI_PROJECT_DIR}/compiled/lib - compiled/bin/scord -f --force-console & - - build/examples/cxx/ping ofi+tcp://127.0.0.1:52000 + - build/examples/cxx/ADM_ping ofi+tcp://127.0.0.1:52000 - pkill -TERM scord cache: key: $CI_COMMIT_REF_SLUG diff --git a/README.md b/README.md index 34351904..ab7dd106 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ Now we can use one of the example programs to send a `ping` RPC to `scord`: ```bash cd $HOME/scord/build/examples -./ping ofi+tcp://192.168.0.111:52000 +./ADM_ping ofi+tcp://192.168.0.111:52000 ``` And the server logs should update with an entry similar the following one: diff --git a/examples/cxx/ping.cpp b/examples/cxx/ADM_ping.cpp similarity index 76% rename from examples/cxx/ping.cpp rename to examples/cxx/ADM_ping.cpp index 32b65480..d687e60f 100644 --- a/examples/cxx/ping.cpp +++ b/examples/cxx/ADM_ping.cpp @@ -23,25 +23,25 @@ *****************************************************************************/ #include -#include +#include int main(int argc, char* argv[]) { if(argc != 2) { fmt::print(stderr, "ERROR: no server address provided\n"); - fmt::print(stderr, "Usage: ping \n"); + fmt::print(stderr, "Usage: ADM_ping \n"); exit(EXIT_FAILURE); } - scord::network::rpc_client rpc_client{"tcp"}; - rpc_client.register_rpcs(); + admire::server server{"tcp", argv[1]}; - auto endp = rpc_client.lookup(argv[1]); - - fmt::print(stdout, "Calling PING remote procedure on {}...\n", argv[1]); - - endp.call("ping"); + try { + admire::ping(server); + } catch(const std::exception& e) { + fmt::print(stderr, "FATAL: ADM_ping() failed: {}\n", e.what()); + exit(EXIT_FAILURE); + } - fmt::print(stdout, "PING remote procedure completed successfully\n"); + fmt::print(stdout, "ADM_ping() remote procedure completed successfully\n"); } diff --git a/examples/cxx/CMakeLists.txt b/examples/cxx/CMakeLists.txt index a884f425..c1e49ffb 100644 --- a/examples/cxx/CMakeLists.txt +++ b/examples/cxx/CMakeLists.txt @@ -23,7 +23,7 @@ ################################################################################ list(APPEND examples_cxx - ping + ADM_ping ADM_register_job ADM_update_job ADM_remove_job ADM_register_adhoc_storage ADM_update_adhoc_storage ADM_remove_adhoc_storage ADM_deploy_adhoc_storage diff --git a/src/api/admire.cpp b/src/api/admire.cpp index 79a83e10..39113f40 100644 --- a/src/api/admire.cpp +++ b/src/api/admire.cpp @@ -54,6 +54,16 @@ init_logger() { namespace admire { +void +ping(const server& srv) { + + if(const auto ec = detail::ping(srv)) { + throw std::runtime_error( + fmt::format("ADM_register_job() error: {}", ADM_strerror(ec))); + } +} + + admire::job register_job(const server& srv, ADM_job_requirements_t reqs) { diff --git a/src/api/admire.h b/src/api/admire.h index a103d4a0..ea992ed9 100644 --- a/src/api/admire.h +++ b/src/api/admire.h @@ -243,6 +243,16 @@ ADM_job_requirements_destroy(ADM_job_requirements_t reqs); /* Public prototypes */ /******************************************************************************/ +/** + * Send an RPC to a server to check if it's online. + * + * @param[in] server The server to which the request is directed + * @return Returns ADM_SUCCESS if the remote procedure has completed + * successfully. + */ +ADM_return_t +ADM_ping(ADM_server_t server); + /** * Register a job and its requirements. * diff --git a/src/api/admire.hpp b/src/api/admire.hpp index 5ab69028..1ab5f55e 100644 --- a/src/api/admire.hpp +++ b/src/api/admire.hpp @@ -43,13 +43,14 @@ struct job { job_id m_id; }; +void +ping(const server& srv); admire::job register_job(const server& srv, ADM_job_requirements_t reqs); ADM_return_t -update_job(const server& srv, ADM_job_t job, - ADM_job_requirements_t reqs); +update_job(const server& srv, ADM_job_t job, ADM_job_requirements_t reqs); ADM_return_t remove_job(const server& srv, ADM_job_t job); @@ -60,8 +61,7 @@ register_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_storage_handle_t* adhoc_handle); ADM_return_t -update_adhoc_storage(const server& srv, ADM_job_t job, - ADM_adhoc_context_t ctx, +update_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t adhoc_handle); ADM_return_t @@ -83,8 +83,8 @@ set_dataset_information(const server& srv, ADM_job_t job, ADM_dataset_handle_t target, ADM_dataset_info_t info); ADM_return_t -set_io_resources(const server& srv, ADM_job_t job, - ADM_storage_handle_t tier, ADM_storage_resources_t resources); +set_io_resources(const server& srv, ADM_job_t job, ADM_storage_handle_t tier, + ADM_storage_resources_t resources); ADM_return_t get_transfer_priority(const server& srv, ADM_job_t job, @@ -107,9 +107,8 @@ ADM_return_t set_qos_constraints(const server& srv, ADM_job_t job, ADM_limit_t limit); ADM_return_t -get_qos_constraints(const server& srv, ADM_job_t job, - ADM_qos_scope_t scope, ADM_qos_entity_t entity, - ADM_limit_t** limits); +get_qos_constraints(const server& srv, ADM_job_t job, ADM_qos_scope_t scope, + ADM_qos_entity_t entity, ADM_limit_t** limits); ADM_return_t define_data_operation(const server& srv, ADM_job_t job, const char* path, @@ -131,8 +130,7 @@ link_transfer_to_data_operation(const server& srv, ADM_job_t job, bool should_stream, va_list args); ADM_return_t -get_statistics(const server& srv, ADM_job_t job, - ADM_job_stats_t** stats); +get_statistics(const server& srv, ADM_job_t job, ADM_job_stats_t** stats); } // namespace admire diff --git a/src/api/c_wrapper.cpp b/src/api/c_wrapper.cpp index a8816f58..1a4e03c2 100644 --- a/src/api/c_wrapper.cpp +++ b/src/api/c_wrapper.cpp @@ -173,6 +173,12 @@ ADM_job_create(uint64_t id) { return adm_job; } +ADM_return_t +ADM_ping(ADM_server_t server) { + const admire::server srv{server->s_protocol, server->s_address}; + return admire::detail::ping(srv); +} + ADM_return_t ADM_register_job(ADM_server_t server, ADM_job_requirements_t reqs, ADM_job_t* job) { diff --git a/src/api/detail/impl.cpp b/src/api/detail/impl.cpp index b14f1fe0..ba09387a 100644 --- a/src/api/detail/impl.cpp +++ b/src/api/detail/impl.cpp @@ -28,6 +28,21 @@ namespace admire::detail { +admire::error_code +ping(const server& srv) { + + scord::network::rpc_client rpc_client{srv.m_protocol}; + rpc_client.register_rpcs(); + + auto endp = rpc_client.lookup(srv.m_address); + + LOGGER_INFO("ADM_ping()"); + endp.call("ADM_ping"); + + LOGGER_INFO("ADM_register_job() = {}", ADM_SUCCESS); + return ADM_SUCCESS; +} + tl::expected register_job(const admire::server& srv, ADM_job_requirements_t reqs) { (void) srv; diff --git a/src/api/detail/impl.hpp b/src/api/detail/impl.hpp index 501489c3..cacc056f 100644 --- a/src/api/detail/impl.hpp +++ b/src/api/detail/impl.hpp @@ -34,6 +34,9 @@ using error_code = ADM_return_t; namespace admire::detail { +admire::error_code +ping(const server& srv); + tl::expected register_job(const server& srv, ADM_job_requirements_t reqs); diff --git a/src/network/engine.hpp b/src/network/engine.hpp index c38a60f4..3ecd5963 100644 --- a/src/network/engine.hpp +++ b/src/network/engine.hpp @@ -58,7 +58,7 @@ struct margo_context { void register_rpc(const std::string& name, bool requires_response) { - auto id = MARGO_REGISTER(m_mid, name.c_str(), void, void, ping); + auto id = MARGO_REGISTER(m_mid, name.c_str(), void, void, ADM_ping); m_rpc_names.emplace(name, id); if(!requires_response) { @@ -104,8 +104,8 @@ struct engine { register_rpcs() { // register RPCs manually for now - REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, "ping", void, - void, ping, false); + REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, "ADM_ping", void, + void, ADM_ping, false); REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, "ADM_register_job", ADM_register_job_in_t, @@ -126,22 +126,19 @@ struct engine { ADM_register_adhoc_storage, true); REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, - "ADM_update_adhoc_storage", - ADM_update_adhoc_storage_in_t, - ADM_update_adhoc_storage_out_t, - ADM_update_adhoc_storage, true); + "ADM_update_adhoc_storage", ADM_update_adhoc_storage_in_t, + ADM_update_adhoc_storage_out_t, ADM_update_adhoc_storage, + true); REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, - "ADM_remove_adhoc_storage", - ADM_remove_adhoc_storage_in_t, - ADM_remove_adhoc_storage_out_t, - ADM_remove_adhoc_storage, true); + "ADM_remove_adhoc_storage", ADM_remove_adhoc_storage_in_t, + ADM_remove_adhoc_storage_out_t, ADM_remove_adhoc_storage, + true); REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, - "ADM_deploy_adhoc_storage", - ADM_deploy_adhoc_storage_in_t, - ADM_deploy_adhoc_storage_out_t, - ADM_deploy_adhoc_storage, true); + "ADM_deploy_adhoc_storage", ADM_deploy_adhoc_storage_in_t, + ADM_deploy_adhoc_storage_out_t, ADM_deploy_adhoc_storage, + true); REGISTER_RPC(m_context->m_mid, m_context->m_rpc_names, "ADM_input", ADM_input_in_t, ADM_input_out_t, ADM_input, true); diff --git a/src/network/rpcs.cpp b/src/network/rpcs.cpp index c154f3eb..3f6dd766 100644 --- a/src/network/rpcs.cpp +++ b/src/network/rpcs.cpp @@ -25,7 +25,7 @@ #include "rpcs.hpp" static void -ping(hg_handle_t h) { +ADM_ping(hg_handle_t h) { hg_return_t ret; @@ -37,7 +37,7 @@ ping(hg_handle_t h) { assert(ret == HG_SUCCESS); } -DEFINE_MARGO_RPC_HANDLER(ping); +DEFINE_MARGO_RPC_HANDLER(ADM_ping); static void ADM_register_job(hg_handle_t h) { diff --git a/src/network/rpcs.hpp b/src/network/rpcs.hpp index 0579aae4..23931fb0 100644 --- a/src/network/rpcs.hpp +++ b/src/network/rpcs.hpp @@ -35,69 +35,55 @@ // FIXME: cannot be in a namespace due to Margo limitations // namespace scord::network::rpc { -/// ping -DECLARE_MARGO_RPC_HANDLER(ping); +/// ADM_ping +DECLARE_MARGO_RPC_HANDLER(ADM_ping); /// ADM_register_job -MERCURY_GEN_PROC(ADM_register_job_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_register_job_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_register_job_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_register_job_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_register_job); /// ADM_update_job -MERCURY_GEN_PROC(ADM_update_job_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_update_job_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_update_job_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_update_job_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_update_job); /// ADM_remove_job -MERCURY_GEN_PROC(ADM_remove_job_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_remove_job_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_remove_job_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_remove_job_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_remove_job); /// ADM_register_adhoc_storage -MERCURY_GEN_PROC(ADM_register_adhoc_storage_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_register_adhoc_storage_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_register_adhoc_storage_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_register_adhoc_storage_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_register_adhoc_storage); /// ADM_update_adhoc_storage -MERCURY_GEN_PROC(ADM_update_adhoc_storage_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_update_adhoc_storage_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_update_adhoc_storage_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_update_adhoc_storage_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_update_adhoc_storage); /// ADM_remove_adhoc_storage -MERCURY_GEN_PROC(ADM_remove_adhoc_storage_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_remove_adhoc_storage_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_remove_adhoc_storage_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_remove_adhoc_storage_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_remove_adhoc_storage); /// ADM_deploy_adhoc_storage -MERCURY_GEN_PROC(ADM_deploy_adhoc_storage_in_t, - ((int32_t) (reqs))) +MERCURY_GEN_PROC(ADM_deploy_adhoc_storage_in_t, ((int32_t) (reqs))) -MERCURY_GEN_PROC(ADM_deploy_adhoc_storage_out_t, - ((int32_t) (ret))) +MERCURY_GEN_PROC(ADM_deploy_adhoc_storage_out_t, ((int32_t) (ret))) DECLARE_MARGO_RPC_HANDLER(ADM_deploy_adhoc_storage); -- GitLab