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