From 72d27adc34de488279941b44027ddb800e09e166 Mon Sep 17 00:00:00 2001 From: Zeke Morton Date: Thu, 20 Jul 2023 15:50:44 -0700 Subject: [PATCH] resource query: remove subgraph feature 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 --- resource/utilities/command.cpp | 57 ++++++++++++++++++++++++++++++++-- resource/utilities/command.hpp | 2 ++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/resource/utilities/command.cpp b/resource/utilities/command.cpp index 5e1007c28..7a1d261aa 100644 --- a/resource/utilities/command.cpp +++ b/resource/utilities/command.cpp @@ -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" }, @@ -430,14 +432,40 @@ static int attach (std::shared_ptr &ctx, // Unpack_at currently does not use the vertex attachment point. // This functionality is currently experimental. vtx_t v = boost::graph_traits::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 &ctx, + std::vector &args) +{ + const std::string node_path = args[1]; + std::shared_ptr 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; } @@ -457,7 +485,7 @@ int cmd_attach (std::shared_ptr &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) { @@ -468,6 +496,29 @@ int cmd_attach (std::shared_ptr &ctx, return 0; } +int cmd_remove (std::shared_ptr &ctx, + std::vector &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 &ctx, std::vector &args) { diff --git a/resource/utilities/command.hpp b/resource/utilities/command.hpp index 54b9e9b53..54e139122 100644 --- a/resource/utilities/command.hpp +++ b/resource/utilities/command.hpp @@ -75,6 +75,8 @@ int cmd_update (std::shared_ptr &ctx, std::vector &args); int cmd_attach (std::shared_ptr &ctx, std::vector &args); +int cmd_remove (std::shared_ptr &ctx, + std::vector &args); int cmd_find (std::shared_ptr &ctx, std::vector &args); int cmd_cancel (std::shared_ptr &ctx,