def get(self): self.response.headers['Content-Type'] = 'application/json' test_id, branch_id, platform_id = _get_test_branch_platform_ids(self) runs = PersistentCache.get_cache(Test.cache_key(test_id, branch_id, platform_id)) if runs: self.response.out.write(runs) else: schedule_runs_update(test_id, branch_id, platform_id)
def post(self): self.response.headers['Content-Type'] = 'text/plain; charset=utf-8' test_id, branch_id, platform_id = _get_test_branch_platform_ids(self) branch = model_from_numeric_id(branch_id, Branch) platform = model_from_numeric_id(platform_id, Platform) test = model_from_numeric_id(test_id, Test) assert branch assert platform assert test PersistentCache.set_cache(Test.cache_key(test_id, branch_id, platform_id), Runs(branch, platform, test.name).to_json()) self.response.out.write('OK')
def get(self): self.response.headers['Content-Type'] = 'application/json' try: test_id = int(self.request.get('id', 0)) branch_id = int(self.request.get('branchid', 0)) platform_id = int(self.request.get('platformid', 0)) except TypeError: # FIXME: Output an error here test_id = 0 branch_id = 0 platform_id = 0 runs = PersistentCache.get_cache(Test.cache_key(test_id, branch_id, platform_id)) if runs: self.response.out.write(runs) else: schedule_runs_update(test_id, branch_id, platform_id)
def post(self): self.response.headers['Content-Type'] = 'text/plain; charset=utf-8' headers = "\n".join([key + ': ' + value for key, value in self.request.headers.items()]) # Do as best as we can to remove the password request_body_without_password = re.sub(r'"password"\s*:\s*".+?",', '', self.request.body) log = ReportLog(timestamp=datetime.now(), headers=headers, payload=request_body_without_password) log.put() try: self._body = json.loads(self.request.body) except ValueError: return self._output('Failed to parse the payload as a json. Report key: %d' % log.key().id()) builder = self._model_by_key_name_in_body_or_error(Builder, 'builder-name') branch = self._model_by_key_name_in_body_or_error(Branch, 'branch') platform = self._model_by_key_name_in_body_or_error(Platform, 'platform') build_number = self._integer_in_body('build-number') timestamp = self._timestamp_in_body() revision = self._integer_in_body('webkit-revision') chromium_revision = self._integer_in_body('webkit-revision') if 'chromium-revision' in self._body else None failed = False if builder and not (self.bypass_authentication() or builder.authenticate(self._body.get('password', ''))): self._output('Authentication failed') failed = True if not self._results_are_valid(): self._output("The payload doesn't contain results or results are malformed") failed = True if not (builder and branch and platform and build_number and revision and timestamp) or failed: return build = self._create_build_if_possible(builder, build_number, branch, platform, timestamp, revision, chromium_revision) if not build: return def _float_or_none(dictionary, key): value = dictionary.get(key) if value: return float(value) return None for test_name, result in self._body['results'].iteritems(): test = self._add_test_if_needed(test_name, branch, platform) memcache.delete(Test.cache_key(test.id, branch.id, platform.id)) if isinstance(result, dict): TestResult(name=test_name, build=build, value=float(result['avg']), valueMedian=_float_or_none(result, 'median'), valueStdev=_float_or_none(result, 'stdev'), valueMin=_float_or_none(result, 'min'), valueMax=_float_or_none(result, 'max')).put() else: TestResult(name=test_name, build=build, value=float(result)).put() log = ReportLog.get(log.key()) log.delete() # We need to update dashboard and manifest because they are affected by the existance of test results memcache.delete('dashboard') memcache.delete('manifest') return self._output('OK')
def get(self): self.response.headers['Content-Type'] = 'application/json; charset=utf-8' try: test_id = int(self.request.get('id', 0)) branch_id = int(self.request.get('branchid', 0)) platform_id = int(self.request.get('platformid', 0)) except TypeError: # FIXME: Output an error here test_id = 0 branch_id = 0 platform_id = 0 # FIXME: Just fetch builds specified by "days" # days = self.request.get('days', 365) cache_key = Test.cache_key(test_id, branch_id, platform_id) cache = memcache.get(cache_key) if cache: self.response.out.write(cache) return builds = Build.all() builds.filter('branch =', modelFromNumericId(branch_id, Branch)) builds.filter('platform =', modelFromNumericId(platform_id, Platform)) test = modelFromNumericId(test_id, Test) test_name = test.name if test else None test_runs = [] averages = {} values = [] timestamps = [] for build in builds: results = TestResult.all() results.filter('name =', test_name) results.filter('build =', build) for result in results: builderId = build.builder.key().id() posixTimestamp = mktime(build.timestamp.timetuple()) statistics = None if result.valueStdev != None and result.valueMin != None and result.valueMax != None: statistics = {'stdev': result.valueStdev, 'min': result.valueMin, 'max': result.valueMax} test_runs.append([result.key().id(), [build.key().id(), build.buildNumber, build.revision], posixTimestamp, result.value, 0, # runNumber [], # annotations builderId, statistics]) # FIXME: Calculate the average; in practice, we wouldn't have more than one value for a given revision averages[build.revision] = result.value values.append(result.value) timestamps.append(posixTimestamp) result = json.dumps({ 'test_runs': test_runs, 'averages': averages, 'min': min(values) if values else None, 'max': max(values) if values else None, 'date_range': [min(timestamps), max(timestamps)] if timestamps else None, 'stat': 'ok'}) self.response.out.write(result) memcache.add(cache_key, result)
def cache_runs(test_id, branch_id, platform_id, cache): PersistentCache.set_cache(Test.cache_key(test_id, branch_id, platform_id), cache)