From 10f0f744c4b0f8ac5332effcd03b7438121ebf6e Mon Sep 17 00:00:00 2001 From: Daniel Milroy Date: Tue, 14 Jan 2025 18:23:56 -0800 Subject: [PATCH] reapi: add shrink function to C++ API --- resource/reapi/bindings/c++/reapi.hpp | 16 +++++++ resource/reapi/bindings/c++/reapi_cli.hpp | 2 + .../reapi/bindings/c++/reapi_cli_impl.hpp | 48 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/resource/reapi/bindings/c++/reapi.hpp b/resource/reapi/bindings/c++/reapi.hpp index eee25b58b..5fd344033 100644 --- a/resource/reapi/bindings/c++/reapi.hpp +++ b/resource/reapi/bindings/c++/reapi.hpp @@ -204,6 +204,22 @@ class reapi_t { return -1; } + /*! Update the resource state with R. + * + * \param h Opaque handle. How it is used is an implementation + * detail. However, when it is used within a Flux's + * service module, it is expected to be a pointer + * to a flux_t object. + * \param subgraph_path String representing the path from the cluster root + * to the root of the subgraph to be removed from + * the resource graph + * \return 0 on success; -1 on error. + */ + static int shrink (void *h, const std::string &subgraph_path) + { + return -1; + } + /*! Cancel the allocation or reservation corresponding to jobid. * * \param h Opaque handle. How it is used is an implementation diff --git a/resource/reapi/bindings/c++/reapi_cli.hpp b/resource/reapi/bindings/c++/reapi_cli.hpp index 1892b0131..77e5fcee0 100644 --- a/resource/reapi/bindings/c++/reapi_cli.hpp +++ b/resource/reapi/bindings/c++/reapi_cli.hpp @@ -90,6 +90,7 @@ class resource_query_t { int remove_job (const uint64_t jobid); int remove_job (const uint64_t jobid, const std::string &R, bool &full_removal); int grow (const std::string &R_subgraph); + int shrink (const std::string &subgraph_path); void incr_job_counter (); /* Run the traverser to match the jobspec */ @@ -150,6 +151,7 @@ class reapi_cli_t : public reapi_t { double &ov, std::string &R_out); static int grow (void *h, const std::string &R_subgraph); + static int shrink (void *h, const std::string &subgraph_path); static int cancel (void *h, const uint64_t jobid, bool noent_ok); static int cancel (void *h, const uint64_t jobid, diff --git a/resource/reapi/bindings/c++/reapi_cli_impl.hpp b/resource/reapi/bindings/c++/reapi_cli_impl.hpp index 5e3335a0d..57df3ebf3 100644 --- a/resource/reapi/bindings/c++/reapi_cli_impl.hpp +++ b/resource/reapi/bindings/c++/reapi_cli_impl.hpp @@ -178,6 +178,19 @@ int reapi_cli_t::grow (void *h, const std::string &R_subgraph) return rc; } +int reapi_cli_t::shrink (void *h, const std::string &subgraph_path) +{ + resource_query_t *rq = static_cast (h); + int rc = -1; + + if ((rc = rq->shrink (subgraph_path)) != 0) { + m_err_msg += __FUNCTION__; + m_err_msg += ": ERROR: shrink error: " + std::string (strerror (errno)) + "\n"; + } + + return rc; +} + int reapi_cli_t::match_allocate_multi (void *h, bool orelse_reserve, const char *jobs, @@ -769,6 +782,41 @@ int resource_query_t::grow (const std::string &R_subgraph) return rc; } +int resource_query_t::shrink (const std::string &subgraph_path) +{ + int rc = -1; + std::shared_ptr reader; + + if (subgraph_path == "") { + errno = EINVAL; + return rc; + } + if (params.load_format != "jgf") { + m_err_msg = __FUNCTION__; + m_err_msg += ": ERROR: shrinking a resource graph not "; + m_err_msg += " initialized with JGF is unsupported\n"; + errno = ENOTSUP; + return rc; + } + if ((reader = create_resource_reader ("jgf")) == nullptr) { + m_err_msg = __FUNCTION__; + m_err_msg += ": ERROR: can't create JGF reader\n"; + return rc; + } + if ((rc = reader->remove_subgraph (db->resource_graph, db->metadata, subgraph_path)) != 0) { + m_err_msg = __FUNCTION__; + m_err_msg += ": ERROR: reader returned error: "; + m_err_msg += reader->err_message () + "\n"; + return rc; + } + if ((rc = traverser->initialize (db, matcher)) != 0) { + m_err_msg = __FUNCTION__; + m_err_msg += ": ERROR: reinitialize traverser after shrink. "; + m_err_msg += reader->err_message () + "\n"; + } + return rc; +} + void resource_query_t::incr_job_counter () { jobid_counter++;