diff --git a/CMakeLists.txt b/CMakeLists.txt index 3199c66c0cdd600eda898ab76fa9f0e28a2716cf..21909d93a59684b212d42e058826c16cfb7e527e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ cmake_minimum_required(VERSION 3.14) project( scord VERSION 0.1.0 - LANGUAGES CXX + LANGUAGES C CXX ) # Set default build type and also populate a list of available options @@ -209,6 +209,21 @@ FetchContent_Declare( FetchContent_MakeAvailable(genopts) +### expected: required for using tl::expected in the C++ library implementation +### until std::expected makes it to C++ + +message(STATUS "[${PROJECT_NAME}] Downloading and building tl::expected") +set(EXPECTED_BUILD_PACKAGE OFF) +set(EXPECTED_BUILD_TESTS OFF) +FetchContent_Declare( + expected + GIT_REPOSITORY https://github.com/TartanLlama/expected + GIT_TAG 96d547c03d2feab8db64c53c3744a9b4a7c8f2c5 # latest + GIT_SHALLOW ON + GIT_PROGRESS ON +) + +FetchContent_MakeAvailable(expected) ### Mark any CMake variables imported from {fmt} and spdlog as advanced, so ### that they don't appear in cmake-gui or ccmake. Similarly for FETCHCONTENT diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e7620f25ebad4ee8ab2f37b42c77aeeffe391745..91d8ee9b4507035e0d417f5242731886b1de7a48 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2021, Barcelona Supercomputing Center (BSC), Spain # +# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain # # # # This software was partially supported by the EuroHPC-funded project ADMIRE # # (Project ID: 956748, https://www.admire-eurohpc.eu). # @@ -22,20 +22,5 @@ # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ -list(APPEND examples - 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 - ADM_in_situ_ops ADM_in_transit_ops ADM_transfer_dataset - ADM_set_dataset_information ADM_set_io_resources ADM_get_transfer_priority - ADM_set_transfer_priority ADM_cancel_transfer ADM_get_pending_transfers - ADM_set_qos_constraints ADM_get_qos_constraints ADM_define_data_operation ADM_connect_data_operation - ADM_finalize_data_operation ADM_link_transfer_to_data_operation ADM_get_statistics) - -foreach (example IN LISTS examples) - add_executable(${example}) - target_sources(${example} PRIVATE ${example}.cpp) - target_link_libraries(${example} - PUBLIC network_engine fmt::fmt adm_iosched) -endforeach() +add_subdirectory(c) +add_subdirectory(cxx) diff --git a/examples/c/ADM_register_job.c b/examples/c/ADM_register_job.c new file mode 100644 index 0000000000000000000000000000000000000000..d9df64f32e3f4d9a6cf7a38262c097f14964857f --- /dev/null +++ b/examples/c/ADM_register_job.c @@ -0,0 +1,68 @@ +#include +#include +#include + +#define NINPUTS 10 +#define NOUTPUTS 5 + +int +main(int argc, char* argv[]) { + + if(argc != 3) { + fprintf(stderr, "ERROR: no location provided\n"); + fprintf(stderr, "Usage: ADM_register_job \n"); + exit(EXIT_FAILURE); + } + + int exit_status = EXIT_SUCCESS; + ADM_server_t server = ADM_server_create("tcp", argv[1]); + + + ADM_job_t job; + ADM_dataset_handle_t inputs[NINPUTS]; + + for(int i = 0; i < NINPUTS; ++i) { + const char* pattern = "input-dataset-%d"; + size_t n = snprintf(NULL, 0, pattern, i); + char* id = (char*) malloc(n + 1); + snprintf(id, n, pattern, i); + inputs[i] = ADM_dataset_create(id); + } + + ADM_dataset_handle_t outputs[NOUTPUTS]; + + for(int i = 0; i < NOUTPUTS; ++i) { + const char* pattern = "output-dataset-%d"; + size_t n = snprintf(NULL, 0, pattern, i); + char* id = (char*) malloc(n + 1); + snprintf(id, n, pattern, i); + outputs[i] = ADM_dataset_create(id); + } + + ADM_job_requirements_t reqs = ADM_job_requirements_create( + inputs, NINPUTS, outputs, NOUTPUTS, NULL); + ADM_return_t ret = ADM_register_job(server, reqs, &job); + + if(ret != ADM_SUCCESS) { + fprintf(stdout, "ADM_register_job() remote procedure not completed " + "successfully\n"); + exit_status = EXIT_FAILURE; + goto cleanup; + } + + fprintf(stdout, "ADM_register_job() remote procedure completed " + "successfully\n"); + +cleanup: + + for(int i = 0; i < NINPUTS; ++i) { + ADM_dataset_destroy(inputs[i]); + } + + for(int i = 0; i < NOUTPUTS; ++i) { + ADM_dataset_destroy(outputs[i]); + } + + ADM_server_destroy(server); + exit(exit_status); +} diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ff36f94ac65f6402b2f6ffec6b5d6cedc23c889d --- /dev/null +++ b/examples/c/CMakeLists.txt @@ -0,0 +1,32 @@ +################################################################################ +# Copyright 2021-2022, 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 . # +# # +# SPDX-License-Identifier: GPL-3.0-or-later # +################################################################################ + +list(APPEND examples_c ADM_register_job) + +foreach(example IN LISTS examples_c) + add_executable(${example}_c) + target_sources(${example}_c PRIVATE ${example}.c) + target_link_libraries(${example}_c PUBLIC adm_iosched) + set_target_properties(${example}_c PROPERTIES OUTPUT_NAME ${example}) +endforeach() diff --git a/examples/ADM_cancel_transfer.cpp b/examples/cxx/ADM_cancel_transfer.cpp similarity index 97% rename from examples/ADM_cancel_transfer.cpp rename to examples/cxx/ADM_cancel_transfer.cpp index 3a0137fd2d5025758e1cbf9aa620a378c43acfc4..04c9eacb040ae93c5ca4a7f280c435f45d74497e 100644 --- a/examples/ADM_cancel_transfer.cpp +++ b/examples/cxx/ADM_cancel_transfer.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_transfer_handle_t tx_handle{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_connect_data_operation.cpp b/examples/cxx/ADM_connect_data_operation.cpp similarity index 98% rename from examples/ADM_connect_data_operation.cpp rename to examples/cxx/ADM_connect_data_operation.cpp index a8cf7b12f33da835be34df1b4590622e48c0c69e..98e046f00d43c5d77dedba1026c48f1a47110fe5 100644 --- a/examples/ADM_connect_data_operation.cpp +++ b/examples/cxx/ADM_connect_data_operation.cpp @@ -26,7 +26,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_dataset_handle_t input{}; ADM_dataset_handle_t output{}; bool should_stream = false; diff --git a/examples/ADM_define_data_operation.cpp b/examples/cxx/ADM_define_data_operation.cpp similarity index 97% rename from examples/ADM_define_data_operation.cpp rename to examples/cxx/ADM_define_data_operation.cpp index 571a19f763ed6bf06e22fc458ad6668b6fd17196..36c90205cd1c80ebb168d4fa82f549d39eab639e 100644 --- a/examples/ADM_define_data_operation.cpp +++ b/examples/cxx/ADM_define_data_operation.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; const char* path = ""; ADM_data_operation_handle_t op_handle; va_list args; // FIXME: placeholder diff --git a/examples/ADM_deploy_adhoc_storage.cpp b/examples/cxx/ADM_deploy_adhoc_storage.cpp similarity index 97% rename from examples/ADM_deploy_adhoc_storage.cpp rename to examples/cxx/ADM_deploy_adhoc_storage.cpp index 0bf4fd9c2c738a0652780d10aecbf0c73a590c7f..207ebaa20bc441ea2217802b130d91f1b07bd816 100644 --- a/examples/ADM_deploy_adhoc_storage.cpp +++ b/examples/cxx/ADM_deploy_adhoc_storage.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_adhoc_storage_handle_t adhoc_handle{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_finalize_data_operation.cpp b/examples/cxx/ADM_finalize_data_operation.cpp similarity index 97% rename from examples/ADM_finalize_data_operation.cpp rename to examples/cxx/ADM_finalize_data_operation.cpp index 8227ac342d55b4731e0539a467d0db8859ec3a25..e396577b49a500a8ab07f6e968aa3c85abf6ea22 100644 --- a/examples/ADM_finalize_data_operation.cpp +++ b/examples/cxx/ADM_finalize_data_operation.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_data_operation_handle_t op_handle{}; ADM_data_operation_status_t status; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_get_pending_transfers.cpp b/examples/cxx/ADM_get_pending_transfers.cpp similarity index 97% rename from examples/ADM_get_pending_transfers.cpp rename to examples/cxx/ADM_get_pending_transfers.cpp index 1729e7b41fe8c87959821bfc88c663e4e8686028..75e64d7dfb90549ca6d581ae70dbdf22add92c5c 100644 --- a/examples/ADM_get_pending_transfers.cpp +++ b/examples/cxx/ADM_get_pending_transfers.cpp @@ -13,7 +13,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_transfer_handle_t** tx_handles = nullptr; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_get_qos_constraints.cpp b/examples/cxx/ADM_get_qos_constraints.cpp similarity index 97% rename from examples/ADM_get_qos_constraints.cpp rename to examples/cxx/ADM_get_qos_constraints.cpp index 3b52fd69c161424dd12420a772a2ccb401386603..b0bf615665d9f5fd4df4b3fdde44404dec3261c9 100644 --- a/examples/ADM_get_qos_constraints.cpp +++ b/examples/cxx/ADM_get_qos_constraints.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_qos_scope_t scope{}; ADM_qos_entity_t entity{}; ADM_limit_t* limits; diff --git a/examples/ADM_get_statistics.cpp b/examples/cxx/ADM_get_statistics.cpp similarity index 97% rename from examples/ADM_get_statistics.cpp rename to examples/cxx/ADM_get_statistics.cpp index c9e03dc3a00bb07384a5c3dc5dd351a56d6a74c6..eccb9f8963806c7bfa0f0d92419e32c044fd0175 100644 --- a/examples/ADM_get_statistics.cpp +++ b/examples/cxx/ADM_get_statistics.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_job_stats_t* stats = nullptr; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_get_transfer_priority.cpp b/examples/cxx/ADM_get_transfer_priority.cpp similarity index 97% rename from examples/ADM_get_transfer_priority.cpp rename to examples/cxx/ADM_get_transfer_priority.cpp index a8ef68a2052d339fd52951d4397617a516906062..3637e65811570e4d24ae225412a23fef97a56a6b 100644 --- a/examples/ADM_get_transfer_priority.cpp +++ b/examples/cxx/ADM_get_transfer_priority.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_transfer_handle_t tx_handle{}; ADM_transfer_priority_t priority; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_in_situ_ops.cpp b/examples/cxx/ADM_in_situ_ops.cpp similarity index 100% rename from examples/ADM_in_situ_ops.cpp rename to examples/cxx/ADM_in_situ_ops.cpp diff --git a/examples/ADM_in_transit_ops.cpp b/examples/cxx/ADM_in_transit_ops.cpp similarity index 100% rename from examples/ADM_in_transit_ops.cpp rename to examples/cxx/ADM_in_transit_ops.cpp diff --git a/examples/ADM_link_transfer_to_data_operation.cpp b/examples/cxx/ADM_link_transfer_to_data_operation.cpp similarity index 97% rename from examples/ADM_link_transfer_to_data_operation.cpp rename to examples/cxx/ADM_link_transfer_to_data_operation.cpp index db1a4f0935b4e98af1284c6a5a5f75873c908440..df0e726877bb7b89f10aae40dcc9995f43af532d 100644 --- a/examples/ADM_link_transfer_to_data_operation.cpp +++ b/examples/cxx/ADM_link_transfer_to_data_operation.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_data_operation_handle_t op_handle; bool should_stream = false; va_list args; diff --git a/examples/ADM_register_adhoc_storage.cpp b/examples/cxx/ADM_register_adhoc_storage.cpp similarity index 97% rename from examples/ADM_register_adhoc_storage.cpp rename to examples/cxx/ADM_register_adhoc_storage.cpp index 60dd044ac10d1d9eb2433b0e4b340a9ed27d3905..e7971aa119f1b214ddc9f0031a1254d5e27dfaa3 100644 --- a/examples/ADM_register_adhoc_storage.cpp +++ b/examples/cxx/ADM_register_adhoc_storage.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_adhoc_context_t ctx{}; ADM_adhoc_storage_handle_t adhoc_handle{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_register_job.cpp b/examples/cxx/ADM_register_job.cpp similarity index 64% rename from examples/ADM_register_job.cpp rename to examples/cxx/ADM_register_job.cpp index 56672509a2947b8279efa97a1e6e2dc85b694a88..5001058b58cbb77d501d289af7159028a26c7bb8 100644 --- a/examples/ADM_register_job.cpp +++ b/examples/cxx/ADM_register_job.cpp @@ -13,24 +13,19 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; ADM_job_requirements_t reqs{}; - ADM_dataset_info_t info{}; - ADM_return_t ret = ADM_SUCCESS; try { - ret = admire::register_job(server, reqs, &job); - } catch(const std::exception& e) { - fmt::print(stderr, "FATAL: ADM_register_job() failed: {}\n", e.what()); - exit(EXIT_FAILURE); - } - if(ret != ADM_SUCCESS) { - fmt::print(stdout, "ADM_register_job() remote procedure not completed " + [[maybe_unused]] const auto job = admire::register_job(server, reqs); + + // do something with job + + fmt::print(stdout, "ADM_register_job() remote procedure completed " "successfully\n"); + exit(EXIT_SUCCESS); + } catch(const std::exception& e) { + fmt::print(stderr, "FATAL: ADM_register_job() failed: {}\n", e.what()); exit(EXIT_FAILURE); } - - fmt::print(stdout, "ADM_register_job() remote procedure completed " - "successfully\n"); } diff --git a/examples/ADM_remove_adhoc_storage.cpp b/examples/cxx/ADM_remove_adhoc_storage.cpp similarity index 93% rename from examples/ADM_remove_adhoc_storage.cpp rename to examples/cxx/ADM_remove_adhoc_storage.cpp index 9cfd194def855ec53e83ef0b21a675d6692a9740..bee611439c75b974c3220e99965ff0a68afaa3c5 100644 --- a/examples/ADM_remove_adhoc_storage.cpp +++ b/examples/cxx/ADM_remove_adhoc_storage.cpp @@ -1,5 +1,5 @@ -#include -#include +#include "fmt/format.h" +#include "admire.hpp" int @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_adhoc_storage_handle_t adhoc_handle{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_remove_job.cpp b/examples/cxx/ADM_remove_job.cpp similarity index 96% rename from examples/ADM_remove_job.cpp rename to examples/cxx/ADM_remove_job.cpp index f489c2c1d13b14f66ab798ebf422d6ba4bf7f001..fc037a10e8f6b7f34adec1e400515c7cbc858aba 100644 --- a/examples/ADM_remove_job.cpp +++ b/examples/cxx/ADM_remove_job.cpp @@ -13,7 +13,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_return_t ret = ADM_SUCCESS; try { diff --git a/examples/ADM_set_dataset_information.cpp b/examples/cxx/ADM_set_dataset_information.cpp similarity index 97% rename from examples/ADM_set_dataset_information.cpp rename to examples/cxx/ADM_set_dataset_information.cpp index 0ac0e2e79ed487a5b9fe3a92ad67e823d196ecbd..57f19c9c763643691c172d62e02561dc68b08abc 100644 --- a/examples/ADM_set_dataset_information.cpp +++ b/examples/cxx/ADM_set_dataset_information.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_dataset_handle_t target{}; ADM_dataset_info_t info{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_set_io_resources.cpp b/examples/cxx/ADM_set_io_resources.cpp similarity index 97% rename from examples/ADM_set_io_resources.cpp rename to examples/cxx/ADM_set_io_resources.cpp index d2a3be647fe8233a7fd73600f184a12e9ca316a9..b7c8e050ae67a245076f4fd9de7c3d60fb19a725 100644 --- a/examples/ADM_set_io_resources.cpp +++ b/examples/cxx/ADM_set_io_resources.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_storage_handle_t tier{}; ADM_storage_resources_t resources{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_set_qos_constraints.cpp b/examples/cxx/ADM_set_qos_constraints.cpp similarity index 97% rename from examples/ADM_set_qos_constraints.cpp rename to examples/cxx/ADM_set_qos_constraints.cpp index ed2b0e05808a3c26173978acc3212705a58718bc..6662602edb873d7a214277cc909187d5d0e3cb04 100644 --- a/examples/ADM_set_qos_constraints.cpp +++ b/examples/cxx/ADM_set_qos_constraints.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_limit_t limit{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_set_transfer_priority.cpp b/examples/cxx/ADM_set_transfer_priority.cpp similarity index 97% rename from examples/ADM_set_transfer_priority.cpp rename to examples/cxx/ADM_set_transfer_priority.cpp index b00e7283b6392497aebdd86d3fbfaa1e89f9a3f6..3a280f250c92ab040fa682b25194ea0ad041c30e 100644 --- a/examples/ADM_set_transfer_priority.cpp +++ b/examples/cxx/ADM_set_transfer_priority.cpp @@ -15,7 +15,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_transfer_handle_t tx_handle{}; int incr = 42; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/ADM_transfer_dataset.cpp b/examples/cxx/ADM_transfer_dataset.cpp similarity index 98% rename from examples/ADM_transfer_dataset.cpp rename to examples/cxx/ADM_transfer_dataset.cpp index 96312a7ec6193e5fd44452c2a80bde2b4a41c37d..986d7ad405d10f8ad45dec4874d29b308769807b 100644 --- a/examples/ADM_transfer_dataset.cpp +++ b/examples/cxx/ADM_transfer_dataset.cpp @@ -16,7 +16,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_dataset_handle_t** sources = nullptr; ADM_dataset_handle_t** targets = nullptr; ADM_limit_t** limits = nullptr; diff --git a/examples/ADM_update_adhoc_storage.cpp b/examples/cxx/ADM_update_adhoc_storage.cpp similarity index 72% rename from examples/ADM_update_adhoc_storage.cpp rename to examples/cxx/ADM_update_adhoc_storage.cpp index fc4355271bbf3ca0dcf1cedcd21e63140fb59baf..46219a17c251f0fba2a6df91ba6d85444e09ec66 100644 --- a/examples/ADM_update_adhoc_storage.cpp +++ b/examples/cxx/ADM_update_adhoc_storage.cpp @@ -14,7 +14,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_adhoc_context_t ctx{}; ADM_adhoc_storage_handle_t adhoc_handle{}; ADM_return_t ret = ADM_SUCCESS; @@ -28,14 +28,12 @@ main(int argc, char* argv[]) { } if(ret != ADM_SUCCESS) { - fmt::print( - stdout, - "ADM_update_adhoc_storage() remote procedure not completed " - "successfully\n"); + fmt::print(stdout, + "ADM_update_adhoc_storage() remote procedure not completed " + "successfully\n"); exit(EXIT_FAILURE); } - fmt::print(stdout, - "ADM_update_adhoc_storage() remote procedure completed " - "successfully\n"); + fmt::print(stdout, "ADM_update_adhoc_storage() remote procedure completed " + "successfully\n"); } diff --git a/examples/ADM_update_job.cpp b/examples/cxx/ADM_update_job.cpp similarity index 97% rename from examples/ADM_update_job.cpp rename to examples/cxx/ADM_update_job.cpp index ab82690fb8b87ca71bfe548909c52eaca5ec03f7..8d1cfcb5264e4a558a702e509d83e9124ac143ea 100644 --- a/examples/ADM_update_job.cpp +++ b/examples/cxx/ADM_update_job.cpp @@ -13,7 +13,7 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - ADM_job_handle_t job{}; + ADM_job_t job{}; ADM_job_requirements_t reqs{}; ADM_dataset_info_t info{}; ADM_return_t ret = ADM_SUCCESS; diff --git a/examples/cxx/CMakeLists.txt b/examples/cxx/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a884f425762597e699388ebc9eac04f054d91b1e --- /dev/null +++ b/examples/cxx/CMakeLists.txt @@ -0,0 +1,42 @@ +################################################################################ +# Copyright 2021-2022, 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 . # +# # +# SPDX-License-Identifier: GPL-3.0-or-later # +################################################################################ + +list(APPEND examples_cxx + 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 + ADM_in_situ_ops ADM_in_transit_ops ADM_transfer_dataset + ADM_set_dataset_information ADM_set_io_resources ADM_get_transfer_priority + ADM_set_transfer_priority ADM_cancel_transfer ADM_get_pending_transfers + ADM_set_qos_constraints ADM_get_qos_constraints ADM_define_data_operation ADM_connect_data_operation + ADM_finalize_data_operation ADM_link_transfer_to_data_operation ADM_get_statistics) + +foreach (example IN LISTS examples_cxx) + add_executable(${example}_cxx) + target_sources(${example}_cxx PRIVATE ${example}.cpp) + target_link_libraries(${example}_cxx + PUBLIC network_engine fmt::fmt adm_iosched) + set_target_properties(${example}_cxx PROPERTIES OUTPUT_NAME ${example}) +endforeach() diff --git a/examples/ping.cpp b/examples/cxx/ping.cpp similarity index 100% rename from examples/ping.cpp rename to examples/cxx/ping.cpp diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index ae30d58f94680bcbcfbcb507ee9cfc96b2102a48..77cb0bd87cf00672276500180a8f1a39e8b8d712 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -22,15 +22,15 @@ # SPDX-License-Identifier: GPL-3.0-or-later # ################################################################################ -add_library(adm_iosched SHARED c_wrapper.cpp admire.hpp) +add_library(adm_iosched SHARED) target_sources(adm_iosched - PUBLIC admire.h - PRIVATE admire.cpp) + PUBLIC admire.h admire.hpp + PRIVATE admire.cpp c_wrapper.cpp detail/impl.hpp detail/impl.cpp) target_include_directories(adm_iosched PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(adm_iosched PRIVATE network_engine) +target_link_libraries(adm_iosched PRIVATE network_engine PUBLIC tl::expected) install( TARGETS adm_iosched diff --git a/src/api/admire.cpp b/src/api/admire.cpp index c9ab9e7b0f241fb2e677ef5d5e404a365f036a52..b358642682cbf68d7e8dfd371759826c42346121 100644 --- a/src/api/admire.cpp +++ b/src/api/admire.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "detail/impl.hpp" namespace { @@ -47,41 +48,27 @@ init_logger() { scord::logger::create_global_logger("libadm_iosched", "console color"); } + } // namespace namespace admire { -ADM_return_t -register_job(const server& srv, ADM_job_requirements_t reqs, - ADM_job_handle_t* job) { - (void) srv; - (void) reqs; - (void) job; +admire::job +register_job(const server& srv, ADM_job_requirements_t reqs) { - scord::network::rpc_client rpc_client{srv.m_protocol}; - rpc_client.register_rpcs(); + const auto rv = detail::register_job(srv, reqs); - auto endp = rpc_client.lookup(srv.m_address); - - LOGGER_INFO("ADM_register_job(...)"); - - ADM_register_job_in_t in{}; - ADM_register_job_out_t out; - - endp.call("ADM_register_job", &in, &out); - - if(out.ret < 0) { - LOGGER_ERROR("ADM_register_job() = {}", out.ret); - return static_cast(out.ret); + if(!rv) { + /* TODO ADM_strerror(rv.error()) */ + throw std::runtime_error("ADM_register_job() error"); } - LOGGER_INFO("ADM_register_job() = {}", ADM_SUCCESS); - return ADM_SUCCESS; + return rv.value(); } ADM_return_t -update_job(const server& srv, ADM_job_handle_t job, +update_job(const server& srv, ADM_job_t job, ADM_job_requirements_t reqs) { (void) srv; (void) job; @@ -109,7 +96,7 @@ update_job(const server& srv, ADM_job_handle_t job, } ADM_return_t -remove_job(const server& srv, ADM_job_handle_t job) { +remove_job(const server& srv, ADM_job_t job) { (void) srv; (void) job; @@ -135,7 +122,7 @@ remove_job(const server& srv, ADM_job_handle_t job) { } ADM_return_t -register_adhoc_storage(const server& srv, ADM_job_handle_t job, +register_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t* adhoc_handle) { (void) srv; @@ -165,7 +152,7 @@ register_adhoc_storage(const server& srv, ADM_job_handle_t job, } ADM_return_t -update_adhoc_storage(const server& srv, ADM_job_handle_t job, +update_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t adhoc_handle) { (void) srv; @@ -195,7 +182,7 @@ update_adhoc_storage(const server& srv, ADM_job_handle_t job, } ADM_return_t -remove_adhoc_storage(const server& srv, ADM_job_handle_t job, +remove_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle) { (void) srv; (void) job; @@ -223,7 +210,7 @@ remove_adhoc_storage(const server& srv, ADM_job_handle_t job, } ADM_return_t -deploy_adhoc_storage(const server& srv, ADM_job_handle_t job, +deploy_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle) { (void) srv; (void) job; @@ -251,7 +238,7 @@ deploy_adhoc_storage(const server& srv, ADM_job_handle_t job, } ADM_return_t -transfer_dataset(const server& srv, ADM_job_handle_t job, +transfer_dataset(const server& srv, ADM_job_t job, ADM_dataset_handle_t** sources, ADM_dataset_handle_t** targets, ADM_limit_t** limits, ADM_tx_mapping_t mapping, ADM_transfer_handle_t* tx_handle) { @@ -285,7 +272,7 @@ transfer_dataset(const server& srv, ADM_job_handle_t job, } ADM_return_t -set_dataset_information(const server& srv, ADM_job_handle_t job, +set_dataset_information(const server& srv, ADM_job_t job, ADM_dataset_handle_t target, ADM_dataset_info_t info) { (void) srv; (void) job; @@ -314,7 +301,7 @@ set_dataset_information(const server& srv, ADM_job_handle_t job, } ADM_return_t -set_io_resources(const server& srv, ADM_job_handle_t job, +set_io_resources(const server& srv, ADM_job_t job, ADM_storage_handle_t tier, ADM_storage_resources_t resources) { (void) srv; (void) job; @@ -343,7 +330,7 @@ set_io_resources(const server& srv, ADM_job_handle_t job, } ADM_return_t -get_transfer_priority(const server& srv, ADM_job_handle_t job, +get_transfer_priority(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle, ADM_transfer_priority_t* priority) { (void) srv; @@ -373,7 +360,7 @@ get_transfer_priority(const server& srv, ADM_job_handle_t job, } ADM_return_t -set_transfer_priority(const server& srv, ADM_job_handle_t job, +set_transfer_priority(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle, int incr) { (void) srv; (void) job; @@ -402,7 +389,7 @@ set_transfer_priority(const server& srv, ADM_job_handle_t job, } ADM_return_t -cancel_transfer(const server& srv, ADM_job_handle_t job, +cancel_transfer(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle) { (void) job; @@ -431,7 +418,7 @@ cancel_transfer(const server& srv, ADM_job_handle_t job, } ADM_return_t -get_pending_transfers(const server& srv, ADM_job_handle_t job, +get_pending_transfers(const server& srv, ADM_job_t job, ADM_transfer_handle_t** pending_transfers) { (void) srv; (void) job; @@ -460,7 +447,7 @@ get_pending_transfers(const server& srv, ADM_job_handle_t job, } ADM_return_t -set_qos_constraints(const server& srv, ADM_job_handle_t job, +set_qos_constraints(const server& srv, ADM_job_t job, ADM_limit_t limit) { (void) srv; (void) job; @@ -490,7 +477,7 @@ set_qos_constraints(const server& srv, ADM_job_handle_t job, } ADM_return_t -get_qos_constraints(const server& srv, ADM_job_handle_t job, +get_qos_constraints(const server& srv, ADM_job_t job, ADM_qos_scope_t scope, ADM_qos_entity_t entity, ADM_limit_t** limits) { (void) srv; @@ -523,7 +510,7 @@ get_qos_constraints(const server& srv, ADM_job_handle_t job, } ADM_return_t -define_data_operation(const server& srv, ADM_job_handle_t job, const char* path, +define_data_operation(const server& srv, ADM_job_t job, const char* path, ADM_data_operation_handle_t* op, va_list args) { (void) srv; (void) job; @@ -555,7 +542,7 @@ define_data_operation(const server& srv, ADM_job_handle_t job, const char* path, } ADM_return_t -connect_data_operation(const server& srv, ADM_job_handle_t job, +connect_data_operation(const server& srv, ADM_job_t job, ADM_dataset_handle_t input, ADM_dataset_handle_t output, bool should_stream, va_list args) { (void) srv; @@ -589,7 +576,7 @@ connect_data_operation(const server& srv, ADM_job_handle_t job, } ADM_return_t -finalize_data_operation(const server& srv, ADM_job_handle_t job, +finalize_data_operation(const server& srv, ADM_job_t job, ADM_data_operation_handle_t op, ADM_data_operation_status_t* status) { (void) srv; @@ -621,7 +608,7 @@ finalize_data_operation(const server& srv, ADM_job_handle_t job, } ADM_return_t -link_transfer_to_data_operation(const server& srv, ADM_job_handle_t job, +link_transfer_to_data_operation(const server& srv, ADM_job_t job, ADM_data_operation_handle_t op, bool should_stream, va_list args) { (void) srv; @@ -654,7 +641,7 @@ link_transfer_to_data_operation(const server& srv, ADM_job_handle_t job, } ADM_return_t -get_statistics(const server& srv, ADM_job_handle_t job, +get_statistics(const server& srv, ADM_job_t job, ADM_job_stats_t** stats) { (void) srv; (void) job; diff --git a/src/api/admire.h b/src/api/admire.h index 73c9e19064a5ba340ba6e8af379da13ce6abe00a..33d19e6ae2992cdd9795f172645d1b1726f0488b 100644 --- a/src/api/admire.h +++ b/src/api/admire.h @@ -25,7 +25,9 @@ #ifndef SCORD_ADMIRE_H #define SCORD_ADMIRE_H +#include #include +#include #ifdef __cplusplus extern "C" { @@ -36,46 +38,85 @@ extern "C" { #define ADM_IOSCHED_API_VERSION_MINOR 1 #define ADM_IOSCHED_API_VERSION_PATCH 0 -/** - * Public type and struct definitions - */ + +/******************************************************************************/ +/* Public type definitions and type-related functions */ +/******************************************************************************/ /* Error return codes */ -enum ADM_return_t { +typedef enum { ADM_SUCCESS = 0, - // FIXME: generic error only for now + ADM_EINVAL, + // generic error code ADM_OTHER_ERROR -}; +} ADM_return_t; /* A server */ -typedef struct adm_server ADM_server_t; +typedef struct adm_server* ADM_server_t; + +/** + * Initialize a server from a user-provided name/address. + * + * @remark Servers need to be freed by calling ADM_server_destroy(). + * + * @param[in] protocol The protocol that will be used to access the server. + * @param[in] address The address of server. + * @return A valid ADM_server_t if successful or NULL in case of failure. + */ +ADM_server_t +ADM_server_create(const char* protocol, const char* address); + +/** + * Destroy a server created by ADM_server_create(). + * + * @param[in] server A pointer to a ADM_server_t + * @return ADM_SUCCESS or corresponding ADM error code + */ +ADM_return_t +ADM_server_destroy(ADM_server_t server); /* A node */ -typedef const char* ADM_node_t; +typedef char* ADM_node_t; /* A dataset handle */ typedef struct adm_dataset* ADM_dataset_handle_t; +/** + * Create a dataset from a user-provided id (e.g. a path for POSIX-like file + * systems or key for key-value stores). + * + * @remark Datasets need to be freed by calling ADM_dataset_destroy(). + * + * @param[in] id The id for the dataset. + * @return A valid ADM_dataset_handle_t if successful or NULL in case of + * failure. + */ +ADM_dataset_handle_t +ADM_dataset_create(const char* id); + +ADM_return_t +ADM_dataset_destroy(ADM_dataset_handle_t dataset); + /* A job handle */ -typedef struct adm_job* ADM_job_handle_t; +typedef struct adm_job* ADM_job_t; /* The scope affected by a QoS limit */ -enum ADM_qos_scope_t { +typedef enum { ADM_QOS_SCOPE_DATASET, ADM_QOS_SCOPE_NODE, ADM_QOS_SCOPE_JOB -}; +} ADM_qos_scope_t; /** The class of QoS limit applied to a scope */ -enum ADM_qos_class_t { ADM_QOS_CLASS_BANDWIDTH, ADM_QOS_CLASS_IOPS }; +typedef enum { ADM_QOS_CLASS_BANDWIDTH, ADM_QOS_CLASS_IOPS } ADM_qos_class_t; /** An ADMIRE entity upon which QoS can be defined */ -union ADM_qos_entity_t { +typedef union { ADM_node_t l_node; - ADM_job_handle_t l_job; + ADM_job_t l_job; ADM_dataset_handle_t l_dataset; -}; +} ADM_qos_entity_t; /** A QoS limit */ typedef struct { @@ -161,14 +202,39 @@ typedef struct { typedef ADM_adhoc_context_t* ADM_adhoc_storage_handle_t; /** The I/O requirements for a job */ -typedef struct { - /** A list of input datasets */ - ADM_dataset_handle_t** r_inputs; - /** A list of output datasets */ - ADM_dataset_handle_t** r_outputs; - /** A definition for a specific adhoc storage instance */ - ADM_adhoc_storage_handle_t r_adhoc_storage; -} ADM_job_requirements_t; +typedef struct adm_job_requirements* ADM_job_requirements_t; + +/** + * Create a JOB_REQUIREMENTS from user-provided information. + * + * @remark JOB_REQUIREMENTS created by this function need to be freed by calling + * ADM_job_requirements_destroy(). + * + * @param[in] inputs An array of DATASET_DESCRIPTORS describing the input + * information required by the job. + * @param[in] inputs_len The number of DATASET_DESCRIPTORS stored in inputs. + * @param[in] outputs An array of DATASET_DESCRIPTORS describing the output + * information generated by the job. + * @param[in] outputs_len The number of DATASET_DESCRIPTORS stored in outputs. + * @param[in] adhoc_storage An optional ADHOC_DESCRIPTOR describing the adhoc + * storage system required by the job (can be set to NULL if no adhoc storage + * system is required). + * @return A valid ADM_job_requirements_t if sucessfull or NULL in case of + * failure. + */ +ADM_job_requirements_t +ADM_job_requirements_create(ADM_dataset_handle_t inputs[], size_t inputs_len, + ADM_dataset_handle_t outputs[], size_t outputs_len, + ADM_adhoc_storage_handle_t adhoc_storage); + +/** + * Destroy a ADM_job_requirements_t created by ADM_job_requirements_create(). + * + * @param[in] reqs The ADM_job_requirements_t to destroy. + * @return ADM_SUCCESS or corresponding error code. + */ +ADM_return_t +ADM_job_requirements_destroy(ADM_job_requirements_t reqs); /******************************************************************************/ @@ -178,29 +244,30 @@ typedef struct { /** * Register a job and its requirements. * + * @remark The returned ADM_JOB will be freed when passed to + * ADM_remove_job(). + * * @param[in] server The server to which the request is directed * @param[in] reqs The requirements for the job. - * @param[out] job An ADHOC_HANDLE referring to the newly-created - * adhoc storage instance. + * @param[out] job An ADM_JOB referring to the newly-registered job. * @return Returns ADM_SUCCESS if the remote procedure has completed * successfully. */ ADM_return_t ADM_register_job(ADM_server_t server, ADM_job_requirements_t reqs, - ADM_job_handle_t* job); + ADM_job_t* job); ADM_return_t -ADM_update_job(ADM_server_t server, ADM_job_handle_t job, - ADM_job_requirements_t reqs); +ADM_update_job(ADM_server_t server, ADM_job_t job, ADM_job_requirements_t reqs); ADM_return_t -ADM_remove_job(ADM_server_t server, ADM_job_handle_t job); +ADM_remove_job(ADM_server_t server, ADM_job_t job); /** * Register an adhoc storage system. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] ctx The EXECUTION_CONTEXT for the adhoc storage system. * @param[out] adhoc_handle An ADHOC_HANDLE referring to the newly-created * adhoc storage instance. @@ -208,7 +275,7 @@ ADM_remove_job(ADM_server_t server, ADM_job_handle_t job); * successfully. */ ADM_return_t -ADM_register_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_register_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t* adhoc_handle); @@ -216,7 +283,7 @@ ADM_register_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, * Update an already-registered adhoc storage system. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] ctx The updated EXECUTION_CONTEXT for the adhoc storage system. * @param[in] adhoc_handle An ADHOC_HANDLE referring to the adhoc storage * instance of interest. @@ -224,7 +291,7 @@ ADM_register_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, * successfully. */ ADM_return_t -ADM_update_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_update_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t adhoc_handle); @@ -232,27 +299,27 @@ ADM_update_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, * Remove an already-registered adhoc storage system. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] adhoc_handle An ADHOC_HANDLE referring to the adhoc storage * instance of interest. * @return Returns ADM_SUCCESS if the remote procedure has completed * successfully. */ ADM_return_t -ADM_remove_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_remove_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle); /** * Initiate the deployment of an adhoc storage system instance. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] adhoc_handle An ADHOC_HANDLE referring to the adhoc storage * instance of interest. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle); /** @@ -262,7 +329,7 @@ ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, * operation (i.e., get statistics, or status). * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] sources A list of DATASETs identifying the source dataset/s * to be transferred. * @param[in] targets A list of DATASETs identifying the destination @@ -279,7 +346,7 @@ ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, * successfully or not. */ ADM_return_t -ADM_transfer_dataset(ADM_server_t server, ADM_job_handle_t job, +ADM_transfer_dataset(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t** sources, ADM_dataset_handle_t** targets, ADM_limit_t** limits, ADM_tx_mapping_t mapping, @@ -290,7 +357,7 @@ ADM_transfer_dataset(ADM_server_t server, ADM_job_handle_t job, * Sets information for the dataset identified by resource_id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] target A DATASET_HANDLE referring to the dataset of interest. * @param[in] info A DATASET_INFO with information about the * dataset (e.g. its lifespan, access methods, intended usage, etc.). @@ -298,7 +365,7 @@ ADM_transfer_dataset(ADM_server_t server, ADM_job_handle_t job, * successfully. */ ADM_return_t -ADM_set_dataset_information(ADM_server_t server, ADM_job_handle_t job, +ADM_set_dataset_information(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t target, ADM_dataset_info_t info); @@ -307,7 +374,7 @@ ADM_set_dataset_information(ADM_server_t server, ADM_job_handle_t job, * System. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] tier A STORAGE_HANDLE referring to the target storage tier. * @param[in] resources A RESOURCES argument containing information * about the I/O resources to set (e.g. number of I/O nodes.). @@ -315,7 +382,7 @@ ADM_set_dataset_information(ADM_server_t server, ADM_job_handle_t job, * successfully. */ ADM_return_t -ADM_set_io_resources(ADM_server_t server, ADM_job_handle_t job, +ADM_set_io_resources(ADM_server_t server, ADM_job_t job, ADM_storage_handle_t tier, ADM_storage_resources_t resources); @@ -324,7 +391,7 @@ ADM_set_io_resources(ADM_server_t server, ADM_job_handle_t job, * Returns the priority of the pending transfer identified by transfer_id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] tx_handle A TRANSFER_HANDLE referring to a pending transfer * @param[out] priority The priority of the pending transfer or an error code if * it didn’t exist or is no longer pending. @@ -332,7 +399,7 @@ ADM_set_io_resources(ADM_server_t server, ADM_job_handle_t job, * successfully. */ ADM_return_t -ADM_get_transfer_priority(ADM_server_t server, ADM_job_handle_t job, +ADM_get_transfer_priority(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle, ADM_transfer_priority_t* priority); @@ -342,14 +409,14 @@ ADM_get_transfer_priority(ADM_server_t server, ADM_job_handle_t job, * its scheduling queue. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] tx_handle A TRANSFER_HANDLE referring to a pending transfer * @param[in] incr A positive or negative number for the number of * positions the transfer should go up or down in its scheduling queue. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_set_transfer_priority(ADM_server_t server, ADM_job_handle_t job, +ADM_set_transfer_priority(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle, int incr); @@ -357,12 +424,12 @@ ADM_set_transfer_priority(ADM_server_t server, ADM_job_handle_t job, * Cancels the pending transfer identified by transfer_id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] tx_handle A TRANSFER_HANDLE referring to a pending transfer. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_cancel_transfer(ADM_server_t server, ADM_job_handle_t job, +ADM_cancel_transfer(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle); @@ -370,12 +437,12 @@ ADM_cancel_transfer(ADM_server_t server, ADM_job_handle_t job, * Returns a list of pending transfers. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[out] pending_transfers A list of pending_transfers. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_get_pending_transfers(ADM_server_t server, ADM_job_handle_t job, +ADM_get_pending_transfers(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t** pending_transfers); @@ -384,7 +451,7 @@ ADM_get_pending_transfers(ADM_server_t server, ADM_job_handle_t job, * identified by id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] limit A QOS_LIMIT specifying at least: * - The QOS_SCOPE the limit should be applied to: e.g. * dataset, node, or job. @@ -395,24 +462,23 @@ ADM_get_pending_transfers(ADM_server_t server, ADM_job_handle_t job, * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_set_qos_constraints(ADM_server_t server, ADM_job_handle_t job, - ADM_limit_t limit); +ADM_set_qos_constraints(ADM_server_t server, ADM_job_t job, ADM_limit_t limit); /** * Returns a list of QoS constraints defined for an element identified for id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] scope The scope being queried: dataset, node, or job. * @param[in] entity An QOS_ENTITY referring to the target of the query, i.e. a - * RESOURCE_HANDLE, a NODE hostname, or a JOB_HANDLE. + * RESOURCE_HANDLE, a NODE hostname, or a ADM_JOB. * @param[in] limits A list of QOS_LIMITS that includes all the classes * currently defined for the element as well as the values set for them. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_get_qos_constraints(ADM_server_t server, ADM_job_handle_t job, +ADM_get_qos_constraints(ADM_server_t server, ADM_job_t job, ADM_qos_scope_t scope, ADM_qos_entity_t entity, ADM_limit_t** limits); @@ -423,16 +489,15 @@ ADM_get_qos_constraints(ADM_server_t server, ADM_job_handle_t job, * defined, using the next format "arg0, arg1, arg2, ... ". * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] path A valid path for the operation executable. * @param[in] ... A list of ARGUMENTS for the operation. * @param[out] op An OPERATION_HANDLE for the newly-defined operation. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_define_data_operation(ADM_server_t server, ADM_job_handle_t job, - const char* path, ADM_data_operation_handle_t* op, - ...); +ADM_define_data_operation(ADM_server_t server, ADM_job_t job, const char* path, + ADM_data_operation_handle_t* op, ...); /** @@ -443,7 +508,7 @@ ADM_define_data_operation(ADM_server_t server, ADM_job_handle_t job, * set to true. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] op The OPERATION_HANDLE of the operation to be connected. * @param[in] input An input DATASET_HANDLE for the operation. * @param[in] output An output DATASET_HANDLE where the result of @@ -454,7 +519,7 @@ ADM_define_data_operation(ADM_server_t server, ADM_job_handle_t job, * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_connect_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_connect_data_operation(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t input, ADM_dataset_handle_t output, bool should_stream, ...); @@ -464,14 +529,14 @@ ADM_connect_data_operation(ADM_server_t server, ADM_job_handle_t job, * Finalises the operation defined with operation_id. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] op The OPERATION_HANDLE of the operation to be connected. * @return[out] status An OPERATION_STATUS type indicating whether the * operation was successful. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_finalize_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_finalize_data_operation(ADM_server_t server, ADM_job_t job, ADM_data_operation_handle_t op, ADM_data_operation_status_t* status); @@ -484,18 +549,18 @@ ADM_finalize_data_operation(ADM_server_t server, ADM_job_handle_t job, * to true. * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] op The OPERATION_HANDLE of the operation to be connected. * @param[in] tx_handle The TRANSFER_HANDLE referring to the pending transfer * the operation should be linked to. - * @param[in] job A JOB_HANDLE identifying the originating job. + * @param[in] job An ADM_JOB identifying the originating job. * @param[in] should_stream A boolean indicating whether the operation * should be executed in a streaming fashion. * @param[in] ... The VALUES for the arguments required by the operation. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_t job, ADM_data_operation_handle_t op, bool should_stream, ...); @@ -506,14 +571,13 @@ ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_handle_t job, * easy-to-process format, e.g., JSON (see Listing 3.1). * * @param[in] server The server to which the request is directed - * @param[in] job A JOB_HANDLE identifying the originating job and, + * @param[in] job An ADM_JOB identifying the originating job and, * optionally, its JOB_STEP. * @return[out] stats A list of JOB_STATS. * @return Returns ADM_SUCCESS if the remote procedure has completed */ ADM_return_t -ADM_get_statistics(ADM_server_t server, ADM_job_handle_t job, - ADM_job_stats_t** stats); +ADM_get_statistics(ADM_server_t server, ADM_job_t job, ADM_job_stats_t** stats); #ifdef __cplusplus } // extern "C" diff --git a/src/api/admire.hpp b/src/api/admire.hpp index e340c1e6c9273a2ec82fa3fc454ece52ff7e28f2..5ab690281fd87281882a379f27e947e5eee79c2a 100644 --- a/src/api/admire.hpp +++ b/src/api/admire.hpp @@ -23,6 +23,7 @@ *****************************************************************************/ #include +#include #include #include @@ -31,100 +32,106 @@ namespace admire { +using job_id = int64_t; + struct server { std::string m_protocol; std::string m_address; }; -ADM_return_t -register_job(const server& srv, ADM_job_requirements_t reqs, - ADM_job_handle_t* job); +struct job { + job_id m_id; +}; + + +admire::job +register_job(const server& srv, ADM_job_requirements_t reqs); ADM_return_t -update_job(const server& srv, ADM_job_handle_t job, +update_job(const server& srv, ADM_job_t job, ADM_job_requirements_t reqs); ADM_return_t -remove_job(const server& srv, ADM_job_handle_t job); +remove_job(const server& srv, ADM_job_t job); ADM_return_t -register_adhoc_storage(const server& srv, ADM_job_handle_t job, +register_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t* adhoc_handle); ADM_return_t -update_adhoc_storage(const server& srv, ADM_job_handle_t job, +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 -remove_adhoc_storage(const server& srv, ADM_job_handle_t job, +remove_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle); ADM_return_t -deploy_adhoc_storage(const server& srv, ADM_job_handle_t job, +deploy_adhoc_storage(const server& srv, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle); ADM_return_t -transfer_dataset(const server& srv, ADM_job_handle_t job, +transfer_dataset(const server& srv, ADM_job_t job, ADM_dataset_handle_t** sources, ADM_dataset_handle_t** targets, ADM_limit_t** limits, ADM_tx_mapping_t mapping, ADM_transfer_handle_t* tx_handle); ADM_return_t -set_dataset_information(const server& srv, ADM_job_handle_t job, +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_handle_t job, +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_handle_t job, +get_transfer_priority(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle, ADM_transfer_priority_t* priority); ADM_return_t -set_transfer_priority(const server& srv, ADM_job_handle_t job, +set_transfer_priority(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle, int incr); ADM_return_t -cancel_transfer(const server& srv, ADM_job_handle_t job, +cancel_transfer(const server& srv, ADM_job_t job, ADM_transfer_handle_t tx_handle); ADM_return_t -get_pending_transfers(const server& srv, ADM_job_handle_t job, +get_pending_transfers(const server& srv, ADM_job_t job, ADM_transfer_handle_t** pending_transfers); ADM_return_t -set_qos_constraints(const server& srv, ADM_job_handle_t job, ADM_limit_t limit); +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_handle_t job, +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_handle_t job, const char* path, +define_data_operation(const server& srv, ADM_job_t job, const char* path, ADM_data_operation_handle_t* op, va_list args); ADM_return_t -connect_data_operation(const server& srv, ADM_job_handle_t job, +connect_data_operation(const server& srv, ADM_job_t job, ADM_dataset_handle_t input, ADM_dataset_handle_t output, bool should_stream, va_list args); ADM_return_t -finalize_data_operation(const server& srv, ADM_job_handle_t job, +finalize_data_operation(const server& srv, ADM_job_t job, ADM_data_operation_handle_t op, ADM_data_operation_status_t* status); ADM_return_t -link_transfer_to_data_operation(const server& srv, ADM_job_handle_t job, +link_transfer_to_data_operation(const server& srv, ADM_job_t job, ADM_data_operation_handle_t op, bool should_stream, va_list args); ADM_return_t -get_statistics(const server& srv, ADM_job_handle_t job, +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 9c4547958a27ee3025cf1858e51c48cc20408f62..2496c43ba7cdc33740915f10240b673f286692d9 100644 --- a/src/api/c_wrapper.cpp +++ b/src/api/c_wrapper.cpp @@ -24,171 +24,326 @@ #include #include +#include +#include "detail/impl.hpp" struct adm_server { const char* s_protocol; const char* s_address; }; +struct adm_job { + uint64_t j_id; +}; + +struct adm_dataset { + const char* d_id; +}; + +/** The I/O requirements for a job */ +struct adm_job_requirements { + /** An array of input datasets */ + ADM_dataset_handle_t* r_inputs; + /** The number of datasets in r_inputs */ + size_t r_num_inputs; + /** A list of output datasets */ + ADM_dataset_handle_t* r_outputs; + /** The number of datasets in r_outputs */ + size_t r_num_outputs; + /** An optional definition for a specific adhoc storage instance */ + ADM_adhoc_storage_handle_t r_adhoc_storage; +}; + +ADM_server_t +ADM_server_create(const char* protocol, const char* address) { + + struct adm_server* adm_server = + (struct adm_server*) malloc(sizeof(struct adm_server)); + + if(!adm_server) { + LOGGER_ERROR("Could not allocate ADM_server_t") + return NULL; + } + + adm_server->s_protocol = protocol; + adm_server->s_address = address; + + return adm_server; +} + +ADM_return_t +ADM_server_destroy(ADM_server_t server) { + ADM_return_t ret = ADM_SUCCESS; + + if(!server) { + LOGGER_ERROR("Invalid ADM_server_t") + return ADM_EINVAL; + } + + free(server); + return ret; +} + +ADM_dataset_handle_t +ADM_dataset_create(const char* id) { + + struct adm_dataset* adm_dataset = + (struct adm_dataset*) malloc(sizeof(struct adm_dataset)); + + if(!adm_dataset) { + LOGGER_ERROR("Could not allocate ADM_dataset_t") + return NULL; + } + + adm_dataset->d_id = id; + + return adm_dataset; +} + +ADM_return_t +ADM_dataset_destroy(ADM_dataset_handle_t dataset) { + ADM_return_t ret = ADM_SUCCESS; + + if(!dataset) { + LOGGER_ERROR("Invalid ADM_dataset_t") + return ADM_EINVAL; + } + + free(dataset); + return ret; +} + +ADM_job_requirements_t +ADM_job_requirements_create(ADM_dataset_handle_t inputs[], size_t inputs_len, + ADM_dataset_handle_t outputs[], size_t outputs_len, + ADM_adhoc_storage_handle_t adhoc_storage) { + + struct adm_job_requirements* adm_job_reqs = + (struct adm_job_requirements*) malloc( + sizeof(struct adm_job_requirements)); + + if(!adm_job_reqs) { + LOGGER_ERROR("Could not allocate ADM_job_requirements_t") + return NULL; + } + + adm_job_reqs->r_inputs = inputs; + adm_job_reqs->r_num_inputs = inputs_len; + adm_job_reqs->r_outputs = outputs; + adm_job_reqs->r_num_outputs = outputs_len; + adm_job_reqs->r_adhoc_storage = adhoc_storage; + + return adm_job_reqs; +} + +ADM_return_t +ADM_job_requirements_destroy(ADM_job_requirements_t reqs) { + ADM_return_t ret = ADM_SUCCESS; + + if(!reqs) { + LOGGER_ERROR("Invalid ADM_job_requirements_t") + return ADM_EINVAL; + } + + free(reqs); + return ret; +} + +/** + * Initialize a job handle that can be used by clients to refer to a job. + * + * @remark This function is not actually part of the public API, but it is + * useful to have for internal purposes + * + * @param [in] id The identifier for this job + * @return A valid JOB HANDLE or NULL in case of failure. + */ +static ADM_job_t +ADM_job_create(uint64_t id) { + + struct adm_job* adm_job = (struct adm_job*) malloc(sizeof(struct adm_job)); + + if(!adm_job) { + LOGGER_ERROR("Could not allocate ADM_job_t") + return NULL; + } + + adm_job->j_id = id; + + return adm_job; +} + ADM_return_t ADM_register_job(ADM_server_t server, ADM_job_requirements_t reqs, - ADM_job_handle_t* job) { + ADM_job_t* job) { + + const admire::server srv{server->s_protocol, server->s_address}; + + const auto rv = admire::detail::register_job(srv, reqs); + + if(!rv) { + return rv.error(); + } + + const auto jh = ADM_job_create(rv->m_id); + + if(!jh) { + return ADM_OTHER_ERROR; + } - const admire::server srv{server.s_protocol, server.s_address}; + *job = jh; - return admire::register_job(srv, reqs, job); + return ADM_SUCCESS; } ADM_return_t -ADM_update_job(ADM_server_t server, ADM_job_handle_t job, +ADM_update_job(ADM_server_t server, ADM_job_t job, ADM_job_requirements_t reqs) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::update_job(srv, job, reqs); } ADM_return_t -ADM_remove_job(ADM_server_t server, ADM_job_handle_t job) { +ADM_remove_job(ADM_server_t server, ADM_job_t job) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::remove_job(srv, job); } ADM_return_t -ADM_register_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_register_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t* adhoc_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::register_adhoc_storage(srv, job, ctx, adhoc_handle); } ADM_return_t -ADM_update_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_update_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_context_t ctx, ADM_adhoc_storage_handle_t adhoc_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::update_adhoc_storage(srv, job, ctx, adhoc_handle); } ADM_return_t -ADM_remove_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_remove_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::remove_adhoc_storage(srv, job, adhoc_handle); } ADM_return_t -ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_handle_t job, +ADM_deploy_adhoc_storage(ADM_server_t server, ADM_job_t job, ADM_adhoc_storage_handle_t adhoc_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::deploy_adhoc_storage(srv, job, adhoc_handle); } ADM_return_t -ADM_transfer_dataset(ADM_server_t server, ADM_job_handle_t job, +ADM_transfer_dataset(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t** sources, ADM_dataset_handle_t** targets, ADM_limit_t** limits, ADM_tx_mapping_t mapping, ADM_transfer_handle_t* tx_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::transfer_dataset(srv, job, sources, targets, limits, mapping, tx_handle); } ADM_return_t -ADM_set_dataset_information(ADM_server_t server, ADM_job_handle_t job, +ADM_set_dataset_information(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t target, ADM_dataset_info_t info) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::set_dataset_information(srv, job, target, info); } ADM_return_t -ADM_set_io_resources(ADM_server_t server, ADM_job_handle_t job, +ADM_set_io_resources(ADM_server_t server, ADM_job_t job, ADM_storage_handle_t tier, ADM_storage_resources_t resources) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::set_io_resources(srv, job, tier, resources); } ADM_return_t -ADM_get_transfer_priority(ADM_server_t server, ADM_job_handle_t job, +ADM_get_transfer_priority(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle, ADM_transfer_priority_t* priority) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::get_transfer_priority(srv, job, tx_handle, priority); } ADM_return_t -ADM_set_transfer_priority(ADM_server_t server, ADM_job_handle_t job, +ADM_set_transfer_priority(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle, int incr) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::set_transfer_priority(srv, job, tx_handle, incr); } ADM_return_t -ADM_cancel_transfer(ADM_server_t server, ADM_job_handle_t job, +ADM_cancel_transfer(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t tx_handle) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::cancel_transfer(srv, job, tx_handle); } ADM_return_t -ADM_get_pending_transfers(ADM_server_t server, ADM_job_handle_t job, +ADM_get_pending_transfers(ADM_server_t server, ADM_job_t job, ADM_transfer_handle_t** pending_transfers) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::get_pending_transfers(srv, job, pending_transfers); } ADM_return_t -ADM_set_qos_constraints(ADM_server_t server, ADM_job_handle_t job, - ADM_limit_t limit) { +ADM_set_qos_constraints(ADM_server_t server, ADM_job_t job, ADM_limit_t limit) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::set_qos_constraints(srv, job, limit); } ADM_return_t -ADM_get_qos_constraints(ADM_server_t server, ADM_job_handle_t job, +ADM_get_qos_constraints(ADM_server_t server, ADM_job_t job, ADM_qos_scope_t scope, ADM_qos_entity_t entity, ADM_limit_t** limits) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::get_qos_constraints(srv, job, scope, entity, limits); } ADM_return_t -ADM_define_data_operation(ADM_server_t server, ADM_job_handle_t job, - const char* path, ADM_data_operation_handle_t* op, - ...) { +ADM_define_data_operation(ADM_server_t server, ADM_job_t job, const char* path, + ADM_data_operation_handle_t* op, ...) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; va_list args; va_start(args, op); @@ -199,12 +354,12 @@ ADM_define_data_operation(ADM_server_t server, ADM_job_handle_t job, } ADM_return_t -ADM_connect_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_connect_data_operation(ADM_server_t server, ADM_job_t job, ADM_dataset_handle_t input, ADM_dataset_handle_t output, bool should_stream, ...) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; va_list args; va_start(args, should_stream); @@ -216,21 +371,21 @@ ADM_connect_data_operation(ADM_server_t server, ADM_job_handle_t job, } ADM_return_t -ADM_finalize_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_finalize_data_operation(ADM_server_t server, ADM_job_t job, ADM_data_operation_handle_t op, ADM_data_operation_status_t* status) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::finalize_data_operation(srv, job, op, status); } ADM_return_t -ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_handle_t job, +ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_t job, ADM_data_operation_handle_t op, bool should_stream, ...) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; va_list args; va_start(args, should_stream); @@ -242,8 +397,8 @@ ADM_link_transfer_to_data_operation(ADM_server_t server, ADM_job_handle_t job, } ADM_return_t -ADM_get_statistics(ADM_server_t server, ADM_job_handle_t job, +ADM_get_statistics(ADM_server_t server, ADM_job_t job, ADM_job_stats_t** stats) { - const admire::server srv{server.s_protocol, server.s_address}; + const admire::server srv{server->s_protocol, server->s_address}; return admire::get_statistics(srv, job, stats); } diff --git a/src/api/detail/impl.cpp b/src/api/detail/impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..962444dec7856428e7a1dd2eb4e62eb30ae73e0e --- /dev/null +++ b/src/api/detail/impl.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** + * Copyright 2021-2022, 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + *****************************************************************************/ + +#include +#include +#include "impl.hpp" + +namespace admire::detail { + +tl::expected +register_job(const admire::server& srv, ADM_job_requirements_t reqs) { + (void) srv; + (void) reqs; + + scord::network::rpc_client rpc_client{srv.m_protocol}; + rpc_client.register_rpcs(); + + auto endp = rpc_client.lookup(srv.m_address); + + LOGGER_INFO("ADM_register_job(...)"); + + ADM_register_job_in_t in{}; + ADM_register_job_out_t out; + + endp.call("ADM_register_job", &in, &out); + + if(out.ret < 0) { + LOGGER_ERROR("ADM_register_job() = {}", out.ret); + /* TODO ADM_strerror(out.ret) */ + throw std::runtime_error("ADM_register_job() error"); + } + + LOGGER_INFO("ADM_register_job() = {}", ADM_SUCCESS); + return admire::job{42}; +} + +} // namespace admire::detail diff --git a/src/api/detail/impl.hpp b/src/api/detail/impl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..501489c3888660975a2262bf4899e9a2ce51c184 --- /dev/null +++ b/src/api/detail/impl.hpp @@ -0,0 +1,42 @@ +/****************************************************************************** + * Copyright 2021-2022, 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + *****************************************************************************/ + + +#ifndef SCORD_ADMIRE_IMPL_HPP +#define SCORD_ADMIRE_IMPL_HPP + +#include + +namespace admire { +using error_code = ADM_return_t; +} // namespace admire + +namespace admire::detail { + +tl::expected +register_job(const server& srv, ADM_job_requirements_t reqs); + +} // namespace admire::detail + +#endif // SCORD_ADMIRE_IMPL_HPP