From d700d29c547455fa60c38b299fb309b4868ed2e3 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Mon, 17 Oct 2022 18:09:30 +0200 Subject: [PATCH 1/6] types: Create internal_types.hpp scord::job_info is now admire::internal::job_info --- src/common/api/CMakeLists.txt | 2 +- src/common/api/admire_types.hpp | 4 +++ src/common/api/internal_types.hpp | 60 +++++++++++++++++++++++++++++++ src/common/api/types.cpp | 1 + src/scord/job_manager.hpp | 49 +++++++------------------ 5 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 src/common/api/internal_types.hpp diff --git a/src/common/api/CMakeLists.txt b/src/common/api/CMakeLists.txt index d81fa158..97365630 100644 --- a/src/common/api/CMakeLists.txt +++ b/src/common/api/CMakeLists.txt @@ -25,7 +25,7 @@ add_library(_api_types STATIC) target_sources(_api_types PUBLIC admire_types.h admire_types.hpp PRIVATE - types.cpp convert.hpp convert.cpp) + types.cpp convert.hpp convert.cpp internal_types.hpp) target_include_directories(_api_types PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/common/api/admire_types.hpp b/src/common/api/admire_types.hpp index 104adb30..81bea1fd 100644 --- a/src/common/api/admire_types.hpp +++ b/src/common/api/admire_types.hpp @@ -42,6 +42,10 @@ using job_id = std::uint64_t; using slurm_job_id = std::uint64_t; using transfer_id = std::uint64_t; +namespace internal { +struct job_info; +} // namespace internal + struct server { server(std::string protocol, std::string address); diff --git a/src/common/api/internal_types.hpp b/src/common/api/internal_types.hpp new file mode 100644 index 00000000..1a6dac5d --- /dev/null +++ b/src/common/api/internal_types.hpp @@ -0,0 +1,60 @@ +/****************************************************************************** + * 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_INTERNAL_TYPES_HPP +#define SCORD_INTERNAL_TYPES_HPP + +namespace admire::internal { + +struct job_info { + explicit job_info(admire::job job) : m_job(std::move(job)) {} + job_info(admire::job job, admire::job::resources resources, + admire::job_requirements requirements) + : m_job(std::move(job)), m_resources(std::move(resources)), + m_requirements(std::move(requirements)) {} + + admire::job + job() const { + return m_job; + } + + std::optional + resources() const { + return m_resources; + } + + std::optional + requirements() const { + return m_requirements; + } + + admire::job m_job; + std::optional m_resources; + std::optional m_requirements; +}; + +} // namespace admire::internal + +#endif // SCORD_INTERNAL_TYPES_HPP diff --git a/src/common/api/types.cpp b/src/common/api/types.cpp index aa3065a4..5f1e5977 100644 --- a/src/common/api/types.cpp +++ b/src/common/api/types.cpp @@ -31,6 +31,7 @@ #include #include #include "admire_types.hpp" +#include "internal_types.hpp" /******************************************************************************/ /* C Type definitions and related functions */ diff --git a/src/scord/job_manager.hpp b/src/scord/job_manager.hpp index 45d7d493..c01a9e06 100644 --- a/src/scord/job_manager.hpp +++ b/src/scord/job_manager.hpp @@ -26,6 +26,7 @@ #define SCORD_JOB_MANAGER_HPP #include +#include #include #include #include @@ -36,37 +37,10 @@ namespace scord { -struct job_info { - explicit job_info(admire::job job) : m_job(std::move(job)) {} - job_info(admire::job job, admire::job::resources resources, - admire::job_requirements requirements) - : m_job(std::move(job)), m_resources(std::move(resources)), - m_requirements(std::move(requirements)) {} - - admire::job - job() const { - return m_job; - } - - std::optional - resources() const { - return m_resources; - } - - std::optional - requirements() const { - return m_requirements; - } - - admire::job m_job; - std::optional m_resources; - std::optional m_requirements; -}; struct job_manager : scord::utils::singleton { - - tl::expected + tl::expected create(admire::slurm_job_id slurm_id, admire::job::resources job_resources, admire::job_requirements job_requirements) { @@ -76,10 +50,11 @@ struct job_manager : scord::utils::singleton { abt::unique_lock lock(m_jobs_mutex); if(const auto it = m_jobs.find(id); it == m_jobs.end()) { - const auto& [it_job, inserted] = - m_jobs.emplace(id, job_info{admire::job{id, slurm_id}, - std::move(job_resources), - std::move(job_requirements)}); + const auto& [it_job, inserted] = m_jobs.emplace( + id, + admire::internal::job_info{admire::job{id, slurm_id}, + std::move(job_resources), + std::move(job_requirements)}); if(!inserted) { LOGGER_ERROR("{}: Emplace failed", __FUNCTION__); @@ -102,9 +77,9 @@ struct job_manager : scord::utils::singleton { if(const auto it = m_jobs.find(id); it != m_jobs.end()) { const auto& current_job_info = it->second; - it->second = - job_info{current_job_info.job(), std::move(job_resources), - std::move(job_requirements)}; + it->second = admire::internal::job_info{ + current_job_info.job(), std::move(job_resources), + std::move(job_requirements)}; return ADM_SUCCESS; } @@ -112,7 +87,7 @@ struct job_manager : scord::utils::singleton { return ADM_ENOENT; } - tl::expected + tl::expected find(admire::job_id id) { abt::shared_lock lock(m_jobs_mutex); @@ -145,7 +120,7 @@ private: job_manager() = default; mutable abt::shared_mutex m_jobs_mutex; - std::unordered_map m_jobs; + std::unordered_map m_jobs; }; } // namespace scord -- GitLab From 254f470248116d7cee36d61d634f4515b341dd11 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Mon, 17 Oct 2022 18:31:20 +0200 Subject: [PATCH 2/6] job_manager: Store shared_ptr instead of T --- src/scord/job_manager.hpp | 22 ++++++++++++++-------- src/scord/rpc_handlers.cpp | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/scord/job_manager.hpp b/src/scord/job_manager.hpp index c01a9e06..1ea15752 100644 --- a/src/scord/job_manager.hpp +++ b/src/scord/job_manager.hpp @@ -40,7 +40,8 @@ namespace scord { struct job_manager : scord::utils::singleton { - tl::expected + tl::expected, + admire::error_code> create(admire::slurm_job_id slurm_id, admire::job::resources job_resources, admire::job_requirements job_requirements) { @@ -52,9 +53,9 @@ struct job_manager : scord::utils::singleton { if(const auto it = m_jobs.find(id); it == m_jobs.end()) { const auto& [it_job, inserted] = m_jobs.emplace( id, - admire::internal::job_info{admire::job{id, slurm_id}, - std::move(job_resources), - std::move(job_requirements)}); + std::make_shared( + admire::job{id, slurm_id}, std::move(job_resources), + std::move(job_requirements))); if(!inserted) { LOGGER_ERROR("{}: Emplace failed", __FUNCTION__); @@ -77,9 +78,11 @@ struct job_manager : scord::utils::singleton { if(const auto it = m_jobs.find(id); it != m_jobs.end()) { const auto& current_job_info = it->second; - it->second = admire::internal::job_info{ - current_job_info.job(), std::move(job_resources), + const auto new_job_info = admire::internal::job_info{ + current_job_info->job(), std::move(job_resources), std::move(job_requirements)}; + + *it->second = new_job_info; return ADM_SUCCESS; } @@ -87,7 +90,8 @@ struct job_manager : scord::utils::singleton { return ADM_ENOENT; } - tl::expected + tl::expected, + admire::error_code> find(admire::job_id id) { abt::shared_lock lock(m_jobs_mutex); @@ -120,7 +124,9 @@ private: job_manager() = default; mutable abt::shared_mutex m_jobs_mutex; - std::unordered_map m_jobs; + std::unordered_map> + m_jobs; }; } // namespace scord diff --git a/src/scord/rpc_handlers.cpp b/src/scord/rpc_handlers.cpp index 6a4987d6..c99b01b6 100644 --- a/src/scord/rpc_handlers.cpp +++ b/src/scord/rpc_handlers.cpp @@ -104,7 +104,7 @@ ADM_register_job(hg_handle_t h) { const auto rv = jm.create(slurm_id, job_resources, reqs); if(rv) { - const auto& job = rv->job(); + const auto& job = rv.value()->job(); out.op_id = rpc_id; out.retval = ec; out.job = admire::api::convert(job).release(); @@ -119,7 +119,7 @@ ADM_register_job(hg_handle_t h) { LOGGER_INFO("rpc id: {} name: {} to: {} <= " "body: {{retval: {}, job: {}}}", rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)), - ec, rv ? fmt::format("{}", rv->job()) : "none"); + ec, rv ? fmt::format("{}", rv.value()->job()) : "none"); ret = margo_respond(h, &out); assert(ret == HG_SUCCESS); -- GitLab From 7c0bf64f64c4ce77d7cb6520df5930cd91b38449 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Mon, 17 Oct 2022 18:40:51 +0200 Subject: [PATCH 3/6] adhoc_storage_manager: Store shared_ptr instead of T --- src/scord/adhoc_storage_manager.hpp | 26 +++++++++++++++----------- src/scord/rpc_handlers.cpp | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/scord/adhoc_storage_manager.hpp b/src/scord/adhoc_storage_manager.hpp index 7f519f08..1f8ba650 100644 --- a/src/scord/adhoc_storage_manager.hpp +++ b/src/scord/adhoc_storage_manager.hpp @@ -27,6 +27,7 @@ #define SCORD_ADHOC_STORAGE_MANAGER_HPP #include +#include #include #include #include @@ -38,19 +39,20 @@ namespace scord { struct adhoc_storage_manager : scord::utils::singleton { - tl::expected + tl::expected, admire::error_code> create(enum admire::adhoc_storage::type type, const std::string& name, const admire::adhoc_storage::ctx& ctx) { static std::atomic_uint64_t current_id; - admire::job_id id = current_id++; + std::uint64_t id = current_id++; abt::unique_lock lock(m_adhoc_storages_mutex); if(const auto it = m_adhoc_storages.find(id); it == m_adhoc_storages.end()) { const auto& [it_adhoc, inserted] = m_adhoc_storages.emplace( - id, admire::adhoc_storage{type, name, current_id++, ctx}); + id, std::make_shared( + type, name, current_id++, ctx)); if(!inserted) { LOGGER_ERROR("{}: Emplace failed", __FUNCTION__); @@ -72,11 +74,12 @@ struct adhoc_storage_manager : scord::utils::singleton { if(const auto it = m_adhoc_storages.find(id); it != m_adhoc_storages.end()) { - const auto& current_adhoc = it->second; + const auto& current_adhoc_ptr = it->second; - it->second = admire::adhoc_storage{ - current_adhoc.type(), current_adhoc.name(), - current_adhoc.id(), std::move(ctx)}; + const auto new_adhoc = admire::adhoc_storage{ + current_adhoc_ptr->type(), current_adhoc_ptr->name(), + current_adhoc_ptr->id(), std::move(ctx)}; + *it->second = new_adhoc; return ADM_SUCCESS; } @@ -84,8 +87,8 @@ struct adhoc_storage_manager : scord::utils::singleton { return ADM_ENOENT; } - tl::expected - find(admire::job_id id) { + tl::expected, admire::error_code> + find(std::uint64_t id) { abt::shared_lock lock(m_adhoc_storages_mutex); @@ -100,7 +103,7 @@ struct adhoc_storage_manager : scord::utils::singleton { } admire::error_code - remove(admire::job_id id) { + remove(std::uint64_t id) { abt::unique_lock lock(m_adhoc_storages_mutex); @@ -121,7 +124,8 @@ private: adhoc_storage_manager() = default; mutable abt::shared_mutex m_adhoc_storages_mutex; - std::unordered_map m_adhoc_storages; + std::unordered_map> + m_adhoc_storages; }; } // namespace scord diff --git a/src/scord/rpc_handlers.cpp b/src/scord/rpc_handlers.cpp index c99b01b6..3d53f5e1 100644 --- a/src/scord/rpc_handlers.cpp +++ b/src/scord/rpc_handlers.cpp @@ -270,7 +270,7 @@ ADM_register_adhoc_storage(hg_handle_t h) { admire::error_code ec = ADM_SUCCESS; if(rv) { - const auto& adhoc_storage = rv.value(); + const auto& adhoc_storage = *rv.value(); out.op_id = rpc_id; out.retval = ec; out.id = adhoc_storage.id(); -- GitLab From 4291f4e93e33f1d3b90316e5b2806ae301f0e5f5 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 18 Oct 2022 11:50:39 +0200 Subject: [PATCH 4/6] Keep track of adhoc storage instances client jobs * adhoc_storage: Add job client information * adhoc_storage_manager: Now stores adhoc_storage_info records and provides functions to update them. * adhoc_storage_info: New synchronized type keeping updated information about the client job assigned to a adhoc_storage instance * adhoc_storage: The context can now be updated using a new update() function (non-synchronized for now, because it is only ever called via the adhoc_storage_manager). * job_info: Type is now synchronized. * errors: Add ADM_EADHOC_BUSY. Fix missing error messages for ADM_ENOENT and ADM_EEXISTS. * abt/shared_mutex: Is now movable. --- CMakeLists.txt | 1 + src/common/abt_cxx/shared_mutex.hpp | 22 +++++++++ src/common/api/CMakeLists.txt | 2 +- src/common/api/admire_types.h | 3 +- src/common/api/admire_types.hpp | 34 +++++-------- src/common/api/internal_types.hpp | 46 +++++++++++++++++ src/common/api/types.cpp | 11 +++++ src/lib/errors.c | 4 ++ src/scord/adhoc_storage_manager.hpp | 50 ++++++++++++++----- src/scord/job_manager.hpp | 11 +++-- src/scord/rpc_handlers.cpp | 76 +++++++++++++++++++---------- 11 files changed, 194 insertions(+), 66 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf1a30c9..5c2feca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,7 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(fmt) +set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) ### spdlog: required for logging message(STATUS "[${PROJECT_NAME}] Downloading and building spdlog") diff --git a/src/common/abt_cxx/shared_mutex.hpp b/src/common/abt_cxx/shared_mutex.hpp index 59964fb2..1ec4b230 100644 --- a/src/common/abt_cxx/shared_mutex.hpp +++ b/src/common/abt_cxx/shared_mutex.hpp @@ -22,6 +22,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later *****************************************************************************/ +#include #include #include #include @@ -59,9 +60,30 @@ public: // copy constructor and copy assignment operator are disabled shared_mutex(const shared_mutex&) = delete; + shared_mutex(shared_mutex&& rhs) noexcept { + m_lock = rhs.m_lock; + rhs.m_lock = ABT_RWLOCK_NULL; + } + shared_mutex& operator=(const shared_mutex&) = delete; + shared_mutex& + operator=(shared_mutex&& other) noexcept { + + if(this == &other) { + return *this; + } + + [[maybe_unused]] const auto ret = ABT_rwlock_free(&m_lock); + assert(ret == ABT_SUCCESS); + m_lock = other.m_lock; + other.m_lock = ABT_RWLOCK_NULL; + + return *this; + } + + // Exclusive ownership void diff --git a/src/common/api/CMakeLists.txt b/src/common/api/CMakeLists.txt index 97365630..b4c84785 100644 --- a/src/common/api/CMakeLists.txt +++ b/src/common/api/CMakeLists.txt @@ -30,7 +30,7 @@ target_sources(_api_types PUBLIC admire_types.h admire_types.hpp PRIVATE target_include_directories(_api_types PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(_api_types PRIVATE - Margo::Margo common::logger PUBLIC fmt::fmt) + Margo::Margo common::logger PUBLIC fmt::fmt common::abt_cxx) set_property(TARGET _api_types PROPERTY POSITION_INDEPENDENT_CODE ON) diff --git a/src/common/api/admire_types.h b/src/common/api/admire_types.h index cfb056a7..40de25e7 100644 --- a/src/common/api/admire_types.h +++ b/src/common/api/admire_types.h @@ -46,9 +46,10 @@ typedef enum { ADM_ESNAFU, ADM_EBADARGS, ADM_ENOMEM, - ADM_EOTHER, ADM_EEXISTS, ADM_ENOENT, + ADM_EADHOC_BUSY, + ADM_EOTHER, ADM_ERR_MAX = 512 } ADM_return_t; diff --git a/src/common/api/admire_types.hpp b/src/common/api/admire_types.hpp index 81bea1fd..ce9859b9 100644 --- a/src/common/api/admire_types.hpp +++ b/src/common/api/admire_types.hpp @@ -44,6 +44,7 @@ using transfer_id = std::uint64_t; namespace internal { struct job_info; +struct adhoc_storage_info; } // namespace internal struct server { @@ -356,6 +357,9 @@ struct adhoc_storage : public storage { std::shared_ptr context() const final; + void + update(admire::adhoc_storage::ctx new_ctx); + private: class impl; std::unique_ptr m_pimpl; @@ -456,15 +460,18 @@ struct fmt::formatter : formatter { case ADM_ENOMEM: name = "ADM_ENOMEM"; break; - case ADM_EOTHER: - name = "ADM_EOTHER"; - break; case ADM_EEXISTS: name = "ADM_EEXISTS"; break; case ADM_ENOENT: name = "ADM_ENOENT"; break; + case ADM_EADHOC_BUSY: + name = "ADM_EADHOC_BUSY"; + break; + case ADM_EOTHER: + name = "ADM_EOTHER"; + break; default: break; } @@ -640,28 +647,13 @@ struct fmt::formatter> } }; -template <> -struct fmt::formatter> - : formatter { +template +struct fmt::formatter> : formatter { // parse is inherited from formatter. template auto - format(const std::optional& v, FormatContext& ctx) const { - return formatter::format( - v ? std::to_string(v.value()) : "none", ctx); - } -}; - -template <> -struct fmt::formatter> - : formatter { - - // parse is inherited from formatter. - template - auto - format(const std::optional& v, - FormatContext& ctx) const { + format(const std::optional& v, FormatContext& ctx) const { return formatter::format( v ? fmt::format("{}", v.value()) : "none", ctx); } diff --git a/src/common/api/internal_types.hpp b/src/common/api/internal_types.hpp index 1a6dac5d..a1c1fdde 100644 --- a/src/common/api/internal_types.hpp +++ b/src/common/api/internal_types.hpp @@ -26,10 +26,13 @@ #ifndef SCORD_INTERNAL_TYPES_HPP #define SCORD_INTERNAL_TYPES_HPP +#include + namespace admire::internal { struct job_info { explicit job_info(admire::job job) : m_job(std::move(job)) {} + job_info(admire::job job, admire::job::resources resources, admire::job_requirements requirements) : m_job(std::move(job)), m_resources(std::move(resources)), @@ -55,6 +58,49 @@ struct job_info { std::optional m_requirements; }; +struct adhoc_storage_info { + + explicit adhoc_storage_info(admire::adhoc_storage adhoc_storage) + : m_adhoc_storage(std::move(adhoc_storage)) {} + + admire::adhoc_storage + adhoc_storage() const { + return m_adhoc_storage; + } + + admire::error_code + add_client_info(std::shared_ptr job_info) { + + scord::abt::unique_lock lock(m_info_mutex); + + if(m_client_info) { + LOGGER_ERROR("adhoc storage {} already has a client", + m_adhoc_storage.id()); + return ADM_EADHOC_BUSY; + } + + m_client_info = std::move(job_info); + + return ADM_SUCCESS; + } + + void + remove_client_info() { + scord::abt::unique_lock lock(m_info_mutex); + m_client_info.reset(); + } + + std::shared_ptr + client_info() const { + scord::abt::shared_lock lock(m_info_mutex); + return m_client_info; + } + + admire::adhoc_storage m_adhoc_storage; + std::shared_ptr m_client_info; + mutable scord::abt::shared_mutex m_info_mutex; +}; + } // namespace admire::internal #endif // SCORD_INTERNAL_TYPES_HPP diff --git a/src/common/api/types.cpp b/src/common/api/types.cpp index 5f1e5977..3e5b35f4 100644 --- a/src/common/api/types.cpp +++ b/src/common/api/types.cpp @@ -1371,6 +1371,11 @@ public: return m_ctx; } + void + update(adhoc_storage::ctx new_ctx) { + m_ctx = std::move(new_ctx); + } + private: std::uint64_t m_id; adhoc_storage::ctx m_ctx; @@ -1426,6 +1431,12 @@ std::shared_ptr adhoc_storage::context() const { return std::make_shared(m_pimpl->context()); } + +void +adhoc_storage::update(admire::adhoc_storage::ctx new_ctx) { + return m_pimpl->update(std::move(new_ctx)); +} + adhoc_storage::~adhoc_storage() = default; pfs_storage::ctx::ctx(std::filesystem::path mount_point) diff --git a/src/lib/errors.c b/src/lib/errors.c index 87985cae..3a57c926 100644 --- a/src/lib/errors.c +++ b/src/lib/errors.c @@ -29,9 +29,13 @@ const char* const adm_errlist[ADM_ERR_MAX + 1] = { [ADM_ESNAFU] = "Internal error", [ADM_EBADARGS] = "Bad arguments", [ADM_ENOMEM] = "Cannot allocate memory", + [ADM_EEXISTS] = "Entity already exists", + [ADM_ENOENT] = "Entity does not exist", + [ADM_EADHOC_BUSY] = "Adhoc storage already in use", [ADM_EOTHER] = "Undetermined error", + /* fallback */ [ADM_ERR_MAX] = "Unknown error", diff --git a/src/scord/adhoc_storage_manager.hpp b/src/scord/adhoc_storage_manager.hpp index 1f8ba650..29081561 100644 --- a/src/scord/adhoc_storage_manager.hpp +++ b/src/scord/adhoc_storage_manager.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -39,7 +40,8 @@ namespace scord { struct adhoc_storage_manager : scord::utils::singleton { - tl::expected, admire::error_code> + tl::expected, + admire::error_code> create(enum admire::adhoc_storage::type type, const std::string& name, const admire::adhoc_storage::ctx& ctx) { @@ -51,8 +53,9 @@ struct adhoc_storage_manager : scord::utils::singleton { if(const auto it = m_adhoc_storages.find(id); it == m_adhoc_storages.end()) { const auto& [it_adhoc, inserted] = m_adhoc_storages.emplace( - id, std::make_shared( - type, name, current_id++, ctx)); + id, std::make_shared( + admire::adhoc_storage{type, name, current_id++, + ctx})); if(!inserted) { LOGGER_ERROR("{}: Emplace failed", __FUNCTION__); @@ -67,19 +70,18 @@ struct adhoc_storage_manager : scord::utils::singleton { } admire::error_code - update(std::uint64_t id, admire::adhoc_storage::ctx ctx) { + update(std::uint64_t id, admire::adhoc_storage::ctx new_ctx) { abt::unique_lock lock(m_adhoc_storages_mutex); if(const auto it = m_adhoc_storages.find(id); it != m_adhoc_storages.end()) { - const auto& current_adhoc_ptr = it->second; + const auto current_adhoc_info = it->second; + auto tmp_adhoc = current_adhoc_info->adhoc_storage(); + tmp_adhoc.update(std::move(new_ctx)); - const auto new_adhoc = admire::adhoc_storage{ - current_adhoc_ptr->type(), current_adhoc_ptr->name(), - current_adhoc_ptr->id(), std::move(ctx)}; - *it->second = new_adhoc; + *it->second = admire::internal::adhoc_storage_info{tmp_adhoc}; return ADM_SUCCESS; } @@ -87,7 +89,8 @@ struct adhoc_storage_manager : scord::utils::singleton { return ADM_ENOENT; } - tl::expected, admire::error_code> + tl::expected, + admire::error_code> find(std::uint64_t id) { abt::shared_lock lock(m_adhoc_storages_mutex); @@ -119,12 +122,37 @@ struct adhoc_storage_manager : scord::utils::singleton { return ADM_ENOENT; } + admire::error_code + add_client_info(std::uint64_t adhoc_id, + std::shared_ptr job_info) { + + if(auto am_result = find(adhoc_id); am_result.has_value()) { + const auto adhoc_storage_info = am_result.value(); + return adhoc_storage_info->add_client_info(std::move(job_info)); + } + + return ADM_ENOENT; + } + + admire::error_code + remove_client_info(std::uint64_t adhoc_id) { + if(auto am_result = find(adhoc_id); am_result.has_value()) { + const auto adhoc_storage_info = *am_result; + adhoc_storage_info->remove_client_info(); + return ADM_SUCCESS; + } + + return ADM_ENOENT; + } + + private: friend class scord::utils::singleton; adhoc_storage_manager() = default; mutable abt::shared_mutex m_adhoc_storages_mutex; - std::unordered_map> + std::unordered_map> m_adhoc_storages; }; diff --git a/src/scord/job_manager.hpp b/src/scord/job_manager.hpp index 1ea15752..186434e6 100644 --- a/src/scord/job_manager.hpp +++ b/src/scord/job_manager.hpp @@ -104,19 +104,20 @@ struct job_manager : scord::utils::singleton { return tl::make_unexpected(ADM_ENOENT); } - admire::error_code + tl::expected, + admire::error_code> remove(admire::job_id id) { abt::unique_lock lock(m_jobs_mutex); - if(m_jobs.count(id) != 0) { - m_jobs.erase(id); - return ADM_SUCCESS; + if(const auto it = m_jobs.find(id); it != m_jobs.end()) { + auto nh = m_jobs.extract(it); + return nh.mapped(); } LOGGER_ERROR("Job '{}' was not registered or was already deleted", id); - return ADM_ENOENT; + return tl::make_unexpected(ADM_ENOENT); } private: diff --git a/src/scord/rpc_handlers.cpp b/src/scord/rpc_handlers.cpp index 3d53f5e1..fdf084af 100644 --- a/src/scord/rpc_handlers.cpp +++ b/src/scord/rpc_handlers.cpp @@ -99,27 +99,37 @@ ADM_register_job(hg_handle_t h) { job_resources, reqs, slurm_id); admire::error_code ec = ADM_SUCCESS; - + std::optional out_job; auto& jm = scord::job_manager::instance(); - const auto rv = jm.create(slurm_id, job_resources, reqs); - if(rv) { - const auto& job = rv.value()->job(); - out.op_id = rpc_id; - out.retval = ec; - out.job = admire::api::convert(job).release(); + if(const auto jm_result = jm.create(slurm_id, job_resources, reqs); + jm_result.has_value()) { + + const auto& job_info = jm_result.value(); + + // if the job requires an adhoc storage instance, inform the appropriate + // adhoc_storage instance (if registered) + if(reqs.adhoc_storage()) { + const auto adhoc_id = reqs.adhoc_storage()->id(); + auto& adhoc_manager = scord::adhoc_storage_manager::instance(); + ec = adhoc_manager.add_client_info(adhoc_id, job_info); + } + + out_job = job_info->job(); } else { LOGGER_ERROR("rpc id: {} error_msg: \"Error creating job: {}\"", rpc_id, - rv.error()); - out.op_id = rpc_id; - out.retval = rv.error(); - out.job = nullptr; + jm_result.error()); + ec = jm_result.error(); } + out.op_id = rpc_id; + out.retval = ec; + out.job = out_job ? admire::api::convert(*out_job).release() : nullptr; + LOGGER_INFO("rpc id: {} name: {} to: {} <= " "body: {{retval: {}, job: {}}}", rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)), - ec, rv ? fmt::format("{}", rv.value()->job()) : "none"); + ec, out_job); ret = margo_respond(h, &out); assert(ret == HG_SUCCESS); @@ -211,12 +221,24 @@ ADM_remove_job(hg_handle_t h) { rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)), job); + admire::error_code ec = ADM_SUCCESS; auto& jm = scord::job_manager::instance(); - const auto ec = jm.remove(job.id()); + const auto jm_result = jm.remove(job.id()); - if(ec != ADM_SUCCESS) { + if(jm_result) { + // if the job was using an adhoc storage instance, inform the + // appropriate adhoc_storage that the job is no longer its client + const auto& job_info = jm_result.value(); + + if(const auto adhoc_storage = job_info->requirements()->adhoc_storage(); + adhoc_storage.has_value()) { + auto& adhoc_manager = scord::adhoc_storage_manager::instance(); + ec = adhoc_manager.remove_client_info(adhoc_storage->id()); + } + } else { LOGGER_ERROR("rpc id: {} error_msg: \"Error removing job: {}\"", rpc_id, - ec); + job.id()); + ec = jm_result.error(); } out.op_id = rpc_id; @@ -264,25 +286,25 @@ ADM_register_adhoc_storage(hg_handle_t h) { rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)), name, type, ctx); - auto& adhoc_manager = scord::adhoc_storage_manager::instance(); - const auto rv = adhoc_manager.create(type, name, ctx); - admire::error_code ec = ADM_SUCCESS; + std::uint64_t out_adhoc_id = 0; + auto& adhoc_manager = scord::adhoc_storage_manager::instance(); - if(rv) { - const auto& adhoc_storage = *rv.value(); - out.op_id = rpc_id; - out.retval = ec; - out.id = adhoc_storage.id(); + if(const auto am_result = adhoc_manager.create(type, name, ctx); + am_result.has_value()) { + const auto& adhoc_storage_info = am_result.value(); + out_adhoc_id = adhoc_storage_info->adhoc_storage().id(); } else { LOGGER_ERROR("rpc id: {} error_msg: \"Error creating adhoc_storage: " "{}\"", - rpc_id, rv.error()); - out.op_id = rpc_id; - out.retval = ec; - out.id = 0; + rpc_id, am_result.error()); + ec = am_result.error(); } + out.op_id = rpc_id; + out.retval = ec; + out.id = out_adhoc_id; + LOGGER_INFO("rpc id: {} name: {} to: {} => " "body: {{retval: {}, id: {}}}", rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)), -- GitLab From 7e9d1bd09ea098c83c37fde9e5049808c463e429 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 18 Oct 2022 20:18:02 +0200 Subject: [PATCH 5/6] adhoc_storage: Fix bug with shadowed id Closes #88 --- src/common/api/admire_types.hpp | 6 ------ src/common/api/types.cpp | 23 +---------------------- src/scord/adhoc_storage_manager.hpp | 3 +-- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/common/api/admire_types.hpp b/src/common/api/admire_types.hpp index ce9859b9..2f9b3455 100644 --- a/src/common/api/admire_types.hpp +++ b/src/common/api/admire_types.hpp @@ -348,12 +348,6 @@ struct adhoc_storage : public storage { operator=(adhoc_storage&&) noexcept; ~adhoc_storage() override; - const std::uint64_t& - id() const; - - std::uint64_t& - id(); - std::shared_ptr context() const final; diff --git a/src/common/api/types.cpp b/src/common/api/types.cpp index 3e5b35f4..1eee0ec0 100644 --- a/src/common/api/types.cpp +++ b/src/common/api/types.cpp @@ -1347,7 +1347,7 @@ adhoc_storage::ctx::should_flush() const { class adhoc_storage::impl { public: - explicit impl(adhoc_storage::ctx ctx) : m_id(), m_ctx(std::move(ctx)) {} + explicit impl(adhoc_storage::ctx ctx) : m_ctx(std::move(ctx)) {} impl(const impl& rhs) = default; impl(impl&& rhs) = default; impl& @@ -1356,16 +1356,6 @@ public: operator=(impl&&) noexcept = default; ~impl() = default; - const std::uint64_t& - id() const { - return m_id; - } - - std::uint64_t& - id() { - return m_id; - } - adhoc_storage::ctx context() const { return m_ctx; @@ -1377,7 +1367,6 @@ public: } private: - std::uint64_t m_id; adhoc_storage::ctx m_ctx; }; @@ -1417,16 +1406,6 @@ adhoc_storage::operator=(const adhoc_storage& other) noexcept { adhoc_storage& adhoc_storage::operator=(adhoc_storage&&) noexcept = default; -const std::uint64_t& -adhoc_storage::id() const { - return m_pimpl->id(); -} - -std::uint64_t& -adhoc_storage::id() { - return m_pimpl->id(); -} - std::shared_ptr adhoc_storage::context() const { return std::make_shared(m_pimpl->context()); diff --git a/src/scord/adhoc_storage_manager.hpp b/src/scord/adhoc_storage_manager.hpp index 29081561..78b22ba9 100644 --- a/src/scord/adhoc_storage_manager.hpp +++ b/src/scord/adhoc_storage_manager.hpp @@ -54,8 +54,7 @@ struct adhoc_storage_manager : scord::utils::singleton { it == m_adhoc_storages.end()) { const auto& [it_adhoc, inserted] = m_adhoc_storages.emplace( id, std::make_shared( - admire::adhoc_storage{type, name, current_id++, - ctx})); + admire::adhoc_storage{type, name, id, ctx})); if(!inserted) { LOGGER_ERROR("{}: Emplace failed", __FUNCTION__); -- GitLab From c5de29133f6fc9e06305a4314e092e50368aeef7 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 18 Oct 2022 20:21:36 +0200 Subject: [PATCH 6/6] examples: Ensure ADM_remove_job is called Print error messages to stderr instead of stdout Closes #86 --- examples/c/ADM_cancel_transfer.c | 28 ++++++++++++------ examples/c/ADM_connect_data_operation.c | 18 ++++++++---- examples/c/ADM_define_data_operation.c | 21 +++++++++----- examples/c/ADM_deploy_adhoc_storage.c | 11 +++---- examples/c/ADM_finalize_data_operation.c | 22 +++++++++----- examples/c/ADM_get_pending_transfers.c | 22 +++++++++----- examples/c/ADM_get_qos_constraints.c | 21 +++++++++----- examples/c/ADM_get_statistics.c | 23 ++++++++++----- examples/c/ADM_get_transfer_priority.c | 27 ++++++++++------- .../c/ADM_link_transfer_to_data_operation.c | 29 ++++++++++++------- examples/c/ADM_register_adhoc_storage.c | 6 ++-- examples/c/ADM_register_job.c | 12 +++++--- examples/c/ADM_register_pfs_storage.c | 5 ++-- examples/c/ADM_remove_adhoc_storage.c | 10 ++++--- examples/c/ADM_remove_job.c | 21 +++++++++----- examples/c/ADM_remove_pfs_storage.c | 10 ++++--- examples/c/ADM_set_dataset_information.c | 20 ++++++++----- examples/c/ADM_set_io_resources.c | 22 +++++++++----- examples/c/ADM_set_qos_constraints.c | 20 ++++++++----- examples/c/ADM_set_transfer_priority.c | 27 ++++++++++------- examples/c/ADM_transfer_datasets.c | 22 +++++++++----- examples/c/ADM_update_adhoc_storage.c | 11 +++---- examples/c/ADM_update_job.c | 19 ++++++++---- examples/c/ADM_update_pfs_storage.c | 10 ++++--- 24 files changed, 276 insertions(+), 161 deletions(-) diff --git a/examples/c/ADM_cancel_transfer.c b/examples/c/ADM_cancel_transfer.c index ce046dc9..478f3ed3 100644 --- a/examples/c/ADM_cancel_transfer.c +++ b/examples/c/ADM_cancel_transfer.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,8 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_adhoc_storage() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_register_adhoc_storage() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -89,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t* sources = NULL; @@ -107,8 +112,10 @@ main(int argc, char* argv[]) { targets_len, limits, limits_len, mapping, &tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_transfer_datasets() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_transfer_datasets() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -116,8 +123,10 @@ main(int argc, char* argv[]) { ret = ADM_cancel_transfer(server, job, tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_cancel_transfer() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_cancel_transfer() remote procedure not completed " + "successfully\n, %s", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -126,6 +135,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: + ADM_remove_job(server, job); ADM_server_destroy(server); destroy_datasets(inputs, NINPUTS); destroy_datasets(outputs, NOUTPUTS); diff --git a/examples/c/ADM_connect_data_operation.c b/examples/c/ADM_connect_data_operation.c index 230ed0b1..8b6bf16f 100644 --- a/examples/c/ADM_connect_data_operation.c +++ b/examples/c/ADM_connect_data_operation.c @@ -71,9 +71,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } exit_status = EXIT_SUCCESS; @@ -103,9 +107,10 @@ main(int argc, char* argv[]) { if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_connect_data_operation() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -122,6 +127,7 @@ cleanup: ADM_dataset_destroy(outputs[i]); } + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_define_data_operation.c b/examples/c/ADM_define_data_operation.c index dc4a95f5..0c9520ab 100644 --- a/examples/c/ADM_define_data_operation.c +++ b/examples/c/ADM_define_data_operation.c @@ -46,7 +46,7 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -76,9 +76,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,9 +92,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_data_operation_t op; @@ -103,9 +107,10 @@ main(int argc, char* argv[]) { ret = ADM_define_data_operation(server, job, path, &op); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_define_data_operation() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -114,7 +119,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_deploy_adhoc_storage.c b/examples/c/ADM_deploy_adhoc_storage.c index 810043ce..05d1ad4c 100644 --- a/examples/c/ADM_deploy_adhoc_storage.c +++ b/examples/c/ADM_deploy_adhoc_storage.c @@ -67,9 +67,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -80,9 +81,10 @@ main(int argc, char* argv[]) { ret = ADM_deploy_adhoc_storage(server, adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_deploy_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,7 +93,6 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_finalize_data_operation.c b/examples/c/ADM_finalize_data_operation.c index 1e0f05f9..9b125281 100644 --- a/examples/c/ADM_finalize_data_operation.c +++ b/examples/c/ADM_finalize_data_operation.c @@ -46,7 +46,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -72,9 +72,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,10 +92,14 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } + ADM_data_operation_t op; const char* path = "/tmpxxxxx"; @@ -104,9 +109,10 @@ main(int argc, char* argv[]) { ret = ADM_finalize_data_operation(server, job, op, &status); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_finalize_data_operation() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -115,7 +121,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_get_pending_transfers.c b/examples/c/ADM_get_pending_transfers.c index 7a2e602c..d0c49c43 100644 --- a/examples/c/ADM_get_pending_transfers.c +++ b/examples/c/ADM_get_pending_transfers.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,18 +91,23 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } + ADM_transfer_t** tx = NULL; ret = ADM_get_pending_transfers(server, job, tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_get_pending_transfers() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -110,7 +116,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_get_qos_constraints.c b/examples/c/ADM_get_qos_constraints.c index 296151af..bd9ba065 100644 --- a/examples/c/ADM_get_qos_constraints.c +++ b/examples/c/ADM_get_qos_constraints.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -71,9 +71,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_qos_entity_t entity = NULL; @@ -101,9 +105,10 @@ main(int argc, char* argv[]) { ret = ADM_get_qos_constraints(server, job, entity, &limits); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_get_qos_constraints() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -112,7 +117,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_get_statistics.c b/examples/c/ADM_get_statistics.c index 431b2997..17f93842 100644 --- a/examples/c/ADM_get_statistics.c +++ b/examples/c/ADM_get_statistics.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -71,9 +71,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,17 +91,23 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } + ADM_job_stats_t* stats = NULL; ret = ADM_get_statistics(server, job, &stats); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_get_statistics() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_get_statistics() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -109,7 +116,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_get_transfer_priority.c b/examples/c/ADM_get_transfer_priority.c index b00a6af2..30593254 100644 --- a/examples/c/ADM_get_transfer_priority.c +++ b/examples/c/ADM_get_transfer_priority.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t* sources = NULL; @@ -108,8 +112,10 @@ main(int argc, char* argv[]) { targets_len, limits, limits_len, mapping, &tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_transfer_datasets() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_transfer_datasets() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -118,9 +124,10 @@ main(int argc, char* argv[]) { ret = ADM_get_transfer_priority(server, job, tx, &priority); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_get_transfer_priority() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -129,7 +136,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_link_transfer_to_data_operation.c b/examples/c/ADM_link_transfer_to_data_operation.c index 3098c25c..7765f5cf 100644 --- a/examples/c/ADM_link_transfer_to_data_operation.c +++ b/examples/c/ADM_link_transfer_to_data_operation.c @@ -46,7 +46,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -72,9 +72,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,9 +92,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_data_operation_t op; @@ -114,8 +118,10 @@ main(int argc, char* argv[]) { if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_transfer_datasets() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_transfer_datasets() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -125,9 +131,10 @@ main(int argc, char* argv[]) { ret = ADM_link_transfer_to_data_operation(server, job, op, tx, should_stream, args); if(ret != ADM_SUCCESS) { - fprintf(stdout, - "ADM_link_transfer_to_data_operation() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_link_transfer_to_data_operation() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -137,7 +144,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_register_adhoc_storage.c b/examples/c/ADM_register_adhoc_storage.c index be126cce..70888670 100644 --- a/examples/c/ADM_register_adhoc_storage.c +++ b/examples/c/ADM_register_adhoc_storage.c @@ -67,9 +67,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -78,7 +79,6 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_register_job.c b/examples/c/ADM_register_job.c index dc248151..09147bd6 100644 --- a/examples/c/ADM_register_job.c +++ b/examples/c/ADM_register_job.c @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,8 +91,10 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -114,6 +117,7 @@ cleanup: ADM_job_requirements_destroy(reqs); + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_register_pfs_storage.c b/examples/c/ADM_register_pfs_storage.c index 149631a4..d5c86e0b 100644 --- a/examples/c/ADM_register_pfs_storage.c +++ b/examples/c/ADM_register_pfs_storage.c @@ -60,9 +60,10 @@ main(int argc, char* argv[]) { ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_pfs_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } diff --git a/examples/c/ADM_remove_adhoc_storage.c b/examples/c/ADM_remove_adhoc_storage.c index 1818f555..98a74596 100644 --- a/examples/c/ADM_remove_adhoc_storage.c +++ b/examples/c/ADM_remove_adhoc_storage.c @@ -67,9 +67,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -80,9 +81,10 @@ main(int argc, char* argv[]) { ret = ADM_remove_adhoc_storage(server, adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_remove_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } diff --git a/examples/c/ADM_remove_job.c b/examples/c/ADM_remove_job.c index 9842c5c4..219cff71 100644 --- a/examples/c/ADM_remove_job.c +++ b/examples/c/ADM_remove_job.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,16 +91,21 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ret = ADM_remove_job(server, job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_remove_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_remove_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -108,7 +114,6 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_remove_pfs_storage.c b/examples/c/ADM_remove_pfs_storage.c index b24b4178..ee2638b9 100644 --- a/examples/c/ADM_remove_pfs_storage.c +++ b/examples/c/ADM_remove_pfs_storage.c @@ -46,9 +46,10 @@ main(int argc, char* argv[]) { ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_pfs_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -59,9 +60,10 @@ main(int argc, char* argv[]) { ret = ADM_remove_pfs_storage(server, pfs_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_remove_pfs_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } diff --git a/examples/c/ADM_set_dataset_information.c b/examples/c/ADM_set_dataset_information.c index 235d5986..4dd160da 100644 --- a/examples/c/ADM_set_dataset_information.c +++ b/examples/c/ADM_set_dataset_information.c @@ -46,7 +46,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -72,9 +72,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,9 +92,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t target = NULL; @@ -101,9 +105,10 @@ main(int argc, char* argv[]) { ret = ADM_set_dataset_information(server, job, target, info); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_set_dataset_information() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -113,6 +118,7 @@ main(int argc, char* argv[]) { cleanup: + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_set_io_resources.c b/examples/c/ADM_set_io_resources.c index 2543d37d..21d0c5bd 100644 --- a/examples/c/ADM_set_io_resources.c +++ b/examples/c/ADM_set_io_resources.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -71,9 +71,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_storage_t tier = NULL; @@ -100,8 +104,10 @@ main(int argc, char* argv[]) { ret = ADM_set_io_resources(server, job, tier, resources); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_set_io_resources() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_set_io_resources() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -110,7 +116,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_set_qos_constraints.c b/examples/c/ADM_set_qos_constraints.c index dd87df90..0cfed1bf 100644 --- a/examples/c/ADM_set_qos_constraints.c +++ b/examples/c/ADM_set_qos_constraints.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_qos_entity_t entity = NULL; @@ -101,9 +105,10 @@ main(int argc, char* argv[]) { ret = ADM_set_qos_constraints(server, job, entity, limit); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_set_qos_constraints() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -113,6 +118,7 @@ main(int argc, char* argv[]) { cleanup: + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_set_transfer_priority.c b/examples/c/ADM_set_transfer_priority.c index 9e0629d8..62ce6241 100644 --- a/examples/c/ADM_set_transfer_priority.c +++ b/examples/c/ADM_set_transfer_priority.c @@ -45,7 +45,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t* sources = NULL; @@ -108,8 +112,10 @@ main(int argc, char* argv[]) { targets_len, limits, limits_len, mapping, &tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_transfer_datasets() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_transfer_datasets() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -118,9 +124,10 @@ main(int argc, char* argv[]) { ret = ADM_set_transfer_priority(server, job, tx, incr); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_set_transfer_priority() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -129,7 +136,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_transfer_datasets.c b/examples/c/ADM_transfer_datasets.c index 6c0906a2..d7b2ce66 100644 --- a/examples/c/ADM_transfer_datasets.c +++ b/examples/c/ADM_transfer_datasets.c @@ -48,7 +48,7 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_job_t job; + ADM_job_t job = NULL; ADM_node_t* job_nodes = prepare_nodes(NJOB_NODES); assert(job_nodes); ADM_node_t* adhoc_nodes = prepare_nodes(NADHOC_NODES); @@ -78,9 +78,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -93,9 +94,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t* sources = prepare_datasets("source-dataset-%d", NSOURCES); @@ -111,8 +115,10 @@ main(int argc, char* argv[]) { NTARGETS, limits, NLIMITS, mapping, &tx); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_transfer_datasets() remote procedure not " - "completed successfully\n"); + fprintf(stderr, + "ADM_transfer_datasets() remote procedure not " + "completed successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -121,7 +127,7 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_update_adhoc_storage.c b/examples/c/ADM_update_adhoc_storage.c index 7cb64a29..b20bf515 100644 --- a/examples/c/ADM_update_adhoc_storage.c +++ b/examples/c/ADM_update_adhoc_storage.c @@ -67,9 +67,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -80,9 +81,10 @@ main(int argc, char* argv[]) { ret = ADM_update_adhoc_storage(server, ctx, adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_update_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -91,7 +93,6 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_update_job.c b/examples/c/ADM_update_job.c index afeb521c..a9ecf2c1 100644 --- a/examples/c/ADM_update_job.c +++ b/examples/c/ADM_update_job.c @@ -75,9 +75,10 @@ main(int argc, char* argv[]) { server, name, ADM_STORAGE_GEKKOFS, ctx, &adhoc_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_adhoc_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -90,9 +91,12 @@ main(int argc, char* argv[]) { ret = ADM_register_job(server, job_resources, reqs, slurm_job_id, &job); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_register_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_register_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; + goto cleanup; } ADM_dataset_t new_inputs[NINPUTS]; @@ -121,8 +125,10 @@ main(int argc, char* argv[]) { ret = ADM_update_job(server, job, job_resources, new_reqs); if(ret != ADM_SUCCESS) { - fprintf(stdout, "ADM_update_job() remote procedure not completed " - "successfully\n"); + fprintf(stderr, + "ADM_update_job() remote procedure not completed " + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -140,6 +146,7 @@ cleanup: ADM_dataset_destroy(outputs[i]); } + ADM_remove_job(server, job); ADM_server_destroy(server); exit(exit_status); } diff --git a/examples/c/ADM_update_pfs_storage.c b/examples/c/ADM_update_pfs_storage.c index 96a95afa..90d0cf75 100644 --- a/examples/c/ADM_update_pfs_storage.c +++ b/examples/c/ADM_update_pfs_storage.c @@ -46,9 +46,10 @@ main(int argc, char* argv[]) { ADM_return_t ret = ADM_register_pfs_storage(server, ctx, &pfs_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_register_pfs_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } @@ -59,9 +60,10 @@ main(int argc, char* argv[]) { ret = ADM_update_pfs_storage(server, ctx, pfs_storage); if(ret != ADM_SUCCESS) { - fprintf(stdout, + fprintf(stderr, "ADM_update_pfs_storage() remote procedure not completed " - "successfully\n"); + "successfully: %s\n", + ADM_strerror(ret)); exit_status = EXIT_FAILURE; goto cleanup; } -- GitLab