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

Side by Side Diff: milo/appengine/buildbucket/builder.go

Issue 2944633003: [milo] Add BuildSummary and common models. (Closed)
Patch Set: add comments Created 3 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
« no previous file with comments | « milo/appengine/buildbucket/buckets.go ('k') | milo/appengine/buildbucket/common.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 buildbucket 5 package buildbucket
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "fmt" 9 "fmt"
10 "net/url" 10 "net/url"
(...skipping 10 matching lines...) Expand all
21 "github.com/luci/gae/service/info" 21 "github.com/luci/gae/service/info"
22 "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1" 22 "github.com/luci/luci-go/common/api/buildbucket/buildbucket/v1"
23 "github.com/luci/luci-go/common/clock" 23 "github.com/luci/luci-go/common/clock"
24 "github.com/luci/luci-go/common/errors" 24 "github.com/luci/luci-go/common/errors"
25 "github.com/luci/luci-go/common/logging" 25 "github.com/luci/luci-go/common/logging"
26 "github.com/luci/luci-go/common/retry" 26 "github.com/luci/luci-go/common/retry"
27 "github.com/luci/luci-go/common/sync/parallel" 27 "github.com/luci/luci-go/common/sync/parallel"
28 28
29 "github.com/luci/luci-go/milo/api/resp" 29 "github.com/luci/luci-go/milo/api/resp"
30 "github.com/luci/luci-go/milo/appengine/common" 30 "github.com/luci/luci-go/milo/appengine/common"
31 "github.com/luci/luci-go/milo/appengine/common/model"
31 ) 32 )
32 33
33 // search executes the search request with retries and exponential back-off. 34 // search executes the search request with retries and exponential back-off.
34 func search(c context.Context, client *buildbucket.Service, req *buildbucket.Sea rchCall) ( 35 func search(c context.Context, client *buildbucket.Service, req *buildbucket.Sea rchCall) (
35 *buildbucket.ApiSearchResponseMessage, error) { 36 *buildbucket.ApiSearchResponseMessage, error) {
36 37
37 var res *buildbucket.ApiSearchResponseMessage 38 var res *buildbucket.ApiSearchResponseMessage
38 err := retry.Retry( 39 err := retry.Retry(
39 c, 40 c,
40 retry.TransientOnly(retry.Default), 41 retry.TransientOnly(retry.Default),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 if result.Revision == "" { 113 if result.Revision == "" {
113 result.Revision = params.Properties.Revision 114 result.Revision = params.Properties.Revision
114 } 115 }
115 116
116 var err error 117 var err error
117 result.Status, err = parseStatus(build) 118 result.Status, err = parseStatus(build)
118 if err != nil { 119 if err != nil {
119 // almost never happens 120 // almost never happens
120 logging.WithError(err).Errorf(c, "could not convert status of bu ild %d", build.Id) 121 logging.WithError(err).Errorf(c, "could not convert status of bu ild %d", build.Id)
121 » » result.Status = resp.InfraFailure 122 » » result.Status = model.InfraFailure
122 result.Text = append(result.Text, fmt.Sprintf("invalid build: %s ", err)) 123 result.Text = append(result.Text, fmt.Sprintf("invalid build: %s ", err))
123 } 124 }
124 125
125 result.PendingTime.Started = parseTimestamp(build.CreatedTs) 126 result.PendingTime.Started = parseTimestamp(build.CreatedTs)
126 switch build.Status { 127 switch build.Status {
127 case "SCHEDULED": 128 case "SCHEDULED":
128 result.PendingTime.Duration = clock.Since(c, result.PendingTime. Started) 129 result.PendingTime.Duration = clock.Since(c, result.PendingTime. Started)
129 130
130 case "STARTED": 131 case "STARTED":
131 result.ExecutionTime.Started = parseTimestamp(build.StatusChange dTs) 132 result.ExecutionTime.Started = parseTimestamp(build.StatusChange dTs)
(...skipping 20 matching lines...) Expand all
152 // map milo links to itself 153 // map milo links to itself
153 switch { 154 switch {
154 case err != nil: 155 case err != nil:
155 logging.Errorf(c, "invalid URL in build %d: %s", build.I d, err) 156 logging.Errorf(c, "invalid URL in build %d: %s", build.I d, err)
156 case parsed.Host == info.DefaultVersionHostname(c): 157 case parsed.Host == info.DefaultVersionHostname(c):
157 parsed.Host = "" 158 parsed.Host = ""
158 parsed.Scheme = "" 159 parsed.Scheme = ""
159 u = parsed.String() 160 u = parsed.String()
160 } 161 }
161 162
162 » » result.Link = &resp.Link{ 163 » » result.Link = resp.NewLink(strconv.FormatInt(build.Id, 10), u)
163 » » » URL: u,
164 » » » Label: strconv.FormatInt(build.Id, 10),
165 » » }
166 164
167 // compute the best link label 165 // compute the best link label
168 if taskID := tags["swarming_task_id"]; taskID != "" { 166 if taskID := tags["swarming_task_id"]; taskID != "" {
169 result.Link.Label = taskID 167 result.Link.Label = taskID
170 } else if resultDetails.Properties.BuildNumber != 0 { 168 } else if resultDetails.Properties.BuildNumber != 0 {
171 result.Link.Label = strconv.Itoa(resultDetails.Propertie s.BuildNumber) 169 result.Link.Label = strconv.Itoa(resultDetails.Propertie s.BuildNumber)
172 } else if parsed != nil { 170 } else if parsed != nil {
173 // does the URL look like a buildbot build URL? 171 // does the URL look like a buildbot build URL?
174 pattern := fmt.Sprintf( 172 pattern := fmt.Sprintf(
175 `/%s/builders/%s/builds/`, 173 `/%s/builders/%s/builds/`,
(...skipping 21 matching lines...) Expand all
197 defer resFile.Close() 195 defer resFile.Close()
198 196
199 res := &buildbucket.ApiSearchResponseMessage{} 197 res := &buildbucket.ApiSearchResponseMessage{}
200 if err := json.NewDecoder(resFile).Decode(res); err != nil { 198 if err := json.NewDecoder(resFile).Decode(res); err != nil {
201 return err 199 return err
202 } 200 }
203 201
204 for _, bb := range res.Builds { 202 for _, bb := range res.Builds {
205 mb := toMiloBuild(c, bb) 203 mb := toMiloBuild(c, bb)
206 switch mb.Status { 204 switch mb.Status {
207 » » case resp.NotRun: 205 » » case model.NotRun:
208 target.PendingBuilds = append(target.PendingBuilds, mb) 206 target.PendingBuilds = append(target.PendingBuilds, mb)
209 207
210 » » case resp.Running: 208 » » case model.Running:
211 target.CurrentBuilds = append(target.CurrentBuilds, mb) 209 target.CurrentBuilds = append(target.CurrentBuilds, mb)
212 210
213 » » case resp.Success, resp.Failure, resp.InfraFailure, resp.Warning : 211 » » case model.Success, model.Failure, model.InfraFailure, model.War ning:
214 if len(target.FinishedBuilds) < maxCompletedBuilds { 212 if len(target.FinishedBuilds) < maxCompletedBuilds {
215 target.FinishedBuilds = append(target.FinishedBu ilds, mb) 213 target.FinishedBuilds = append(target.FinishedBu ilds, mb)
216 } 214 }
217 215
218 default: 216 default:
219 panic("impossible") 217 panic("impossible")
220 } 218 }
221 } 219 }
222 return nil 220 return nil
223 } 221 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() 287 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC()
290 } 288 }
291 289
292 type newBuildsFirst []*resp.BuildSummary 290 type newBuildsFirst []*resp.BuildSummary
293 291
294 func (a newBuildsFirst) Len() int { return len(a) } 292 func (a newBuildsFirst) Len() int { return len(a) }
295 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 293 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
296 func (a newBuildsFirst) Less(i, j int) bool { 294 func (a newBuildsFirst) Less(i, j int) bool {
297 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) 295 return a[i].PendingTime.Started.After(a[j].PendingTime.Started)
298 } 296 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbucket/buckets.go ('k') | milo/appengine/buildbucket/common.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698