From 24d813b3c3b25ffafb11542bf25b6a2442fa922b Mon Sep 17 00:00:00 2001 From: Zeke Morton Date: Tue, 4 Apr 2023 11:42:32 -0700 Subject: [PATCH] reapi: implement find Problem: the resource api does not include find functionality in resource query. Add new functions find() and traverser_find() that mimic the functionaility in resource query. --- resource/reapi/bindings/c++/reapi_cli.hpp | 2 ++ .../reapi/bindings/c++/reapi_cli_impl.hpp | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/resource/reapi/bindings/c++/reapi_cli.hpp b/resource/reapi/bindings/c++/reapi_cli.hpp index 8ba32dc2a..0ff9ed84b 100644 --- a/resource/reapi/bindings/c++/reapi_cli.hpp +++ b/resource/reapi/bindings/c++/reapi_cli.hpp @@ -88,6 +88,7 @@ class resource_query_t { /* Run the traverser to match the jobspec */ int traverser_run (Flux::Jobspec::Jobspec &job, match_op_t op, int64_t jobid, int64_t &at); + int traverser_find (std::string criteria); // must be public; results in a deleted stringstream if converted to // a private member function @@ -137,6 +138,7 @@ class reapi_cli_t : public reapi_t { const std::string &R, int64_t &at, double &ov, std::string &R_out); static int cancel (void *h, const uint64_t jobid, bool noent_ok); + static int find (void *h, std::string criteria, json_t *&o ); static int info (void *h, const uint64_t jobid, std::string &mode, bool &reserved, int64_t &at, double &ov); static int stat (void *h, int64_t &V, int64_t &E,int64_t &J, diff --git a/resource/reapi/bindings/c++/reapi_cli_impl.hpp b/resource/reapi/bindings/c++/reapi_cli_impl.hpp index 7694ed26b..6a1dab1c2 100644 --- a/resource/reapi/bindings/c++/reapi_cli_impl.hpp +++ b/resource/reapi/bindings/c++/reapi_cli_impl.hpp @@ -186,6 +186,32 @@ int reapi_cli_t::cancel (void *h, const uint64_t jobid, bool noent_ok) return rc; } +int reapi_cli_t::find (void *h, std::string criteria, + json_t *&o ) +{ + int rc = -1; + resource_query_t *rq = static_cast (h); + + if ( (rc = rq->traverser_find (criteria)) < 0) { + if (rq->get_traverser_err_msg () != "") { + m_err_msg += __FUNCTION__; + m_err_msg += rq->get_traverser_err_msg (); + rq->clear_traverser_err_msg (); + } + return rc; + } + + + if ( (rc = rq->writers->emit_json (&o)) < 0) { + m_err_msg += __FUNCTION__; + m_err_msg += ": ERROR: find writer emit: " + + std::string (strerror (errno)) + "\n"; + return rc; + } + + return rc; +} + int reapi_cli_t::info (void *h, const uint64_t jobid, std::string &mode, bool &reserved, int64_t &at, double &ov) { @@ -648,6 +674,11 @@ int resource_query_t::traverser_run (Flux::Jobspec::Jobspec &job, match_op_t op, return traverser->run (job, writers, op, jobid, &at); } +int resource_query_t::traverser_find (std::string criteria) +{ + return traverser->find (writers, criteria); +} + } // namespace Flux::resource_model::detail } // namespace Flux::resource_model