Skip to content

Commit 3abccaa

Browse files
authored
Merge pull request #1133 from zekemorton/reapi_match_options
Add match options and match satisfy to reapi
2 parents d18a279 + 40e20e6 commit 3abccaa

File tree

26 files changed

+700
-75
lines changed

26 files changed

+700
-75
lines changed

cmake/GolangSimple.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ function(BUILD_GO_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)
2424

2525
add_custom_target(${NAME}_all ALL DEPENDS ${NAME})
2626
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${NAME} DESTINATION bin)
27-
endfunction(BUILD_GO_PROGRAM)
27+
endfunction(BUILD_GO_PROGRAM)

resource/policies/base/match_op.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef MATCH_OP_H
2+
#define MATCH_OP_H
3+
4+
5+
typedef enum match_op_t { MATCH_UNKNOWN,
6+
MATCH_ALLOCATE,
7+
MATCH_ALLOCATE_W_SATISFIABILITY,
8+
MATCH_ALLOCATE_ORELSE_RESERVE,
9+
MATCH_SATISFIABILITY } match_op_t;
10+
11+
static const char *match_op_to_string (match_op_t match_op) {
12+
switch (match_op) {
13+
case MATCH_ALLOCATE: return "allocate";
14+
case MATCH_ALLOCATE_ORELSE_RESERVE: return "allocate_orelse_reserve";
15+
case MATCH_ALLOCATE_W_SATISFIABILITY: return "allocate_with_satisfiability";
16+
case MATCH_SATISFIABILITY: return "satisfiability";
17+
default: return "error";
18+
}
19+
}
20+
21+
static bool match_op_valid (match_op_t match_op) {
22+
23+
if ( (match_op != MATCH_ALLOCATE) &&
24+
(match_op != MATCH_ALLOCATE_W_SATISFIABILITY) &&
25+
(match_op != MATCH_ALLOCATE_ORELSE_RESERVE) &&
26+
(match_op != MATCH_SATISFIABILITY) ) {
27+
28+
return false;
29+
}
30+
31+
return true;
32+
}
33+
34+
#endif //MATCH_OP_H

resource/policies/base/matcher.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "resource/libjobspec/jobspec.hpp"
2020
#include "resource/schema/data_std.hpp"
2121
#include "resource/planner/c/planner.h"
22+
#include "resource/policies/base/match_op.h"
2223

