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