From 089b4a82364bacb8999d98c9894c24f84f1b1cc7 Mon Sep 17 00:00:00 2001
From: Yan Li
Date: Fri, 9 Jun 2023 10:22:34 +0800
Subject: [PATCH] add example of query multiple jobs with single calling to mbd
---
examples/get_jobs_info.py | 60 +++++++++++++++++++++++++++++++++++++++
pythonlsf/lsf.i | 14 +++++++++
2 files changed, 74 insertions(+)
create mode 100755 examples/get_jobs_info.py
diff --git a/examples/get_jobs_info.py b/examples/get_jobs_info.py
new file mode 100755
index 0000000..84aeaea
--- /dev/null
+++ b/examples/get_jobs_info.py
@@ -0,0 +1,60 @@
+from pythonlsf import lsf
+import sys
+
+def get_job_info(list) :
+ if lsf.lsb_init("test") > 0:
+ print("failed to initialize")
+ return
+ if len(list) == 0 :
+ print("no valid job id given")
+ return
+ print("request below job's info: {}".format(list))
+ clusterName = lsf.ls_getclustername()
+ print("retrieve cluster name : {}".format(clusterName))
+ query = "jobIds=("
+ for l in list:
+ query += l +","
+ query = query[:-1]
+ query += ")jobSouceClusterNames=("
+ for i in range(len(list)):
+ query += clusterName + ","
+ query = query[:-1]
+ query += ") options=" + str(lsf.ALL_JOB) + " "
+
+ jobQuery = lsf.jobInfoQuery()
+ jobQuery.nCols = 10
+ jobQuery.colIndexs = lsf.buildQueryColIndexs()
+
+ jobQuery.query = query
+ jobQuery.submitExt = lsf.submit_ext()
+ more = lsf.new_intp()
+ print("request: {}".format(jobQuery.query))
+ jobInfoPtr = lsf.jobInfoHeadExt()
+ jobInfoPtr = lsf.lsb_queryjobinfo_ext_2(jobQuery, clusterName)
+ foundJob = False
+ if jobInfoPtr != None :
+ if jobInfoPtr.jobInfoHead != None :
+ foundJob = True
+ if not foundJob :
+ print("faild to query jobs")
+ else :
+ print("found job number : {}".format(jobInfoPtr.jobInfoHead.numJobs))
+ if jobInfoPtr.jobInfoHead.numJobs > 0 :
+ job = lsf.jobInfoEnt()
+ job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)
+ if job == None:
+ print("no job found")
+ while job != None:
+ print("job <{}> from user ({}) status is {}".format(lsf.lsb_jobid2str(job.jobId),job.user, job.status))
+ job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)
+
+
+if __name__ == "__main__":
+ joblist = []
+ if len(sys.argv) < 2:
+ joblist = ['0']
+ else:
+ for jobid in sys.argv[1:]:
+ joblist.append(jobid)
+ joblist = ['3530','3531']
+ get_job_info(joblist)
diff --git a/pythonlsf/lsf.i b/pythonlsf/lsf.i
index ba1e52e..ac6af86 100755
--- a/pythonlsf/lsf.i
+++ b/pythonlsf/lsf.i
@@ -712,4 +712,18 @@ PyObject * get_pids_from_stream(struct jRusage * jrusage) {
return result;
}
+long * buildQueryColIndexs() {
+ long * colIndexs = NULL;
+ int i = 0;
+
+ colIndexs = calloc(113, sizeof(long));
+ for (i= 0; i < 113; i++) {
+ colIndexs[i] = i;
+ }
+ colIndexs[1] = 2;
+ colIndexs[2] = 1;
+ colIndexs[9] = 10;
+ return colIndexs;
+}
+
%}