Skip to content

Commit 19270a3

Browse files
committed
reapi: add match options for go bindings
Problem: reapi go bindings only use 2 of the 4 match options for match allocate. Create new functions match and match_satisfy where match is a general purpose match allocate function that can use all 4 match options. match_satisfy and match_allocate both call match for with their corresponding match options.
1 parent 07df1f8 commit 19270a3

File tree

2 files changed

+127
-18
lines changed

2 files changed

+127
-18
lines changed

resource/reapi/bindings/go/src/fluxcli/reapi_cli.go

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ package fluxcli
1616
import "C"
1717
import (
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

2129
type (
@@ -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.

resource/reapi/bindings/go/src/fluxmodule/reapi_module.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import (
1717
"unsafe"
1818
)
1919

20+
const (
21+
matchAllocate = "allocate"
22+
matchAllocateOrelseReserve = "allocate_orelse_reserve"
23+
matchAllocateWSatisfiability = "allocate_with_satisfiability"
24+
matchSatisfiability = "satisfiability"
25+
)
26+
2027
type (
2128
ReapiCtx C.struct_reapi_module_ctx_t
2229
ReapiModule struct {
@@ -51,11 +58,11 @@ func (m *ReapiModule) Destroy() {
5158
C.reapi_module_destroy((*C.struct_reapi_module_ctx)(m.ctx))
5259
}
5360

54-
// MatchAllocate matches and allocates resources
55-
// int reapi_module_match_allocate (reapi_module_ctx_t *ctx, bool orelse_reserve,
61+
// Match matches and allocates resources
62+
// int reapi_module_match_allocate (reapi_module_ctx_t *ctx, char *match_op,
5663
// at: is the scheduled time "at"
57-
func (m *ReapiModule) MatchAllocate(
58-
orelse_reserve bool,
64+
func (m *ReapiModule) Match(
65+
match_op string,
5966
jobspec string,
6067
jobid int,
6168
) (reserved bool, allocated string, at int64, overhead float64, err error) {
@@ -65,8 +72,8 @@ func (m *ReapiModule) MatchAllocate(
6572
// Jobspec as a CString
6673
spec := C.CString(jobspec)
6774

68-
fluxerr := (int)(C.reapi_module_match_allocate((*C.struct_reapi_module_ctx)(m.ctx),
69-
(C.bool)(orelse_reserve),
75+
fluxerr := (int)(C.reapi_module_match((*C.struct_reapi_module_ctx)(m.ctx),
76+
(C.CString)(match_op),
7077
spec,
7178
(C.ulong)(jobid),
7279
(*C.bool)(&reserved),
@@ -76,10 +83,39 @@ func (m *ReapiModule) MatchAllocate(
7683

7784
allocated = C.GoString(r)
7885

86+
defer C.free(unsafe.Pointer(r))
87+
defer C.free(unsafe.Pointer(spec))
88+
7989
err = retvalToError(fluxerr, "issue matching allocation for resource api")
8090
return reserved, allocated, at, overhead, err
8191
}
8292

93+
// MatchAllocate matches and allocates resources
94+
func (m *ReapiModule) MatchAllocate(
95+
orelse_reserve bool,
96+
jobspec string,
97+
jobid int,
98+
) (reserved bool, allocated string, at int64, overhead float64, err error) {
99+
var match_op string
100+
101+
if orelse_reserve {
102+
match_op = matchAllocateOrelseReserve
103+
} else {
104+
match_op = matchAllocate
105+
}
106+
107+
return m.Match(match_op, jobspec, jobid)
108+
}
109+
110+
// MatchSatisfy runs satisfiability check on jobspec
111+
func (m *ReapiModule) MatchSatisfy(
112+
jobspec string,
113+
jobid int,
114+
) (reserved bool, allocated string, at int64, overhead float64, err error) {
115+
match_op := matchSatisfiability
116+
return m.Match(match_op, jobspec, jobid)
117+
}
118+
83119
// Info gets the information on the allocation or reservation corresponding
84120
// to jobid.
85121
//
@@ -123,4 +159,4 @@ func (m *ReapiModule) Cancel(jobid int64, noent_ok bool) (err error) {
123159
(C.ulong)(jobid),
124160
(C.bool)(noent_ok)))
125161
return retvalToError(fluxerr, "issue with cancel")
126-
}
162+
}

0 commit comments

Comments
 (0)