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 "compress/zlib" | 10 "compress/zlib" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 // Name of the buildbot master. | 73 // Name of the buildbot master. |
| 74 Name string `gae:"$id"` | 74 Name string `gae:"$id"` |
| 75 // Internal | 75 // Internal |
| 76 Internal bool | 76 Internal bool |
| 77 // Data is the json serialzed and gzipped blob of the master data. | 77 // Data is the json serialzed and gzipped blob of the master data. |
| 78 Data []byte `gae:",noindex"` | 78 Data []byte `gae:",noindex"` |
| 79 // Modified is when this entry was last modified. | 79 // Modified is when this entry was last modified. |
| 80 Modified time.Time | 80 Modified time.Time |
| 81 } | 81 } |
| 82 | 82 |
| 83 // buildbotMasterPublic is a struct that exists for public builtbot masters, and | |
| 84 // not for internal masters. It's used for ACL checks. | |
| 85 type buildbotMasterPublic struct { | |
|
dnj
2017/07/11 18:46:34
Is there a potential problem with already-ingested
iannucci
2017/07/11 21:01:39
We'll deploy the pubsub module first and make sure
| |
| 86 Name string `gae:"$id"` | |
| 87 } | |
| 88 | |
| 83 func putDSMasterJSON( | 89 func putDSMasterJSON( |
| 84 c context.Context, master *buildbotMaster, internal bool) error { | 90 c context.Context, master *buildbotMaster, internal bool) error { |
| 85 for _, builder := range master.Builders { | 91 for _, builder := range master.Builders { |
| 86 // Trim out extra info in the "Changes" portion of the pending b uild state, | 92 // Trim out extra info in the "Changes" portion of the pending b uild state, |
| 87 // we don't actually need comments, files, and properties | 93 // we don't actually need comments, files, and properties |
| 88 for _, pbs := range builder.PendingBuildStates { | 94 for _, pbs := range builder.PendingBuildStates { |
| 89 for i := range pbs.Source.Changes { | 95 for i := range pbs.Source.Changes { |
| 90 pbs.Source.Changes[i].Comments = "" | 96 pbs.Source.Changes[i].Comments = "" |
| 91 pbs.Source.Changes[i].Files = nil | 97 pbs.Source.Changes[i].Files = nil |
| 92 pbs.Source.Changes[i].Properties = nil | 98 pbs.Source.Changes[i].Properties = nil |
| 93 } | 99 } |
| 94 } | 100 } |
| 95 } | 101 } |
| 96 entry := buildbotMasterEntry{ | 102 entry := buildbotMasterEntry{ |
| 97 Name: master.Name, | 103 Name: master.Name, |
| 98 Internal: internal, | 104 Internal: internal, |
| 99 Modified: clock.Now(c).UTC(), | 105 Modified: clock.Now(c).UTC(), |
| 100 } | 106 } |
| 107 toPut := []interface{}{&entry} | |
|
Ryan Tseng
2017/07/11 18:37:16
why not []*entry{}?
dnj
2017/07/11 18:46:34
b/c this contains both a "buildbotMasterEntry" and
iannucci
2017/07/11 21:01:39
yep
| |
| 108 if internal { | |
| 109 // do the deletion immediately so that the 'public' bit is remov ed from | |
| 110 // datastore before any internal details are actually written to datastore. | |
| 111 if err := ds.Delete(c, &buildbotMasterPublic{master.Name}); err != nil && err != ds.ErrNoSuchEntity { | |
|
dnj
2017/07/11 18:46:34
nit: declare the public variable outside of this c
iannucci
2017/07/11 21:01:39
Done.
| |
| 112 return err | |
| 113 } | |
| 114 } else { | |
| 115 toPut = append(toPut, &buildbotMasterPublic{master.Name}) | |
| 116 } | |
| 101 gzbs := bytes.Buffer{} | 117 gzbs := bytes.Buffer{} |
| 102 gsw := gzip.NewWriter(&gzbs) | 118 gsw := gzip.NewWriter(&gzbs) |
| 103 cw := iotools.CountingWriter{Writer: gsw} | 119 cw := iotools.CountingWriter{Writer: gsw} |
| 104 e := json.NewEncoder(&cw) | 120 e := json.NewEncoder(&cw) |
| 105 if err := e.Encode(master); err != nil { | 121 if err := e.Encode(master); err != nil { |
| 106 return err | 122 return err |
| 107 } | 123 } |
| 108 gsw.Close() | 124 gsw.Close() |
| 109 entry.Data = gzbs.Bytes() | 125 entry.Data = gzbs.Bytes() |
| 110 logging.Debugf(c, "Length of json data: %d", cw.Count) | 126 logging.Debugf(c, "Length of json data: %d", cw.Count) |
| 111 logging.Debugf(c, "Length of gzipped data: %d", len(entry.Data)) | 127 logging.Debugf(c, "Length of gzipped data: %d", len(entry.Data)) |
| 112 » return ds.Put(c, &entry) | 128 » return ds.Put(c, toPut) |
| 113 } | 129 } |
| 114 | 130 |
| 115 // GetData returns the expanded form of Data (decoded from base64). | 131 // GetData returns the expanded form of Data (decoded from base64). |
| 116 func (m *pubSubSubscription) GetData() ([]byte, error) { | 132 func (m *pubSubSubscription) GetData() ([]byte, error) { |
| 117 return base64.StdEncoding.DecodeString(m.Message.Data) | 133 return base64.StdEncoding.DecodeString(m.Message.Data) |
| 118 } | 134 } |
| 119 | 135 |
| 120 // unmarshal a gzipped byte stream into a list of buildbot builds and masters. | 136 // unmarshal a gzipped byte stream into a list of buildbot builds and masters. |
| 121 func unmarshal( | 137 func unmarshal( |
| 122 c context.Context, msg []byte) ([]*buildbotBuild, *buildbotMaster, error ) { | 138 c context.Context, msg []byte) ([]*buildbotBuild, *buildbotMaster, error ) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 | 414 |
| 399 } | 415 } |
| 400 if master != nil { | 416 if master != nil { |
| 401 code := doMaster(c, master, internal) | 417 code := doMaster(c, master, internal) |
| 402 if code != 0 { | 418 if code != 0 { |
| 403 return code | 419 return code |
| 404 } | 420 } |
| 405 } | 421 } |
| 406 return http.StatusOK | 422 return http.StatusOK |
| 407 } | 423 } |
| OLD | NEW |