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

Side by Side Diff: common/api/dm/service/v1/ensure_graph_data_normalize.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file Created 4 years, 6 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 package dm 5 package dm
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 "github.com/luci/luci-go/common/errors" 10 "github.com/luci/luci-go/common/errors"
11 ) 11 )
12 12
13 // Normalize returns an error iff the TemplateInstantiation is invalid. 13 // Normalize returns an error iff the TemplateInstantiation is invalid.
14 func (t *TemplateInstantiation) Normalize() error { 14 func (t *TemplateInstantiation) Normalize() error {
15 if t.Project == "" { 15 if t.Project == "" {
16 return errors.New("empty project") 16 return errors.New("empty project")
17 } 17 }
18 return t.Specifier.Normalize() 18 return t.Specifier.Normalize()
19 } 19 }
20 20
21 // Normalize returns an error iff the request is invalid. 21 // Normalize returns an error iff the request is invalid.
22 func (r *EnsureGraphDataReq) Normalize() error { 22 func (r *EnsureGraphDataReq) Normalize() error {
23 if r.ForExecution != nil {
24 if err := r.ForExecution.Normalize(); err != nil {
25 return err
26 }
27 }
28
23 if err := r.Attempts.Normalize(); err != nil { 29 if err := r.Attempts.Normalize(); err != nil {
24 return err 30 return err
25 } 31 }
26 32
27 hasAttempts := false 33 hasAttempts := false
28 » for _, nums := range r.Attempts.To { 34 » if r.Attempts != nil {
29 » » hasAttempts = true 35 » » for _, nums := range r.Attempts.To {
30 » » if len(nums.Nums) == 0 { 36 » » » hasAttempts = true
31 » » » return errors.New("EnsureGraphDataReq.attempts must only include valid (non-0, non-empty) attempt numbers") 37 » » » if len(nums.Nums) == 0 {
38 » » » » return errors.New("EnsureGraphDataReq.attempts m ust only include valid (non-0, non-empty) attempt numbers")
39 » » » }
32 } 40 }
33 } 41 }
34 42
35 if len(r.TemplateQuest) != len(r.TemplateAttempt) { 43 if len(r.TemplateQuest) != len(r.TemplateAttempt) {
36 return errors.New("mismatched template_attempt v. template_quest lengths") 44 return errors.New("mismatched template_attempt v. template_quest lengths")
37 } 45 }
38 46
39 if len(r.TemplateQuest) > 0 { 47 if len(r.TemplateQuest) > 0 {
40 for i, q := range r.TemplateQuest { 48 for i, q := range r.TemplateQuest {
41 if err := q.Normalize(); err != nil { 49 if err := q.Normalize(); err != nil {
42 return fmt.Errorf("template_quests[%d]: %s", i, err) 50 return fmt.Errorf("template_quests[%d]: %s", i, err)
43 } 51 }
44 if err := r.TemplateAttempt[i].Normalize(); err != nil { 52 if err := r.TemplateAttempt[i].Normalize(); err != nil {
45 return fmt.Errorf("template_attempts[%d]: %s", i , err) 53 return fmt.Errorf("template_attempts[%d]: %s", i , err)
46 } 54 }
47 if len(r.TemplateAttempt[i].Nums) == 0 { 55 if len(r.TemplateAttempt[i].Nums) == 0 {
48 return fmt.Errorf("template_attempts[%d]: empty attempt list", i) 56 return fmt.Errorf("template_attempts[%d]: empty attempt list", i)
49 } 57 }
50 } 58 }
51 } 59 }
52 60
61 for i, desc := range r.Quest {
62 if err := desc.Normalize(); err != nil {
63 return fmt.Errorf("quest[%d]: %s", i, err)
64 }
65 }
66
53 if len(r.Quest) == 0 && !hasAttempts { 67 if len(r.Quest) == 0 && !hasAttempts {
54 return errors.New("EnsureGraphDataReq must have at least one of quests and attempts") 68 return errors.New("EnsureGraphDataReq must have at least one of quests and attempts")
55 } 69 }
56 70
57 if r.Limit == nil { 71 if r.Limit == nil {
58 r.Limit = &EnsureGraphDataReq_Limit{} 72 r.Limit = &EnsureGraphDataReq_Limit{}
59 } 73 }
60 if r.Limit.MaxDataSize == 0 { 74 if r.Limit.MaxDataSize == 0 {
61 r.Limit.MaxDataSize = DefaultLimitMaxDataSize 75 r.Limit.MaxDataSize = DefaultLimitMaxDataSize
62 } 76 }
63 if r.Limit.MaxDataSize > MaxLimitMaxDataSize { 77 if r.Limit.MaxDataSize > MaxLimitMaxDataSize {
64 r.Limit.MaxDataSize = MaxLimitMaxDataSize 78 r.Limit.MaxDataSize = MaxLimitMaxDataSize
65 } 79 }
66 80
67 if r.Include == nil { 81 if r.Include == nil {
68 r.Include = &EnsureGraphDataReq_Include{} 82 r.Include = &EnsureGraphDataReq_Include{}
69 } 83 }
70 return nil 84 return nil
71 } 85 }
OLDNEW
« no previous file with comments | « common/api/dm/service/v1/ensure_graph_data.pb.go ('k') | common/api/dm/service/v1/execution_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698