Skip to content

Commit

Permalink
Merge pull request #1020 from zekemorton/reapi-find
Browse files Browse the repository at this point in the history
reapi: implement find
  • Loading branch information
mergify[bot] authored May 18, 2023
2 parents e791e1a + 24d813b commit c65026c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resource/reapi/bindings/c++/reapi_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<resource_query_t *> (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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c65026c

Please sign in to comment.