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 | 4 |
5 from datetime import datetime | 5 from datetime import datetime |
6 import logging | 6 import logging |
7 | 7 |
8 from google.appengine.ext import ndb | 8 from google.appengine.ext import ndb |
9 | 9 |
10 from model.build_analysis import BuildAnalysis | 10 from model.build_analysis import BuildAnalysis |
11 from model.build_analysis_status import BuildAnalysisStatus | 11 from model.build_analysis_status import BuildAnalysisStatus |
12 from waterfall.base_pipeline import BasePipeline | 12 from waterfall.base_pipeline import BasePipeline |
13 from waterfall.detect_first_failure_pipeline import DetectFirstFailurePipeline | 13 from waterfall.detect_first_failure_pipeline import DetectFirstFailurePipeline |
| 14 from waterfall.extract_signal_pipeline import ExtractSignalPipeline |
| 15 from waterfall.identify_culprit_pipeline import IdentifyCulpritPipeline |
| 16 from waterfall.pull_changelog_pipeline import PullChangelogPipeline |
14 | 17 |
15 | 18 |
16 class BuildFailurePipeline(BasePipeline): | 19 class BuildFailurePipeline(BasePipeline): |
17 | 20 |
18 def __init__(self, master_name, builder_name, build_number): | 21 def __init__(self, master_name, builder_name, build_number): |
19 super(BuildFailurePipeline, self).__init__( | 22 super(BuildFailurePipeline, self).__init__( |
20 master_name, builder_name, build_number) | 23 master_name, builder_name, build_number) |
21 self.master_name = master_name | 24 self.master_name = master_name |
22 self.builder_name = builder_name | 25 self.builder_name = builder_name |
23 self.build_number = build_number | 26 self.build_number = build_number |
24 | 27 |
25 def finalized(self): | 28 def finalized(self): |
26 analysis = BuildAnalysis.GetBuildAnalysis( | 29 # When this root pipeline or its sub-pipelines still run into any error |
27 self.master_name, self.builder_name, self.build_number) | 30 # after auto-retries, this root pipeline will be aborted. So, mark the |
| 31 # analysis as ERROR. The analysis is created before the pipeline starts. |
28 if self.was_aborted: # pragma: no cover | 32 if self.was_aborted: # pragma: no cover |
29 analysis.status = BuildAnalysisStatus.ERROR | 33 analysis = BuildAnalysis.GetBuildAnalysis( |
30 else: | 34 self.master_name, self.builder_name, self.build_number) |
31 analysis.status = BuildAnalysisStatus.ANALYZED | 35 if analysis: # In case the analysis is deleted manually. |
32 analysis.put() | 36 analysis.status = BuildAnalysisStatus.ERROR |
| 37 analysis.put() |
33 | 38 |
34 # Arguments number differs from overridden method - pylint: disable=W0221 | 39 # Arguments number differs from overridden method - pylint: disable=W0221 |
35 def run(self, master_name, builder_name, build_number): | 40 def run(self, master_name, builder_name, build_number): |
36 analysis = BuildAnalysis.GetBuildAnalysis( | 41 analysis = BuildAnalysis.GetBuildAnalysis( |
37 master_name, builder_name, build_number) | 42 master_name, builder_name, build_number) |
38 analysis.pipeline_url = self.pipeline_status_url() | 43 analysis.pipeline_url = self.pipeline_status_url() |
39 analysis.status = BuildAnalysisStatus.ANALYZING | 44 analysis.status = BuildAnalysisStatus.ANALYZING |
40 analysis.start_time = datetime.utcnow() | 45 analysis.start_time = datetime.utcnow() |
41 analysis.put() | 46 analysis.put() |
42 | 47 |
43 yield DetectFirstFailurePipeline(master_name, builder_name, build_number) | 48 # The yield statements below return PipelineFutures, which allow subsequent |
| 49 # pipelines to refer to previous output values. |
| 50 # https://github.com/GoogleCloudPlatform/appengine-pipelines/wiki/Python |
| 51 failure_info = yield DetectFirstFailurePipeline( |
| 52 master_name, builder_name, build_number) |
| 53 change_logs = yield PullChangelogPipeline(failure_info) |
| 54 signals = yield ExtractSignalPipeline(failure_info) |
| 55 yield IdentifyCulpritPipeline(failure_info, change_logs, signals) |
44 | 56 |
45 | 57 |
46 @ndb.transactional | 58 @ndb.transactional |
47 def NeedANewAnalysis(master_name, builder_name, build_number, force): | 59 def NeedANewAnalysis(master_name, builder_name, build_number, force): |
48 """Checks status of analysis for the build and decides if a new one is needed. | 60 """Checks status of analysis for the build and decides if a new one is needed. |
49 | 61 |
50 A BuildAnalysis entity for the given build will be created if none exists. | 62 A BuildAnalysis entity for the given build will be created if none exists. |
51 | 63 |
52 Returns: | 64 Returns: |
53 True if an analysis is needed, otherwise False. | 65 True if an analysis is needed, otherwise False. |
(...skipping 28 matching lines...) Expand all Loading... |
82 pipeline_job = BuildFailurePipeline(master_name, builder_name, build_number) | 94 pipeline_job = BuildFailurePipeline(master_name, builder_name, build_number) |
83 pipeline_job.start(queue_name=queue_name) | 95 pipeline_job.start(queue_name=queue_name) |
84 | 96 |
85 logging.info('An analysis triggered on build %s, %s, %s: %s', | 97 logging.info('An analysis triggered on build %s, %s, %s: %s', |
86 master_name, builder_name, build_number, | 98 master_name, builder_name, build_number, |
87 pipeline_job.pipeline_status_url()) | 99 pipeline_job.pipeline_status_url()) |
88 else: # pragma: no cover | 100 else: # pragma: no cover |
89 logging.info('Analysis was already triggered or the result is recent.') | 101 logging.info('Analysis was already triggered or the result is recent.') |
90 | 102 |
91 return BuildAnalysis.GetBuildAnalysis(master_name, builder_name, build_number) | 103 return BuildAnalysis.GetBuildAnalysis(master_name, builder_name, build_number) |
OLD | NEW |