Skip to content

Commit

Permalink
python: Add JSC interface to python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
SteVwonder committed Sep 7, 2016
1 parent 410e764 commit 07184a6
Showing 1 changed file with 77 additions and 3 deletions.
80 changes: 77 additions & 3 deletions src/bindings/python/flux/jsc.py
@@ -1,9 +1,48 @@
from flux.wrapper import Wrapper, WrapperPimpl
from flux._jsc import ffi, lib

# Constants taken from jstatctl.h
JSC_STATE_PAIR = "state-pair"
JSC_STATE_PAIR_OSTATE = "ostate"
JSC_STATE_PAIR_NSTATE = "nstate"
JSC_RDESC = "rdesc"
JSC_RDESC_NNODES = "nnodes"
JSC_RDESC_NTASKS = "ntasks"
JSC_RDESC_WALLTIME = "walltime"
JSC_RDL = "rdl"
JSC_RDL_ALLOC = "rdl_alloc"
JSC_RDL_ALLOC_CONTAINED = "contained"
JSC_RDL_ALLOC_CONTAINING_RANK = "cmbdrank"
JSC_RDL_ALLOC_CONTAINED_NCORES = "cmbdncores"
JSC_PDESC = "pdesc"
JSC_PDESC_SIZE = "procsize"
JSC_PDESC_HOSTNAMES = "hostnames"
JSC_PDESC_EXECS = "executables"
JSC_PDESC_PDARRAY = "pdarray"
JSC_PDESC_RANK_PDARRAY_PID = "pid"
JSC_PDESC_RANK_PDARRAY_HINDX = "hindx"
JSC_PDESC_RANK_PDARRAY_EINDX = "eindx"

J_NULL = 1
J_RESERVED = 2
J_SUBMITTED = 3
J_PENDING = 4
J_SCHEDREQ = 5
J_SELECTED = 6
J_ALLOCATED = 7
J_RUNREQUEST = 8
J_STARTING = 9
J_STOPPED = 10
J_RUNNING = 11
J_CANCELLED = 12
J_COMPLETE = 13
J_REAPED = 14
J_FAILED = 15
J_FOR_RENT = 16

class JSCWrapper(Wrapper):
"""
Generic JSC wrapper, you probably do not want or need one of these.
"""
Generic JSC wrapper
"""

def __init__(self):
Expand All @@ -14,5 +53,40 @@ def __init__(self):
'jsc_',
])

raw = JSCWrapper()
_raw = JSCWrapper()

def query_jcb(flux_handle, jobid, key):
jcb_str = ffi.new('char *[1]')
_raw.query_jcb(flux_handle, jobid, key, jcb_str)
if jcb_str[0] == ffi.NULL:
return None
else:
return ffi.string(jcb_str[0])

def update_jcb(flux_handle, jobid, key, jcb):
return _raw.jsc_update_jcb(flux_handle, jobid, key, jcb)

@ffi.callback('jsc_handler_f')
def JSCNotifyWrapper(jcb, arg, errnum):
if jcb != ffi.NULL:
jcb = ffi.string(jcb)
cb, real_arg = ffi.from_handle(arg)
# TODO: necessary to check errnum?
ret = cb(jcb, real_arg, errnum)
return ret if ret is not None else 0

handles = []

def notify_status(flux_handle, fun, arg):
warg = (fun, arg)
whandle = ffi.new_handle(warg)
# TODO: another way to keep in scope to prevent GC?
handles.append(whandle)
return _raw.notify_status(flux_handle, JSCNotifyWrapper, whandle)

def job_num2state(job_state):
ret = _raw.job_num2state(job_state)
if ret == ffi.NULL:
return None
else:
return ffi.string(ret)

0 comments on commit 07184a6

Please sign in to comment.