OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 package deps | 5 package deps |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 | 9 |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 muts = append(muts, mut) | 137 muts = append(muts, mut) |
138 } | 138 } |
139 for qid, nums := range newAttempts.To { | 139 for qid, nums := range newAttempts.To { |
140 muts = append(muts, &mutate.EnsureQuestAttempts{ | 140 muts = append(muts, &mutate.EnsureQuestAttempts{ |
141 Quest: &model.Quest{ID: qid}, | 141 Quest: &model.Quest{ID: qid}, |
142 AIDs: nums.Nums, | 142 AIDs: nums.Nums, |
143 DoNotMergeQuest: true, | 143 DoNotMergeQuest: true, |
144 }) | 144 }) |
145 } | 145 } |
146 » return grpcAnnotate(tumble.AddToJournal(c, muts...), codes.Internal). | 146 » return grpcAnnotate(tumble.AddToJournal(c, muts...), codes.Internal, "at
tempting to journal").Err() |
147 » » Reason("attempting to journal").Err() | |
148 } | 147 } |
149 | 148 |
150 func (d *deps) ensureGraphData(c context.Context, req *dm.EnsureGraphDataReq, ne
wQuests []*model.Quest, newAttempts *dm.AttemptList, rsp *dm.EnsureGraphDataRsp)
(err error) { | 149 func (d *deps) ensureGraphData(c context.Context, req *dm.EnsureGraphDataReq, ne
wQuests []*model.Quest, newAttempts *dm.AttemptList, rsp *dm.EnsureGraphDataRsp)
(err error) { |
151 var ( | 150 var ( |
152 fwdDepExists *ds.ExistsResult | 151 fwdDepExists *ds.ExistsResult |
153 fwdDepKeys []*ds.Key | 152 fwdDepKeys []*ds.Key |
154 ) | 153 ) |
155 if req.ForExecution != nil { | 154 if req.ForExecution != nil { |
156 fwdDepKeys = model.FwdDepKeysFromList(c, req.ForExecution.Id.Att
emptID(), newAttempts) | 155 fwdDepKeys = model.FwdDepKeysFromList(c, req.ForExecution.Id.Att
emptID(), newAttempts) |
157 } | 156 } |
(...skipping 11 matching lines...) Expand all Loading... |
169 gen <- func() (err error) { | 168 gen <- func() (err error) { |
170 fwdDepExists, err = ds.Exists(c, fwdDepKeys) | 169 fwdDepExists, err = ds.Exists(c, fwdDepKeys) |
171 if err != nil { | 170 if err != nil { |
172 err = fmt.Errorf("while finding FwdDeps:
%s", err) | 171 err = fmt.Errorf("while finding FwdDeps:
%s", err) |
173 } | 172 } |
174 return err | 173 return err |
175 } | 174 } |
176 } | 175 } |
177 }) | 176 }) |
178 if err != nil { | 177 if err != nil { |
179 » » return grpcAnnotate(err, codes.Internal).Reason("failed to gathe
r prerequisites").Err() | 178 » » return grpcAnnotate(err, codes.Internal, "failed to gather prere
quisites").Err() |
180 } | 179 } |
181 | 180 |
182 // Now that we've walked the graph, prune the lists of new Quest and Att
empts | 181 // Now that we've walked the graph, prune the lists of new Quest and Att
empts |
183 // by the information retrieved in the graph walk. newQuest and newAttem
pts | 182 // by the information retrieved in the graph walk. newQuest and newAttem
pts |
184 // will be reduced to contain only the missing information. | 183 // will be reduced to contain only the missing information. |
185 newQuests, newQuestSet := filterQuestsByNewTemplateData(rsp.Result, newQ
uests) | 184 newQuests, newQuestSet := filterQuestsByNewTemplateData(rsp.Result, newQ
uests) |
186 newAttempts, newAttemptsLen, err := filterAttemptsByDNE(rsp.Result, newA
ttempts, newQuestSet) | 185 newAttempts, newAttemptsLen, err := filterAttemptsByDNE(rsp.Result, newA
ttempts, newQuestSet) |
187 if err != nil { | 186 if err != nil { |
188 » » return grpcAnnotate(err, codes.InvalidArgument).Reason("filterAt
temptsByDNE").Err() | 187 » » return grpcAnnotate(err, codes.InvalidArgument, "filterAttemptsB
yDNE").Err() |
189 } | 188 } |
190 | 189 |
191 // we're just asserting nodes, no edges, so journal whatever's left | 190 // we're just asserting nodes, no edges, so journal whatever's left |
192 if req.ForExecution == nil { | 191 if req.ForExecution == nil { |
193 logging.Fields{"qs": len(newQuests), "atmpts": newAttemptsLen}.I
nfof(c, | 192 logging.Fields{"qs": len(newQuests), "atmpts": newAttemptsLen}.I
nfof(c, |
194 "journaling without deps") | 193 "journaling without deps") |
195 err := journalQuestAttempts(c, newQuests, newAttempts) | 194 err := journalQuestAttempts(c, newQuests, newAttempts) |
196 rsp.Accepted = err == nil | 195 rsp.Accepted = err == nil |
197 return err | 196 return err |
198 } | 197 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 291 |
293 d, ok := dists[qDesc.DistributorConfigName] | 292 d, ok := dists[qDesc.DistributorConfigName] |
294 if !ok { | 293 if !ok { |
295 if d, _, err = reg.MakeDistributor(c, qDesc.DistributorC
onfigName); err != nil { | 294 if d, _, err = reg.MakeDistributor(c, qDesc.DistributorC
onfigName); err != nil { |
296 return | 295 return |
297 } | 296 } |
298 dists[qDesc.DistributorConfigName] = d | 297 dists[qDesc.DistributorConfigName] = d |
299 } | 298 } |
300 | 299 |
301 if err = d.Validate(qDesc.DistributorParameters); err != nil { | 300 if err = d.Validate(qDesc.DistributorParameters); err != nil { |
302 » » » err = grpcAnnotate(err, codes.InvalidArgument). | 301 » » » err = grpcAnnotate(err, codes.InvalidArgument, |
303 » » » » Reason("JSON distributor parameters are invalid
for this distributor configuration.").Err() | 302 » » » » "JSON distributor parameters are invalid for thi
s distributor configuration.").Err() |
304 return | 303 return |
305 } | 304 } |
306 | 305 |
307 if _, ok := newQuests[q.ID]; !ok { | 306 if _, ok := newQuests[q.ID]; !ok { |
308 newQuests[q.ID] = q | 307 newQuests[q.ID] = q |
309 } | 308 } |
310 rsp.QuestIds = append(rsp.QuestIds, dm.NewQuestID(q.ID)) | 309 rsp.QuestIds = append(rsp.QuestIds, dm.NewQuestID(q.ID)) |
311 anums := newAttempts.To[q.ID] | 310 anums := newAttempts.To[q.ID] |
312 if anums == nil { | 311 if anums == nil { |
313 anums = &dm.AttemptList_Nums{} | 312 anums = &dm.AttemptList_Nums{} |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 360 } |
362 | 361 |
363 return | 362 return |
364 } | 363 } |
365 | 364 |
366 func (d *deps) EnsureGraphData(c context.Context, req *dm.EnsureGraphDataReq) (r
sp *dm.EnsureGraphDataRsp, err error) { | 365 func (d *deps) EnsureGraphData(c context.Context, req *dm.EnsureGraphDataReq) (r
sp *dm.EnsureGraphDataRsp, err error) { |
367 if req.ForExecution != nil { | 366 if req.ForExecution != nil { |
368 logging.Fields{"execution": req.ForExecution.Id}.Infof(c, "on be
half of") | 367 logging.Fields{"execution": req.ForExecution.Id}.Infof(c, "on be
half of") |
369 _, _, err := model.AuthenticateExecution(c, req.ForExecution) | 368 _, _, err := model.AuthenticateExecution(c, req.ForExecution) |
370 if err != nil { | 369 if err != nil { |
371 » » » return nil, grpcAnnotate(err, codes.Unauthenticated).Rea
son("bad execution auth").Err() | 370 » » » return nil, grpcAnnotate(err, codes.Unauthenticated, "ba
d execution auth").Err() |
372 } | 371 } |
373 } else { | 372 } else { |
374 if err = canWrite(c); err != nil { | 373 if err = canWrite(c); err != nil { |
375 return | 374 return |
376 } | 375 } |
377 } | 376 } |
378 | 377 |
379 // render any quest descriptions, templates and template attempts into | 378 // render any quest descriptions, templates and template attempts into |
380 // a single merged set of new quests and new attempts | 379 // a single merged set of new quests and new attempts |
381 rsp, newQuests, newAttempts, err := renderRequest(c, req) | 380 rsp, newQuests, newAttempts, err := renderRequest(c, req) |
382 if err != nil || len(rsp.TemplateError) > 0 { | 381 if err != nil || len(rsp.TemplateError) > 0 { |
383 return | 382 return |
384 } | 383 } |
385 | 384 |
386 newQuestList := make([]*model.Quest, 0, len(newQuests)) | 385 newQuestList := make([]*model.Quest, 0, len(newQuests)) |
387 for _, q := range newQuests { | 386 for _, q := range newQuests { |
388 newQuestList = append(newQuestList, q) | 387 newQuestList = append(newQuestList, q) |
389 } | 388 } |
390 | 389 |
391 err = d.ensureGraphData(c, req, newQuestList, newAttempts, rsp) | 390 err = d.ensureGraphData(c, req, newQuestList, newAttempts, rsp) |
392 | 391 |
393 return | 392 return |
394 } | 393 } |
OLD | NEW |