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

Side by Side Diff: dm/tools/jobsim_client/main.go

Issue 2339413003: Refactor and test jobsim_client. (Closed)
Patch Set: Remove old script Created 4 years, 3 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 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // Jobsim client is a self-contained binary that implements various toy job 5 // Jobsim client is a self-contained binary that implements various toy job
6 // algorithms for use in testing DM with live distributors (like swarming). 6 // algorithms for use in testing DM with live distributors (like swarming).
7 package main 7 package main
8 8
9 import ( 9 import (
10 "encoding/json" 10 "encoding/json"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return err 105 return err
106 }, retry.LogCallback(r, "ActivateExecution")) 106 }, retry.LogCallback(r, "ActivateExecution"))
107 if err != nil { 107 if err != nil {
108 panic(err) 108 panic(err)
109 } 109 }
110 110
111 // activated with key! 111 // activated with key!
112 r.exAuth.Token = key 112 r.exAuth.Token = key
113 } 113 }
114 114
115 func (r *cmdRun) depOn(jobProperties ...interface{}) []string { 115 func (r *cmdRun) depOn(jobProperties ...interface{}) (data []string, stop bool) {
116 req := &dm.EnsureGraphDataReq{ 116 req := &dm.EnsureGraphDataReq{
117 ForExecution: r.exAuth, 117 ForExecution: r.exAuth,
118 118
119 Quest: make([]*dm.Quest_Desc, len(jobProperties)), 119 Quest: make([]*dm.Quest_Desc, len(jobProperties)),
120 QuestAttempt: make([]*dm.AttemptList_Nums, len(jobProperties)), 120 QuestAttempt: make([]*dm.AttemptList_Nums, len(jobProperties)),
121 121
122 Include: &dm.EnsureGraphDataReq_Include{ 122 Include: &dm.EnsureGraphDataReq_Include{
123 Attempt: &dm.EnsureGraphDataReq_Include_Options{Result: true}, 123 Attempt: &dm.EnsureGraphDataReq_Include_Options{Result: true},
124 }, 124 },
125 } 125 }
(...skipping 10 matching lines...) Expand all
136 136
137 rsp := (*dm.EnsureGraphDataRsp)(nil) 137 rsp := (*dm.EnsureGraphDataRsp)(nil)
138 err := retry.Retry(r, retry.Default, func() (err error) { 138 err := retry.Retry(r, retry.Default, func() (err error) {
139 rsp, err = r.client.EnsureGraphData(r, req) 139 rsp, err = r.client.EnsureGraphData(r, req)
140 return 140 return
141 }, retry.LogCallback(r, "EnsureGraphData")) 141 }, retry.LogCallback(r, "EnsureGraphData"))
142 if err != nil { 142 if err != nil {
143 panic(err) 143 panic(err)
144 } 144 }
145 if rsp.ShouldHalt { 145 if rsp.ShouldHalt {
146 » » logging.Infof(r, "got ShouldHalt, quitting") 146 » » logging.Infof(r, "got ShouldHalt")
147 » » os.Exit(0) 147 » » return nil, true
148 } 148 }
149 149
150 ret := make([]string, len(jobProperties)) 150 ret := make([]string, len(jobProperties))
151 for i, qid := range rsp.QuestIds { 151 for i, qid := range rsp.QuestIds {
152 ret[i] = rsp.Result.Quests[qid.Id].Attempts[1].Data.GetFinished( ).Data.Object 152 ret[i] = rsp.Result.Quests[qid.Id].Attempts[1].Data.GetFinished( ).Data.Object
153 } 153 }
154 154
155 » return ret 155 » return ret, false
156 } 156 }
157 157
158 func (r *cmdRun) finish(data interface{}) { 158 func (r *cmdRun) finish(data interface{}) int {
159 encData, err := json.Marshal(data) 159 encData, err := json.Marshal(data)
160 if err != nil { 160 if err != nil {
161 panic(err) 161 panic(err)
162 } 162 }
163 err = retry.Retry(r, retry.Default, func() error { 163 err = retry.Retry(r, retry.Default, func() error {
164 _, err := r.client.FinishAttempt(r, &dm.FinishAttemptReq{ 164 _, err := r.client.FinishAttempt(r, &dm.FinishAttemptReq{
165 Auth: r.exAuth, Data: dm.NewJsonResult(string(encData)), 165 Auth: r.exAuth, Data: dm.NewJsonResult(string(encData)),
166 }) 166 })
167 return err 167 return err
168 }, retry.LogCallback(r, "FinishAttempt")) 168 }, retry.LogCallback(r, "FinishAttempt"))
169 if err != nil { 169 if err != nil {
170 panic(err) 170 panic(err)
171 } 171 }
172 » os.Exit(0) 172 » return 0
173 } 173 }
174 174
175 // argErr prints an err and usage to stderr and returns an exit code. 175 // argErr prints an err and usage to stderr and returns an exit code.
176 func (r *cmdRun) argErr(format string, a ...interface{}) int { 176 func (r *cmdRun) argErr(format string, a ...interface{}) int {
177 if format != "" { 177 if format != "" {
178 fmt.Fprintf(os.Stderr, format+"\n", a...) 178 fmt.Fprintf(os.Stderr, format+"\n", a...)
179 } 179 }
180 fmt.Fprintln(os.Stderr, r.cmd.ShortDesc) 180 fmt.Fprintln(os.Stderr, r.cmd.ShortDesc)
181 fmt.Fprintln(os.Stderr, r.cmd.UsageLine) 181 fmt.Fprintln(os.Stderr, r.cmd.UsageLine)
182 fmt.Fprintln(os.Stderr, "\nFlags:") 182 fmt.Fprintln(os.Stderr, "\nFlags:")
183 r.Flags.PrintDefaults() 183 r.Flags.PrintDefaults()
184 return -1 184 return -1
185 } 185 }
186 186
187 var application = &cli.Application{ 187 var application = &cli.Application{
188 Name: "jobsim_client", 188 Name: "jobsim_client",
189 Title: "Executable Job simulator client", 189 Title: "Executable Job simulator client",
190 Context: func(ctx context.Context) context.Context { 190 Context: func(ctx context.Context) context.Context {
191 return gologger.StdConfig.Use(ctx) 191 return gologger.StdConfig.Use(ctx)
192 }, 192 },
193 Commands: []*subcommands.Command{ 193 Commands: []*subcommands.Command{
194 cmdEditDistance, 194 cmdEditDistance,
195 subcommands.CmdHelp, 195 subcommands.CmdHelp,
196 }, 196 },
197 } 197 }
198 198
199 func main() { 199 func main() {
200 os.Exit(subcommands.Run(application, os.Args[1:])) 200 os.Exit(subcommands.Run(application, os.Args[1:]))
201 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698