@@ -16,6 +16,14 @@ package fluxcli
1616import "C"
1717import (
1818 "fmt"
19+ "unsafe"
20+ )
21+
22+ const (
23+ matchAllocate = "allocate"
24+ matchAllocateOrelseReserve = "allocate_orelse_reserve"
25+ matchAllocateWSatisfiability = "allocate_with_satisfiability"
26+ matchSatisfiability = "satisfiability"
1927)
2028
2129type (
@@ -72,14 +80,13 @@ func (cli *ReapiClient) InitContext(jgf string, options string) (err error) {
7280 return retvalToError (fluxerr , "issue initializing resource api client" )
7381}
7482
75- // MatchAllocate matches a jobspec to the "best" resources and either allocate
76- //
77- // orelse reserve them. The best resources are determined by
78- // the selected match policy.
83+ // Match matches a jobspec to the "best" resources based on match option.
84+
85+ // The best resources are determined by the selected match policy.
7986//
80- // \param orelse_reserve
81- // Boolean: if false, only allocate; otherwise, first try
82- // to allocate and if that fails, reserve.
87+ // \param match_op String to indicate the match type. Options include:
88+ // allocate, allocate_orelse_reserve, satisfiability,
89+ // allocate_with_satsfiability
8390// \param jobspec jobspec string.
8491// \param jobid jobid of the uint64_t type.
8592// \param reserved Boolean into which to return true if this job has been
@@ -92,15 +99,15 @@ func (cli *ReapiClient) InitContext(jgf string, options string) (err error) {
9299// in terms of elapse time needed to complete
93100// the match operation.
94101// \return 0 on success; -1 on error.
95- func (cli * ReapiClient ) MatchAllocate (
96- orelse_reserve bool ,
102+ func (cli * ReapiClient ) Match (
103+ match_op string ,
97104 jobspec string ,
98105) (reserved bool , allocated string , at int64 , overhead float64 , jobid uint64 , err error ) {
99106 var r = C .CString ("" )
100107 spec := C .CString (jobspec )
101108
102- fluxerr := (int )(C .reapi_cli_match_allocate ((* C .struct_reapi_cli_ctx )(cli .ctx ),
103- (C .bool )( orelse_reserve ),
109+ fluxerr := (int )(C .reapi_cli_match ((* C .struct_reapi_cli_ctx )(cli .ctx ),
110+ (C .CString )( match_op ),
104111 spec ,
105112 (* C .ulong )(& jobid ),
106113 (* C .bool )(& reserved ),
@@ -110,11 +117,77 @@ func (cli *ReapiClient) MatchAllocate(
110117
111118 allocated = C .GoString (r )
112119
120+ defer C .free (unsafe .Pointer (r ))
121+ defer C .free (unsafe .Pointer (spec ))
122+
113123 err = retvalToError (fluxerr , "issue resource api client matching allocate" )
114124 return reserved , allocated , at , overhead , jobid , err
115125
116126}
117127
128+ // MatchAllocate matches a jobspec to the "best" resources and either allocate
129+ //
130+ // orelse reserve them. The best resources are determined by
131+ // the selected match policy.
132+ //
133+ // \param orelse_reserve
134+ // Boolean: if false, only allocate; otherwise, first try
135+ // to allocate and if that fails, reserve.
136+ // \param jobspec jobspec string.
137+ // \param jobid jobid of the uint64_t type.
138+ // \param reserved Boolean into which to return true if this job has been
139+ // reserved instead of allocated.
140+ // \param R String into which to return the resource set either
141+ // allocated or reserved.
142+ // \param at If allocated, 0 is returned; if reserved, actual time
143+ // at which the job is reserved.
144+ // \param ov Double into which to return performance overhead
145+ // in terms of elapse time needed to complete
146+ // the match operation.
147+ // \return 0 on success; -1 on error.
148+ func (cli * ReapiClient ) MatchAllocate (
149+ orelse_reserve bool ,
150+ jobspec string ,
151+ ) (reserved bool , allocated string , at int64 , overhead float64 , jobid uint64 , err error ) {
152+ var match_op string
153+
154+ if orelse_reserve {
155+ match_op = matchAllocateOrelseReserve
156+ } else {
157+ match_op = matchAllocate
158+ }
159+
160+ return cli .Match (match_op , jobspec )
161+ }
162+
163+ // MatchSatisfy runs satisfiability check on jobspec.
164+ //
165+ // \param jobspec jobspec string.
166+ // \param jobid jobid of the uint64_t type.
167+ // \param reserved Boolean into which to return true if this job has been
168+ // reserved instead of allocated.
169+ // \param R String into which to return the resource set either
170+ // allocated or reserved.
171+ // \param at If allocated, 0 is returned; if reserved, actual time
172+ // at which the job is reserved.
173+ // \param ov Double into which to return performance overhead
174+ // in terms of elapse time needed to complete
175+ // the match operation.
176+ // \return 0 on success; -1 on error.
177+ func (cli * ReapiClient ) MatchSatisfy (
178+ jobspec string ,
179+ ) (sat bool , overhead float64 , err error ) {
180+ spec := C .CString (jobspec )
181+
182+ fluxerr := (int )(C .reapi_cli_match_satisfy ((* C .struct_reapi_cli_ctx )(cli .ctx ),
183+ spec ,
184+ (* C .bool )(& sat ),
185+ (* C .double )(& overhead )))
186+
187+ err = retvalToError (fluxerr , "issue resource api client matching satisfy" )
188+ return sat , overhead , err
189+ }
190+
118191// UpdateAllocate updates the resource state with R.
119192//
120193// \param jobid jobid of the uint64_t type.
0 commit comments