| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 | 6 |
| 7 from model.wf_analysis import WfAnalysis | 7 from model.wf_analysis import WfAnalysis |
| 8 from model import wf_analysis_status | 8 from model import wf_analysis_status |
| 9 from waterfall.base_pipeline import BasePipeline | 9 from waterfall.base_pipeline import BasePipeline |
| 10 from waterfall.detect_first_failure_pipeline import DetectFirstFailurePipeline | 10 from waterfall.detect_first_failure_pipeline import DetectFirstFailurePipeline |
| 11 from waterfall.extract_deps_info_pipeline import ExtractDEPSInfoPipeline |
| 11 from waterfall.extract_signal_pipeline import ExtractSignalPipeline | 12 from waterfall.extract_signal_pipeline import ExtractSignalPipeline |
| 12 from waterfall.identify_culprit_pipeline import IdentifyCulpritPipeline | 13 from waterfall.identify_culprit_pipeline import IdentifyCulpritPipeline |
| 13 from waterfall.pull_changelog_pipeline import PullChangelogPipeline | 14 from waterfall.pull_changelog_pipeline import PullChangelogPipeline |
| 14 | 15 |
| 15 | 16 |
| 16 class AnalyzeBuildFailurePipeline(BasePipeline): | 17 class AnalyzeBuildFailurePipeline(BasePipeline): |
| 17 | 18 |
| 18 def __init__(self, master_name, builder_name, build_number): | 19 def __init__(self, master_name, builder_name, build_number): |
| 19 super(AnalyzeBuildFailurePipeline, self).__init__( | 20 super(AnalyzeBuildFailurePipeline, self).__init__( |
| 20 master_name, builder_name, build_number) | 21 master_name, builder_name, build_number) |
| 21 self.master_name = master_name | 22 self.master_name = master_name |
| 22 self.builder_name = builder_name | 23 self.builder_name = builder_name |
| 23 self.build_number = build_number | 24 self.build_number = build_number |
| 24 | 25 |
| 25 def _LogUnexpectedAborting(self, was_aborted): | 26 def _LogUnexpectedAborting(self, was_aborted): |
| 26 """Marks the WfAnalysis status as error, indicating that it was aborted. | 27 """Marks the WfAnalysis status as error, indicating that it was aborted. |
| 27 | 28 |
| 28 Args: | 29 Args: |
| 29 was_aborted (bool): True if the pipeline was aborted, otherwise False. | 30 was_aborted (bool): True if the pipeline was aborted, otherwise False. |
| 30 """ | 31 """ |
| 31 if was_aborted: | 32 if was_aborted: |
| 32 analysis = WfAnalysis.Get( | 33 analysis = WfAnalysis.Get( |
| 33 self.master_name, self.builder_name, self.build_number) | 34 self.master_name, self.builder_name, self.build_number) |
| 34 if analysis: # In case the analysis is deleted manually. | 35 if analysis: # In case the analysis is deleted manually. |
| 35 analysis.status = wf_analysis_status.ERROR | 36 analysis.status = wf_analysis_status.ERROR |
| 36 analysis.result_status = None | 37 analysis.result_status = None |
| 37 analysis.put() | 38 analysis.put() |
| 38 | 39 |
| 39 def finalized(self): | 40 def finalized(self): |
| 40 self._LogUnexpectedAborting(self.was_aborted) | 41 self._LogUnexpectedAborting(self.was_aborted) |
| 41 | 42 |
| 42 def pipeline_status_path(self): | 43 def pipeline_status_path(self): |
| 43 """Returns an absolute path to look up the status of the pipeline.""" | 44 """Returns an absolute path to look up the status of the pipeline.""" |
| 44 return '/_ah/pipeline/status?root=%s&auto=false' % self.root_pipeline_id | 45 return '/_ah/pipeline/status?root=%s&auto=false' % self.root_pipeline_id |
| 45 | 46 |
| 46 def _ResetAnalysis(self, master_name, builder_name, build_number): | 47 def _ResetAnalysis(self, master_name, builder_name, build_number): |
| 47 analysis = WfAnalysis.Get(master_name, builder_name, build_number) | 48 analysis = WfAnalysis.Get(master_name, builder_name, build_number) |
| 48 analysis.pipeline_status_path = self.pipeline_status_path() | 49 analysis.pipeline_status_path = self.pipeline_status_path() |
| 49 analysis.status = wf_analysis_status.ANALYZING | 50 analysis.status = wf_analysis_status.ANALYZING |
| 50 analysis.result_status = None | 51 analysis.result_status = None |
| 51 analysis.start_time = datetime.utcnow() | 52 analysis.start_time = datetime.utcnow() |
| 52 analysis.put() | 53 analysis.put() |
| 53 | 54 |
| 54 # Arguments number differs from overridden method - pylint: disable=W0221 | 55 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 55 def run(self, master_name, builder_name, build_number): | 56 def run(self, master_name, builder_name, build_number): |
| 56 self._ResetAnalysis(master_name, builder_name, build_number) | 57 self._ResetAnalysis(master_name, builder_name, build_number) |
| 57 | 58 |
| 58 # The yield statements below return PipelineFutures, which allow subsequent | 59 # The yield statements below return PipelineFutures, which allow subsequent |
| 59 # pipelines to refer to previous output values. | 60 # pipelines to refer to previous output values. |
| 60 # https://github.com/GoogleCloudPlatform/appengine-pipelines/wiki/Python | 61 # https://github.com/GoogleCloudPlatform/appengine-pipelines/wiki/Python |
| 61 failure_info = yield DetectFirstFailurePipeline( | 62 failure_info = yield DetectFirstFailurePipeline( |
| 62 master_name, builder_name, build_number) | 63 master_name, builder_name, build_number) |
| 63 change_logs = yield PullChangelogPipeline(failure_info) | 64 change_logs = yield PullChangelogPipeline(failure_info) |
| 65 deps_info = yield ExtractDEPSInfoPipeline(failure_info, change_logs) |
| 64 signals = yield ExtractSignalPipeline(failure_info) | 66 signals = yield ExtractSignalPipeline(failure_info) |
| 65 yield IdentifyCulpritPipeline(failure_info, change_logs, signals) | 67 yield IdentifyCulpritPipeline( |
| 68 failure_info, change_logs, deps_info, signals) |
| OLD | NEW |