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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/dm/frontend/init.go
diff --git a/appengine/cmd/dm/frontend/init.go b/appengine/cmd/dm/frontend/init.go
index 1a6d0c55fac6d675e28c6721d20f9591a0a6ec44..8075b6155a0c83783d038eaa4b491113012544fa 100644
--- a/appengine/cmd/dm/frontend/init.go
+++ b/appengine/cmd/dm/frontend/init.go
@@ -5,46 +5,90 @@
package frontend
import (
+ "fmt"
"net/http"
+ "os"
"golang.org/x/net/context"
+ "google.golang.org/appengine"
+
"github.com/julienschmidt/httprouter"
"github.com/luci/luci-go/appengine/cmd/dm/deps"
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor"
+ "github.com/luci/luci-go/appengine/cmd/dm/mutate"
"github.com/luci/luci-go/appengine/gaeconfig"
"github.com/luci/luci-go/appengine/gaemiddleware"
"github.com/luci/luci-go/appengine/tumble"
"github.com/luci/luci-go/common/config"
+ "github.com/luci/luci-go/common/config/impl/filesystem"
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/server/discovery"
"github.com/luci/luci-go/server/middleware"
"github.com/luci/luci-go/server/prpc"
)
-func base(h middleware.Handler) httprouter.Handle {
+func addConfigProd(c context.Context) context.Context {
+ cfg, err := gaeconfig.New(c)
+ switch err {
+ case nil:
+ c = config.Set(c, cfg)
+ case gaeconfig.ErrNotConfigured:
+ logging.Warningf(c, "luci-config service url not configured. Configure this at /admin/settings/gaeconfig.")
+ fallthrough
+ default:
+ panic(err)
+ }
+ return c
+}
+
+func baseProd(h middleware.Handler) httprouter.Handle {
newH := func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
- cfg, err := gaeconfig.New(c)
- switch err {
- case nil:
- c = config.Set(c, cfg)
- case gaeconfig.ErrNotConfigured:
- logging.Warningf(c, "luci-config service url not configured. Configure this at /admin/settings/gaeconfig.")
- default:
- panic(err)
- }
- h(c, rw, r, p)
+ h(addConfigProd(c), rw, r, p)
}
return gaemiddleware.BaseProd(newH)
}
+func addConfigDev(c context.Context) context.Context {
+ fpath := os.Getenv("LUCI_DM_CONFIG_BASE_PATH")
+ if fpath == "" {
+ panic(fmt.Errorf("LUCI_DM_CONFIG_BASE_PATH must be set in the environment"))
+ }
+ fs, err := filesystem.New(fpath)
+ if err != nil {
+ panic(fmt.Errorf("while setting up LUCI_DM_CONFIG_BASE_PATH: %s", err))
+ }
+ return config.Set(c, fs)
+}
+
+func baseDev(h middleware.Handler) httprouter.Handle {
+ return gaemiddleware.BaseProd(func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
+ h(addConfigDev(c), rw, r, p)
+ })
+}
+
func init() {
router := httprouter.New()
tmb := tumble.Service{}
+ reg := distributor.NewRegistry(nil, mutate.FinishExecutionFn)
+
+ base := baseProd
+ tmb.Middleware = func(c context.Context) context.Context {
+ return distributor.WithRegistry(addConfigProd(c), reg)
+ }
+ if appengine.IsDevAppServer() {
+ base = baseDev
+ tmb.Middleware = func(c context.Context) context.Context {
+ return distributor.WithRegistry(addConfigDev(c), reg)
+ }
+ }
+
+ distributor.InstallHandlers(reg, router, base)
+
svr := prpc.Server{}
- deps.RegisterDepsServer(&svr)
+ deps.RegisterDepsServer(&svr, reg)
discovery.Enable(&svr)
-
svr.InstallHandlers(router, base)
tmb.InstallHandlers(router)
gaemiddleware.InstallHandlers(router, base)
« 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