| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. | 1 // Copyright 2015 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package frontend | 15 package frontend |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "fmt" |
| 18 "net/http" | 19 "net/http" |
| 19 | 20 |
| 20 "github.com/golang/protobuf/proto" | 21 "github.com/golang/protobuf/proto" |
| 21 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 22 | 23 |
| 23 "github.com/luci/luci-go/appengine/gaemiddleware" | 24 "github.com/luci/luci-go/appengine/gaemiddleware" |
| 24 "github.com/luci/luci-go/grpc/discovery" | 25 "github.com/luci/luci-go/grpc/discovery" |
| 25 "github.com/luci/luci-go/grpc/grpcmon" | 26 "github.com/luci/luci-go/grpc/grpcmon" |
| 26 "github.com/luci/luci-go/grpc/prpc" | 27 "github.com/luci/luci-go/grpc/prpc" |
| 28 "github.com/luci/luci-go/server/router" |
| 29 |
| 27 milo "github.com/luci/luci-go/milo/api/proto" | 30 milo "github.com/luci/luci-go/milo/api/proto" |
| 31 "github.com/luci/luci-go/milo/buildsource" |
| 28 "github.com/luci/luci-go/milo/buildsource/buildbot" | 32 "github.com/luci/luci-go/milo/buildsource/buildbot" |
| 29 "github.com/luci/luci-go/milo/buildsource/buildbucket" | 33 "github.com/luci/luci-go/milo/buildsource/buildbucket" |
| 30 "github.com/luci/luci-go/milo/buildsource/rawpresentation" | 34 "github.com/luci/luci-go/milo/buildsource/rawpresentation" |
| 31 "github.com/luci/luci-go/milo/buildsource/swarming" | 35 "github.com/luci/luci-go/milo/buildsource/swarming" |
| 32 "github.com/luci/luci-go/milo/common" | |
| 33 "github.com/luci/luci-go/milo/frontend/console" | |
| 34 "github.com/luci/luci-go/milo/rpc" | 36 "github.com/luci/luci-go/milo/rpc" |
| 35 "github.com/luci/luci-go/server/router" | |
| 36 ) | 37 ) |
| 37 | 38 |
| 38 func emptyPrelude(c context.Context, methodName string, req proto.Message) (cont
ext.Context, error) { | 39 func emptyPrelude(c context.Context, methodName string, req proto.Message) (cont
ext.Context, error) { |
| 39 return c, nil | 40 return c, nil |
| 40 } | 41 } |
| 41 | 42 |
| 42 // Run sets up all the routes and runs the server. | 43 // Run sets up all the routes and runs the server. |
| 43 func Run(templatePath string) { | 44 func Run(templatePath string) { |
| 44 // Register plain ol' http handlers. | 45 // Register plain ol' http handlers. |
| 45 r := router.New() | 46 r := router.New() |
| 46 gaemiddleware.InstallHandlers(r) | 47 gaemiddleware.InstallHandlers(r) |
| 47 | 48 |
| 48 » basemw := common.Base(templatePath) | 49 » basemw := base(templatePath) |
| 49 r.GET("/", basemw, frontpageHandler) | 50 r.GET("/", basemw, frontpageHandler) |
| 50 | 51 |
| 51 // Admin and cron endpoints. | 52 // Admin and cron endpoints. |
| 52 r.GET("/admin/update", basemw.Extend(gaemiddleware.RequireCron), UpdateC
onfigHandler) | 53 r.GET("/admin/update", basemw.Extend(gaemiddleware.RequireCron), UpdateC
onfigHandler) |
| 53 r.GET("/admin/configs", basemw, ConfigsHandler) | 54 r.GET("/admin/configs", basemw, ConfigsHandler) |
| 54 | 55 |
| 55 // Console | 56 // Console |
| 56 » r.GET("/console/:project/:name", basemw, console.ConsoleHandler) | 57 » r.GET("/console/:project/:name", basemw, ConsoleHandler) |
| 57 » r.GET("/console/:project", basemw, console.Main) | 58 » r.GET("/console/:project", basemw, ConsoleMainHandler) |
| 58 | 59 |
| 59 // Swarming | 60 // Swarming |
| 60 » r.GET(swarming.URLBase+"/:id/steps/*logname", basemw, swarming.LogHandle
r) | 61 » r.GET(swarming.URLBase+"/:id/steps/*logname", basemw, func(c *router.Con
text) { |
| 61 » r.GET(swarming.URLBase+"/:id", basemw, swarming.BuildHandler) | 62 » » LogHandler(c, &swarming.BuildID{ |
| 63 » » » TaskID: c.Params.ByName("id"), |
| 64 » » }, c.Params.ByName("logname")) |
| 65 » }) |
| 66 » r.GET(swarming.URLBase+"/:id", basemw, func(c *router.Context) { |
| 67 » » BuildHandler(c, &swarming.BuildID{TaskID: c.Params.ByName("id")}
) |
| 68 » }) |
| 62 // Backward-compatible URLs for Swarming: | 69 // Backward-compatible URLs for Swarming: |
| 63 » r.GET("/swarming/prod/:id/steps/*logname", basemw, swarming.LogHandler) | 70 » r.GET("/swarming/prod/:id/steps/*logname", basemw, func(c *router.Contex
t) { |
| 64 » r.GET("/swarming/prod/:id", basemw, swarming.BuildHandler) | 71 » » LogHandler(c, &swarming.BuildID{ |
| 72 » » » TaskID: c.Params.ByName("id"), |
| 73 » » }, c.Params.ByName("logname")) |
| 74 » }) |
| 75 » r.GET("/swarming/prod/:id", basemw, func(c *router.Context) { |
| 76 » » BuildHandler(c, &swarming.BuildID{TaskID: c.Params.ByName("id")}
) |
| 77 » }) |
| 65 | 78 |
| 66 // Buildbucket | 79 // Buildbucket |
| 67 » r.GET("/buildbucket/:bucket/:builder", basemw, buildbucket.BuilderHandle
r) | 80 » r.GET("/buildbucket/:bucket/:builder", basemw, func(c *router.Context) { |
| 81 » » BuilderHandler(c, buildsource.BuilderID( |
| 82 » » » fmt.Sprintf("buildbucket/%s/%s", c.Params.ByName("bucket
"), c.Params.ByName("builder")))) |
| 83 » }) |
| 68 | 84 |
| 69 // Buildbot | 85 // Buildbot |
| 70 » r.GET("/buildbot/:master/:builder/:build", basemw, buildbot.BuildHandler
) | 86 » r.GET("/buildbot/:master/:builder/:build", basemw, func(c *router.Contex
t) { |
| 71 » r.GET("/buildbot/:master/:builder/", basemw, buildbot.BuilderHandler) | 87 » » BuildHandler(c, &buildbot.BuildID{ |
| 88 » » » Master: c.Params.ByName("master"), |
| 89 » » » BuilderName: c.Params.ByName("builder"), |
| 90 » » » BuildNumber: c.Params.ByName("build"), |
| 91 » » }) |
| 92 » }) |
| 93 » r.GET("/buildbot/:master/:builder/", basemw, func(c *router.Context) { |
| 94 » » BuilderHandler(c, buildsource.BuilderID( |
| 95 » » » fmt.Sprintf("buildbot/%s/%s", c.Params.ByName("master"),
c.Params.ByName("builder")))) |
| 96 » }) |
| 72 | 97 |
| 73 // LogDog Milo Annotation Streams. | 98 // LogDog Milo Annotation Streams. |
| 74 // This mimicks the `logdog://logdog_host/project/*path` url scheme seen
on | 99 // This mimicks the `logdog://logdog_host/project/*path` url scheme seen
on |
| 75 // swarming tasks. | 100 // swarming tasks. |
| 76 » r.GET("/raw/build/:logdog_host/:project/*path", basemw, rawpresentation.
BuildHandler) | 101 » r.GET("/raw/build/:logdog_host/:project/*path", basemw, func(c *router.C
ontext) { |
| 102 » » BuildHandler(c, rawpresentation.NewBuildID( |
| 103 » » » c.Params.ByName("logdog_host"), |
| 104 » » » c.Params.ByName("project"), |
| 105 » » » c.Params.ByName("path"), |
| 106 » » )) |
| 107 » }) |
| 77 | 108 |
| 78 // PubSub subscription endpoints. | 109 // PubSub subscription endpoints. |
| 79 r.POST("/_ah/push-handlers/buildbot", basemw, buildbot.PubSubHandler) | 110 r.POST("/_ah/push-handlers/buildbot", basemw, buildbot.PubSubHandler) |
| 80 r.POST("/_ah/push-handlers/buildbucket", basemw, buildbucket.PubSubHandl
er) | 111 r.POST("/_ah/push-handlers/buildbucket", basemw, buildbucket.PubSubHandl
er) |
| 81 | 112 |
| 82 // pRPC style endpoints. | 113 // pRPC style endpoints. |
| 83 api := prpc.Server{ | 114 api := prpc.Server{ |
| 84 UnaryServerInterceptor: grpcmon.NewUnaryServerInterceptor(nil), | 115 UnaryServerInterceptor: grpcmon.NewUnaryServerInterceptor(nil), |
| 85 } | 116 } |
| 86 milo.RegisterBuildbotServer(&api, &milo.DecoratedBuildbot{ | 117 milo.RegisterBuildbotServer(&api, &milo.DecoratedBuildbot{ |
| 87 Service: &buildbot.Service{}, | 118 Service: &buildbot.Service{}, |
| 88 Prelude: emptyPrelude, | 119 Prelude: emptyPrelude, |
| 89 }) | 120 }) |
| 90 milo.RegisterBuildInfoServer(&api, &milo.DecoratedBuildInfo{ | 121 milo.RegisterBuildInfoServer(&api, &milo.DecoratedBuildInfo{ |
| 91 Service: &rpc.BuildInfoService{}, | 122 Service: &rpc.BuildInfoService{}, |
| 92 Prelude: emptyPrelude, | 123 Prelude: emptyPrelude, |
| 93 }) | 124 }) |
| 94 discovery.Enable(&api) | 125 discovery.Enable(&api) |
| 95 api.InstallHandlers(r, gaemiddleware.BaseProd()) | 126 api.InstallHandlers(r, gaemiddleware.BaseProd()) |
| 96 | 127 |
| 97 http.DefaultServeMux.Handle("/", r) | 128 http.DefaultServeMux.Handle("/", r) |
| 98 } | 129 } |
| OLD | NEW |