Revert "Merge pull request #16567 from calavera/context_per_request"

This reverts commit ff92f45be49146cd7ac7716c36d89de989cb262e, reversing
changes made to 80e31df3b6fdf6c1fbd6a5d0aceb0a148066508c.

Reverting to make the next revert easier.

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: 79c31f4b13d331d4011b2975a96dcdeab2036865
Component: engine
This commit is contained in:
Tibor Vass
2015-09-29 13:40:46 -04:00
parent 1e6abba179
commit fef14476a9
17 changed files with 94 additions and 82 deletions
+9 -9
View File
@@ -112,7 +112,7 @@ func (s *Server) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
OutStream: output,
}
err = s.daemon.Repositories().Pull(ctx, image, tag, imagePullConfig)
err = s.daemon.Repositories(ctx).Pull(ctx, image, tag, imagePullConfig)
} else { //import
if tag == "" {
repo, tag = parsers.ParseRepositoryTag(repo)
@@ -129,7 +129,7 @@ func (s *Server) postImagesCreate(ctx context.Context, w http.ResponseWriter, r
return err
}
err = s.daemon.Repositories().Import(ctx, src, repo, tag, message, r.Body, output, newConfig)
err = s.daemon.Repositories(ctx).Import(ctx, src, repo, tag, message, r.Body, output, newConfig)
}
if err != nil {
if !output.Flushed() {
@@ -184,7 +184,7 @@ func (s *Server) postImagesPush(ctx context.Context, w http.ResponseWriter, r *h
w.Header().Set("Content-Type", "application/json")
if err := s.daemon.Repositories().Push(ctx, name, imagePushConfig); err != nil {
if err := s.daemon.Repositories(ctx).Push(ctx, name, imagePushConfig); err != nil {
if !output.Flushed() {
return err
}
@@ -212,7 +212,7 @@ func (s *Server) getImagesGet(ctx context.Context, w http.ResponseWriter, r *htt
names = r.Form["names"]
}
if err := s.daemon.Repositories().ImageExport(names, output); err != nil {
if err := s.daemon.Repositories(ctx).ImageExport(names, output); err != nil {
if !output.Flushed() {
return err
}
@@ -223,7 +223,7 @@ func (s *Server) getImagesGet(ctx context.Context, w http.ResponseWriter, r *htt
}
func (s *Server) postImagesLoad(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return s.daemon.Repositories().Load(r.Body, w)
return s.daemon.Repositories(ctx).Load(r.Body, w)
}
func (s *Server) deleteImages(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
@@ -256,7 +256,7 @@ func (s *Server) getImagesByName(ctx context.Context, w http.ResponseWriter, r *
return fmt.Errorf("Missing parameter")
}
imageInspect, err := s.daemon.Repositories().Lookup(vars["name"])
imageInspect, err := s.daemon.Repositories(ctx).Lookup(vars["name"])
if err != nil {
return err
}
@@ -364,7 +364,7 @@ func (s *Server) getImagesJSON(ctx context.Context, w http.ResponseWriter, r *ht
}
// FIXME: The filter parameter could just be a match filter
images, err := s.daemon.Repositories().Images(r.Form.Get("filters"), r.Form.Get("filter"), boolValue(r, "all"))
images, err := s.daemon.Repositories(ctx).Images(r.Form.Get("filters"), r.Form.Get("filter"), boolValue(r, "all"))
if err != nil {
return err
}
@@ -378,7 +378,7 @@ func (s *Server) getImagesHistory(ctx context.Context, w http.ResponseWriter, r
}
name := vars["name"]
history, err := s.daemon.Repositories().History(name)
history, err := s.daemon.Repositories(ctx).History(name)
if err != nil {
return err
}
@@ -398,7 +398,7 @@ func (s *Server) postImagesTag(ctx context.Context, w http.ResponseWriter, r *ht
tag := r.Form.Get("tag")
force := boolValue(r, "force")
name := vars["name"]
if err := s.daemon.Repositories().Tag(repo, tag, name, force); err != nil {
if err := s.daemon.Repositories(ctx).Tag(repo, tag, name, force); err != nil {
return err
}
s.daemon.EventsService.Log(ctx, "tag", utils.ImageReference(repo, tag), "")
+5 -7
View File
@@ -42,12 +42,12 @@ type Server struct {
}
// New returns a new instance of the server based on the specified configuration.
func New(cfg *Config) *Server {
func New(ctx context.Context, cfg *Config) *Server {
srv := &Server{
cfg: cfg,
start: make(chan struct{}),
}
srv.router = createRouter(srv)
srv.router = createRouter(ctx, srv)
return srv
}
@@ -291,7 +291,7 @@ func (s *Server) initTCPSocket(addr string) (l net.Listener, err error) {
return
}
func (s *Server) makeHTTPHandler(localMethod string, localRoute string, localHandler HTTPAPIFunc) http.HandlerFunc {
func (s *Server) makeHTTPHandler(ctx context.Context, localMethod string, localRoute string, localHandler HTTPAPIFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// log the handler generation
logrus.Debugf("Calling %s %s", localMethod, localRoute)
@@ -303,8 +303,6 @@ func (s *Server) makeHTTPHandler(localMethod string, localRoute string, localHan
// apply to all requests. Data that is specific to the
// immediate function being called should still be passed
// as 'args' on the function call.
ctx := context.Background()
reqID := stringid.TruncateID(stringid.GenerateNonCryptoID())
ctx = context.WithValue(ctx, context.RequestID, reqID)
handlerFunc := s.handleWithGlobalMiddlewares(localHandler)
@@ -318,7 +316,7 @@ func (s *Server) makeHTTPHandler(localMethod string, localRoute string, localHan
// createRouter initializes the main router the server uses.
// we keep enableCors just for legacy usage, need to be removed in the future
func createRouter(s *Server) *mux.Router {
func createRouter(ctx context.Context, s *Server) *mux.Router {
r := mux.NewRouter()
if os.Getenv("DEBUG") != "" {
profilerSetup(r, "/debug/")
@@ -398,7 +396,7 @@ func createRouter(s *Server) *mux.Router {
localMethod := method
// build the handler function
f := s.makeHTTPHandler(localMethod, localRoute, localFct)
f := s.makeHTTPHandler(ctx, localMethod, localRoute, localFct)
// add the new route
if localRoute == "" {
@@ -2,8 +2,12 @@
package server
func (s *Server) registerSubRouter() {
httpHandler := s.daemon.NetworkAPIRouter()
import (
"github.com/docker/docker/context"
)
func (s *Server) registerSubRouter(ctx context.Context) {
httpHandler := s.daemon.NetworkAPIRouter(ctx)
subrouter := s.router.PathPrefix("/v{version:[0-9.]+}/networks").Subrouter()
subrouter.Methods("GET", "POST", "PUT", "DELETE").HandlerFunc(httpHandler)
+5 -1
View File
@@ -2,5 +2,9 @@
package server
func (s *Server) registerSubRouter() {
import (
"github.com/docker/docker/context"
)
func (s *Server) registerSubRouter(ctx context.Context) {
}
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"net/http"
"strconv"
"github.com/docker/docker/context"
"github.com/docker/docker/daemon"
"github.com/docker/docker/pkg/sockets"
"github.com/docker/libnetwork/portallocator"
@@ -63,10 +64,10 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
// AcceptConnections allows clients to connect to the API server.
// Referenced Daemon is notified about this server, and waits for the
// daemon acknowledgement before the incoming connections are accepted.
func (s *Server) AcceptConnections(d *daemon.Daemon) {
func (s *Server) AcceptConnections(ctx context.Context, d *daemon.Daemon) {
// Tell the init daemon we are accepting requests
s.daemon = d
s.registerSubRouter()
s.registerSubRouter(ctx)
go systemdDaemon.SdNotify("READY=1")
// close the lock so the listeners start accepting connections
select {
@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"github.com/docker/docker/context"
"github.com/docker/docker/daemon"
)
@@ -42,9 +43,9 @@ func (s *Server) newServer(proto, addr string) ([]serverCloser, error) {
}
// AcceptConnections allows router to start listening for the incoming requests.
func (s *Server) AcceptConnections(d *daemon.Daemon) {
func (s *Server) AcceptConnections(ctx context.Context, d *daemon.Daemon) {
s.daemon = d
s.registerSubRouter()
s.registerSubRouter(ctx)
// close the lock so the listeners start accepting connections
select {
case <-s.start: