@@ -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+
143159out:
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+
237283int 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+
608664void resource_query_t::clear_resource_query_err_msg ()
609665{
610666 m_err_msg = " " ;
0 commit comments