Skip to content

Commit

Permalink
reapi: add shrink function to C++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
milroy committed Jan 15, 2025
1 parent 701dfbe commit 10f0f74
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions resource/reapi/bindings/c++/reapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 @@ -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 */
Expand Down Expand Up @@ -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,
Expand Down
48 changes: 48 additions & 0 deletions resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<resource_query_t *> (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,
Expand Down Expand Up @@ -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<resource_reader_base_t> 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++;
Expand Down

0 comments on commit 10f0f74

Please sign in to comment.