Skip to content

Commit 23ea5da

Browse files
authored
Merge pull request #8204 from fstagni/90_fixes14
[9.0] fix: getJobParameters expects a list
2 parents db263d5 + 5aea4d7 commit 23ea5da

File tree

5 files changed

+26
-43
lines changed

5 files changed

+26
-43
lines changed

src/DIRAC/MonitoringSystem/Service/WebAppHandler.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ def export_getJobPageSummaryWeb(self, selectDict, sortList, startItem, maxItems,
188188
)
189189
summaryJobList = validJobs
190190

191-
res = self.jobDB.getJobsAttributes(summaryJobList)
192-
if not res["OK"]:
193-
return res
194-
return S_OK(strToIntDict(res["Value"]))
191+
result = self.jobDB.getJobsAttributes(summaryJobList)
192+
if not result["OK"]:
193+
return result
195194

196195
summaryDict = result["Value"]
197196
# If no jobs can be selected after the properties check
@@ -352,14 +351,9 @@ def export_getDistinctAttributeValues(cls, attribute, selectDict):
352351

353352
@classmethod
354353
def export_getTransformationFilesSummaryWeb(cls, selectDict, sortList, startItem, maxItems):
355-
selectColumns = (["TransformationID", "Status", "UsedSE", "TargetSE"],)
356-
timeStamp = ("LastUpdate",)
357-
statusColumn = ("Status",)
358354
fromDate = selectDict.get("FromDate", None)
359355
if fromDate:
360356
del selectDict["FromDate"]
361-
# if not fromDate:
362-
# fromDate = last_update
363357
toDate = selectDict.get("ToDate", None)
364358
if toDate:
365359
del selectDict["ToDate"]
@@ -369,26 +363,21 @@ def export_getTransformationFilesSummaryWeb(cls, selectDict, sortList, startItem
369363
else:
370364
orderAttribute = None
371365
# Get the columns that match the selection
372-
fcn = None
373-
fcnName = "getTransformationFiles"
374-
if hasattr(cls.transformationDB, fcnName) and callable(getattr(cls.transformationDB, fcnName)):
375-
fcn = getattr(cls.transformationDB, fcnName)
376-
if not fcn:
377-
return S_ERROR(f"Unable to invoke gTransformationDB.{fcnName}, it isn't a member function")
378-
res = fcn(condDict=selectDict, older=toDate, newer=fromDate, timeStamp=timeStamp, orderAttribute=orderAttribute)
366+
res = cls.transformationDB.getTransformationFiles(
367+
condDict=selectDict, older=toDate, newer=fromDate, timeStamp="LastUpdate", orderAttribute=orderAttribute
368+
)
379369
if not res["OK"]:
380370
return res
381-
382-
# The full list of columns in contained here
383371
allRows = res["Value"]
372+
384373
# Prepare the standard structure now within the resultDict dictionary
385374
resultDict = {}
386-
# Create the total records entry
387375
resultDict["TotalRecords"] = len(allRows)
388376

389-
# Get the rows which are within the selected window
390-
if resultDict["TotalRecords"] == 0:
377+
if not allRows:
391378
return S_OK(resultDict)
379+
380+
# Get the rows which are within the selected window
392381
ini = startItem
393382
last = ini + maxItems
394383
if ini >= resultDict["TotalRecords"]:
@@ -403,25 +392,25 @@ def export_getTransformationFilesSummaryWeb(cls, selectDict, sortList, startItem
403392

404393
# Create the ParameterNames entry
405394
resultDict["ParameterNames"] = list(selectedRows[0].keys())
406-
# Find which element in the tuple contains the requested status
407-
if statusColumn not in resultDict["ParameterNames"]:
408-
return S_ERROR("Provided status column not present")
409395

410396
# Generate the status dictionary
411397
statusDict = {}
412398
for row in selectedRows:
413-
status = row[statusColumn]
399+
status = row["Status"]
414400
statusDict[status] = statusDict.setdefault(status, 0) + 1
415401
resultDict["Extras"] = statusDict
416402

417403
# Obtain the distinct values of the selection parameters
418404
res = cls.transformationDB.getTableDistinctAttributeValues(
419-
"TransformationFiles", selectColumns, selectDict, older=toDate, newer=fromDate
405+
"TransformationFiles",
406+
["TransformationID", "Status", "UsedSE", "TargetSE"],
407+
selectDict,
408+
older=toDate,
409+
newer=fromDate,
420410
)
421-
distinctSelections = zip(selectColumns, [])
422-
if res["OK"]:
423-
distinctSelections = res["Value"]
424-
resultDict["Selections"] = distinctSelections
411+
if not res["OK"]:
412+
return res
413+
resultDict["Selections"] = res["Value"]
425414

426415
return S_OK(resultDict)
427416

src/DIRAC/WorkloadManagementSystem/Agent/StalledJobAgent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _failStalledJobs(self, jobID):
254254

255255
def _getJobPilotStatus(self, jobID):
256256
"""Get the job pilot status."""
257-
result = getJobParameters(jobID, "Pilot_Reference")
257+
result = getJobParameters([jobID], "Pilot_Reference")
258258
if not result["OK"]:
259259
return result
260260
pilotReference = result["Value"].get("Pilot_Reference")
@@ -389,11 +389,11 @@ def _sendAccounting(self, jobID):
389389
if lastHeartBeatTime is not None and lastHeartBeatTime > endTime:
390390
endTime = lastHeartBeatTime
391391

392-
result = getJobParameters(jobID, "CPUNormalizationFactor")
393-
if not result["OK"] or not result["Value"]:
392+
result = getJobParameters([jobID], "CPUNormalizationFactor")
393+
if not result["OK"] or not result["Value"] or not result["Value"].get("CPUNormalizationFactor"):
394394
self.log.error(
395395
"Error getting Job Parameter CPUNormalizationFactor, setting 0",
396-
result.get("Message", "No such value"),
396+
result.get("Message"),
397397
)
398398
cpuNormalization = 0.0
399399
else:

src/DIRAC/WorkloadManagementSystem/DB/JobParametersDB.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _createIndex(self, indexName: str) -> None:
6969
raise RuntimeError(result["Message"])
7070
self.log.always("Index created:", indexName)
7171

72-
def getJobParameters(self, jobIDs: int | list[int], vo: str, paramList=None) -> dict:
72+
def getJobParameters(self, jobIDs: int | list[int], vo: str, paramList: list[str] | None = None) -> dict:
7373
"""Get Job Parameters defined for jobID.
7474
Returns a dictionary with the Job Parameters.
7575
If paramList is empty - all the parameters are returned.

src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def export_getJobParameter(self, jobID, parName):
247247
:param str/int jobID: one single Job ID
248248
:param str parName: one single parameter name
249249
"""
250-
res = self.elasticJobParametersDB.getJobParameters(int(jobID), self.vo, [parName])
250+
res = getJobParameters([int(jobID)], parName, self.vo or "")
251251
if not res["OK"]:
252252
return res
253253
return S_OK(res["Value"].get(int(jobID), {}))
@@ -266,7 +266,7 @@ def export_getJobOptParameters(cls, jobID):
266266
def export_getJobParameters(self, jobIDs, parName=None):
267267
"""
268268
:param str/int/list jobIDs: one single job ID or a list of them
269-
:param str parName: one single parameter name, a list or None (meaning all of them)
269+
:param str parName: one single parameter name, or None (meaning all of them)
270270
"""
271271
if not isinstance(jobIDs, list):
272272
jobIDs = [jobIDs]

tests/Integration/FutureClient/WorkloadManagement/Test_JobMonitoring.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ def test_getJobSite():
108108
pytest.skip()
109109

110110

111-
def test_getJobStats():
112-
# JobMonitoringClient().getJobStats(attribute: str, selectDict: dict)
113-
method = JobMonitoringClient().getJobStats
114-
pytest.skip()
115-
116-
117111
def test_getJobSummary():
118112
# JobMonitoringClient().getJobSummary(jobID: int)
119113
method = JobMonitoringClient().getJobSummary

0 commit comments

Comments
 (0)