Skip to content

Commit 647a05c

Browse files
committed
fix(resources): apply suggestions in Condor/HTCondor
1 parent d54ce8e commit 647a05c

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/DIRAC/Resources/Computing/BatchSystems/Condor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
HOLD_REASON_SUBCODE = "55"
2828

29+
STATE_ATTRIBUTES = "ClusterId,ProcId,JobStatus,HoldReasonCode,HoldReasonSubCode,HoldReason"
30+
2931
subTemplate = """
3032
# Environment
3133
# -----------
@@ -94,7 +96,7 @@ def getCondorStatus(jobMetadata):
9496
"""parse the condor_q or condor_history output for the job status
9597
9698
:param jobMetadata: dict with job metadata
97-
:type lines: dict[str, str | int]
99+
:type jobMetadata: dict[str, str | int]
98100
:returns: Status as known by DIRAC, and a reason if the job is being held
99101
"""
100102
if jobMetadata["JobStatus"] != 5:
@@ -272,10 +274,9 @@ def getJobStatus(self, **kwargs):
272274

273275
# Prepare the command to get the status of the jobs
274276
cmdJobs = " ".join(str(jobID) for jobID in jobIDList)
275-
attributes = "ClusterId,ProcId,JobStatus,HoldReasonCode,HoldReasonSubCode,HoldReason"
276277

277278
# Get the status of the jobs currently active
278-
cmd = "condor_q %s -attributes %s -json" % (cmdJobs, attributes)
279+
cmd = "condor_q %s -attributes %s -json" % (cmdJobs, STATE_ATTRIBUTES)
279280
sp = subprocess.Popen(
280281
shlex.split(cmd),
281282
stdout=subprocess.PIPE,
@@ -290,10 +291,10 @@ def getJobStatus(self, **kwargs):
290291
resultDict["Message"] = error
291292
return resultDict
292293

293-
jobMetadata = json.loads(output)
294+
jobsMetadata = json.loads(output)
294295

295296
# Get the status of the jobs in the history
296-
condorHistCall = "condor_history %s -attributes %s -json" % (cmdJobs, attributes)
297+
condorHistCall = "condor_history %s -attributes %s -json" % (cmdJobs, STATE_ATTRIBUTES)
297298
sp = subprocess.Popen(
298299
shlex.split(condorHistCall),
299300
stdout=subprocess.PIPE,
@@ -308,12 +309,12 @@ def getJobStatus(self, **kwargs):
308309
resultDict["Message"] = error
309310
return resultDict
310311

311-
jobMetadata += json.loads(output)
312+
jobsMetadata += json.loads(output)
312313

313314
statusDict = {}
314-
# Build a set of job IDs found in jobMetadata
315+
# Build a set of job IDs found in jobsMetadata
315316
foundJobIDs = set()
316-
for jobDict in jobMetadata:
317+
for jobDict in jobsMetadata:
317318
jobID = "%s.%s" % (jobDict["ClusterId"], jobDict["ProcId"])
318319
statusDict[jobID], _ = getCondorStatus(jobDict)
319320
foundJobIDs.add(jobID)

src/DIRAC/Resources/Computing/HTCondorCEComputingElement.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@
6464
from DIRAC.Core.Utilities.List import breakListIntoChunks
6565
from DIRAC.Core.Utilities.Subprocess import systemCall
6666
from DIRAC.FrameworkSystem.private.authorization.utils.Tokens import writeToTokenFile
67-
from DIRAC.Resources.Computing.BatchSystems.Condor import HOLD_REASON_SUBCODE, getCondorStatus, subTemplate
67+
from DIRAC.Resources.Computing.BatchSystems.Condor import (
68+
HOLD_REASON_SUBCODE,
69+
STATE_ATTRIBUTES,
70+
getCondorStatus,
71+
subTemplate,
72+
)
6873
from DIRAC.Resources.Computing.ComputingElement import ComputingElement
6974
from DIRAC.WorkloadManagementSystem.Client import PilotStatus
7075

@@ -409,38 +414,36 @@ def getJobStatus(self, jobIDList):
409414
jobReference = jobReference.split(":::")[0]
410415
condorIDs[self._jobReferenceToCondorID(jobReference)] = jobReference
411416

412-
attributes = "ClusterId,ProcId,JobStatus,HoldReasonCode,HoldReasonSubCode,HoldReason"
413-
414-
qList = []
417+
jobsMetadata = []
415418
for _condorIDs in breakListIntoChunks(condorIDs.keys(), 100):
416419
cmd = ["condor_q"]
417420
cmd.extend(self.remoteScheddOptions.strip().split(" "))
418421
cmd.extend(_condorIDs)
419-
cmd.extend(["-attributes", attributes])
422+
cmd.extend(["-attributes", STATE_ATTRIBUTES])
420423
cmd.extend(["-json"])
421424
result = self._executeCondorCommand(cmd, keepTokenFile=True)
422425
if not result["OK"]:
423426
return result
424427

425428
if result["Value"]:
426-
qList.extend(json.loads(result["Value"]))
429+
jobsMetadata.extend(json.loads(result["Value"]))
427430

428431
condorHistCall = ["condor_history"]
429432
condorHistCall.extend(self.remoteScheddOptions.strip().split(" "))
430433
condorHistCall.extend(_condorIDs)
431-
condorHistCall.extend(["-attributes", attributes])
434+
condorHistCall.extend(["-attributes", STATE_ATTRIBUTES])
432435
condorHistCall.extend(["-json"])
433436
result = self._executeCondorCommand(cmd, keepTokenFile=True)
434437
if not result["OK"]:
435438
return result
436439

437440
if result["Value"]:
438-
qList.extend(json.loads(result["Value"]))
441+
jobsMetadata.extend(json.loads(result["Value"]))
439442

440443
foundJobIDs = set()
441-
for jobMetadata in qList:
442-
jobStatus, reason = getCondorStatus(jobMetadata)
443-
condorId = f"{jobMetadata['ClusterId']}.{jobMetadata['ProcId']}"
444+
for jobDict in jobsMetadata:
445+
jobStatus, reason = getCondorStatus(jobDict)
446+
condorId = f"{jobDict['ClusterId']}.{jobDict['ProcId']}"
444447
jobReference = condorIDs.get(condorId)
445448

446449
if jobStatus == PilotStatus.ABORTED:

0 commit comments

Comments
 (0)