Skip to content

Commit c7fa140

Browse files
committed
reapi: add match options for c++ bindings
Problem: reapi match allocate functions use a boolean parameter to toggle beteween 2 of the 4 total match options. This leads to the other 2 match options being inaccesible from the reapi. Overload the C++ bindings for match allocate to accept a different parameter that allows for all 4 options. Rework old function to call new function with correct match option to maintain backwards compatibility.
1 parent d18a279 commit c7fa140

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

resource/reapi/bindings/c++/reapi_cli.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class reapi_cli_t : public reapi_t {
133133
const std::string &jobspec,
134134
const uint64_t jobid, bool &reserved,
135135
std::string &R, int64_t &at, double &ov);
136+
static int match_allocate (void *h, match_op_t match_op,
137+
const std::string &jobspec,
138+
const uint64_t jobid, bool &reserved,
139+
std::string &R, int64_t &at, double &ov);
136140
static int match_allocate_multi (void *h, bool orelse_reserve,
137141
const char *jobs,
138142
queue_adapter_base_t *adapter);

resource/reapi/bindings/c++/reapi_cli_impl.hpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::string reapi_cli_t::m_err_msg = "";
5151
* *
5252
****************************************************************************/
5353

54-
int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
54+
int reapi_cli_t::match_allocate (void *h, match_op_t match_op,
5555
const std::string &jobspec,
5656
const uint64_t jobid, bool &reserved,
5757
std::string &R, int64_t &at, double &ov)
@@ -76,13 +76,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
7676
goto out;
7777
}
7878

79-
if (orelse_reserve)
80-
rc = rq->traverser_run (job,
81-
match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE,
82-
(int64_t)jobid, at);
83-
else
84-
rc = rq->traverser_run (job, match_op_t::MATCH_ALLOCATE,
85-
(int64_t)jobid, at);
79+
rc = rq->traverser_run (job, match_op, (int64_t)jobid, at);
8680

8781
if (rq->get_traverser_err_msg () != "") {
8882
m_err_msg += __FUNCTION__;
@@ -110,7 +104,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
110104
}
111105

112106
// Check for an unsuccessful match
113-
if (rc == 0) {
107+
if ( (rc == 0) && (match_op != match_op_t::MATCH_SATISFIABILITY)) {
114108
matched = true;
115109
}
116110

@@ -154,12 +148,26 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
154148

155149
}
156150

157-
rq->incr_job_counter ();
151+
if (match_op != match_op_t::MATCH_SATISFIABILITY)
152+
rq->incr_job_counter ();
158153

159154
out:
160155
return rc;
161156
}
162157

158+
int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
159+
const std::string &jobspec,
160+
const uint64_t jobid, bool &reserved,
161+
std::string &R, int64_t &at, double &ov)
162+
{
163+
match_op_t match_op = orelse_reserve ?
164+
match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE :
165+
match_op_t::MATCH_ALLOCATE;
166+
167+
return match_allocate (h, match_op, jobspec, jobid, reserved,
168+
R, at, ov);
169+
}
170+
163171
int reapi_cli_t::update_allocate (void *h, const uint64_t jobid,
164172
const std::string &R, int64_t &at, double &ov,
165173
std::string &R_out)

resource/reapi/bindings/c++/reapi_module.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ namespace detail {
2828

2929
class reapi_module_t : public reapi_t {
3030
public:
31+
static int match_allocate (void *h, const char *cmd,
32+
const std::string &jobspec,
33+
const uint64_t jobid, bool &reserved,
34+
std::string &R, int64_t &at, double &ov);
3135
static int match_allocate (void *h, bool orelse_reserve,
3236
const std::string &jobspec,
3337
const uint64_t jobid, bool &reserved,
3438
std::string &R, int64_t &at, double &ov);
3539
static int match_allocate_multi (void *h, bool orelse_reserve,
3640
const char *jobs,
3741
queue_adapter_base_t *adapter);
42+
static int match_allocate_multi (void *h, const char *cmd,
43+
const char *jobs,
44+
queue_adapter_base_t *adapter);
3845
static int update_allocate (void *h, const uint64_t jobid,
3946
const std::string &R, int64_t &at, double &ov,
4047
std::string &R_out);

resource/reapi/bindings/c++/reapi_module_impl.hpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Flux {
2525
namespace resource_model {
2626
namespace detail {
2727

28-
int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
28+
int reapi_module_t::match_allocate (void *h, const char *cmd,
2929
const std::string &jobspec,
3030
const uint64_t jobid, bool &reserved,
3131
std::string &R, int64_t &at, double &ov)
@@ -36,8 +36,6 @@ int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
3636
flux_future_t *f = NULL;
3737
const char *rset = NULL;
3838
const char *status = NULL;
39-
const char *cmd = (orelse_reserve)? "allocate_orelse_reserve"
40-
: "allocate_with_satisfiability";
4139

4240
if (!fh || jobspec == "" || jobid > INT64_MAX) {
4341
errno = EINVAL;
@@ -70,6 +68,18 @@ int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
7068
return rc;
7169
}
7270

71+
int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
72+
const std::string &jobspec,
73+
const uint64_t jobid, bool &reserved,
74+
std::string &R, int64_t &at, double &ov)
75+
{
76+
const char *cmd = (orelse_reserve)? "allocate_orelse_reserve"
77+
: "allocate_with_satisfiability";
78+
79+
return match_allocate (h, cmd, jobspec, jobid, reserved, R, at, ov);
80+
81+
}
82+
7383
void match_allocate_multi_cont (flux_future_t *f, void *arg)
7484
{
7585
int64_t rj = -1;
@@ -101,16 +111,14 @@ void match_allocate_multi_cont (flux_future_t *f, void *arg)
101111
}
102112

103113
int reapi_module_t::match_allocate_multi (void *h,
104-
bool orelse_reserve,
114+
const char *cmd,
105115
const char *jobs,
106116
queue_adapter_base_t *adapter)
107117
{
108118
int rc = -1;
109119
flux_t *fh = static_cast<flux_t *> (h);
110120
flux_future_t *f = nullptr;
111121

112-
const char *cmd = orelse_reserve ? "allocate_orelse_reserve"
113-
: "allocate_with_satisfiability";
114122
if (!fh) {
115123
errno = EINVAL;
116124
goto error;
@@ -134,6 +142,16 @@ int reapi_module_t::match_allocate_multi (void *h,
134142
return rc;
135143
}
136144

145+
int reapi_module_t::match_allocate_multi (void *h,
146+
bool orelse_reserve,
147+
const char *jobs,
148+
queue_adapter_base_t *adapter)
149+
{
150+
const char *cmd = orelse_reserve ? "allocate_orelse_reserve"
151+
: "allocate_with_satisfiability";
152+
return match_allocate_multi (h, cmd, jobs, adapter);
153+
}
154+
137155
int reapi_module_t::update_allocate (void *h, const uint64_t jobid,
138156
const std::string &R, int64_t &at,
139157
double &ov, std::string &R_out)

0 commit comments

Comments
 (0)