Skip to content

Commit a3720b8

Browse files
author
Robin VAN DE MERGHEL
committed
feat: Update job monitoring to use diracX functions
1 parent 1532612 commit a3720b8

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

src/DIRAC/WorkloadManagementSystem/FutureClient/JobMonitoringClient.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def fetch(self, parameters, jobIDs):
88
with DiracXClient() as api:
99
jobs = api.jobs.search(
1010
parameters=["JobID"] + parameters,
11-
search=[{"parameter": "JobID", "operator": "in", "values": jobIDs}],
11+
search=[{"parameter": "JobID", "operator": "in", "values": jobIDs}], # type: ignore
1212
)
1313
return {j["JobID"]: {param: j[param] for param in parameters} for j in jobs}
1414

@@ -20,6 +20,66 @@ def getJobsMinorStatus(self, jobIDs):
2020
def getJobsStates(self, jobIDs):
2121
return self.fetch(["Status", "MinorStatus", "ApplicationStatus"], jobIDs)
2222

23+
@convertToReturnValue
24+
def getJobsApplicationStatus(self, jobIDs):
25+
return self.fetch(["ApplicationStatus"], jobIDs)
26+
2327
@convertToReturnValue
2428
def getJobsSites(self, jobIDs):
2529
return self.fetch(["Site"], jobIDs)
30+
31+
@convertToReturnValue
32+
def getJobsStatus(self, jobIDs):
33+
return self.fetch(["Status"], jobIDs)
34+
35+
@convertToReturnValue
36+
def getJobParameters(self, jobIDs):
37+
# if isinstance(jobIDs, int):
38+
# jobIDs = [jobIDs]
39+
40+
# with DiracXClient() as api:
41+
# result = {}
42+
43+
# for jobID in jobIDs:
44+
# return api.jobs.get_job_parameters(
45+
# job_id=jobID
46+
# )
47+
# Need a coffee to understand DIRAC code...
48+
pass
49+
50+
@convertToReturnValue
51+
def getInputData(self, jobIDs):
52+
with DiracXClient() as api:
53+
# It's a mess
54+
if isinstance(jobIDs, int):
55+
jobIDs = [jobIDs]
56+
elif isinstance(jobIDs, str):
57+
jobIDs = [int(jobIDs)]
58+
elif isinstance(jobIDs, list):
59+
if isinstance(jobIDs[0], str):
60+
jobIDs = [int(jobID) for jobID in jobIDs]
61+
62+
reqDict = {}
63+
64+
for jobID in jobIDs:
65+
reqDict[jobID] = api.jobs.get_input_data(jobID) # type: ignore
66+
67+
def cleanLFN(data):
68+
lfn = data["LFN"]
69+
if lfn.lower().startswith("lfn:"):
70+
return lfn[4:]
71+
return lfn
72+
73+
# WARNING /!\: Old code is super bizarre.
74+
# It can return list as well as dict...
75+
# By default, it's better to return a dict.
76+
77+
return_dict = {}
78+
for data in reqDict:
79+
job_id = data["JobID"]
80+
if not job_id in return_dict:
81+
return_dict[job_id] = []
82+
83+
return_dict[job_id].append(cleanLFN(data))
84+
85+
return return_dict

0 commit comments

Comments
 (0)