Skip to content

Commit a2ec590

Browse files
committed
fix: fixes to StatesAccountingAgent for new fields
1 parent 3586349 commit a2ec590

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/DIRAC/AccountingSystem/Client/Types/BaseAccountingType.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def setValuesFromDict(self, dataDict):
9797
if errKeys:
9898
return S_ERROR(f"Key(s) {', '.join(errKeys)} are not valid")
9999
for key in dataDict:
100-
self.setValueByKey(key, dataDict[key])
100+
res = self.setValueByKey(key, dataDict[key])
101+
if not res["OK"]:
102+
return res
101103
return S_OK()
102104

103105
def getValue(self, key):

src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ class StatesAccountingAgent(AgentModule):
3232
__summaryKeyFieldsMapping = [
3333
"Status",
3434
"Site",
35-
"User",
36-
"UserGroup",
35+
"Owner",
36+
"OwnerGroup",
3737
"JobGroup",
3838
"VO",
3939
"JobType",
4040
"ApplicationStatus",
4141
"MinorStatus",
4242
]
43-
__summaryDefinedFields = [("ApplicationStatus", "unset"), ("MinorStatus", "unset")]
44-
__summaryValueFieldsMapping = ["Jobs", "Reschedules"]
45-
__renameFieldsMapping = {"JobType": "JobSplitType"}
43+
__summaryValueFieldsMapping = ["JobCount", "RescheduleSum"]
44+
__renameFieldsMapping = {
45+
"Owner": "User",
46+
"OwnerGroup": "UserGroup",
47+
"JobType": "JobSplitType",
48+
"JobCount": "Jobs",
49+
"RescheduleSum": "Reschedules",
50+
}
4651

4752
# PilotsHistory fields
4853
__pilotsMapping = ["GridSite", "ComputingElement", "GridType", "Status", "VO", "NumOfPilots"]
@@ -98,7 +103,7 @@ def execute(self):
98103
f"{result['Message']}: won't commit PilotsHistory at this cycle",
99104
)
100105

101-
values = result["Value"][1]
106+
values = result["Value"]
102107
for record in values:
103108
rD = {}
104109
for iP, _ in enumerate(self.__pilotsMapping):
@@ -114,25 +119,20 @@ def execute(self):
114119

115120
# WMSHistory to Monitoring or Accounting
116121
self.log.info(f"Committing WMSHistory to {'and '.join(self.jobMonitoringOption)} backend")
117-
result = JobDB()._query("SELECT * FROM JobsHistorySummary")
122+
result = JobDB()._query(
123+
f"SELECT {','.join(self.__summaryKeyFieldsMapping + self.__summaryValueFieldsMapping)} FROM JobsHistorySummary ORDER BY {','.join(self.__summaryKeyFieldsMapping)}"
124+
)
118125
if not result["OK"]:
119126
self.log.error("Can't get the JobDB summary", f"{result['Message']}: won't commit WMSHistory at this cycle")
120127
return S_ERROR()
121128

122-
values = result["Value"][1]
123-
129+
values = result["Value"]
124130
now = datetime.datetime.utcnow()
125131
self.log.info("Start sending WMSHistory records")
126132
for record in values:
127133
rD = {}
128-
for fV in self.__summaryDefinedFields:
129-
rD[fV[0]] = fV[1]
130-
for iP, _ in enumerate(self.__summaryKeyFieldsMapping):
131-
fieldName = self.__summaryKeyFieldsMapping[iP]
134+
for iP, fieldName in enumerate(self.__summaryKeyFieldsMapping + self.__summaryValueFieldsMapping):
132135
rD[self.__renameFieldsMapping.get(fieldName, fieldName)] = record[iP]
133-
record = record[len(self.__summaryKeyFieldsMapping) :]
134-
for iP, _ in enumerate(self.__summaryValueFieldsMapping):
135-
rD[self.__summaryValueFieldsMapping[iP]] = int(record[iP])
136136

137137
for backend in self.datastores:
138138
if backend.lower() == "monitoring":
@@ -143,6 +143,8 @@ def execute(self):
143143
self.datastores["Monitoring"].addRecord(rD)
144144

145145
elif backend.lower() == "accounting":
146+
rD.pop("VO") # Remove VO field for Accounting
147+
rD.pop("ApplicationStatus") # Remove ApplicationStatus for Accounting
146148
acWMS = WMSHistory()
147149
acWMS.setStartTime(now)
148150
acWMS.setEndTime(now)

0 commit comments

Comments
 (0)