|
14 | 14 |
|
15 | 15 | # futures |
16 | 16 | from __future__ import division, print_function |
17 | | -from future.utils import viewvalues |
18 | 17 |
|
19 | 18 | import json |
20 | 19 | import re |
@@ -207,78 +206,57 @@ def execute(self, reqStatus): |
207 | 206 | self.logger.info("MSRuleCleaner is running in mode: %s.", self.mode) |
208 | 207 |
|
209 | 208 | # Build the list of workflows to work on: |
| 209 | + #requestRecords = {} |
210 | 210 | try: |
211 | | - requestRecords = {} |
| 211 | + self.getGlobalLocks() |
| 212 | + # in this loop we'll only allocate single wflow object, process it and collect metrics |
| 213 | + # therefore, the memory allocation will be flat regardless of number of records. |
| 214 | + cleanNumRequests = 0 |
| 215 | + totalNumRequests = 0 |
212 | 216 | for status in reqStatus: |
213 | | - requestRecords.update(self.getRequestRecords(status)) |
| 217 | + req = self.getRequestRecords(status) |
| 218 | + wflow = MSRuleCleanerWflow(req) |
| 219 | + self._dispatchWflow(wflow) |
| 220 | + msg = "\n----------------------------------------------------------" |
| 221 | + msg += "\nMSRuleCleanerWflow: %s" |
| 222 | + msg += "\n----------------------------------------------------------" |
| 223 | + self.logger.debug(msg, pformat(wflow)) |
| 224 | + totalNumRequests += 1 |
| 225 | + if self._checkClean(wflow): |
| 226 | + cleanNumRequests += 1 |
| 227 | + |
| 228 | + # Report the counters: |
| 229 | + for pline in self.cleanuplines: |
| 230 | + msg = "Workflows cleaned by pipeline: %s: %d" |
| 231 | + self.logger.info(msg, pline.name, self.wfCounters['cleaned'][pline.name]) |
| 232 | + normalArchivedNumRequests = self.wfCounters['archived']['normalArchived'] |
| 233 | + forceArchivedNumRequests = self.wfCounters['archived']['forceArchived'] |
| 234 | + self.logger.info("Workflows normally archived: %d", self.wfCounters['archived']['normalArchived']) |
| 235 | + self.logger.info("Workflows force archived: %d", self.wfCounters['archived']['forceArchived']) |
| 236 | + |
| 237 | + self.updateAllMetrics(summary, totalNumRequests, cleanNumRequests, normalArchivedNumRequests, forceArchivedNumRequests) |
| 238 | + |
214 | 239 | except Exception as err: # general error |
215 | 240 | msg = "Unknown exception while fetching requests from ReqMgr2. Error: %s", str(err) |
216 | 241 | self.logger.exception(msg) |
217 | 242 | self.updateReportDict(summary, "error", msg) |
218 | 243 |
|
219 | | - # Call _execute() and feed the relevant pipeline with the objects popped from requestRecords |
220 | | - try: |
221 | | - self.getGlobalLocks() |
222 | | - totalNumRequests, cleanNumRequests, normalArchivedNumRequests, forceArchivedNumRequests = self._execute(requestRecords) |
223 | | - msg = "\nNumber of processed workflows: %s." |
224 | | - msg += "\nNumber of properly cleaned workflows: %s." |
225 | | - msg += "\nNumber of normally archived workflows: %s." |
226 | | - msg += "\nNumber of force archived workflows: %s." |
227 | | - self.logger.info(msg, |
228 | | - totalNumRequests, |
229 | | - cleanNumRequests, |
230 | | - normalArchivedNumRequests, |
231 | | - forceArchivedNumRequests) |
232 | | - self.updateReportDict(summary, "total_num_requests", totalNumRequests) |
233 | | - self.updateReportDict(summary, "clean_num_requests", cleanNumRequests) |
234 | | - self.updateReportDict(summary, "normal_archived_num_requests", normalArchivedNumRequests) |
235 | | - self.updateReportDict(summary, "force_archived_num_requests", forceArchivedNumRequests) |
236 | | - except Exception as ex: |
237 | | - msg = "Unknown exception while running MSRuleCleaner thread Error: {}".format(str(ex)) |
238 | | - self.logger.exception(msg) |
239 | | - self.updateReportDict(summary, "error", msg) |
240 | | - |
241 | 244 | return summary |
242 | 245 |
|
243 | | - def _execute(self, reqRecords): |
244 | | - """ |
245 | | - Executes the MSRuleCleaner pipelines based on the workflow status |
246 | | - :param reqList: A list of RequestRecords to work on |
247 | | - :return: a tuple with: |
248 | | - number of properly cleaned requests |
249 | | - number of processed workflows |
250 | | - number of archived workflows |
251 | | - number of forced archived workflows |
252 | | - """ |
253 | | - # NOTE: The Input Cleanup, the Block Level Cleanup and the Archival |
254 | | - # Pipelines are executed sequentially in the above order. |
255 | | - # This way we assure ourselves that we archive only workflows |
256 | | - # that have accomplished the needed cleanup |
257 | | - |
258 | | - cleanNumRequests = 0 |
259 | | - totalNumRequests = 0 |
260 | | - |
261 | | - # Call the workflow dispatcher: |
262 | | - for req in viewvalues(reqRecords): |
263 | | - wflow = MSRuleCleanerWflow(req) |
264 | | - self._dispatchWflow(wflow) |
265 | | - msg = "\n----------------------------------------------------------" |
266 | | - msg += "\nMSRuleCleanerWflow: %s" |
267 | | - msg += "\n----------------------------------------------------------" |
268 | | - self.logger.debug(msg, pformat(wflow)) |
269 | | - totalNumRequests += 1 |
270 | | - if self._checkClean(wflow): |
271 | | - cleanNumRequests += 1 |
272 | | - |
273 | | - # Report the counters: |
274 | | - for pline in self.cleanuplines: |
275 | | - msg = "Workflows cleaned by pipeline: %s: %d" |
276 | | - self.logger.info(msg, pline.name, self.wfCounters['cleaned'][pline.name]) |
277 | | - normalArchivedNumRequests = self.wfCounters['archived']['normalArchived'] |
278 | | - forceArchivedNumRequests = self.wfCounters['archived']['forceArchived'] |
279 | | - self.logger.info("Workflows normally archived: %d", self.wfCounters['archived']['normalArchived']) |
280 | | - self.logger.info("Workflows force archived: %d", self.wfCounters['archived']['forceArchived']) |
281 | | - return totalNumRequests, cleanNumRequests, normalArchivedNumRequests, forceArchivedNumRequests |
| 246 | + def updateAllMetrics(self, summary, totalNumRequests, cleanNumRequests, normalArchivedNumRequests, forceArchivedNumRequests): |
| 247 | + msg = "\nNumber of processed workflows: %s." |
| 248 | + msg += "\nNumber of properly cleaned workflows: %s." |
| 249 | + msg += "\nNumber of normally archived workflows: %s." |
| 250 | + msg += "\nNumber of force archived workflows: %s." |
| 251 | + self.logger.info(msg, |
| 252 | + totalNumRequests, |
| 253 | + cleanNumRequests, |
| 254 | + normalArchivedNumRequests, |
| 255 | + forceArchivedNumRequests) |
| 256 | + self.updateReportDict(summary, "total_num_requests", totalNumRequests) |
| 257 | + self.updateReportDict(summary, "clean_num_requests", cleanNumRequests) |
| 258 | + self.updateReportDict(summary, "normal_archived_num_requests", normalArchivedNumRequests) |
| 259 | + self.updateReportDict(summary, "force_archived_num_requests", forceArchivedNumRequests) |
282 | 260 |
|
283 | 261 | def _dispatchWflow(self, wflow): |
284 | 262 | """ |
|
0 commit comments