Chromium Code Reviews| 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 "bytes" | 8 "bytes" |
| 9 "compress/gzip" | 9 "compress/gzip" |
| 10 "encoding/json" | 10 "encoding/json" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 Text string `json:"text"` | 64 Text string `json:"text"` |
| 65 } | 65 } |
| 66 | 66 |
| 67 func (a *buildbotLinkAlias) toLink() *resp.Link { | 67 func (a *buildbotLinkAlias) toLink() *resp.Link { |
| 68 return &resp.Link{ | 68 return &resp.Link{ |
| 69 Label: a.Text, | 69 Label: a.Text, |
| 70 URL: a.URL, | 70 URL: a.URL, |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 type buildbotProperty struct { | |
| 75 Name string | |
| 76 Value interface{} | |
| 77 Source string | |
| 78 } | |
| 79 | |
| 80 func (p *buildbotProperty) MarshalJSON() ([]byte, error) { | |
| 81 return json.Marshal([]interface{}{p.Name, p.Value, p.Source}) | |
|
hinoka
2017/02/03 01:06:17
This works??? I am amazed and terrified at the sam
dnj
2017/02/03 01:30:00
Yep, Marshal will just see it as it was prior to t
| |
| 82 } | |
| 83 | |
| 84 func (p *buildbotProperty) UnmarshalJSON(d []byte) error { | |
| 85 // The raw BuildBot representation is a slice of interfaces. | |
| 86 var raw []interface{} | |
| 87 if err := json.Unmarshal(d, &raw); err != nil { | |
| 88 return err | |
| 89 } | |
| 90 | |
| 91 switch len(raw) { | |
| 92 case 3: | |
| 93 if s, ok := raw[2].(string); ok { | |
| 94 p.Source = s | |
| 95 } | |
| 96 fallthrough | |
| 97 | |
| 98 case 2: | |
| 99 p.Value = raw[1] | |
| 100 fallthrough | |
| 101 | |
| 102 case 1: | |
| 103 if s, ok := raw[0].(string); ok { | |
| 104 p.Name = s | |
| 105 } | |
| 106 } | |
| 107 return nil | |
| 108 } | |
| 109 | |
| 74 // buildbotBuild is a single build json on buildbot. | 110 // buildbotBuild is a single build json on buildbot. |
| 75 type buildbotBuild struct { | 111 type buildbotBuild struct { |
| 76 Master string `gae:"$master"` | 112 Master string `gae:"$master"` |
| 77 Blame []string `json:"blame" gae:"-"` | 113 Blame []string `json:"blame" gae:"-"` |
| 78 Buildername string `json:"builderName"` | 114 Buildername string `json:"builderName"` |
| 79 // This needs to be reflected. This can be either a String or a buildbo tStep. | 115 // This needs to be reflected. This can be either a String or a buildbo tStep. |
| 80 Currentstep interface{} `json:"currentStep" gae:"-"` | 116 Currentstep interface{} `json:"currentStep" gae:"-"` |
| 81 // We don't care about this one. | 117 // We don't care about this one. |
| 82 Eta interface{} `json:"eta" gae:"-"` | 118 Eta interface{} `json:"eta" gae:"-"` |
| 83 Logs [][]string `json:"logs" gae:"-"` | 119 Logs [][]string `json:"logs" gae:"-"` |
| 84 Number int `json:"number"` | 120 Number int `json:"number"` |
| 85 // This is a slice of tri-tuples of [property name, value, source]. | 121 // This is a slice of tri-tuples of [property name, value, source]. |
| 86 // property name is always a string | 122 // property name is always a string |
| 87 // value can be a string or float | 123 // value can be a string or float |
| 88 // source is optional, but is always a string if present | 124 // source is optional, but is always a string if present |
| 89 » Properties [][]interface{} `json:"properties" gae:"-"` | 125 » Properties []*buildbotProperty `json:"properties" gae:"-"` |
| 90 Reason string `json:"reason"` | 126 Reason string `json:"reason"` |
| 91 Results *int `json:"results" gae:"-"` | 127 Results *int `json:"results" gae:"-"` |
| 92 Slave string `json:"slave"` | 128 Slave string `json:"slave"` |
| 93 Sourcestamp *buildbotSourceStamp `json:"sourceStamp" gae:"-"` | 129 Sourcestamp *buildbotSourceStamp `json:"sourceStamp" gae:"-"` |
| 94 Steps []buildbotStep `json:"steps" gae:"-"` | 130 Steps []buildbotStep `json:"steps" gae:"-"` |
| 95 Text []string `json:"text" gae:"-"` | 131 Text []string `json:"text" gae:"-"` |
| 96 Times []*float64 `json:"times" gae:"-"` | 132 Times []*float64 `json:"times" gae:"-"` |
| 97 // This one is injected by Milo. Does not exist in a normal json query. | 133 // This one is injected by Milo. Does not exist in a normal json query. |
| 98 TimeStamp *int `json:"timeStamp" gae:"-"` | 134 TimeStamp *int `json:"timeStamp" gae:"-"` |
| 99 // This one is marked by Milo, denotes whether or not the build is inter nal. | 135 // This one is marked by Milo, denotes whether or not the build is inter nal. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 if err != nil { | 231 if err != nil { |
| 196 return err | 232 return err |
| 197 } | 233 } |
| 198 bs, err := ioutil.ReadAll(reader) | 234 bs, err := ioutil.ReadAll(reader) |
| 199 if err != nil { | 235 if err != nil { |
| 200 return err | 236 return err |
| 201 } | 237 } |
| 202 return json.Unmarshal(bs, b) | 238 return json.Unmarshal(bs, b) |
| 203 } | 239 } |
| 204 | 240 |
| 241 func (b *buildbotBuild) getPropertyValue(name string) interface{} { | |
| 242 for _, prop := range b.Properties { | |
| 243 if prop.Name == name { | |
| 244 return prop.Value | |
| 245 } | |
| 246 } | |
| 247 return "" | |
| 248 } | |
| 249 | |
| 205 type errTooBig struct { | 250 type errTooBig struct { |
| 206 error | 251 error |
| 207 } | 252 } |
| 208 | 253 |
| 209 // Save returns a property map of the struct to save in the datastore. It | 254 // Save returns a property map of the struct to save in the datastore. It |
| 210 // contains two fields, the ID which is the key, and a data field which is a | 255 // contains two fields, the ID which is the key, and a data field which is a |
| 211 // serialized and gzipped representation of the entire struct. | 256 // serialized and gzipped representation of the entire struct. |
| 212 func (b *buildbotBuild) Save(withMeta bool) (datastore.PropertyMap, error) { | 257 func (b *buildbotBuild) Save(withMeta bool) (datastore.PropertyMap, error) { |
| 213 bs, err := json.Marshal(b) | 258 bs, err := json.Marshal(b) |
| 214 if err != nil { | 259 if err != nil { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 PendingBuilds int `json:"pending_builds"` | 414 PendingBuilds int `json:"pending_builds"` |
| 370 State string `json:"state"` | 415 State string `json:"state"` |
| 371 TotalSlaves int `json:"total_slaves"` | 416 TotalSlaves int `json:"total_slaves"` |
| 372 } `json:"builders"` | 417 } `json:"builders"` |
| 373 ServerUptime float64 `json:"server_uptime"` | 418 ServerUptime float64 `json:"server_uptime"` |
| 374 } `json:"varz"` | 419 } `json:"varz"` |
| 375 | 420 |
| 376 // This is injected by the pubsub publisher on the buildbot side. | 421 // This is injected by the pubsub publisher on the buildbot side. |
| 377 Name string `json:"name"` | 422 Name string `json:"name"` |
| 378 } | 423 } |
| OLD | NEW |