| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | |
| 9 "sync" | 8 "sync" |
| 10 "sync/atomic" | 9 "sync/atomic" |
| 11 | 10 |
| 12 "github.com/julienschmidt/httprouter" | |
| 13 gaeauthClient "github.com/luci/luci-go/appengine/gaeauth/client" | 11 gaeauthClient "github.com/luci/luci-go/appengine/gaeauth/client" |
| 14 "github.com/luci/luci-go/appengine/logdog/coordinator/config" | 12 "github.com/luci/luci-go/appengine/logdog/coordinator/config" |
| 15 luciConfig "github.com/luci/luci-go/common/config" | 13 luciConfig "github.com/luci/luci-go/common/config" |
| 16 "github.com/luci/luci-go/common/errors" | 14 "github.com/luci/luci-go/common/errors" |
| 17 "github.com/luci/luci-go/common/gcloud/gs" | 15 "github.com/luci/luci-go/common/gcloud/gs" |
| 18 "github.com/luci/luci-go/common/gcloud/pubsub" | 16 "github.com/luci/luci-go/common/gcloud/pubsub" |
| 19 log "github.com/luci/luci-go/common/logging" | 17 log "github.com/luci/luci-go/common/logging" |
| 20 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | 18 "github.com/luci/luci-go/common/proto/logdog/svcconfig" |
| 21 "github.com/luci/luci-go/server/logdog/storage" | 19 "github.com/luci/luci-go/server/logdog/storage" |
| 22 "github.com/luci/luci-go/server/logdog/storage/bigtable" | 20 "github.com/luci/luci-go/server/logdog/storage/bigtable" |
| 23 » "github.com/luci/luci-go/server/middleware" | 21 » "github.com/luci/luci-go/server/router" |
| 24 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 25 "google.golang.org/cloud" | 23 "google.golang.org/cloud" |
| 26 gcps "google.golang.org/cloud/pubsub" | 24 gcps "google.golang.org/cloud/pubsub" |
| 27 "google.golang.org/grpc/metadata" | 25 "google.golang.org/grpc/metadata" |
| 28 ) | 26 ) |
| 29 | 27 |
| 30 // Services is a set of support services used by Coordinator. | 28 // Services is a set of support services used by Coordinator. |
| 31 // | 29 // |
| 32 // Each Services instance is valid for a singel request, but can be re-used | 30 // Each Services instance is valid for a singel request, but can be re-used |
| 33 // throughout that request. This is advised, as the Services instance may | 31 // throughout that request. This is advised, as the Services instance may |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 // The caller must close the returned instance if successful. | 54 // The caller must close the returned instance if successful. |
| 57 IntermediateStorage(context.Context) (storage.Storage, error) | 55 IntermediateStorage(context.Context) (storage.Storage, error) |
| 58 | 56 |
| 59 // GSClient instantiates a Google Storage client. | 57 // GSClient instantiates a Google Storage client. |
| 60 GSClient(context.Context) (gs.Client, error) | 58 GSClient(context.Context) (gs.Client, error) |
| 61 | 59 |
| 62 // ArchivalPublisher returns an ArchivalPublisher instance. | 60 // ArchivalPublisher returns an ArchivalPublisher instance. |
| 63 ArchivalPublisher(context.Context) (ArchivalPublisher, error) | 61 ArchivalPublisher(context.Context) (ArchivalPublisher, error) |
| 64 } | 62 } |
| 65 | 63 |
| 66 // WithProdServices is a middleware Handler that installs a production Services | 64 // WithProdServices is a middleware that installs a production Services |
| 67 // instance into its Context. | 65 // instance into its Context. |
| 68 func WithProdServices(h middleware.Handler) middleware.Handler { | 66 func WithProdServices(c *router.Context, next router.Handler) { |
| 69 » return func(c context.Context, rw http.ResponseWriter, r *http.Request,
params httprouter.Params) { | 67 » c.Context = UseProdServices(c.Context) |
| 70 » » c = UseProdServices(c) | 68 » next(c) |
| 71 » » h(c, rw, r, params) | |
| 72 » } | |
| 73 } | 69 } |
| 74 | 70 |
| 75 // UseProdServices installs production Services instance into the supplied | 71 // UseProdServices installs production Services instance into the supplied |
| 76 // Context. | 72 // Context. |
| 77 func UseProdServices(c context.Context) context.Context { | 73 func UseProdServices(c context.Context) context.Context { |
| 78 return WithServices(c, &prodServicesInst{}) | 74 return WithServices(c, &prodServicesInst{}) |
| 79 } | 75 } |
| 80 | 76 |
| 81 // prodServicesInst is a Service exposing production faciliites. A unique | 77 // prodServicesInst is a Service exposing production faciliites. A unique |
| 82 // instance is bound to each each request. | 78 // instance is bound to each each request. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // value as a sentinel that the archival index has wrapped. | 276 // value as a sentinel that the archival index has wrapped. |
| 281 // | 277 // |
| 282 // This is reasonable, as it is very unlikely that a single request will
issue | 278 // This is reasonable, as it is very unlikely that a single request will
issue |
| 283 // more than MaxInt32 archival tasks. | 279 // more than MaxInt32 archival tasks. |
| 284 v := atomic.AddInt32(&s.archivalIndex, 1) - 1 | 280 v := atomic.AddInt32(&s.archivalIndex, 1) - 1 |
| 285 if v < 0 { | 281 if v < 0 { |
| 286 panic("archival index has wrapped") | 282 panic("archival index has wrapped") |
| 287 } | 283 } |
| 288 return uint64(v) | 284 return uint64(v) |
| 289 } | 285 } |
| OLD | NEW |