Skip to content

Commit 22af916

Browse files
committed
refactor: moved RPC calls to WebAppHandler
1 parent dd8bcb8 commit 22af916

File tree

6 files changed

+112
-161
lines changed

6 files changed

+112
-161
lines changed

src/DIRAC/MonitoringSystem/Service/WebAppHandler.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,74 @@ def export_getSiteSummarySelectors(cls):
333333

334334
return S_OK(resultDict)
335335

336+
types_getApplicationStates = []
337+
338+
@classmethod
339+
def export_getApplicationStates(cls, condDict=None, older=None, newer=None):
340+
"""Return Distinct Values of ApplicationStatus job Attribute in WMS"""
341+
return cls.jobDB.getDistinctJobAttributes("ApplicationStatus", condDict, older, newer)
342+
343+
types_getJobTypes = []
344+
345+
@classmethod
346+
def export_getJobTypes(cls, condDict=None, older=None, newer=None):
347+
"""Return Distinct Values of JobType job Attribute in WMS"""
348+
return cls.jobDB.getDistinctJobAttributes("JobType", condDict, older, newer)
349+
350+
types_getOwners = []
351+
352+
@classmethod
353+
def export_getOwners(cls, condDict=None, older=None, newer=None):
354+
"""
355+
Return Distinct Values of Owner job Attribute in WMS
356+
"""
357+
return cls.jobDB.getDistinctJobAttributes("Owner", condDict, older, newer)
358+
359+
types_getOwnerGroup = []
360+
361+
@classmethod
362+
def export_getOwnerGroup(cls):
363+
"""
364+
Return Distinct Values of OwnerGroup from the JobDB
365+
"""
366+
return cls.jobDB.getDistinctJobAttributes("OwnerGroup")
367+
368+
types_getJobGroups = []
369+
370+
@classmethod
371+
def export_getJobGroups(cls, condDict=None, older=None, cutDate=None):
372+
"""
373+
Return Distinct Values of ProductionId job Attribute in WMS
374+
"""
375+
return cls.jobDB.getDistinctJobAttributes("JobGroup", condDict, older, newer=cutDate)
376+
377+
types_getSites = []
378+
379+
@classmethod
380+
def export_getSites(cls, condDict=None, older=None, newer=None):
381+
"""
382+
Return Distinct Values of Site job Attribute in WMS
383+
"""
384+
return cls.jobDB.getDistinctJobAttributes("Site", condDict, older, newer)
385+
386+
types_getStates = []
387+
388+
@classmethod
389+
def export_getStates(cls, condDict=None, older=None, newer=None):
390+
"""
391+
Return Distinct Values of Status job Attribute in WMS
392+
"""
393+
return cls.jobDB.getDistinctJobAttributes("Status", condDict, older, newer)
394+
395+
types_getMinorStates = []
396+
397+
@classmethod
398+
def export_getMinorStates(cls, condDict=None, older=None, newer=None):
399+
"""
400+
Return Distinct Values of Minor Status job Attribute in WMS
401+
"""
402+
return cls.jobDB.getDistinctJobAttributes("MinorStatus", condDict, older, newer)
403+
336404
##############################################################################
337405
# Transformations
338406
##############################################################################

src/DIRAC/TransformationSystem/Agent/TransformationCleaningAgent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
# # from DIRAC
1818
from DIRAC import S_ERROR, S_OK
19-
from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData
2019
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
2120
from DIRAC.Core.Base.AgentModule import AgentModule
2221
from DIRAC.Core.Utilities.DErrno import cmpError
2322
from DIRAC.Core.Utilities.List import breakListIntoChunks
2423
from DIRAC.Core.Utilities.Proxy import executeWithUserProxy
2524
from DIRAC.Core.Utilities.ReturnValues import returnSingleResult
26-
from DIRAC.DataManagementSystem.Client.DataManager import DataManager
2725
from DIRAC.RequestManagementSystem.Client.File import File
2826
from DIRAC.RequestManagementSystem.Client.Operation import Operation
2927
from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient
@@ -36,6 +34,7 @@
3634
from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient
3735
from DIRAC.WorkloadManagementSystem.Client.JobMonitoringClient import JobMonitoringClient
3836
from DIRAC.WorkloadManagementSystem.Client.WMSClient import WMSClient
37+
from DIRAC.WorkloadManagementSystem.DB.JobDB import JobDB
3938

