Skip to content

Commit ab645ac

Browse files
committed
resource-query: add support for rv1exec update
Problem: the `resource-query` tool currently only supports update via JGF. Add support for rv1exec, including additional options handling. This enables sharness tests for reload and updates under rv1exec.
1 parent bbd693f commit ab645ac

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

resource/utilities/command.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ command_t commands[] = {
3939
"allocate_orelse_reserve): "
4040
"resource-query> multi-match allocate jobspec1 jobspec2 ..."},
4141
{ "update", "u", cmd_update, "Update resources with a JGF subgraph (subcmd: "
42-
"allocate | reserve): "
43-
"resource-query> update allocate jgf_file jobid starttime duration" },
42+
"allocate | reserve), (reader: jgf | rv1exec): "
43+
"resource-query> update allocate jgf jgf_file jobid starttime duration" },
4444
{ "attach", "j", cmd_attach, "Attach a JGF subgraph to the "
4545
"resource graph: resource-query> attach jgf_file" },
4646
{ "remove", "j", cmd_remove, "Experimental: remove a subgraph to the "
@@ -318,17 +318,25 @@ int cmd_match_multi (std::shared_ptr<resource_context_t> &ctx,
318318

319319
static int update_run (std::shared_ptr<resource_context_t> &ctx,
320320
const std::string &fn, const std::string &str,
321-
int64_t id, int64_t at, uint64_t d)
321+
int64_t id, int64_t at, uint64_t d,
322+
const std::string &reader)
322323
{
323324
int rc = -1;
324325
double elapse = 0.0f;
325326
std::stringstream o;
326327
struct timeval st, et;
327328
std::shared_ptr<resource_reader_base_t> rd;
328329

329-
if ( (rd = create_resource_reader ("jgf")) == nullptr) {
330-
std::cerr << "ERROR: can't create JGF reader " << std::endl;
331-
return -1;
330+
if (reader == "jgf") {
331+
if ( (rd = create_resource_reader ("jgf")) == nullptr) {
332+
std::cerr << "ERROR: can't create JGF reader " << std::endl;
333+
return -1;
334+
}
335+
} else {
336+
if ( (rd = create_resource_reader ("rv1exec")) == nullptr) {
337+
std::cerr << "ERROR: can't create rv1exec reader " << std::endl;
338+
return -1;
339+
}
332340
}
333341

334342
gettimeofday (&st, NULL);
@@ -360,26 +368,31 @@ static int update (std::shared_ptr<resource_context_t> &ctx,
360368
int64_t at = 0;
361369
int64_t jobid = 0;
362370
std::string subcmd = args[1];
371+
std::string reader = args[2];
363372
std::stringstream buffer{};
364373

365374
if (!(subcmd == "allocate" || subcmd == "reserve")) {
366375
std::cerr << "ERROR: unknown subcmd " << args[1] << std::endl;
367376
return -1;
368377
}
369-
std::ifstream jgf_file (args[2]);
378+
if (!(reader == "jgf" || reader == "rv1exec")) {
379+
std::cerr << "ERROR: unsupported reader " << args[2] << std::endl;
380+
return -1;
381+
}
382+
std::ifstream jgf_file (args[3]);
370383
if (!jgf_file) {
371-
std::cerr << "ERROR: can't open " << args[2] << std::endl;
384+
std::cerr << "ERROR: can't open " << args[3] << std::endl;
372385
return -1;
373386
}
374387

375-
jobid = static_cast<int64_t> (std::strtoll (args[3].c_str (), NULL, 10));
388+
jobid = static_cast<int64_t> (std::strtoll (args[4].c_str (), NULL, 10));
376389
if (ctx->allocations.find (jobid) != ctx->allocations.end ()
377390
|| ctx->reservations.find (jobid) != ctx->reservations.end ()) {
378391
std::cerr << "ERROR: existing Jobid " << std::endl;
379392
return -1;
380393
}
381-
at = static_cast<int64_t> (std::strtoll (args[4].c_str (), NULL, 10));
382-
d = static_cast<int64_t> (std::strtoll (args[5].c_str (), NULL, 10));
394+
at = static_cast<int64_t> (std::strtoll (args[5].c_str (), NULL, 10));
395+
d = static_cast<int64_t> (std::strtoll (args[6].c_str (), NULL, 10));
383396
if (at < 0 || d == 0) {
384397
std::cerr << "ERROR: invalid time ("
385398
<< at << ", " << d << ")" << std::endl;
@@ -389,14 +402,14 @@ static int update (std::shared_ptr<resource_context_t> &ctx,
389402
buffer << jgf_file.rdbuf ();
390403
jgf_file.close ();
391404

392-
return update_run (ctx, args[2], buffer.str (), jobid, at, d);
405+
return update_run (ctx, args[3], buffer.str (), jobid, at, d, reader);
393406
}
394407

395408
int cmd_update (std::shared_ptr<resource_context_t> &ctx,
396409
std::vector<std::string> &args)
397410
{
398411
try {
399-
if (args.size () != 6) {
412+
if (args.size () != 7) {
400413
std::cerr << "ERROR: malformed command" << std::endl;
401414
return 0;
402415
}

0 commit comments

Comments
 (0)