Skip to content

Commit

Permalink
Merge pull request #1133 from zekemorton/reapi_match_options
Browse files Browse the repository at this point in the history
Add match options and match satisfy to reapi
  • Loading branch information
mergify[bot] authored Feb 16, 2024
2 parents d18a279 + 40e20e6 commit 3abccaa
Show file tree
Hide file tree
Showing 26 changed files with 700 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cmake/GolangSimple.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function(BUILD_GO_PROGRAM NAME MAIN_SRC CGO_CFLAGS CGO_LIBRARY_FLAGS)

add_custom_target(${NAME}_all ALL DEPENDS ${NAME})
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${NAME} DESTINATION bin)
endfunction(BUILD_GO_PROGRAM)
endfunction(BUILD_GO_PROGRAM)
34 changes: 34 additions & 0 deletions resource/policies/base/match_op.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef MATCH_OP_H
#define MATCH_OP_H


typedef enum match_op_t { MATCH_UNKNOWN,
MATCH_ALLOCATE,
MATCH_ALLOCATE_W_SATISFIABILITY,
MATCH_ALLOCATE_ORELSE_RESERVE,
MATCH_SATISFIABILITY } match_op_t;

static const char *match_op_to_string (match_op_t match_op) {
switch (match_op) {
case MATCH_ALLOCATE: return "allocate";
case MATCH_ALLOCATE_ORELSE_RESERVE: return "allocate_orelse_reserve";
case MATCH_ALLOCATE_W_SATISFIABILITY: return "allocate_with_satisfiability";
case MATCH_SATISFIABILITY: return "satisfiability";
default: return "error";
}
}

static bool match_op_valid (match_op_t match_op) {

if ( (match_op != MATCH_ALLOCATE) &&
(match_op != MATCH_ALLOCATE_W_SATISFIABILITY) &&
(match_op != MATCH_ALLOCATE_ORELSE_RESERVE) &&
(match_op != MATCH_SATISFIABILITY) ) {

return false;
}

return true;
}

#endif //MATCH_OP_H
6 changes: 1 addition & 5 deletions resource/policies/base/matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "resource/libjobspec/jobspec.hpp"
#include "resource/schema/data_std.hpp"
#include "resource/planner/c/planner.h"
#include "resource/policies/base/match_op.h"

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

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

enum class match_op_t { MATCH_ALLOCATE,
MATCH_ALLOCATE_W_SATISFIABILITY,
MATCH_ALLOCATE_ORELSE_RESERVE,
MATCH_SATISFIABILITY };

/*! Base matcher data class.
* Provide idioms to specify the target subsystems and
* resource relationship types which then allow for filtering the graph
Expand Down
25 changes: 19 additions & 6 deletions resource/reapi/bindings/c++/reapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ class reapi_t {
* detail. However, when it is used within a Flux's
* service module, it is expected to be a pointer
* to a flux_t object.
* \param orelse_reserve
* Boolean: if false, only allocate; otherwise, first try
* to allocate and if that fails, reserve.
* \param match_op match_op_t: set to specify the specific match option
* from 1 of 4 choices:
* MATCH_ALLOCATE: try to allocate now and fail if resources
* aren't available.
* MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve
* if resources aren't available now.
* MATCH_SATISFIABILITY: Do a satisfiablity check and do not
* allocate.
* MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run
* satisfiability check if resources are not available.
* \param jobspec jobspec string.
* \param jobid jobid of the uint64_t type.
* \param reserved Boolean into which to return true if this job has been
Expand Down Expand Up @@ -131,9 +138,15 @@ class reapi_t {
* detail. However, when it is used within a Flux's
* service module, it is expected to be a pointer
* to a flux_t object.
* \param orelse_reserve
* Boolean: if false, only allocate; otherwise, first try
* to allocate and if that fails, reserve.
* \param match_op match_op_t: set to specify the specific match option
* from 1 of 4 choices:
* MATCH_ALLOCATE: try to allocate now and fail if resources
* aren't available.
* MATCH_ALLOCATE_ORELSE_RESERVE : Try to allocate and reseve
* if resources aren't available now.
* MATCH_SATISFIABILITY: Do a satisfiablity check and do not
* allocate.
* MATCH_ALLOCATE_W_SATISFIABILITY: try to allocate and run
* \param jobs JSON array of jobspecs.
* \param adapter queue_adapter_base_t object that provides
* a set of callback methods to be called each time
Expand Down
3 changes: 2 additions & 1 deletion resource/reapi/bindings/c++/reapi_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {
#include "resource/jobinfo/jobinfo.hpp"
#include "resource/policies/dfu_match_policy_factory.hpp"
#include "resource/traversers/dfu.hpp"
#include "resource/policies/base/match_op.h"

namespace Flux {
namespace resource_model {
Expand Down Expand Up @@ -129,7 +130,7 @@ class resource_query_t {

class reapi_cli_t : public reapi_t {
public:
static int match_allocate (void *h, bool orelse_reserve,
static int match_allocate (void *h, match_op_t match_op,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov);
Expand Down
23 changes: 13 additions & 10 deletions resource/reapi/bindings/c++/reapi_cli_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string reapi_cli_t::m_err_msg = "";
* *
****************************************************************************/

int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
int reapi_cli_t::match_allocate (void *h, match_op_t match_op,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov)
Expand All @@ -66,6 +66,14 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
std::stringstream o;
bool matched = false;

if (!match_op_valid (match_op) ) {
m_err_msg += __FUNCTION__;
m_err_msg += ": ERROR: Invalid Match Option: "
+ std::string (match_op_to_string (match_op)) + "\n";
rc = -1;
goto out;
}

try {
Flux::Jobspec::Jobspec job {jobspec};

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

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

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

// Check for an unsuccessful match
if (rc == 0) {
if ( (rc == 0) && (match_op != match_op_t::MATCH_SATISFIABILITY)) {
matched = true;
}

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

}

rq->incr_job_counter ();
if (match_op != match_op_t::MATCH_SATISFIABILITY)
rq->incr_job_counter ();

out:
return rc;
Expand Down
8 changes: 8 additions & 0 deletions resource/reapi/bindings/c++/reapi_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ extern "C" {
#include <cstdint>
#include <string>
#include "resource/reapi/bindings/c++/reapi.hpp"
#include "resource/policies/base/match_op.h"

namespace Flux {
namespace resource_model {
namespace detail {

class reapi_module_t : public reapi_t {
public:
static int match_allocate (void *h, match_op_t match_op,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov);
static int match_allocate (void *h, bool orelse_reserve,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov);
static int match_allocate_multi (void *h, bool orelse_reserve,
const char *jobs,
queue_adapter_base_t *adapter);
static int match_allocate_multi (void *h, match_op_t match_op,
const char *jobs,
queue_adapter_base_t *adapter);
static int update_allocate (void *h, const uint64_t jobid,
const std::string &R, int64_t &at, double &ov,
std::string &R_out);
Expand Down
33 changes: 27 additions & 6 deletions resource/reapi/bindings/c++/reapi_module_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Flux {
namespace resource_model {
namespace detail {

int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
int reapi_module_t::match_allocate (void *h, match_op_t match_op,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov)
Expand All @@ -36,8 +36,7 @@ int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
flux_future_t *f = NULL;
const char *rset = NULL;
const char *status = NULL;
const char *cmd = (orelse_reserve)? "allocate_orelse_reserve"
: "allocate_with_satisfiability";
const char *cmd = match_op_to_string (match_op);

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

int reapi_module_t::match_allocate (void *h, bool orelse_reserve,
const std::string &jobspec,
const uint64_t jobid, bool &reserved,
std::string &R, int64_t &at, double &ov)
{
match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE
: match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY;

return match_allocate (h, match_op, jobspec, jobid, reserved, R, at, ov);

}

void match_allocate_multi_cont (flux_future_t *f, void *arg)
{
int64_t rj = -1;
Expand Down Expand Up @@ -101,16 +112,15 @@ void match_allocate_multi_cont (flux_future_t *f, void *arg)
}

int reapi_module_t::match_allocate_multi (void *h,
bool orelse_reserve,
match_op_t match_op,
const char *jobs,
queue_adapter_base_t *adapter)
{
int rc = -1;
flux_t *fh = static_cast<flux_t *> (h);
flux_future_t *f = nullptr;
const char *cmd = match_op_to_string (match_op);

const char *cmd = orelse_reserve ? "allocate_orelse_reserve"
: "allocate_with_satisfiability";
if (!fh) {
errno = EINVAL;
goto error;
Expand All @@ -134,6 +144,17 @@ int reapi_module_t::match_allocate_multi (void *h,
return rc;
}

int reapi_module_t::match_allocate_multi (void *h,
bool orelse_reserve,
const char *jobs,
queue_adapter_base_t *adapter)
{
match_op_t match_op = (orelse_reserve)? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE
: match_op_t::MATCH_ALLOCATE_W_SATISFIABILITY;

return match_allocate_multi (h, match_op, jobs, adapter);
}

int reapi_module_t::update_allocate (void *h, const uint64_t jobid,
const std::string &R, int64_t &at,
double &ov, std::string &R_out)
Expand Down
50 changes: 43 additions & 7 deletions resource/reapi/bindings/c/reapi_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ extern "C" int reapi_cli_initialize (reapi_cli_ctx_t *ctx, const char *rgraph,
return rc;
}

extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
bool orelse_reserve, const char *jobspec,
uint64_t *jobid, bool *reserved,
char **R, int64_t *at, double *ov)
extern "C" int reapi_cli_match (reapi_cli_ctx_t *ctx,
match_op_t match_op, const char *jobspec,
uint64_t *jobid, bool *reserved,
char **R, int64_t *at, double *ov)
{
int rc = -1;
std::string R_buf = "";
Expand All @@ -105,11 +105,12 @@ extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
}

*jobid = ctx->rqt->get_job_counter ();
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, orelse_reserve,
if ((rc = reapi_cli_t::match_allocate (ctx->rqt, match_op,
jobspec, *jobid, *reserved,
R_buf, *at, *ov)) < 0) {
goto out;
}

if ( !(R_buf_c = strdup (R_buf.c_str ()))) {
ctx->err_msg = __FUNCTION__;
ctx->err_msg += ": ERROR: can't allocate memory\n";
Expand All @@ -123,9 +124,44 @@ extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
return rc;
}

extern "C" int reapi_cli_match_allocate (reapi_cli_ctx_t *ctx,
bool orelse_reserve, const char *jobspec,
uint64_t *jobid, bool *reserved,
char **R, int64_t *at, double *ov)
{
match_op_t match_op = orelse_reserve ? match_op_t::MATCH_ALLOCATE_ORELSE_RESERVE :
match_op_t::MATCH_ALLOCATE;

return reapi_cli_match (ctx, match_op, jobspec, jobid, reserved,
R, at, ov);
}

extern "C" int reapi_cli_match_satisfy (reapi_cli_ctx_t *ctx,
const char *jobspec,
bool *sat, double *ov)
{
match_op_t match_op = match_op_t::MATCH_SATISFIABILITY;
uint64_t jobid;
bool reserved;
char *R;
int64_t at;
int ret;
*sat = true;

ret = reapi_cli_match (ctx, match_op, jobspec, &jobid,
&reserved, &R, &at, ov);

// check for satisfiability
if (errno == ENODEV)
*sat = false;

return ret;
}

extern "C" int reapi_cli_update_allocate (reapi_cli_ctx_t *ctx,
const uint64_t jobid, const char *R, int64_t *at,
double *ov, const char **R_out)
const uint64_t jobid,
const char *R, int64_t *at,
double *ov, const char **R_out)
{
int rc = -1;
std::string R_buf = "";
Expand Down
Loading

0 comments on commit 3abccaa

Please sign in to comment.