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

Side by Side Diff: appengine/cmd/dm/frontend/init.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: fix imports and make dummy.go a real file Created 4 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 | « appengine/cmd/dm/frontend/index.yaml ('k') | appengine/cmd/dm/model/attempt.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 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 frontend 5 package frontend
6 6
7 import ( 7 import (
8 "fmt"
8 "net/http" 9 "net/http"
10 "os"
9 11
10 "golang.org/x/net/context" 12 "golang.org/x/net/context"
11 13
14 "google.golang.org/appengine"
15
12 "github.com/julienschmidt/httprouter" 16 "github.com/julienschmidt/httprouter"
13 "github.com/luci/luci-go/appengine/cmd/dm/deps" 17 "github.com/luci/luci-go/appengine/cmd/dm/deps"
18 "github.com/luci/luci-go/appengine/cmd/dm/distributor"
19 "github.com/luci/luci-go/appengine/cmd/dm/mutate"
14 "github.com/luci/luci-go/appengine/gaeconfig" 20 "github.com/luci/luci-go/appengine/gaeconfig"
15 "github.com/luci/luci-go/appengine/gaemiddleware" 21 "github.com/luci/luci-go/appengine/gaemiddleware"
16 "github.com/luci/luci-go/appengine/tumble" 22 "github.com/luci/luci-go/appengine/tumble"
17 "github.com/luci/luci-go/common/config" 23 "github.com/luci/luci-go/common/config"
24 "github.com/luci/luci-go/common/config/impl/filesystem"
18 "github.com/luci/luci-go/common/logging" 25 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/server/discovery" 26 "github.com/luci/luci-go/server/discovery"
20 "github.com/luci/luci-go/server/middleware" 27 "github.com/luci/luci-go/server/middleware"
21 "github.com/luci/luci-go/server/prpc" 28 "github.com/luci/luci-go/server/prpc"
22 ) 29 )
23 30
24 func base(h middleware.Handler) httprouter.Handle { 31 func addConfigProd(c context.Context) context.Context {
32 » cfg, err := gaeconfig.New(c)
33 » switch err {
34 » case nil:
35 » » c = config.Set(c, cfg)
36 » case gaeconfig.ErrNotConfigured:
37 » » logging.Warningf(c, "luci-config service url not configured. Con figure this at /admin/settings/gaeconfig.")
38 » » fallthrough
39 » default:
40 » » panic(err)
41 » }
42 » return c
43 }
44
45 func baseProd(h middleware.Handler) httprouter.Handle {
25 newH := func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) { 46 newH := func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
26 » » cfg, err := gaeconfig.New(c) 47 » » h(addConfigProd(c), rw, r, p)
27 » » switch err {
28 » » case nil:
29 » » » c = config.Set(c, cfg)
30 » » case gaeconfig.ErrNotConfigured:
31 » » » logging.Warningf(c, "luci-config service url not configu red. Configure this at /admin/settings/gaeconfig.")
32 » » default:
33 » » » panic(err)
34 » » }
35 » » h(c, rw, r, p)
36 } 48 }
37 return gaemiddleware.BaseProd(newH) 49 return gaemiddleware.BaseProd(newH)
38 } 50 }
39 51
52 func addConfigDev(c context.Context) context.Context {
53 fpath := os.Getenv("LUCI_DM_CONFIG_BASE_PATH")
54 if fpath == "" {
55 panic(fmt.Errorf("LUCI_DM_CONFIG_BASE_PATH must be set in the en vironment"))
56 }
57 fs, err := filesystem.New(fpath)
58 if err != nil {
59 panic(fmt.Errorf("while setting up LUCI_DM_CONFIG_BASE_PATH: %s" , err))
60 }
61 return config.Set(c, fs)
62 }
63
64 func baseDev(h middleware.Handler) httprouter.Handle {
65 return gaemiddleware.BaseProd(func(c context.Context, rw http.ResponseWr iter, r *http.Request, p httprouter.Params) {
66 h(addConfigDev(c), rw, r, p)
67 })
68 }
69
40 func init() { 70 func init() {
41 router := httprouter.New() 71 router := httprouter.New()
42 tmb := tumble.Service{} 72 tmb := tumble.Service{}
43 73
74 reg := distributor.NewRegistry(nil, mutate.FinishExecutionFn)
75
76 base := baseProd
77 tmb.Middleware = func(c context.Context) context.Context {
78 return distributor.WithRegistry(addConfigProd(c), reg)
79 }
80 if appengine.IsDevAppServer() {
81 base = baseDev
82 tmb.Middleware = func(c context.Context) context.Context {
83 return distributor.WithRegistry(addConfigDev(c), reg)
84 }
85 }
86
87 distributor.InstallHandlers(reg, router, base)
88
44 svr := prpc.Server{} 89 svr := prpc.Server{}
45 » deps.RegisterDepsServer(&svr) 90 » deps.RegisterDepsServer(&svr, reg)
46 discovery.Enable(&svr) 91 discovery.Enable(&svr)
47
48 svr.InstallHandlers(router, base) 92 svr.InstallHandlers(router, base)
49 tmb.InstallHandlers(router) 93 tmb.InstallHandlers(router)
50 gaemiddleware.InstallHandlers(router, base) 94 gaemiddleware.InstallHandlers(router, base)
51 95
52 http.Handle("/", router) 96 http.Handle("/", router)
53 } 97 }
OLDNEW
« no previous file with comments | « appengine/cmd/dm/frontend/index.yaml ('k') | appengine/cmd/dm/model/attempt.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698