Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Unified Diff: tools/gardening/lib/src/client.dart

Issue 2912343002: Add BuildBotClient to abstract http/logdog access (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gardening/lib/src/cache.dart ('k') | tools/gardening/lib/src/logdog.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gardening/lib/src/client.dart
diff --git a/tools/gardening/lib/src/client.dart b/tools/gardening/lib/src/client.dart
new file mode 100644
index 0000000000000000000000000000000000000000..05eb1ad29f7a80be0fe57d1bbcb75dbba667793a
--- /dev/null
+++ b/tools/gardening/lib/src/client.dart
@@ -0,0 +1,92 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:io';
+
+import 'buildbot_data.dart';
+import 'buildbot_loading.dart';
+import 'buildbot_structures.dart';
+import 'logdog.dart';
+import 'util.dart';
+
+/// Interface for pulling build bot results.
+abstract class BuildbotClient {
+ /// Reads the [BuildResult] for the [buildUri].
+ Future<BuildResult> readResult(BuildUri buildUri);
+
+ int get mostRecentBuildNumber;
+
+ /// Closes the client and cleans up its state.
+ void close();
+}
+
+/// Buildbot client that pulls build bot results through http.
+class HttpBuildbotClient implements BuildbotClient {
+ final HttpClient _client = new HttpClient();
+
+ @override
+ Future<BuildResult> readResult(BuildUri buildUri) {
+ return readBuildResult(_client, buildUri);
+ }
+
+ int get mostRecentBuildNumber => -2;
+
+ @override
+ void close() {
+ _client.close();
+ }
+}
+
+/// Buildbot client that pulls build bot results through logdog.
+class LogdogBuildbotClient implements BuildbotClient {
+ Map<String, List<int>> _botBuildNumberCache = <String, List<int>>{};
+
+ int get mostRecentBuildNumber => -1;
+
+ Future<List<int>> _getAbsoluteBuildNumbers(BuildUri buildUri) async {
+ List<int> absoluteBuildNumbers = _botBuildNumberCache[buildUri.botName];
+ if (absoluteBuildNumbers == null) {
+ absoluteBuildNumbers = await lookupBotBuildNumbers(buildUri.botName);
+ _botBuildNumberCache[buildUri.botName] = absoluteBuildNumbers;
+ }
+ return absoluteBuildNumbers;
+ }
+
+ @override
+ Future<BuildResult> readResult(BuildUri buildUri) async {
+ List<int> absoluteBuildNumbers;
+ int buildNumberIndex;
+ if (buildUri.buildNumber < 0) {
+ absoluteBuildNumbers = await _getAbsoluteBuildNumbers(buildUri);
+ int buildNumberIndex =
+ getBuildNumberIndex(absoluteBuildNumbers, buildUri.buildNumber);
+ if (buildNumberIndex == null) return null;
+ buildUri =
+ buildUri.withBuildNumber(absoluteBuildNumbers[buildNumberIndex]);
+ }
+ while (true) {
+ try {
+ return await readLogDogResult(buildUri);
+ } on LogdogException catch (e) {
+ if (e.exitKind != LogdogExitKind.error) {
+ return null;
+ }
+ absoluteBuildNumbers ??= await _getAbsoluteBuildNumbers(buildUri);
+ buildNumberIndex =
+ getBuildNumberIndex(absoluteBuildNumbers, buildUri.buildNumber);
+ if (buildNumberIndex == null) return null;
+ if (buildNumberIndex >= absoluteBuildNumbers.length) return null;
+ int buildNumber = absoluteBuildNumbers[buildNumberIndex + 1];
+ log('Skip build number ${buildUri.buildNumber} -> ${buildNumber}');
+ buildUri = buildUri.withBuildNumber(buildNumber);
+ }
+ }
+ }
+
+ @override
+ void close() {
+ // Nothing to do.
+ }
+}
« no previous file with comments | « tools/gardening/lib/src/cache.dart ('k') | tools/gardening/lib/src/logdog.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698