| 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" |
| 11 "encoding/base64" | 11 "encoding/base64" |
| 12 "encoding/json" | 12 "encoding/json" |
| 13 "net/http" | |
| 14 "time" | 13 "time" |
| 15 | 14 |
| 16 "github.com/luci/gae/service/datastore" | 15 "github.com/luci/gae/service/datastore" |
| 17 "github.com/luci/luci-go/common/clock" | 16 "github.com/luci/luci-go/common/clock" |
| 18 "github.com/luci/luci-go/common/iotools" | 17 "github.com/luci/luci-go/common/iotools" |
| 19 log "github.com/luci/luci-go/common/logging" | 18 log "github.com/luci/luci-go/common/logging" |
| 19 "github.com/luci/luci-go/server/router" |
| 20 | 20 |
| 21 "github.com/julienschmidt/httprouter" | |
| 22 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 23 ) | 22 ) |
| 24 | 23 |
| 25 var ( | 24 var ( |
| 26 // subName is the name of the pubsub subscription that milo is expecting
. | 25 // subName is the name of the pubsub subscription that milo is expecting
. |
| 27 // TODO(hinoka): This should be read from luci-config. | 26 // TODO(hinoka): This should be read from luci-config. |
| 28 subName = "projects/luci-milo/subscriptions/buildbot-public" | 27 subName = "projects/luci-milo/subscriptions/buildbot-public" |
| 29 ) | 28 ) |
| 30 | 29 |
| 31 type pubSubMessage struct { | 30 type pubSubMessage struct { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 bm.Builds = append(bm.Builds, build) | 110 bm.Builds = append(bm.Builds, build) |
| 112 slave.RunningbuildsMap[build.Buildername] = append( | 111 slave.RunningbuildsMap[build.Buildername] = append( |
| 113 slave.RunningbuildsMap[build.Buildername], build
.Number) | 112 slave.RunningbuildsMap[build.Buildername], build
.Number) |
| 114 } | 113 } |
| 115 slave.Runningbuilds = nil | 114 slave.Runningbuilds = nil |
| 116 } | 115 } |
| 117 return bm.Builds, bm.Master, nil | 116 return bm.Builds, bm.Master, nil |
| 118 } | 117 } |
| 119 | 118 |
| 120 // PubSubHandler is a webhook that stores the builds coming in from pubsub. | 119 // PubSubHandler is a webhook that stores the builds coming in from pubsub. |
| 121 func PubSubHandler( | 120 func PubSubHandler(ctx *router.Context) { |
| 122 » c context.Context, h http.ResponseWriter, r *http.Request, p httprouter.
Params) { | 121 » c, h, r := ctx.Context, ctx.Writer, ctx.Request |
| 122 |
| 123 msg := pubSubSubscription{} | 123 msg := pubSubSubscription{} |
| 124 defer r.Body.Close() | 124 defer r.Body.Close() |
| 125 dec := json.NewDecoder(r.Body) | 125 dec := json.NewDecoder(r.Body) |
| 126 if err := dec.Decode(&msg); err != nil { | 126 if err := dec.Decode(&msg); err != nil { |
| 127 log.WithError(err).Errorf( | 127 log.WithError(err).Errorf( |
| 128 c, "Could not decode message. %s", err) | 128 c, "Could not decode message. %s", err) |
| 129 h.WriteHeader(200) // This is a hard failure, we don't want PubS
ub to retry. | 129 h.WriteHeader(200) // This is a hard failure, we don't want PubS
ub to retry. |
| 130 return | 130 return |
| 131 } | 131 } |
| 132 if msg.Subscription != subName { | 132 if msg.Subscription != subName { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 if err != nil { | 191 if err != nil { |
| 192 log.WithError(err).Errorf( | 192 log.WithError(err).Errorf( |
| 193 c, "Could not save master in datastore %s", err) | 193 c, "Could not save master in datastore %s", err) |
| 194 // This is transient, we do want PubSub to retry. | 194 // This is transient, we do want PubSub to retry. |
| 195 h.WriteHeader(500) | 195 h.WriteHeader(500) |
| 196 return | 196 return |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 h.WriteHeader(200) | 199 h.WriteHeader(200) |
| 200 } | 200 } |
| OLD | NEW |