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

Unified Diff: ct/go/util/util.go

Issue 1990873002: Use swarming in create_pagesets CT task (Closed) Base URL: https://skia.googlesource.com/buildbot@ct-3-swarming-timeouts
Patch Set: Address comment Created 4 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 | « ct/go/util/constants.go ('k') | ct/go/util/util_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ct/go/util/util.go
diff --git a/ct/go/util/util.go b/ct/go/util/util.go
index e69499571e5931fd2e1900fa47f49b38c967c093..75b2b260cbd654e0ff64a29c0107e8b15eedf27e 100644
--- a/ct/go/util/util.go
+++ b/ct/go/util/util.go
@@ -16,6 +16,7 @@ import (
"time"
"go.skia.org/infra/go/exec"
+ "go.skia.org/infra/go/swarming"
"go.skia.org/infra/go/util"
"github.com/skia-dev/glog"
@@ -390,3 +391,77 @@ func ValidateSKPs(pathToSkps string) error {
return nil
}
+
+// GetStartRange returns the range worker should start processing at based on its num and how many
+// artifacts it is allowed to process.
+func GetStartRange(workerNum, artifactsPerWorker int) int {
+ return ((workerNum - 1) * artifactsPerWorker) + 1
+}
+
+func TriggerSwarmingTask(pagesetType, taskPrefix, isolateName string, hardTimeout, ioTimeout time.Duration, maxPagesPerBot int, isolateExtraArgs map[string]string) error {
+ // Instantiate the swarming client.
+ workDir, err := ioutil.TempDir("", "swarming_work_")
+ if err != nil {
+ return fmt.Errorf("Could not get temp dir: %s", err)
+ }
+ s, err := swarming.NewSwarmingClient(workDir)
+ if err != nil {
+ return fmt.Errorf("Could not instantiate swarming client: %s", err)
+ }
+ defer s.Cleanup()
+ // Create isolated.gen.json files from tasks.
+ genJSONs := []string{}
+ // Get path to isolate files.
+ _, currentFile, _, _ := runtime.Caller(0)
+ pathToIsolates := filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(currentFile))), "isolates")
+ for i := 1; i <= PagesetTypeToInfo[pagesetType].NumPages/maxPagesPerBot; i++ {
+ isolateArgs := map[string]string{
+ "START_RANGE": strconv.Itoa(GetStartRange(i, maxPagesPerBot)),
+ "NUM": strconv.Itoa(maxPagesPerBot),
+ "PAGESET_TYPE": pagesetType,
+ }
+ // Add isolateExtraArgs (if specified) into the isolateArgs.
+ for k, v := range isolateExtraArgs {
+ isolateArgs[k] = v
+ }
+ taskName := fmt.Sprintf("%s_%d", taskPrefix, i)
+ genJSON, err := s.CreateIsolatedGenJSON(path.Join(pathToIsolates, isolateName), s.WorkDir, "linux", taskName, isolateArgs, []string{})
+ if err != nil {
+ return fmt.Errorf("Could not create isolated.gen.json for task %s: %s", taskName, err)
+ }
+ genJSONs = append(genJSONs, genJSON)
+ }
+
+ // Batcharchive the tasks.
+ tasksToHashes, err := s.BatchArchiveTargets(genJSONs, BATCHARCHIVE_TIMEOUT)
+ if err != nil {
+ return fmt.Errorf("Could not batch archive targets: %s", err)
+ }
+ if len(genJSONs) != len(tasksToHashes) {
+ return fmt.Errorf("len(genJSONs) was %d and len(tasksToHashes) was %d", len(genJSONs), len(tasksToHashes))
+ }
+ // Trigger swarming using the isolate hashes.
+ dimensions := map[string]string{"pool": SWARMING_POOL}
+ tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, swarming.RECOMMENDED_PRIORITY, swarming.RECOMMENDED_EXPIRATION, hardTimeout, ioTimeout, false)
+ if err != nil {
+ return fmt.Errorf("Could not trigger swarming task: %s", err)
+ }
+ // Collect all tasks and log the ones that fail.
+ for _, task := range tasks {
+ if _, _, err := task.Collect(s); err != nil {
+ glog.Errorf("task %s failed: %s", task.Title, err)
+ continue
+ }
+ }
+ return nil
+}
+
+// GetPathToPyFiles returns the location of CT's python scripts.
+func GetPathToPyFiles(runOnSwarming bool) string {
+ if runOnSwarming {
+ return filepath.Join(filepath.Dir(filepath.Dir(os.Args[0])), "src", "go.skia.org", "infra", "ct", "py")
+ } else {
+ _, currentFile, _, _ := runtime.Caller(0)
+ return filepath.Join(filepath.Dir(filepath.Dir(filepath.Dir(currentFile))), "py")
+ }
+}
« no previous file with comments | « ct/go/util/constants.go ('k') | ct/go/util/util_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698