| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 json | 5 import json |
| 6 import logging |
| 6 | 7 |
| 7 from common import constants | 8 from common import constants |
| 8 from common.base_handler import BaseHandler | 9 from common.base_handler import BaseHandler |
| 9 from common.base_handler import Permission | 10 from common.base_handler import Permission |
| 10 from common.http_client_appengine import HttpClientAppengine | 11 from common.http_client_appengine import HttpClientAppengine |
| 11 from waterfall import buildbot | 12 from waterfall import buildbot |
| 12 from waterfall import build_failure_analysis_pipelines | 13 from waterfall import build_failure_analysis_pipelines |
| 13 from waterfall import build_util | 14 from waterfall import build_util |
| 14 | 15 |
| 15 | 16 |
| 16 def _TriggerNewAnalysesOnDemand(builds): | 17 def _TriggerNewAnalysesOnDemand(builds): |
| 17 for build in builds: | 18 for build in builds: |
| 18 master_name = build['master_name'] | 19 master_name = build['master_name'] |
| 19 builder_name = build['builder_name'] | 20 builder_name = build['builder_name'] |
| 20 build_number = build['build_number'] | 21 build_number = build['build_number'] |
| 21 failed_steps = build.get('failed_steps') | 22 failed_steps = build.get('failed_steps') |
| 22 | 23 |
| 23 # TODO(stgao): make builder_alerts send information of whether a build | 24 # TODO(stgao): make alerts-dispatcher send information of whether a build |
| 24 # is completed. | 25 # is completed. |
| 25 build = build_util.DownloadBuildData( | 26 build = build_util.DownloadBuildData( |
| 26 master_name, builder_name, build_number) | 27 master_name, builder_name, build_number) |
| 27 if not build or not build.data: | 28 if not build or not build.data: |
| 29 logging.error('Failed to retrieve build data for %s/%s/%s, steps=%s', |
| 30 master_name, builder_name, build_number, repr(failed_steps)) |
| 28 continue # Skip the build, wait for next request to recheck. | 31 continue # Skip the build, wait for next request to recheck. |
| 29 | 32 |
| 30 build_info = buildbot.ExtractBuildInfo( | 33 build_info = buildbot.ExtractBuildInfo( |
| 31 master_name, builder_name, build_number, build.data) | 34 master_name, builder_name, build_number, build.data) |
| 32 | 35 |
| 33 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded( | 36 build_failure_analysis_pipelines.ScheduleAnalysisIfNeeded( |
| 34 master_name, builder_name, build_number, failed_steps=failed_steps, | 37 master_name, builder_name, build_number, failed_steps=failed_steps, |
| 35 build_completed=build_info.completed, | 38 build_completed=build_info.completed, |
| 36 force=False, queue_name=constants.WATERFALL_ANALYSIS_QUEUE) | 39 force=False, queue_name=constants.WATERFALL_ANALYSIS_QUEUE) |
| 37 | 40 |
| 38 | 41 |
| 39 class TriggerAnalyses(BaseHandler): | 42 class ProcessFailureAnalysisRequests(BaseHandler): |
| 40 """Triggers new analyses on demand. | 43 """Triggers new analyses on demand. |
| 41 | 44 |
| 42 This handler checks the build failures in the request, and triggers new | 45 This handler checks the build failures in the request, and triggers new |
| 43 analyes for a build in two situations: | 46 analyses for a build in two situations: |
| 44 1. A new step failed. | 47 1. A new step failed. |
| 45 2. The build became completed after last analysis. This will potentially | 48 2. The build became completed after last analysis. This will potentially |
| 46 trigger a try-job run. | 49 trigger a try-job run. |
| 47 """ | 50 """ |
| 48 | 51 |
| 49 PERMISSION_LEVEL = Permission.ADMIN | 52 PERMISSION_LEVEL = Permission.ADMIN |
| 50 | 53 |
| 51 def HandlePost(self): | 54 def HandlePost(self): |
| 52 builds = json.loads(self.request.body).get('builds', []) | 55 builds = json.loads(self.request.body).get('builds', []) |
| 53 _TriggerNewAnalysesOnDemand(builds) | 56 _TriggerNewAnalysesOnDemand(builds) |
| OLD | NEW |