Skip to content

Commit fe872c8

Browse files
authored
Merge pull request #1101 from zekemorton/reapi-match-allocate
RQ2 minimal functionality and bug fix to reapi match allocate
2 parents 250eac7 + e4f265d commit fe872c8

File tree

16 files changed

+941
-32
lines changed

16 files changed

+941
-32
lines changed

resource/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ schema/test/schema_test01
66
schema/test/schema_test02
77
utilities/grug2dot
88
utilities/resource-query
9+
utilities/rq2

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class resource_query_t {
7272
const std::shared_ptr<job_info_t> &get_job (const uint64_t jobid);
7373
const bool reservation_exists (const uint64_t jobid);
7474
const bool allocation_exists (const uint64_t jobid);
75+
const unsigned int preorder_count ();
76+
const unsigned int postorder_count ();
7577

7678
/* Mutators */
7779
void clear_resource_query_err_msg ();
@@ -141,6 +143,10 @@ class reapi_cli_t : public reapi_t {
141143
static int find (void *h, std::string criteria, json_t *&o );
142144
static int info (void *h, const uint64_t jobid, std::string &mode,
143145
bool &reserved, int64_t &at, double &ov);
146+
static int info (void *h, const uint64_t jobid,
147+
std::shared_ptr<job_info_t> &job);
148+
static unsigned int preorder_count (void *h);
149+
static unsigned int postorder_count (void *h);
144150
static int stat (void *h, int64_t &V, int64_t &E,int64_t &J,
145151
double &load, double &min, double &max, double &avg);
146152
static const std::string &get_err_message ();

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

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
6464
std::shared_ptr<job_info_t> job_info = nullptr;
6565
struct timeval start_time, end_time;
6666
std::stringstream o;
67+
bool matched = false;
6768

6869
try {
6970
Flux::Jobspec::Jobspec job {jobspec};
@@ -99,6 +100,19 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
99100
rc = -1;
100101
goto out;
101102
}
103+
104+
if ( (rc != 0) && (errno == ENOMEM)) {
105+
m_err_msg += __FUNCTION__;
106+
m_err_msg += ": ERROR: Memory error for "
107+
+ std::to_string (rq->get_job_counter ());
108+
rc = -1;
109+
goto out;
110+
}
111+
112+
// Check for an unsuccessful match
113+
if (rc == 0) {
114+
matched = true;
115+
}
102116

103117
if ( (rc = rq->writers->emit (o)) < 0) {
104118
m_err_msg += __FUNCTION__;
@@ -109,28 +123,6 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
109123

110124
R = o.str ();
111125

112-
113-
reserved = (at != 0)? true : false;
114-
st = (reserved)?
115-
job_lifecycle_t::RESERVED : job_lifecycle_t::ALLOCATED;
116-
if (reserved)
117-
rq->set_reservation (jobid);
118-
else
119-
rq->set_allocation (jobid);
120-
121-
job_info = std::make_shared<job_info_t> (jobid, st, at, "", "", ov);
122-
if (job_info == nullptr) {
123-
errno = ENOMEM;
124-
m_err_msg += __FUNCTION__;
125-
m_err_msg += ": ERROR: can't allocate memory: "
126-
+ std::string (strerror (errno))+ "\n";
127-
rc = -1;
128-
goto out;
129-
}
130-
131-
rq->set_job (jobid, job_info);
132-
rq->incr_job_counter ();
133-
134126
if ( (rc = gettimeofday (&end_time, NULL)) < 0) {
135127
m_err_msg += __FUNCTION__;
136128
m_err_msg += ": ERROR: gettimeofday: "
@@ -140,6 +132,30 @@ int reapi_cli_t::match_allocate (void *h, bool orelse_reserve,
140132

141133
ov = get_elapsed_time (start_time, end_time);
142134

135+
if (matched) {
136+
reserved = (at != 0)? true : false;
137+
st = (reserved)?
138+
job_lifecycle_t::RESERVED : job_lifecycle_t::ALLOCATED;
139+
if (reserved)
140+
rq->set_reservation (jobid);
141+
else
142+
rq->set_allocation (jobid);
143+
144+
job_info = std::make_shared<job_info_t> (jobid, st, at, "", "", ov);
145+
if (job_info == nullptr) {
146+
errno = ENOMEM;
147+
m_err_msg += __FUNCTION__;
148+
m_err_msg += ": ERROR: can't allocate memory: "
149+
+ std::string (strerror (errno))+ "\n";
150+
rc = -1;
151+
goto out;
152+
}
153+
rq->set_job (jobid, job_info);
154+
155+
}
156+
157+
rq->incr_job_counter ();
158+
143159
out:
144160
return rc;
145161
}
@@ -234,6 +250,36 @@ int reapi_cli_t::info (void *h, const uint64_t jobid, std::string &mode,
234250
return 0;
235251
}
236252

253+
int reapi_cli_t::info (void *h, const uint64_t jobid,
254+
std::shared_ptr<job_info_t> &job)
255+
{
256+
resource_query_t *rq = static_cast<resource_query_t *> (h);
257+
258+
if ( !(rq->job_exists (jobid))) {
259+
m_err_msg += __FUNCTION__;
260+
m_err_msg += ": ERROR: nonexistent job "
261+
+ std::to_string (jobid) + "\n";
262+
return -1;
263+
}
264+
265+
job = rq->get_job (jobid);
266+
return 0;
267+
}
268+
269+
unsigned int reapi_cli_t::preorder_count (void *h)
270+
{
271+
resource_query_t *rq = static_cast<resource_query_t *> (h);
272+
273+
return rq->preorder_count ();
274+
}
275+
276+
unsigned int reapi_cli_t::postorder_count (void *h)
277+
{
278+
resource_query_t *rq = static_cast<resource_query_t *> (h);
279+
280+
return rq->postorder_count ();
281+
}
282+
237283
int reapi_cli_t::stat (void *h, int64_t &V, int64_t &E,int64_t &J,
238284
double &load, double &min, double &max, double &avg)
239285
{
@@ -605,6 +651,16 @@ const bool resource_query_t::reservation_exists (const uint64_t jobid)
605651
return reservations.find (jobid) != reservations.end ();
606652
}
607653

654+
const unsigned int resource_query_t::preorder_count ()
655+
{
656+
return traverser->get_total_preorder_count ();
657+
}
658+
659+
const unsigned int resource_query_t::postorder_count ()
660+
{
661+
return traverser->get_total_postorder_count ();
662+
}
663+
608664
void resource_query_t::clear_resource_query_err_msg ()
609665
{
610666
m_err_msg = "";

resource/reapi/bindings/go/src/test/main.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
func main() {
2222
jgfPtr := flag.String("jgf", "", "path to jgf")
2323
jobspecPtr := flag.String("jobspec", "", "path to jobspec")
24-
reserve := flag.Bool("reserve", false, "or else reserve?")
24+
reserve := false
2525
flag.Parse()
2626

2727
jgf, err := os.ReadFile(*jgfPtr)
@@ -44,20 +44,32 @@ func main() {
4444
}
4545
fmt.Printf("Jobspec:\n %s\n", jobspec)
4646

47-
reserved, allocated, at, overhead, jobid, err := cli.MatchAllocate(*reserve, string(jobspec))
47+
reserved, allocated, at, overhead, jobid, err := cli.MatchAllocate(reserve, string(jobspec))
4848
if err != nil {
4949
fmt.Printf("Error in ReapiClient MatchAllocate: %v\n", err)
5050
return
5151
}
5252
printOutput(reserved, allocated, at, jobid, err)
53-
reserved, allocated, at, overhead, jobid, err = cli.MatchAllocate(*reserve, string(jobspec))
53+
54+
reserve = true
55+
reserved, allocated, at, overhead, jobid, err = cli.MatchAllocate(reserve, string(jobspec))
56+
fmt.Println("Errors so far: \n", cli.GetErrMsg())
57+
58+
if err != nil {
59+
fmt.Printf("Error in ReapiClient MatchAllocate: %v\n", err)
60+
return
61+
}
62+
printOutput(reserved, allocated, at, jobid, err)
63+
64+
reserved, allocated, at, overhead, jobid, err = cli.MatchAllocate(reserve, string(jobspec))
5465
fmt.Println("Errors so far: \n", cli.GetErrMsg())
5566

5667
if err != nil {
5768
fmt.Printf("Error in ReapiClient MatchAllocate: %v\n", err)
5869
return
5970
}
6071
printOutput(reserved, allocated, at, jobid, err)
72+
6173
err = cli.Cancel(1, false)
6274
if err != nil {
6375
fmt.Printf("Error in ReapiClient Cancel: %v\n", err)

resource/utilities/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ target_link_libraries(resource-query
1919
Boost::filesystem
2020
Boost::headers
2121
)
22+
add_executable(rq2
23+
rq2.cpp
24+
rq2.hpp
25+
)
26+
target_link_libraries(rq2
27+
resource
28+
PkgConfig::LIBEDIT
29+
)
2230

2331
add_subdirectory(test)
2432

0 commit comments

Comments
 (0)