| 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 base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from common import constants | 9 from common import constants |
| 10 from common import appengine_util | 10 from common import appengine_util |
| 11 from common.base_handler import BaseHandler | 11 from common.base_handler import BaseHandler |
| 12 from common.base_handler import Permission | 12 from common.base_handler import Permission |
| 13 from crash import crash_pipeline | 13 from crash import crash_pipeline |
| 14 from crash.crash_report import CrashReport | |
| 15 from gae_libs.gitiles.cached_gitiles_repository import CachedGitilesRepository | 14 from gae_libs.gitiles.cached_gitiles_repository import CachedGitilesRepository |
| 16 from gae_libs.http.http_client_appengine import HttpClientAppengine | 15 from gae_libs.http.http_client_appengine import HttpClientAppengine |
| 17 from model.crash.crash_config import CrashConfig | 16 from model.crash.crash_config import CrashConfig |
| 18 | 17 |
| 19 | 18 |
| 20 class CrashHandler(BaseHandler): | 19 class CrashHandler(BaseHandler): |
| 21 PERMISSION_LEVEL = Permission.ANYONE | 20 PERMISSION_LEVEL = Permission.ANYONE |
| 22 | 21 |
| 23 def HandlePost(self): | 22 def HandlePost(self): |
| 24 """Handles push delivery from Pub/Sub for crash data. | 23 """Handles push delivery from Pub/Sub for crash data. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 at all. | 123 at all. |
| 125 | 124 |
| 126 Args: | 125 Args: |
| 127 crash_data (JSON): ?? | 126 crash_data (JSON): ?? |
| 128 | 127 |
| 129 Returns: | 128 Returns: |
| 130 True if we started a new pipeline; False otherwise. | 129 True if we started a new pipeline; False otherwise. |
| 131 """ | 130 """ |
| 132 client_id = crash_data['client_id'] | 131 client_id = crash_data['client_id'] |
| 133 # N.B., must call FinditForClientID indirectly, for mock testing. | 132 # N.B., must call FinditForClientID indirectly, for mock testing. |
| 134 findit_client = crash_pipeline.FinditForClientID( | 133 findit_client = crash_pipeline.FinditForClientID(client_id, |
| 135 client_id, CachedGitilesRepository.Factory(HttpClientAppengine()), | 134 CachedGitilesRepository.Factory(HttpClientAppengine()), CrashConfig.Get()) |
| 136 CrashConfig.Get()) | 135 crash_data = findit_client.GetCrashData(crash_data) |
| 137 | |
| 138 # Check policy and modify the crash_data as needed. | |
| 139 crash_data = findit_client.CheckPolicy(crash_data) | |
| 140 if crash_data is None: | |
| 141 return False | |
| 142 | 136 |
| 143 # Detect the regression range, and decide if we actually need to | 137 # Detect the regression range, and decide if we actually need to |
| 144 # run a new anlaysis or not. | 138 # run a new anlaysis or not. |
| 145 if not findit_client._NeedsNewAnalysis(crash_data): | 139 if not findit_client.NeedsNewAnalysis(crash_data): |
| 146 return False | 140 return False |
| 147 | 141 |
| 148 crash_identifiers = crash_data['crash_identifiers'] | 142 # N.B., we cannot pass ``findit_client`` directly to the _pipeline_cls, |
| 149 # N.B., we cannot pass ``self`` directly to the _pipeline_cls, because | 143 # because it is not JSON-serializable (and there's no way to make it such, |
| 150 # it is not JSON-serializable (and there's no way to make it such, | |
| 151 # since JSON-serializability is defined by JSON-encoders rather than | 144 # since JSON-serializability is defined by JSON-encoders rather than |
| 152 # as methods on the objects being encoded). | 145 # as methods on the objects being encoded). |
| 153 pipeline = crash_pipeline.CrashWrapperPipeline(client_id, crash_identifiers) | 146 pipeline = crash_pipeline.CrashWrapperPipeline(client_id, |
| 147 crash_data.identifiers) |
| 154 # Attribute defined outside __init__ - pylint: disable=W0201 | 148 # Attribute defined outside __init__ - pylint: disable=W0201 |
| 155 pipeline.target = appengine_util.GetTargetNameForModule( | 149 pipeline.target = appengine_util.GetTargetNameForModule( |
| 156 constants.CRASH_BACKEND[client_id]) | 150 constants.CRASH_BACKEND[client_id]) |
| 157 queue_name = constants.CRASH_ANALYSIS_QUEUE[client_id] | 151 queue_name = constants.CRASH_ANALYSIS_QUEUE[client_id] |
| 158 pipeline.start(queue_name=queue_name) | 152 pipeline.start(queue_name=queue_name) |
| 159 logging.info('New %s analysis is scheduled for %s', client_id, | 153 logging.info('New %s analysis is scheduled for %s', client_id, |
| 160 repr(crash_identifiers)) | 154 repr(crash_data.identifiers)) |
| 161 return True | 155 return True |
| OLD | NEW |