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

Side by Side Diff: ct/go/worker_scripts/create_pagesets/main.go

Issue 1990873002: Use swarming in create_pagesets CT task (Closed) Base URL: https://skia.googlesource.com/buildbot@ct-3-swarming-timeouts
Patch Set: Remove TODOs 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 unified diff | Download patch
OLDNEW
1 // Application that creates pagesets on a CT worker and uploads it to Google 1 // Application that creates pagesets on a CT worker and uploads it to Google
2 // Storage. 2 // Storage.
3 package main 3 package main
4 4
5 import ( 5 import (
6 "flag" 6 "flag"
7 "io" 7 "io"
8 "os" 8 "os"
9 "path"
9 "path/filepath" 10 "path/filepath"
10 "runtime"
11 "time" 11 "time"
12 12
13 "github.com/skia-dev/glog" 13 "github.com/skia-dev/glog"
14 14
15 "strconv" 15 "strconv"
16 16
17 "go.skia.org/infra/ct/go/util" 17 "go.skia.org/infra/ct/go/util"
18 "go.skia.org/infra/ct/go/worker_scripts/worker_common" 18 "go.skia.org/infra/ct/go/worker_scripts/worker_common"
19 "go.skia.org/infra/go/common" 19 "go.skia.org/infra/go/common"
20 skutil "go.skia.org/infra/go/util" 20 skutil "go.skia.org/infra/go/util"
21 ) 21 )
22 22
23 var ( 23 var (
24 » workerNum = flag.Int("worker_num", 1, "The number of this CT worker. I t will be in the {1..100} range.") 24 » startRange = flag.Int("start_range", 1, "The number this worker will st art creating page sets from.")
25 » pagesetType = flag.String("pageset_type", util.PAGESET_TYPE_MOBILE_10k, "The type of pagesets to create from the Alexa CSV list. Eg: 10k, Mobile10k, All .") 25 » num = flag.Int("num", 100, "The total number of pagesets to proc ess starting from the start_range.")
26 » pagesetType = flag.String("pageset_type", util.PAGESET_TYPE_MOBILE_10k, "The type of pagesets to create from the CSV list in util.PagesetTypeToInfo.")
26 ) 27 )
27 28
28 func main() { 29 func main() {
29 defer common.LogPanic() 30 defer common.LogPanic()
30 worker_common.Init() 31 worker_common.Init()
31 defer util.TimeTrack(time.Now(), "Creating Pagesets") 32 defer util.TimeTrack(time.Now(), "Creating Pagesets")
32 defer glog.Flush() 33 defer glog.Flush()
33 // Create the task file so that the master knows this worker is still bu sy.
34 skutil.LogErr(util.CreateTaskFile(util.ACTIVITY_CREATING_PAGESETS))
35 defer util.DeleteTaskFile(util.ACTIVITY_CREATING_PAGESETS)
36 34
37 // Delete and remake the local pagesets directory. 35 // Delete and remake the local pagesets directory.
38 pathToPagesets := filepath.Join(util.PagesetsDir, *pagesetType) 36 pathToPagesets := filepath.Join(util.PagesetsDir, *pagesetType)
39 skutil.RemoveAll(pathToPagesets) 37 skutil.RemoveAll(pathToPagesets)
40 skutil.MkdirAll(pathToPagesets, 0700) 38 skutil.MkdirAll(pathToPagesets, 0700)
39 defer skutil.RemoveAll(pathToPagesets)
41 40
42 // Get info about the specified pageset type. 41 // Get info about the specified pageset type.
43 pagesetTypeInfo := util.PagesetTypeToInfo[*pagesetType] 42 pagesetTypeInfo := util.PagesetTypeToInfo[*pagesetType]
44 csvSource := pagesetTypeInfo.CSVSource 43 csvSource := pagesetTypeInfo.CSVSource
45 numPages := pagesetTypeInfo.NumPages 44 numPages := pagesetTypeInfo.NumPages
46 userAgent := pagesetTypeInfo.UserAgent 45 userAgent := pagesetTypeInfo.UserAgent
47 46
48 // Download the CSV file from Google Storage to a tmp location. 47 // Download the CSV file from Google Storage to a tmp location.
49 gs, err := util.NewGsUtil(nil) 48 gs, err := util.NewGsUtil(nil)
50 if err != nil { 49 if err != nil {
(...skipping 12 matching lines...) Expand all
63 glog.Errorf("Unable to create file %s: %s", csvFile, err) 62 glog.Errorf("Unable to create file %s: %s", csvFile, err)
64 return 63 return
65 } 64 }
66 defer skutil.Close(out) 65 defer skutil.Close(out)
67 defer skutil.Remove(csvFile) 66 defer skutil.Remove(csvFile)
68 if _, err = io.Copy(out, respBody); err != nil { 67 if _, err = io.Copy(out, respBody); err != nil {
69 glog.Error(err) 68 glog.Error(err)
70 return 69 return
71 } 70 }
72 71
73 » // Figure out which pagesets this worker should generate. 72 » // Figure out the endRange of this worker.
74 » numPagesPerSlave := numPages / util.NumWorkers() 73 » endRange := *startRange + (skutil.MinInt(*num, numPages) - 1)
dogben 2016/05/18 17:38:26 Does this want to be skutil.MinInt(*startRange + *
rmistry 2016/05/19 12:59:50 Yes that looks right. Thanks!
75 » if *worker_common.Local {
76 » » // When running locally, just do 10 pagesets to make things fast .
77 » » numPagesPerSlave = 10
78 » }
79 » startNum := (*workerNum-1)*numPagesPerSlave + 1
80 » endNum := *workerNum * numPagesPerSlave
81 74
82 // Construct path to the create_page_set.py python script. 75 // Construct path to the create_page_set.py python script.
83 » _, currentFile, _, _ := runtime.Caller(0) 76 » pathToPyFiles := util.GetPathToPyFiles(!*worker_common.Local)
84 » createPageSetScript := filepath.Join( 77 » createPageSetScript := filepath.Join(pathToPyFiles, "create_page_set.py" )
85 » » filepath.Dir((filepath.Dir(filepath.Dir(filepath.Dir(currentFile ))))),
86 » » "py", "create_page_set.py")
87 78
88 // Execute the create_page_set.py python script. 79 // Execute the create_page_set.py python script.
89 timeoutSecs := util.PagesetTypeToInfo[*pagesetType].CreatePagesetsTimeou tSecs 80 timeoutSecs := util.PagesetTypeToInfo[*pagesetType].CreatePagesetsTimeou tSecs
90 » for currNum := startNum; currNum <= endNum; currNum++ { 81 » for currNum := *startRange; currNum <= endRange; currNum++ {
82 » » destDir := path.Join(pathToPagesets, strconv.Itoa(currNum))
83 » » if err := os.MkdirAll(destDir, 0700); err != nil {
84 » » » glog.Error(err)
85 » » » return
86 » » }
91 args := []string{ 87 args := []string{
92 createPageSetScript, 88 createPageSetScript,
93 "-s", strconv.Itoa(currNum), 89 "-s", strconv.Itoa(currNum),
94 "-e", strconv.Itoa(currNum),
95 "-c", csvFile, 90 "-c", csvFile,
96 "-p", *pagesetType, 91 "-p", *pagesetType,
97 "-u", userAgent, 92 "-u", userAgent,
98 » » » "-o", pathToPagesets, 93 » » » "-o", destDir,
99 } 94 }
100 if err := util.ExecuteCmd("python", args, []string{}, time.Durat ion(timeoutSecs)*time.Second, nil, nil); err != nil { 95 if err := util.ExecuteCmd("python", args, []string{}, time.Durat ion(timeoutSecs)*time.Second, nil, nil); err != nil {
101 glog.Error(err) 96 glog.Error(err)
102 return 97 return
103 } 98 }
104 } 99 }
105 » // Write timestamp to the pagesets dir. 100 » // Upload all page sets to Google Storage.
106 » skutil.LogErr(util.CreateTimestampFile(pathToPagesets)) 101 » if err := gs.UploadSwarmingArtifacts(util.PAGESETS_DIR_NAME, *pagesetTyp e); err != nil {
107
108 » // Upload pagesets dir to Google Storage.
109 » if err := gs.UploadWorkerArtifacts(util.PAGESETS_DIR_NAME, *pagesetType, *workerNum); err != nil {
110 glog.Error(err) 102 glog.Error(err)
111 return 103 return
112 } 104 }
113 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698