Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add grow functions to REAPI #1316

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,7 @@ int resource_reader_jgf_t::unpack_at (resource_graph_t &g,
const std::string &str,
int rank)
{
/* This functionality is currently experimental, as resource graph
* growth causes a resize of the boost vecS vertex container type.
* Resizing the vecS results in lost job allocations and reservations
* as there is no copy constructor for planner.
/* This functionality is currently experimental.
* vtx_t vtx is not implemented and may be used in the future
* for optimization.
*/
Expand Down
15 changes: 15 additions & 0 deletions resource/reapi/bindings/c++/reapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ 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 R_subgraph R string of std::string.
* \return 0 on success; -1 on error.
*/
static int grow (void *h,
const std::string &R_subgraph)
{
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 @@ -89,6 +89,7 @@ class resource_query_t {
void set_job (const uint64_t jobid, const std::shared_ptr<job_info_t> &job);
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);
void incr_job_counter ();

/* Run the traverser to match the jobspec */
Expand Down Expand Up @@ -148,6 +149,7 @@ class reapi_cli_t : public reapi_t {
int64_t &at,
double &ov,
std::string &R_out);
static int grow (void *h, const std::string &R_subgraph);
static int cancel (void *h, const uint64_t jobid, bool noent_ok);
static int cancel (void *h,
const uint64_t jobid,
Expand Down
50 changes: 50 additions & 0 deletions resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@
return NOT_YET_IMPLEMENTED;
}

int reapi_cli_t::grow (void *h,

Check warning on line 168 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L168

Added line #L168 was not covered by tests
const std::string &R_subgraph)
{
resource_query_t *rq = static_cast<resource_query_t *> (h);
int rc = -1;

Check warning on line 172 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L171-L172

Added lines #L171 - L172 were not covered by tests

if ((rc = rq->grow (R_subgraph)) != 0) {
m_err_msg += __FUNCTION__;
m_err_msg += ": ERROR: grow error: " + std::string (strerror (errno)) + "\n";

Check warning on line 176 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L174-L176

Added lines #L174 - L176 were not covered by tests
}

return rc;

Check warning on line 179 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L179

Added line #L179 was not covered by tests
}

int reapi_cli_t::match_allocate_multi (void *h,
bool orelse_reserve,
const char *jobs,
Expand Down Expand Up @@ -722,6 +736,42 @@
return rc;
}

int resource_query_t::grow (const std::string &R_subgraph)

Check warning on line 739 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L739

Added line #L739 was not covered by tests
{
int rc = -1;
std::shared_ptr<resource_reader_base_t> reader;
vtx_t v = boost::graph_traits<resource_graph_t>::null_vertex ();

Check warning on line 743 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L741-L743

Added lines #L741 - L743 were not covered by tests

if (R_subgraph == "") {
errno = EINVAL;
return rc;

Check warning on line 747 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L745-L747

Added lines #L745 - L747 were not covered by tests
}
if (params.load_format != "jgf") {
m_err_msg = __FUNCTION__;
m_err_msg += ": ERROR: growing a resource graph not ";
m_err_msg += " initialized with JGF is unsupported\n";
errno = ENOTSUP;
return rc;

Check warning on line 754 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L749-L754

Added lines #L749 - L754 were not covered by tests
}
if ((reader = create_resource_reader ("jgf")) == nullptr) {
m_err_msg = __FUNCTION__;
m_err_msg += ": ERROR: can't create JGF reader\n";

Check warning on line 758 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L756-L758

Added lines #L756 - L758 were not covered by tests
return rc;
}
if ((rc = reader->unpack_at (db->resource_graph, db->metadata, v, R_subgraph, -1)) != 0) {
m_err_msg = __FUNCTION__;
m_err_msg += ": ERROR: reader returned error: ";
m_err_msg += reader->err_message () + "\n";
return rc;

Check warning on line 765 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L761-L765

Added lines #L761 - L765 were not covered by tests
}
if ((rc = traverser->initialize (db, matcher)) != 0) {
m_err_msg = __FUNCTION__;
m_err_msg += ": ERROR: reinitialize traverser after grow. ";
m_err_msg += reader->err_message () + "\n";

Check warning on line 770 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L767-L770

Added lines #L767 - L770 were not covered by tests
}
return rc;
}

Check warning on line 773 in resource/reapi/bindings/c++/reapi_cli_impl.hpp

View check run for this annotation

Codecov / codecov/patch

resource/reapi/bindings/c++/reapi_cli_impl.hpp#L773

Added line #L773 was not covered by tests

void resource_query_t::incr_job_counter ()
{
jobid_counter++;
Expand Down
22 changes: 17 additions & 5 deletions resource/reapi/bindings/c/reapi_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx,
return rc;
}

extern "C" int reapi_cli_grow (reapi_cli_ctx_t *ctx,
const char *R_subgraph)
{
if (!ctx || !ctx->rqt || !R_subgraph) {
errno = EINVAL;
return -1;
}
return reapi_cli_t::grow (ctx->rqt, R_subgraph);
}

extern "C" int reapi_cli_cancel (reapi_cli_ctx_t *ctx, const uint64_t jobid, bool noent_ok)
{
if (!ctx || !ctx->rqt) {
Expand Down Expand Up @@ -259,11 +269,13 @@ extern "C" const char *reapi_cli_get_err_msg (reapi_cli_ctx_t *ctx)
{
std::string err_buf = "";

if (ctx->rqt)
err_buf = ctx->rqt->get_resource_query_err_msg () + reapi_cli_t::get_err_message ()
+ ctx->err_msg;
else
err_buf = reapi_cli_t::get_err_message () + ctx->err_msg;
if (!ctx || !ctx->rqt) {
errno = EINVAL;
return "ERROR: REAPI context and/or rqt null \n";
}

err_buf = ctx->rqt->get_resource_query_err_msg () + reapi_cli_t::get_err_message ()
+ ctx->err_msg;

return strdup (err_buf.c_str ());
}
Expand Down
12 changes: 12 additions & 0 deletions resource/reapi/bindings/c/reapi_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx,
double *ov,
const char **R_out);

/*! 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 R_subgraph R string
* \return 0 on success; -1 on error.
*/
int reapi_cli_grow (reapi_cli_ctx_t *ctx,
const char *R_subgraph);

/*! Cancel the allocation or reservation corresponding to jobid.
*
* \param ctx reapi_cli_ctx_t context object
Expand Down
5 changes: 4 additions & 1 deletion resource/utilities/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,10 @@ static int remove (std::shared_ptr<resource_context_t> &ctx, std::vector<std::st
std::cerr << "ERROR: " << rd->err_message ();
return -1;
}
// TODO: reinitialize the traverser, see issue #1075
if (ctx->traverser->initialize (ctx->db, ctx->matcher) != 0) {
std::cerr << "ERROR: can't reinitialize traverser after attach" << std::endl;
return -1;
}

return 0;
}
Expand Down
Loading