| OLD | NEW |
| 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 buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "sort" | 10 "sort" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 Duration: duration, | 56 Duration: duration, |
| 57 }, | 57 }, |
| 58 Text: b.Text, | 58 Text: b.Text, |
| 59 Blame: blame(b), | 59 Blame: blame(b), |
| 60 Revision: b.Sourcestamp.Revision, | 60 Revision: b.Sourcestamp.Revision, |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 // getBuilds fetches all of the recent builds from the . Note that | 64 // getBuilds fetches all of the recent builds from the . Note that |
| 65 // getBuilds() does not perform ACL checks. | 65 // getBuilds() does not perform ACL checks. |
| 66 func getBuilds(c context.Context, masterName, builderName string, finished bool)
([]*resp.BuildSummary, error) { | 66 func getBuilds( |
| 67 » c context.Context, masterName, builderName string, finished bool, limit
int) ( |
| 68 » []*resp.BuildSummary, error) { |
| 69 |
| 67 // TODO(hinoka): Builder specific structs. | 70 // TODO(hinoka): Builder specific structs. |
| 68 result := []*resp.BuildSummary{} | 71 result := []*resp.BuildSummary{} |
| 69 q := ds.NewQuery("buildbotBuild") | 72 q := ds.NewQuery("buildbotBuild") |
| 70 q = q.Eq("finished", finished) | 73 q = q.Eq("finished", finished) |
| 71 q = q.Eq("master", masterName) | 74 q = q.Eq("master", masterName) |
| 72 q = q.Eq("builder", builderName) | 75 q = q.Eq("builder", builderName) |
| 73 » q = q.Limit(25) // TODO(hinoka): This should be adjustable | 76 » q = q.Limit(int32(limit)) |
| 74 q = q.Order("-number") | 77 q = q.Order("-number") |
| 75 buildbots := []*buildbotBuild{} | 78 buildbots := []*buildbotBuild{} |
| 76 err := ds.GetAll(c, q, &buildbots) | 79 err := ds.GetAll(c, q, &buildbots) |
| 77 if err != nil { | 80 if err != nil { |
| 78 return nil, err | 81 return nil, err |
| 79 } | 82 } |
| 80 for _, b := range buildbots { | 83 for _, b := range buildbots { |
| 81 result = append(result, getBuildSummary(b)) | 84 result = append(result, getBuildSummary(b)) |
| 82 } | 85 } |
| 83 return result, nil | 86 return result, nil |
| (...skipping 22 matching lines...) Expand all Loading... |
| 106 results = append(results, cb) | 109 results = append(results, cb) |
| 107 } | 110 } |
| 108 } | 111 } |
| 109 return results | 112 return results |
| 110 } | 113 } |
| 111 | 114 |
| 112 // builderImpl is the implementation for getting a milo builder page from buildb
ot. | 115 // builderImpl is the implementation for getting a milo builder page from buildb
ot. |
| 113 // This gets: | 116 // This gets: |
| 114 // * Current Builds from querying the master json from the datastore. | 117 // * Current Builds from querying the master json from the datastore. |
| 115 // * Recent Builds from a cron job that backfills the recent builds. | 118 // * Recent Builds from a cron job that backfills the recent builds. |
| 116 func builderImpl(c context.Context, masterName, builderName string) (*resp.Build
er, error) { | 119 func builderImpl(c context.Context, masterName, builderName string, limit int) (
*resp.Builder, error) { |
| 117 result := &resp.Builder{} | 120 result := &resp.Builder{} |
| 118 master, t, err := getMasterJSON(c, masterName) | 121 master, t, err := getMasterJSON(c, masterName) |
| 119 switch { | 122 switch { |
| 120 case err == ds.ErrNoSuchEntity: | 123 case err == ds.ErrNoSuchEntity: |
| 121 return nil, errMasterNotFound | 124 return nil, errMasterNotFound |
| 122 case err != nil: | 125 case err != nil: |
| 123 return nil, err | 126 return nil, err |
| 124 } | 127 } |
| 125 if clock.Now(c).Sub(t) > 2*time.Minute { | 128 if clock.Now(c).Sub(t) > 2*time.Minute { |
| 126 warning := fmt.Sprintf( | 129 warning := fmt.Sprintf( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 162 } |
| 160 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour
ce.Changes)) | 163 result.PendingBuilds[i].Blame = make([]*resp.Commit, len(pb.Sour
ce.Changes)) |
| 161 for j, cm := range pb.Source.Changes { | 164 for j, cm := range pb.Source.Changes { |
| 162 result.PendingBuilds[i].Blame[j] = &resp.Commit{ | 165 result.PendingBuilds[i].Blame[j] = &resp.Commit{ |
| 163 AuthorEmail: cm.Who, | 166 AuthorEmail: cm.Who, |
| 164 CommitURL: cm.Revlink, | 167 CommitURL: cm.Revlink, |
| 165 } | 168 } |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 » recentBuilds, err := getBuilds(c, masterName, builderName, true) | 172 » recentBuilds, err := getBuilds(c, masterName, builderName, true, limit) |
| 170 if err != nil { | 173 if err != nil { |
| 171 return nil, err | 174 return nil, err |
| 172 } | 175 } |
| 173 currentBuilds, err := getBuilds(c, masterName, builderName, false) | 176 currentBuilds, err := getBuilds(c, masterName, builderName, false) |
| 174 if err != nil { | 177 if err != nil { |
| 175 return nil, err | 178 return nil, err |
| 176 } | 179 } |
| 177 logging.Debugf(c, "Number of current builds: %d", len(currentBuilds)) | 180 logging.Debugf(c, "Number of current builds: %d", len(currentBuilds)) |
| 178 // TODO(hinoka): This works, but there's a lot of junk data from | 181 // TODO(hinoka): This works, but there's a lot of junk data from |
| 179 // masters with unclean shutdown. Need to implement a cleanup | 182 // masters with unclean shutdown. Need to implement a cleanup |
| 180 // procedure of some sort. Once that is done, set: | 183 // procedure of some sort. Once that is done, set: |
| 181 // result.CurrentBuilds = currentBuilds | 184 // result.CurrentBuilds = currentBuilds |
| 182 | 185 |
| 183 for _, fb := range recentBuilds { | 186 for _, fb := range recentBuilds { |
| 184 // Yes recent builds is synonymous with finished builds. | 187 // Yes recent builds is synonymous with finished builds. |
| 185 // TODO(hinoka): Implement limits. | 188 // TODO(hinoka): Implement limits. |
| 186 if fb != nil { | 189 if fb != nil { |
| 187 result.FinishedBuilds = append(result.FinishedBuilds, fb
) | 190 result.FinishedBuilds = append(result.FinishedBuilds, fb
) |
| 188 } | 191 } |
| 189 } | 192 } |
| 190 return result, nil | 193 return result, nil |
| 191 } | 194 } |
| OLD | NEW |