OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import datetime | 5 import datetime |
6 import hashlib | 6 import hashlib |
7 import json | 7 import json |
8 import os | 8 import os |
9 import pytz | 9 import pytz |
10 import time | 10 import time |
11 import urllib | 11 import urllib |
12 import urlparse | 12 import urlparse |
13 | 13 |
14 from buildbot.changes import base | 14 from buildbot.changes import base |
15 from buildbot.schedulers.trysched import BadJobfile | 15 from buildbot.schedulers.trysched import BadJobfile |
16 from buildbot.status.builder import EXCEPTION | 16 from buildbot.status.builder import EXCEPTION |
17 from twisted.application import internet | 17 from twisted.application import internet |
18 from twisted.internet import defer | 18 from twisted.internet import defer |
19 from twisted.python import log | 19 from twisted.python import log |
20 from twisted.web import client | 20 from twisted.web import client |
21 | 21 |
22 from master import master_utils | 22 from master import master_utils |
23 from master.try_job_base import TryJobBase | 23 from master.try_job_base import TryJobBase |
24 | 24 |
25 | 25 |
26 # Number of recent buildsets used to initialize RietveldPollerWithCache's cache. | |
27 MAX_RECENT_BUILDSETS_TO_INIT_CACHE = 10000 | |
28 | |
29 | |
26 class _ValidUserPoller(internet.TimerService): | 30 class _ValidUserPoller(internet.TimerService): |
27 """Check chromium-access for users allowed to send jobs from Rietveld. | 31 """Check chromium-access for users allowed to send jobs from Rietveld. |
28 """ | 32 """ |
29 # The name of the file that contains the password for authenticating | 33 # The name of the file that contains the password for authenticating |
30 # requests to chromium-access. | 34 # requests to chromium-access. |
31 _PWD_FILE = '.try_job_rietveld_password' | 35 _PWD_FILE = '.try_job_rietveld_password' |
32 _NORMAL_DOMAIN = '@chromium.org' | 36 _NORMAL_DOMAIN = '@chromium.org' |
33 _SPECIAL_DOMAIN = '@google.com' | 37 _SPECIAL_DOMAIN = '@google.com' |
34 | 38 |
35 def __init__(self, interval): | 39 def __init__(self, interval): |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 return pollDeferred | 238 return pollDeferred |
235 | 239 |
236 def setServiceParent(self, parent): | 240 def setServiceParent(self, parent): |
237 base.PollingChangeSource.setServiceParent(self, parent) | 241 base.PollingChangeSource.setServiceParent(self, parent) |
238 self._try_job_rietveld = parent | 242 self._try_job_rietveld = parent |
239 | 243 |
240 @defer.inlineCallbacks | 244 @defer.inlineCallbacks |
241 def _InitProcessedKeysCache(self): | 245 def _InitProcessedKeysCache(self): |
242 log.msg('[RPWC] Initializing processed keys cache...') | 246 log.msg('[RPWC] Initializing processed keys cache...') |
243 | 247 |
244 # Get all BuildBot build requests. | 248 # Get recent BuildBot buildsets. |
Paweł Hajdan Jr.
2014/06/03 08:08:47
nit: Add a comment here that we need to limit the
Sergiy Byelozyorov
2014/06/03 08:20:01
Done.
| |
245 brdicts = yield self.master.db.buildrequests.getBuildRequests() | 249 bsdicts = yield self.master.db.buildsets.getRecentBuildsets( |
250 MAX_RECENT_BUILDSETS_TO_INIT_CACHE) | |
246 | 251 |
247 log.msg('[RPWC] Received %d build request dicts' % len(brdicts)) | 252 log.msg('[RPWC] Received %d buildset dicts' % len(bsdicts)) |
248 | 253 |
249 def asNaiveUTC(dt): | 254 def asNaiveUTC(dt): |
250 if dt is None: | 255 if dt is None: |
251 return datetime.datetime.now() | 256 return datetime.datetime.now() |
252 if dt.tzinfo is None: | 257 if dt.tzinfo is None: |
253 return dt | 258 return dt |
254 utc_datetime = dt.astimezone(pytz.utc) | 259 utc_datetime = dt.astimezone(pytz.utc) |
255 return utc_datetime.replace(tzinfo=None) | 260 return utc_datetime.replace(tzinfo=None) |
256 | 261 |
257 # Compose a map of buildset ids to the submission timestamp. | 262 # Compose a map of buildset ids to the submission timestamp. |
258 buildsets = {} | 263 buildsets = {} |
259 for brdict in brdicts: | 264 for bsdict in bsdicts: |
260 bsid = brdict.get('buildsetid') | 265 bsid = bsdict.get('bsid') |
261 if bsid is not None: | 266 if bsid is not None: |
262 buildsets[bsid] = asNaiveUTC(brdict.get('submitted_at')) | 267 buildsets[bsid] = asNaiveUTC(bsdict.get('submitted_at')) |
263 | 268 |
264 log.msg('[RPWC] Processing %d buildsets' % len(buildsets)) | 269 log.msg('[RPWC] Processing %d buildsets' % len(buildsets)) |
265 | 270 |
266 # Find jobs for each buildset and add them to the processed keys cache. | 271 # Find jobs for each buildset and add them to the processed keys cache. |
267 self._processed_keys = {} | 272 self._processed_keys = {} |
268 for bsid in buildsets.keys(): | 273 for bsid in buildsets.keys(): |
269 log.msg('[RPWC] Loading properties of the buildset %d' % bsid) | 274 log.msg('[RPWC] Loading properties of the buildset %d' % bsid) |
270 bsprops = yield self.master.db.buildsets.getBuildsetProperties(bsid) | 275 bsprops = yield self.master.db.buildsets.getBuildsetProperties(bsid) |
271 if 'try_job_key' in bsprops: | 276 if 'try_job_key' in bsprops: |
272 key = bsprops['try_job_key'][0] | 277 key = bsprops['try_job_key'][0] |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 else: | 498 else: |
494 self.processed_keys.add(job['key']) | 499 self.processed_keys.add(job['key']) |
495 log.err('Rietveld not updated: no corresponding service found.') | 500 log.err('Rietveld not updated: no corresponding service found.') |
496 | 501 |
497 # TryJobBase overrides: | 502 # TryJobBase overrides: |
498 def setServiceParent(self, parent): | 503 def setServiceParent(self, parent): |
499 TryJobBase.setServiceParent(self, parent) | 504 TryJobBase.setServiceParent(self, parent) |
500 self._poller.setServiceParent(self) | 505 self._poller.setServiceParent(self) |
501 self._poller.master = self.master | 506 self._poller.master = self.master |
502 self._valid_users.setServiceParent(self) | 507 self._valid_users.setServiceParent(self) |
OLD | NEW |