2324
namespace Flux {
2425
namespace resource_model {
@@ -27,11 +28,6 @@ const std::string ANY_RESOURCE_TYPE = "*";
2728

2829
enum match_score_t { MATCH_UNMET = 0, MATCH_MET = 1 };
2930

30-
enum class match_op_t { MATCH_ALLOCATE,
31-
MATCH_ALLOCATE_W_SATISFIABILITY,
32-
MATCH_ALLOCATE_ORELSE_RESERVE,
33-
MATCH_SATISFIABILITY };
34-
3531
/*! Base matcher data class.
3632
* Provide idioms to specify the target subsystems and
3733
* resource relationship types which then allow for filtering the graph

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,16 @@ class reapi_t {
9999
* detail. However, when it is used within a Flux's
100100
* service module, it is expected to be a pointer
101101
* to a flux_t object.
102-
* \param orelse_reserve
103-
* Boolean: if false, only allocate; otherwise, first try
104-
* to allocate and if that fails, reserve.
102+
* \param match_op match_op_t: set to specify the specific match option
103+
* from 1 of 4 choices:
104+
* MATCH_ALLOCATE: try to allocate now and fail if resources
105+
* aren't available.
106+
* MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve
107+
* if resources aren't available now.
108+
* MATCH_SATISFIABILITY: Do a satisfiablity check and do not
109+
* allocate.
110+
* MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run
111+
* satisfiability check if resources are not available.
105112
* \param jobspec jobspec string.
106113
* \param jobid jobid of the uint64_t type.
107114
* \param reserved Boolean into which to return true if this job has been
@@ -131,9 +138,15 @@ class reapi_t {
131138
* detail. However, when it is used within a Flux's
132139
* service module, it is expected to be a pointer
133140
* to a flux_t object.
134-
* \param orelse_reserve
135-
* Boolean: if false, only allocate; otherwise, first try
136-
* to allocate and if that fails, reserve.
141+
* \param match_op match_op_t: set to specify the specific match option
142+
* from 1 of 4 choices:
143+
* MATCH_ALLOCATE: try to allocate now and fail if resources
144+
* aren't available.
145+
* MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve
146+
* if resources aren't available now.
147+
* MATCH_SATISFIABILITY: Do a satisfiablity check and do not
148+
* allocate.
149+
* MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run
137150
* \param jobs JSON array of jobspecs.
138151
* \param adapter queue_adapter_base_t object that provides
139152
* a set of callback methods to be called each time

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
#include "resource/jobinfo/jobinfo.hpp"
2727
#include "resource/policies/dfu_match_policy_factory.hpp"
2828
#include "resource/traversers/dfu.hpp"
29+
#include "resource/policies/base/match_op.h"
2930

3031
namespace Flux {
3132
namespace resource_model {
@@ -129,7 +130,7 @@ class resource_query_t {
129130

130131
class reapi_cli_t : public reapi_t {
131132
public:
132-
static int match_allocate (void *h, bool orelse_reserve,
133+
static int match_allocate (void *h, match_op_t match_op,
133134
const std::string &jobspec,
134135
const uint64_t jobid, bool &reserved,
135136
std::string &R, int64_t &at, double &ov);

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

Lines changed: 13 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)
@@ -66,6 +66,14 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
6666
std::stringstream o;
6767
bool matched = false;
6868

69+
if (!match_op_valid (match_op) ) {
70+
m_err_msg += __FUNCTION__;
71+
m_err_msg += ": ERROR: Invalid Match Option: "
72+
+ std::string (match_op_to_string (match_op)) + "\n";
73+
rc = -1;
74+
goto out;
75+
}
76+
6977
try {
7078
Flux::Jobspec::Jobspec job {jobspec};
7179

@@ -76,13 +84,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
7684
goto out;
7785
}
7886

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);
87+
rc = rq->traverser_run (job, match_op, (int64_t)jobid, at);
8688

8789
if (rq->get_traverser_err_msg () != "") {
8890
m_err_msg += __FUNCTION__;
@@ -110,7 +112,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
110112
}
111113

112114
// Check for an unsuccessful match
113-
if (rc == 0) {
115+
if ( (rc == 0) && (match_op != match_op_t::MATCH_SATISFIABILITY)) {
114116
matched = true;
115117
}
116118

@@ -154,7 +156,8 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
154156

155157
}
156158

157-
rq->incr_job_counter ();
159+
if (match_op != match_op_t::MATCH_SATISFIABILITY)
160+
rq->incr_job_counter ();
158161

159162
out:
160163
return rc;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,28 @@ extern "C" {
2121
#include <cstdint>
2222
#include <string>
2323
#include "resource/reapi/bindings/c++/reapi.hpp"
24+
#include "resource/policies/base/match_op.h"
2425

2526
namespace Flux {
2627
namespace resource_model {
2728
namespace detail {
2829

2930
class reapi_module_t : public reapi_t {
3031
public:
32+
static int match_allocate (void *h, match_op_t match_op,
33+
const std::string &jobspec,
34+
const uint64_t jobid, bool &reserved,
35+
std::string &R, int64_t &at, double &ov);
3136
static int match_allocate (void *h, bool orelse_reserve,
3237
const std::string &jobspec,
3338
const uint64_t jobid, bool &reserved,
3439
std::string &R, int64_t &at, double &ov);
3540
static int match_allocate_multi (void *h, bool orelse_reserve,
3641
const char *jobs,
3742
queue_adapter_base_t *adapter);
43+
static int match_allocate_multi (void *h, match_op_t match_op,
44+
const char *jobs,
45+
queue_adapter_base_t *adapter);
3846
static int update_allocate (void *h, const uint64_t jobid,
3947
const std::string &R, int64_t &at, double &ov,
4048
std::string &R_out);

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

Lines changed: 27 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, match_op_t match_op,
2929
const std::string &jobspec,
3030
const uint64_t jobid, bool &reserved,
3131
std::string &R, int64_t &at, double &ov)
@@ -36,8 +36,7 @@ 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";
39+
const char *cmd = match_op_to_string (match_op);
4140

4241
if (!fh || jobspec == "" || jobid > INT64_MAX) {
4342
errno = EINVAL;
@@ -70,6 +69,18 @@ int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
7069
return rc;
7170
}
7271

72+
int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
73+
const std::string &jobspec,
74+
const uint64_t jobid, bool &reserved,
75+
std::string &R, int64_t &at, double &ov)
76+
{
77+
match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE
78+
: match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY;
79+
80+
return match_allocate (h, match_op, jobspec, jobid, reserved, R, at, ov);
81+
82+
}
83+
7384
void match_allocate_multi_cont (flux_future_t *f, void *arg)
7485
{
7586
int64_t rj = -1;
@@ -101,16 +112,15 @@ void match_allocate_multi_cont (flux_future_t *f, void *arg)
101112
}
102113

103114
int reapi_module_t::match_allocate_multi (void *h,
104-
bool orelse_reserve,
115+
match_op_t match_op,
105116
const char *jobs,
106117
queue_adapter_base_t *adapter)
107118
{
108119
int rc = -1;
109120
flux_t *fh = static_cast<flux_t *> (h);
110121
flux_future_t *f = nullptr;
122+
const char *cmd = match_op_to_string (match_op);
111123

112-
const char *cmd = orelse_reserve ? "allocate_orelse_reserve"
113-
: "allocate_with_satisfiability";
114124
if (!fh) {
115125
errno = EINVAL;
116126
goto error;
@@ -134,6 +144,17 @@ int reapi_module_t::match_allocate_multi (void *h,
134144
return rc;
135145
}
136146

147+
int reapi_module_t::match_allocate_multi (void *h,
148+
bool orelse_reserve,
149+
const char *jobs,
150+
queue_adapter_base_t *adapter)
151+
{
152+
match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE
153+
: match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY;
154+
155+
return match_allocate_multi (h, match_op, jobs, adapter);
156+
}
157+
137158
int reapi_module_t::update_allocate (void *h, const uint64_t jobid,
138159
const std::string &R, int64_t &at,
139160
double &ov, std::string &R_out)

resource/reapi/bindings/c/reapi_cli.cpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph,
9090
return rc;
9191
}
9292

93-
extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
94-
bool orelse_reserve, const char *jobspec,
95-
uint64_t *jobid, bool *reserved,
96-
char **R, int64_t *at, double *ov)
93+
extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx,
94+
match_op_t match_op, const char *jobspec,
95+
uint64_t *jobid, bool *reserved,
96+
char **R, int64_t *at, double *ov)
9797
{
9898
int rc = -1;
9999
std::string R_buf = "";
@@ -105,11 +105,12 @@ extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
105105
}
106106

107107
*jobid = ctx->rqt->get_job_counter ();
108-
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, orelse_reserve,
108+
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, match_op,
109109
jobspec, *jobid, *reserved,
110110
R_buf, *at, *ov)) < 0) {
111111
goto out;
112112
}
113+
113114
if ( !(R_buf_c = strdup (R_buf.c_str ()))) {
114115
ctx->err_msg = __FUNCTION__;
115116
ctx->err_msg += ": ERROR: can't allocate memory\n";
@@ -123,9 +124,44 @@ extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
123124
return rc;
124125
}
125126

127+
extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
128+
bool orelse_reserve, const char *jobspec,
129+
uint64_t *jobid, bool *reserved,
130+
char **R, int64_t *at, double *ov)
131+
{
132+
match_op_t match_op = orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE :
133+
match_op_t::MATCH_ALLOCATE;
134+
135+
return reapi_cli_match (ctx, match_op, jobspec, jobid, reserved,
136+
R, at, ov);
137+
}
138+
139+
extern "C" int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx,
140+
const char *jobspec,
141+
bool *sat, double *ov)
142+
{
143+
match_op_t match_op = match_op_t::MATCH_SATISFIABILITY;
144+
uint64_t jobid;
145+
bool reserved;
146+
char *R;
147+
int64_t at;
148+
int ret;
149+
*sat = true;
150+
151+
ret = reapi_cli_match (ctx, match_op, jobspec, &jobid,
152+
&reserved, &R, &at, ov);
153+
154+
// check for satisfiability
155+
if (errno == ENODEV)
156+
*sat = false;
157+
158+
return ret;
159+
}
160+
126161
extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx,
127-
const uint64_t jobid, const char *R, int64_t *at,
128-
double *ov, const char **R_out)
162+
const uint64_t jobid,
163+
const char *R, int64_t *at,
164+
double *ov, const char **R_out)
129165
{
130166
int rc = -1;
131167
std::string R_buf = "";

0 commit comments

Comments
 (0)