diff --git a/resource/utilities/command.cpp b/resource/utilities/command.cpp index db598db26..45848c58e 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, "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,14 @@ 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; } @@ -445,6 +447,28 @@ static int attach (std::shared_ptr &ctx, 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; + } + // TODO: reinitialize the traverser, see issue #1075 + + return 0; +} + int cmd_attach (std::shared_ptr &ctx, std::vector &args) { @@ -463,6 +487,24 @@ 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; + } + 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,