diff --git a/examples/cxx/ADM_remove_job.cpp b/examples/cxx/ADM_remove_job.cpp index 0bd8fb87884603d49e711abaa515c2d34de625e7..0f320fae317d28b0e300c3d7f18c56029849f528 100644 --- a/examples/cxx/ADM_remove_job.cpp +++ b/examples/cxx/ADM_remove_job.cpp @@ -24,7 +24,12 @@ #include #include +#include "common.hpp" +#define NJOB_NODES 50 +#define NADHOC_NODES 25 +#define NINPUTS 10 +#define NOUTPUTS 5 int main(int argc, char* argv[]) { @@ -37,16 +42,40 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - admire::job job{42, 42}; + const auto job_nodes = prepare_nodes(NJOB_NODES); + const auto adhoc_nodes = prepare_nodes(NADHOC_NODES); + const auto inputs = prepare_datasets("input-dataset-{}", NINPUTS); + const auto outputs = prepare_datasets("output-dataset-{}", NOUTPUTS); + + std::string name = "adhoc_storage_42"; + const auto adhoc_storage_ctx = admire::adhoc_storage::ctx{ + admire::adhoc_storage::execution_mode::separate_new, + admire::adhoc_storage::access_type::read_write, + admire::adhoc_storage::resources{adhoc_nodes}, 100, false}; try { - [[maybe_unused]] const auto ret = admire::remove_job(server, job); + + const auto adhoc_storage = admire::register_adhoc_storage( + server, name, admire::storage::type::gekkofs, + adhoc_storage_ctx); + + admire::job_requirements reqs(inputs, outputs, adhoc_storage); + + [[maybe_unused]] const auto job = admire::register_job( + server, admire::job::resources{job_nodes}, reqs, 0); + + // do something with job + + fmt::print(stdout, "ADM_register_job() remote procedure completed " + "successfully\n"); + + admire::remove_job(server, job); + fmt::print(stdout, "ADM_remove_job() remote procedure completed " "successfully\n"); exit(EXIT_SUCCESS); } catch(const std::exception& e) { - fmt::print(stdout, "ADM_remove_job() remote procedure not completed " - "successfully\n"); + fmt::print(stderr, "FATAL: example failed: {}\n", e.what()); exit(EXIT_FAILURE); } } diff --git a/examples/cxx/ADM_update_adhoc_storage.cpp b/examples/cxx/ADM_update_adhoc_storage.cpp index a2905446f6500161c9e1a8535aaacf3f8171712c..cf1116daea430b082f8d1aa2c49364a11cb4d49a 100644 --- a/examples/cxx/ADM_update_adhoc_storage.cpp +++ b/examples/cxx/ADM_update_adhoc_storage.cpp @@ -63,22 +63,15 @@ main(int argc, char* argv[]) { server, name, admire::storage::type::gekkofs, adhoc_storage_ctx); - const auto ret = admire::update_adhoc_storage(server, adhoc_storage, - new_adhoc_storage_ctx); - - if(!ret) { - fmt::print(stderr, "FATAL: ADM_update_adhoc_storage() failed: {}\n", - ret.message()); - exit(EXIT_FAILURE); - } + admire::update_adhoc_storage(server, adhoc_storage, + new_adhoc_storage_ctx); fmt::print(stdout, "ADM_update_adhoc_storage() remote procedure completed " "successfully\n"); exit(EXIT_SUCCESS); } catch(const std::exception& e) { - fmt::print(stderr, "FATAL: ADM_register_adhoc_storage() failed: {}\n", - e.what()); + fmt::print(stderr, "FATAL: example failed: {}\n", e.what()); exit(EXIT_FAILURE); } } diff --git a/examples/cxx/ADM_update_job.cpp b/examples/cxx/ADM_update_job.cpp index 223bd33a992b9effe66feb3705bcbe18b228a0c5..c335942124803498be12ee224bca212f0af1a7c2 100644 --- a/examples/cxx/ADM_update_job.cpp +++ b/examples/cxx/ADM_update_job.cpp @@ -65,8 +65,7 @@ main(int argc, char* argv[]) { [[maybe_unused]] const auto job = admire::register_job( server, admire::job::resources{job_nodes}, reqs, 0); - [[maybe_unused]] ADM_return_t ret = admire::update_job( - server, job, admire::job::resources{new_job_nodes}); + admire::update_job(server, job, admire::job::resources{new_job_nodes}); fmt::print( stdout, diff --git a/src/lib/admire.cpp b/src/lib/admire.cpp index 5bb0dae06c905c6930f9eef1958d532dd00a8635..98bc455a22e47b832ab93cb81cdfd37efd83fb2c 100644 --- a/src/lib/admire.cpp +++ b/src/lib/admire.cpp @@ -221,15 +221,27 @@ register_job(const server& srv, const job::resources& resources, return rv.value(); } -admire::error_code +void update_job(const server& srv, const job& job, const job::resources& job_resources) { - return detail::update_job(srv, job, job_resources); + + const auto ec = detail::update_job(srv, job, job_resources); + + if(!ec) { + throw std::runtime_error( + fmt::format("ADM_update_job() error: {}", ec.message())); + } } -admire::error_code +void remove_job(const server& srv, const job& job) { - return detail::remove_job(srv, job); + + const auto ec = detail::remove_job(srv, job); + + if(!ec) { + throw std::runtime_error( + fmt::format("ADM_remove_job() error: {}", ec.message())); + } } admire::adhoc_storage @@ -248,15 +260,27 @@ register_adhoc_storage(const server& srv, const std::string& name, return rv.value(); } -admire::error_code +void update_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage, const adhoc_storage::ctx& adhoc_storage_ctx) { - return detail::update_adhoc_storage(srv, adhoc_storage_ctx, adhoc_storage); + const auto ec = + detail::update_adhoc_storage(srv, adhoc_storage_ctx, adhoc_storage); + + if(!ec) { + throw std::runtime_error(fmt::format( + "ADM_update_adhoc_storage() error: {}", ec.message())); + } } -admire::error_code +void remove_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage) { - return detail::remove_adhoc_storage(srv, adhoc_storage); + + const auto ec = detail::remove_adhoc_storage(srv, adhoc_storage); + + if(!ec) { + throw std::runtime_error(fmt::format( + "ADM_remove_adhoc_storage() error: {}", ec.message())); + } } ADM_return_t diff --git a/src/lib/admire.hpp b/src/lib/admire.hpp index 13ed1b3b18f14666ead863fc402a85b35f5b8c65..4e690b182e2b573678662b726f42e071fa2a9e60 100644 --- a/src/lib/admire.hpp +++ b/src/lib/admire.hpp @@ -51,10 +51,10 @@ admire::job register_job(const server& srv, const job::resources& job_resources, const job_requirements& reqs, admire::slurm_job_id slurm_id); -admire::error_code +void update_job(const server& srv, const job&, const job::resources& job_resources); -admire::error_code +void remove_job(const server& srv, const job& job); admire::adhoc_storage @@ -62,11 +62,11 @@ register_adhoc_storage(const server& srv, const std::string& name, enum adhoc_storage::type type, const adhoc_storage::ctx& ctx); -admire::error_code +void update_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage, const adhoc_storage::ctx& adhoc_storage_ctx); -admire::error_code +void remove_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage); ADM_return_t diff --git a/src/lib/c_wrapper.cpp b/src/lib/c_wrapper.cpp index e9a2e142942cc6d24618dd05039544f27972964d..5cfd5ecab33d751380e056fe961cec8de3c6106e 100644 --- a/src/lib/c_wrapper.cpp +++ b/src/lib/c_wrapper.cpp @@ -68,8 +68,8 @@ ADM_update_job(ADM_server_t server, ADM_job_t job, const admire::server srv{server}; - return admire::update_job(srv, admire::job{job}, - admire::job::resources{job_resources}); + return admire::detail::update_job(srv, admire::job{job}, + admire::job::resources{job_resources}); } ADM_return_t @@ -77,7 +77,7 @@ ADM_remove_job(ADM_server_t server, ADM_job_t job) { const admire::server srv{server}; - return admire::remove_job(srv, admire::job{job}); + return admire::detail::remove_job(srv, admire::job{job}); } ADM_return_t