4039
# # agent's name
4140
AGENT_NAME = "Transformation/TransformationCleaningAgent"
@@ -65,6 +64,8 @@ def __init__(self, *args, **kwargs):
6564
self.reqClient = None
6665
# # file catalog client
6766
self.metadataClient = None
67+
# # JobDB
68+
self.jobDB = None
6869

6970
# # transformations types
7071
self.transformationTypes = None
@@ -127,6 +128,8 @@ def initialize(self):
127128
self.metadataClient = FileCatalogClient()
128129
# # job monitoring client
129130
self.jobMonitoringClient = JobMonitoringClient()
131+
# # job DB
132+
self.jobDB = JobDB()
130133

131134
return S_OK()
132135

@@ -224,7 +227,7 @@ def finalize(self):
224227
So, we should just clean from time to time.
225228
What I added here is done only when the agent finalize, and it's quite light-ish operation anyway.
226229
"""
227-
res = self.jobMonitoringClient.getJobGroups(None, datetime.utcnow() - timedelta(days=365))
230+
res = self.jobDB.getDistinctJobAttributes("JobGroup", None, datetime.utcnow() - timedelta(days=365))
228231
if not res["OK"]:
229232
self.log.error("Failed to get job groups", res["Message"])
230233
return res

src/DIRAC/WorkloadManagementSystem/Service/JobMonitoringHandler.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -50,82 +50,6 @@ def getJobsAttributes(cls, *args, **kwargs):
5050
return res
5151
return S_OK(strToIntDict(res["Value"]))
5252

53-
##############################################################################
54-
types_getApplicationStates = []
55-
56-
@classmethod
57-
def export_getApplicationStates(cls, condDict=None, older=None, newer=None):
58-
"""Return Distinct Values of ApplicationStatus job Attribute in WMS"""
59-
return cls.jobDB.getDistinctJobAttributes("ApplicationStatus", condDict, older, newer)
60-
61-
##############################################################################
62-
types_getJobTypes = []
63-
64-
@classmethod
65-
def export_getJobTypes(cls, condDict=None, older=None, newer=None):
66-
"""Return Distinct Values of JobType job Attribute in WMS"""
67-
return cls.jobDB.getDistinctJobAttributes("JobType", condDict, older, newer)
68-
69-
##############################################################################
70-
types_getOwners = []
71-
72-
@classmethod
73-
def export_getOwners(cls, condDict=None, older=None, newer=None):
74-
"""
75-
Return Distinct Values of Owner job Attribute in WMS
76-
"""
77-
return cls.jobDB.getDistinctJobAttributes("Owner", condDict, older, newer)
78-
79-
##############################################################################
80-
types_getOwnerGroup = []
81-
82-
@classmethod
83-
def export_getOwnerGroup(cls):
84-
"""
85-
Return Distinct Values of OwnerGroup from the JobDB
86-
"""
87-
return cls.jobDB.getDistinctJobAttributes("OwnerGroup")
88-
89-
##############################################################################
90-
types_getJobGroups = []
91-
92-
@classmethod
93-
def export_getJobGroups(cls, condDict=None, older=None, cutDate=None):
94-
"""
95-
Return Distinct Values of ProductionId job Attribute in WMS
96-
"""
97-
return cls.jobDB.getDistinctJobAttributes("JobGroup", condDict, older, newer=cutDate)
98-
99-
##############################################################################
100-
types_getSites = []
101-
102-
@classmethod
103-
def export_getSites(cls, condDict=None, older=None, newer=None):
104-
"""
105-
Return Distinct Values of Site job Attribute in WMS
106-
"""
107-
return cls.jobDB.getDistinctJobAttributes("Site", condDict, older, newer)
108-
109-
##############################################################################
110-
types_getStates = []
111-
112-
@classmethod
113-
def export_getStates(cls, condDict=None, older=None, newer=None):
114-
"""
115-
Return Distinct Values of Status job Attribute in WMS
116-
"""
117-
return cls.jobDB.getDistinctJobAttributes("Status", condDict, older, newer)
118-
119-
##############################################################################
120-
types_getMinorStates = []
121-
122-
@classmethod
123-
def export_getMinorStates(cls, condDict=None, older=None, newer=None):
124-
"""
125-
Return Distinct Values of Minor Status job Attribute in WMS
126-
"""
127-
return cls.jobDB.getDistinctJobAttributes("MinorStatus", condDict, older, newer)
128-
12953
##############################################################################
13054
types_getJobs = []
13155

tests/Integration/FutureClient/WorkloadManagement/Test_JobMonitoring.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
TEST_JOB_IDS = [TEST_JOBS] + TEST_JOBS + [str(x) for x in TEST_JOBS]
1313

1414

15-
def test_getApplicationStates():
16-
# JobMonitoringClient().getApplicationStates(condDict = None, older = None, newer = None)
17-
method = JobMonitoringClient().getApplicationStates
18-
pytest.skip()
19-
20-
2115
def test_getCounters():
2216
# JobMonitoringClient().getCounters(attrList: list, attrDict = None, cutDate = )
2317
method = JobMonitoringClient().getCounters
@@ -42,12 +36,6 @@ def test_getJobAttributes():
4236
pytest.skip()
4337

4438

45-
def test_getJobGroups():
46-
# JobMonitoringClient().getJobGroups(condDict = None, older = None, cutDate = None)
47-
method = JobMonitoringClient().getJobGroups
48-
pytest.skip()
49-
50-
5139
def test_getJobHeartBeatData():
5240
# JobMonitoringClient().getJobHeartBeatData(jobID: int)
5341
method = JobMonitoringClient().getJobHeartBeatData
@@ -90,12 +78,6 @@ def test_getJobSummary():
9078
pytest.skip()
9179

9280

93-
def test_getJobTypes():
94-
# JobMonitoringClient().getJobTypes(condDict = None, older = None, newer = None)
95-
method = JobMonitoringClient().getJobTypes
96-
pytest.skip()
97-
98-
9981
def test_getJobs():
10082
# JobMonitoringClient().getJobs(attrDict = None, cutDate = None)
10183
method = JobMonitoringClient().getJobs
@@ -141,33 +123,3 @@ def test_getJobsSummary():
141123
# JobMonitoringClient().getJobsSummary(jobIDs: list)
142124
method = JobMonitoringClient().getJobsSummary
143125
pytest.skip()
144-
145-
146-
def test_getMinorStates():
147-
# JobMonitoringClient().getMinorStates(condDict = None, older = None, newer = None)
148-
method = JobMonitoringClient().getMinorStates
149-
pytest.skip()
150-
151-
152-
def test_getOwnerGroup():
153-
# JobMonitoringClient().getOwnerGroup()
154-
method = JobMonitoringClient().getOwnerGroup
155-
pytest.skip()
156-
157-
158-
def test_getOwners():
159-
# JobMonitoringClient().getOwners(condDict = None, older = None, newer = None)
160-
method = JobMonitoringClient().getOwners
161-
pytest.skip()
162-
163-
164-
def test_getSites():
165-
# JobMonitoringClient().getSites(condDict = None, older = None, newer = None)
166-
method = JobMonitoringClient().getSites
167-
pytest.skip()
168-
169-
170-
def test_getStates():
171-
# JobMonitoringClient().getStates(condDict = None, older = None, newer = None)
172-
method = JobMonitoringClient().getStates
173-
pytest.skip()
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pylint: disable=invalid-name, missing-docstring
22

3+
import datetime
4+
35
import DIRAC
46

57
DIRAC.initialize() # Initialize configuration
@@ -8,10 +10,45 @@
810
from DIRAC.MonitoringSystem.Client.WebAppClient import WebAppClient
911

1012

11-
def test_WMSAdministratorClient():
13+
def test_WebAppClient():
1214
res = WebAppClient().getSiteSummaryWeb({}, [], 0, 100)
1315
assert res["OK"], res["Message"]
1416
assert res["Value"]["TotalRecords"] in [0, 1, 2, 34]
1517

1618
res = WebAppClient().getSiteSummarySelectors()
1719
assert res["OK"], res["Message"]
20+
21+
res = WebAppClient().getApplicationStates()
22+
assert res["OK"], res["Message"]
23+
24+
res = WebAppClient().getJobTypes()
25+
assert res["OK"], res["Message"]
26+
27+
res = WebAppClient().getOwners()
28+
assert res["OK"], res["Message"]
29+
30+
res = WebAppClient().getOwnerGroup()
31+
assert res["OK"], res["Message"]
32+
33+
res = WebAppClient().getJobGroups()
34+
assert res["OK"], res["Message"]
35+
resJG_empty = res["Value"]
36+
37+
res = WebAppClient().getJobGroups(None, datetime.datetime.utcnow())
38+
assert res["OK"], res["Message"]
39+
resJG_olderThanNow = res["Value"]
40+
assert resJG_empty == resJG_olderThanNow
41+
42+
res = WebAppClient().getJobGroups(None, datetime.datetime.utcnow() - datetime.timedelta(days=365))
43+
assert res["OK"], res["Message"]
44+
resJG_olderThanOneYear = res["Value"]
45+
assert set(resJG_olderThanOneYear).issubset(set(resJG_olderThanNow))
46+
47+
res = WebAppClient().getSites()
48+
assert res["OK"], res["Message"]
49+
50+
res = WebAppClient().getStates()
51+
assert res["OK"], res["Message"]
52+
53+
res = WebAppClient().getMinorStates()
54+
assert res["OK"], res["Message"]

tests/Integration/WorkloadManagementSystem/Test_Client_WMS.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -387,38 +387,6 @@ def test_JobStateUpdateAndJobMonitoringMultiple(lfn: str) -> None:
387387
jobIDs.append(jobID)
388388

389389
try:
390-
res = jobMonitoringClient.getSites()
391-
assert res["OK"], res["Message"]
392-
assert set(res["Value"]) <= {"ANY", "DIRAC.Jenkins.ch", "Site"}
393-
394-
res = jobMonitoringClient.getJobTypes()
395-
assert res["OK"], res["Message"]
396-
397-
res = jobMonitoringClient.getApplicationStates()
398-
assert res["OK"], res["Message"]
399-
assert "Unknown" in res["Value"]
400-
401-
res = jobMonitoringClient.getOwners()
402-
assert res["OK"], res["Message"]
403-
res = jobMonitoringClient.getOwnerGroup()
404-
assert res["OK"], res["Message"]
405-
res = jobMonitoringClient.getJobGroups()
406-
assert res["OK"], res["Message"]
407-
resJG_empty = res["Value"]
408-
res = jobMonitoringClient.getJobGroups(None, datetime.datetime.utcnow())
409-
assert res["OK"], res["Message"]
410-
resJG_olderThanNow = res["Value"]
411-
assert resJG_empty == resJG_olderThanNow
412-
res = jobMonitoringClient.getJobGroups(None, datetime.datetime.utcnow() - datetime.timedelta(days=365))
413-
assert res["OK"], res["Message"]
414-
resJG_olderThanOneYear = res["Value"]
415-
assert set(resJG_olderThanOneYear).issubset(set(resJG_olderThanNow))
416-
417-
res = jobMonitoringClient.getStates()
418-
assert res["OK"], res["Message"]
419-
res = jobMonitoringClient.getMinorStates()
420-
assert res["OK"], res["Message"]
421-
422390
res = jobMonitoringClient.getJobs()
423391
assert res["OK"], res["Message"]
424392
assert {str(x) for x in jobIDs} <= set(res["Value"])
@@ -445,7 +413,6 @@ def test_JobStateUpdateAndJobMonitoringMultiple(lfn: str) -> None:
445413
res = jobMonitoringClient.getJobSummary(int(jobID))
446414
assert res["OK"], res["Message"]
447415
assert res["Value"]["Status"] in (JobStatus.CHECKING, JobStatus.WAITING)
448-
assert res["Value"]["MinorStatus"] == "MinorStatus"
449416

450417
res = jobStateUpdateClient.setJobStatusBulk(
451418
jobID,

0 commit comments

Comments
 (0)