| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import argparse | 4 import argparse |
| 5 import json | 5 import json |
| 6 import logging | 6 import logging |
| 7 import multiprocessing | 7 import multiprocessing |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 | 342 |
| 343 def alerts_for_master(cache, master_url, master_json, old_alerts, | 343 def alerts_for_master(cache, master_url, master_json, old_alerts, |
| 344 builder_name_filter=None, jobs=1): # pragma: no cover | 344 builder_name_filter=None, jobs=1): # pragma: no cover |
| 345 active_builds = [] | 345 active_builds = [] |
| 346 for slave in master_json['slaves'].values(): | 346 for slave in master_json['slaves'].values(): |
| 347 for build in slave['runningBuilds']: | 347 for build in slave['runningBuilds']: |
| 348 active_builds.append(build) | 348 active_builds.append(build) |
| 349 | 349 |
| 350 def process_builder(builder_name): | 350 def process_builder(builder_name): |
| 351 logging.debug('Thread for builder %s has started', builder_name) |
| 351 try: | 352 try: |
| 352 if builder_name_filter and builder_name_filter not in builder_name: | 353 if builder_name_filter and builder_name_filter not in builder_name: |
| 353 return None | 354 return None |
| 354 | 355 |
| 355 builder_json = master_json['builders'][builder_name] | 356 builder_json = master_json['builders'][builder_name] |
| 356 | 357 |
| 357 # cachedBuilds will include runningBuilds. | 358 # cachedBuilds will include runningBuilds. |
| 358 recent_build_ids = builder_json['cachedBuilds'] | 359 recent_build_ids = builder_json['cachedBuilds'] |
| 359 | 360 |
| 360 if not recent_build_ids: | 361 if not recent_build_ids: |
| 361 return None | 362 return None |
| 362 | 363 |
| 363 buildbot.warm_build_cache(cache, master_url, builder_name, | 364 buildbot.warm_build_cache(cache, master_url, builder_name, |
| 364 recent_build_ids, active_builds) | 365 recent_build_ids, active_builds) |
| 365 return alerts_for_builder(cache, master_url, builder_name, | 366 return alerts_for_builder(cache, master_url, builder_name, |
| 366 recent_build_ids, old_alerts) | 367 recent_build_ids, old_alerts) |
| 367 except: | 368 except: |
| 368 # Put all exception text into an exception and raise that so it doesn't | 369 # Put all exception text into an exception and raise that so it doesn't |
| 369 # get eaten by the multiprocessing code. | 370 # get eaten by the multiprocessing code. |
| 370 raise Exception(''.join(traceback.format_exception(*sys.exc_info()))) | 371 raise Exception(''.join(traceback.format_exception(*sys.exc_info()))) |
| 372 finally: |
| 373 logging.debug('Thread for builder %s has finished', builder_name) |
| 371 | 374 |
| 372 pool = multiprocessing.dummy.Pool(processes=jobs) | 375 pool = multiprocessing.dummy.Pool(processes=jobs) |
| 376 logging.debug('Processing all threads via thread pool') |
| 373 builder_alerts = pool.map(process_builder, master_json['builders'].keys()) | 377 builder_alerts = pool.map(process_builder, master_json['builders'].keys()) |
| 378 logging.debug('Closing all threads in thread pool') |
| 374 pool.close() | 379 pool.close() |
| 375 pool.join() | 380 pool.join() |
| 381 logging.debug('Joined all threads in thread pool') |
| 376 | 382 |
| 377 alerts = [] | 383 alerts = [] |
| 378 for alert in builder_alerts: | 384 for alert in builder_alerts: |
| 379 if alert: | 385 if alert: |
| 380 alerts.extend(alert) | 386 alerts.extend(alert) |
| 381 | 387 |
| 382 stale_master_data_alert = alert_for_stale_master_data(master_url, master_json) | 388 stale_master_data_alert = alert_for_stale_master_data(master_url, master_json) |
| 383 return (alerts, stale_master_data_alert) | 389 return (alerts, stale_master_data_alert) |
| 384 | 390 |
| 385 | 391 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 401 master_url = match.group('master_url') | 407 master_url = match.group('master_url') |
| 402 builder_name = urllib.unquote_plus(match.group('builder_name')) | 408 builder_name = urllib.unquote_plus(match.group('builder_name')) |
| 403 master_json = buildbot.fetch_master_json(master_url) | 409 master_json = buildbot.fetch_master_json(master_url) |
| 404 # This is kinda a hack, but uses more of our existing code this way: | 410 # This is kinda a hack, but uses more of our existing code this way: |
| 405 alerts = alerts_for_master(cache, master_url, master_json, builder_name) | 411 alerts = alerts_for_master(cache, master_url, master_json, builder_name) |
| 406 print json.dumps(alerts[0], indent=1) | 412 print json.dumps(alerts[0], indent=1) |
| 407 | 413 |
| 408 | 414 |
| 409 if __name__ == '__main__': | 415 if __name__ == '__main__': |
| 410 sys.exit(main(sys.argv[1:])) | 416 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |