Skip to content

Commit

Permalink
resource query: remove subgraph feature
Browse files Browse the repository at this point in the history
Problem: the remove subgraph feature is a part of the readers but
does not have functionality in resource query

Add support for remove graph in resource query
  • Loading branch information
zekemorton committed Jul 27, 2023
1 parent 3896c70 commit 72d27ad
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
57 changes: 54 additions & 3 deletions resource/utilities/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ command_t commands[] = {
"resource-query> update allocate jgf_file jobid starttime duration" },
{ "attach", "j", cmd_attach, "Experimental: attach a JGF subgraph to the "
"resource graph: resource-query> attach jgf_file" },
{ "remove", "j", cmd_remove, "Experimental: remove a subgraph to the "
"resource graph: resource-query> remove path/to/node/" },
{ "find", "f", cmd_find, "Find resources matched with criteria "
"(predicates: status={up|down} sched-now={allocated|free} sched-future={reserved|free}): "
"resource-query> find status=down and sched-now=allocated" },
Expand Down Expand Up @@ -430,14 +432,40 @@ static int attach (std::shared_ptr<resource_context_t> &ctx,
// Unpack_at currently does not use the vertex attachment point.
// This functionality is currently experimental.
vtx_t v = boost::graph_traits<resource_graph_t>::null_vertex ();
if ( (rd->unpack_at (ctx->db->resource_graph, ctx->db->metadata,
if ( (rd->unpack_at (ctx->db->resource_graph, ctx->db->metadata,
v, buffer.str (), -1)) != 0) {
std::cerr << "ERROR: can't attach JGF subgraph " << std::endl;
std::cerr << "ERROR: " << rd->err_message ();
return -1;
}
if (ctx->traverser->initialize (ctx->fgraph, ctx->db, ctx->matcher) != 0) {
std::cerr << "ERROR: can't reinitialize traverser after attach"
std::cerr << "ERROR: can't reinitialize traverser after attach"
<< std::endl;
return -1;
}

return 0;
}

static int remove (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
const std::string node_path = args[1];
std::shared_ptr<resource_reader_base_t> rd;

if ( (rd = create_resource_reader ("jgf")) == nullptr) {
std::cerr << "ERROR: can't create JGF reader " << std::endl;
return -1;
}

if ( (rd->remove_subgraph (ctx->db->resource_graph, ctx->db->metadata,
node_path)) != 0) {
std::cerr << "ERROR: can't remove subgraph " << std::endl;
std::cerr << "ERROR: " << rd->err_message ();
return -1;
}
if (ctx->traverser->initialize (ctx->fgraph, ctx->db, ctx->matcher) != 0) {
std::cerr << "ERROR: can't reinitialize traverser after remove"
<< std::endl;
return -1;
}
Expand All @@ -457,7 +485,7 @@ int cmd_attach (std::shared_ptr<resource_context_t> &ctx,
std::cerr << "ERROR: attach isn't currently supported when an"
<< " allocation or reservation exists" << std::endl;
return 0;
}
}
attach (ctx, args);

} catch (std::ifstream::failure &e) {
Expand All @@ -468,6 +496,29 @@ int cmd_attach (std::shared_ptr<resource_context_t> &ctx,
return 0;
}

int cmd_remove (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
try {
if (args.size () != 2) {
std::cerr << "ERROR: malformed command" << std::endl;
return 0;
}
if ( !(ctx->allocations.empty () && ctx->reservations.empty ())) {
std::cerr << "ERROR: remove isn't currently supported when an"
<< " allocation or reservation exists" << std::endl;
return 0;
}
remove (ctx, args);

} catch (std::ifstream::failure &e) {
std::cerr << "ERROR: file I/O exception: " << e.what () << std::endl;
} catch (std::out_of_range &e) {
std::cerr << "ERROR: " << e.what () << std::endl;
}
return 0;
}

int cmd_find (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
Expand Down
2 changes: 2 additions & 0 deletions resource/utilities/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ int cmd_update (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_attach (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_remove (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_find (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_cancel (std::shared_ptr<resource_context_t> &ctx,
Expand Down

0 comments on commit 72d27ad

Please sign in to comment.