Skip to content

Commit

Permalink
reapi: update return code and info for match allocate
Browse files Browse the repository at this point in the history
Problem: reapi_cli_t::match_allocate does not reutrn or track
whether a match was successful or not. It also sets the job info
with an unset value for overhead.

Add in a new return code to track, rc2. Use a check on rc2 to
determine if a match was succesfull and a job_info_t needs to be
created. Return combination of rc1 and rc2 to pass failue back to
calling function.

Move code blocks that set overhead value ov above blocks where
job info is created.
  • Loading branch information
zekemorton committed Oct 9, 2023
1 parent 07c36dd commit aae6506
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
{
resource_query_t *rq = static_cast<resource_query_t *> (h);
int rc = -1;
int rc2 = 0;
at = 0;
ov = 0.0f;
job_lifecycle_t st;
Expand All @@ -76,11 +77,11 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
}

if (orelse_reserve)
rc = rq->traverser_run (job,
rc2 = rq->traverser_run (job,
match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE,
(int64_t)jobid, at);
else
rc = rq->traverser_run (job, match_op_t::MATCH_ALLOCATE,
rc2 = rq->traverser_run (job, match_op_t::MATCH_ALLOCATE,
(int64_t)jobid, at);

if (rq->get_traverser_err_msg () != "") {
Expand Down Expand Up @@ -109,28 +110,14 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,

R = o.str ();


reserved = (at != 0)? true : false;
st = (reserved)?
job_lifecycle_t::RESERVED : job_lifecycle_t::ALLOCATED;
if (reserved)
rq->set_reservation (jobid);
else
rq->set_allocation (jobid);

job_info = std::make_shared<job_info_t> (jobid, st, at, "", "", ov);
if (job_info == nullptr) {
errno = ENOMEM;
m_err_msg += __FUNCTION__;
m_err_msg += ": ERROR: can't allocate memory: "
+ std::string (strerror (errno))+ "\n";
rc = -1;
goto out;
}

rq->set_job (jobid, job_info);
rq->incr_job_counter ();


if ( (rc = gettimeofday (&end_time, NULL)) < 0) {
m_err_msg += __FUNCTION__;
m_err_msg += ": ERROR: gettimeofday: "
Expand All @@ -140,8 +127,24 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,

ov = get_elapsed_time (start_time, end_time);

if (rc2 == 0){
job_info = std::make_shared<job_info_t> (jobid, st, at, "", "", ov);
if (job_info == nullptr) {
errno = ENOMEM;
m_err_msg += __FUNCTION__;
m_err_msg += ": ERROR: can't allocate memory: "
+ std::string (strerror (errno))+ "\n";
rc = -1;
goto out;
}

rq->set_job (jobid, job_info);
}

rq->incr_job_counter ();

out:
return rc;
return rc + rc2;
}

int reapi_cli_t::update_allocate (void *h, const uint64_t jobid,
Expand Down

0 comments on commit aae6506

Please sign in to comment.