From 63503cafe4addb7d275244fbcce0e10d67225cc9 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 8 Aug 2014 09:12:39 +0000 Subject: [PATCH] Remove deprecated server/ package Victory! Signed-off-by: Solomon Hykes --- api/server/server.go | 2 +- builtins/builtins.go | 4 --- daemon/daemon.go | 6 ++++ daemonconfig/config.go | 41 ------------------------ docker/daemon.go | 56 ++++++++++++++++++++------------- integration/runtime_test.go | 2 +- integration/server_test.go | 11 +++---- integration/utils_test.go | 37 ++++++++++------------ server/MAINTAINERS | 3 -- server/init.go | 62 ------------------------------------- server/server.go | 36 --------------------- 11 files changed, 63 insertions(+), 197 deletions(-) delete mode 100644 server/MAINTAINERS delete mode 100644 server/init.go delete mode 100644 server/server.go diff --git a/api/server/server.go b/api/server/server.go index df72786b10..ae73660b6b 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1194,7 +1194,7 @@ func ServeFd(addr string, handle http.Handler) error { chErrors := make(chan error, len(ls)) // We don't want to start serving on these sockets until the - // "initserver" job has completed. Otherwise required handlers + // daemon is initialized and installed. Otherwise required handlers // won't be ready. <-activationLock diff --git a/builtins/builtins.go b/builtins/builtins.go index ea1e7c6b84..0aa2f43c16 100644 --- a/builtins/builtins.go +++ b/builtins/builtins.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/events" "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/registry" - "github.com/docker/docker/server" ) func Register(eng *engine.Engine) error { @@ -54,9 +53,6 @@ func remote(eng *engine.Engine) error { // These components should be broken off into plugins of their own. // func daemon(eng *engine.Engine) error { - if err := eng.Register("initserver", server.InitServer); err != nil { - return err - } return eng.Register("init_networkdriver", bridge.InitDriver) } diff --git a/daemon/daemon.go b/daemon/daemon.go index 5e2870f392..d65bad8b82 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -135,6 +135,12 @@ func (daemon *Daemon) Install(eng *engine.Engine) error { return err } } + if err := daemon.Repositories().Install(eng); err != nil { + return err + } + // FIXME: this hack is necessary for legacy integration tests to access + // the daemon object. + eng.Hack_SetGlobalVar("httpapi.daemon", daemon) return nil } diff --git a/daemonconfig/config.go b/daemonconfig/config.go index c46f1853ba..13c2a5db5c 100644 --- a/daemonconfig/config.go +++ b/daemonconfig/config.go @@ -2,7 +2,6 @@ package daemonconfig import ( "github.com/docker/docker/daemon/networkdriver" - "github.com/docker/docker/engine" "net" ) @@ -34,46 +33,6 @@ type Config struct { Sockets []string } -// ConfigFromJob creates and returns a new DaemonConfig object -// by parsing the contents of a job's environment. -func ConfigFromJob(job *engine.Job) *Config { - config := &Config{ - Pidfile: job.Getenv("Pidfile"), - Root: job.Getenv("Root"), - AutoRestart: job.GetenvBool("AutoRestart"), - EnableIptables: job.GetenvBool("EnableIptables"), - EnableIpForward: job.GetenvBool("EnableIpForward"), - BridgeIP: job.Getenv("BridgeIP"), - BridgeIface: job.Getenv("BridgeIface"), - DefaultIp: net.ParseIP(job.Getenv("DefaultIp")), - InterContainerCommunication: job.GetenvBool("InterContainerCommunication"), - GraphDriver: job.Getenv("GraphDriver"), - ExecDriver: job.Getenv("ExecDriver"), - EnableSelinuxSupport: job.GetenvBool("EnableSelinuxSupport"), - } - if graphOpts := job.GetenvList("GraphOptions"); graphOpts != nil { - config.GraphOptions = graphOpts - } - - if dns := job.GetenvList("Dns"); dns != nil { - config.Dns = dns - } - if dnsSearch := job.GetenvList("DnsSearch"); dnsSearch != nil { - config.DnsSearch = dnsSearch - } - if mtu := job.GetenvInt("Mtu"); mtu != 0 { - config.Mtu = mtu - } else { - config.Mtu = GetDefaultNetworkMtu() - } - config.DisableNetwork = config.BridgeIface == DisableNetworkBridge - if sockets := job.GetenvList("Sockets"); sockets != nil { - config.Sockets = sockets - } - - return config -} - func GetDefaultNetworkMtu() int { if iface, err := networkdriver.GetDefaultRouteIface(); err == nil { return iface.MTU diff --git a/docker/daemon.go b/docker/daemon.go index e886f99a1b..6a4d767733 100644 --- a/docker/daemon.go +++ b/docker/daemon.go @@ -7,8 +7,10 @@ import ( "net" "github.com/docker/docker/builtins" + "github.com/docker/docker/daemon" _ "github.com/docker/docker/daemon/execdriver/lxc" _ "github.com/docker/docker/daemon/execdriver/native" + "github.com/docker/docker/daemonconfig" "github.com/docker/docker/dockerversion" "github.com/docker/docker/engine" flag "github.com/docker/docker/pkg/mflag" @@ -46,27 +48,38 @@ func mainDaemon() { // the http api so that connections don't fail while the daemon // is booting go func() { - // Load plugin: httpapi - job := eng.Job("initserver") - // include the variable here too, for the server config - job.Setenv("Pidfile", *pidfile) - job.Setenv("Root", *flRoot) - job.SetenvBool("AutoRestart", *flAutoRestart) - job.SetenvList("Dns", flDns.GetAll()) - job.SetenvList("DnsSearch", flDnsSearch.GetAll()) - job.SetenvBool("EnableIptables", *flEnableIptables) - job.SetenvBool("EnableIpForward", *flEnableIpForward) - job.Setenv("BridgeIface", *bridgeName) - job.Setenv("BridgeIP", *bridgeIp) - job.Setenv("DefaultIp", *flDefaultIp) - job.SetenvBool("InterContainerCommunication", *flInterContainerComm) - job.Setenv("GraphDriver", *flGraphDriver) - job.SetenvList("GraphOptions", flGraphOpts.GetAll()) - job.Setenv("ExecDriver", *flExecDriver) - job.SetenvInt("Mtu", *flMtu) - job.SetenvBool("EnableSelinuxSupport", *flSelinuxEnabled) - job.SetenvList("Sockets", flHosts.GetAll()) - if err := job.Run(); err != nil { + // FIXME: daemonconfig and CLI flag parsing should be directly integrated + cfg := &daemonconfig.Config{ + Pidfile: *pidfile, + Root: *flRoot, + AutoRestart: *flAutoRestart, + EnableIptables: *flEnableIptables, + EnableIpForward: *flEnableIpForward, + BridgeIP: *bridgeIp, + BridgeIface: *bridgeName, + DefaultIp: net.ParseIP(*flDefaultIp), + InterContainerCommunication: *flInterContainerComm, + GraphDriver: *flGraphDriver, + ExecDriver: *flExecDriver, + EnableSelinuxSupport: *flSelinuxEnabled, + GraphOptions: flGraphOpts.GetAll(), + Dns: flDns.GetAll(), + DnsSearch: flDnsSearch.GetAll(), + Mtu: *flMtu, + Sockets: flHosts.GetAll(), + } + // FIXME this should be initialized in NewDaemon or somewhere in daemonconfig. + // Currently it is copy-pasted in `integration` to create test daemons that work. + if cfg.Mtu == 0 { + cfg.Mtu = daemonconfig.GetDefaultNetworkMtu() + } + cfg.DisableNetwork = cfg.BridgeIface == daemonconfig.DisableNetworkBridge + + d, err := daemon.NewDaemon(cfg, eng) + if err != nil { + log.Fatal(err) + } + if err := d.Install(eng); err != nil { log.Fatal(err) } // after the daemon is done setting up we can tell the api to start @@ -75,7 +88,6 @@ func mainDaemon() { log.Fatal(err) } }() - // TODO actually have a resolved graphdriver to show? log.Printf("docker daemon: %s %s; execdriver: %s; graphdriver: %s", dockerversion.VERSION, diff --git a/integration/runtime_test.go b/integration/runtime_test.go index 5148af01ba..52839253d1 100644 --- a/integration/runtime_test.go +++ b/integration/runtime_test.go @@ -202,7 +202,7 @@ func spawnHttpsDaemon(addr, cacert, cert, key string) *engine.Engine { if err != nil { t.Fatal(err) } - // FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false, + // FIXME: here we don't use NewTestEngine because it configures the daemon with Autorestart=false, // and we want to set it to true. eng := newTestEngine(t, true, root) diff --git a/integration/server_test.go b/integration/server_test.go index 241ca76bfe..363236fd68 100644 --- a/integration/server_test.go +++ b/integration/server_test.go @@ -100,7 +100,6 @@ func TestMergeConfigOnCommit(t *testing.T) { func TestRestartKillWait(t *testing.T) { eng := NewTestEngine(t) - srv := mkServerFromEngine(eng, t) runtime := mkDaemonFromEngine(eng, t) defer runtime.Nuke() @@ -138,9 +137,8 @@ func TestRestartKillWait(t *testing.T) { } eng = newTestEngine(t, false, runtime.Config().Root) - srv = mkServerFromEngine(eng, t) - job = srv.Eng.Job("containers") + job = eng.Job("containers") job.SetenvBool("all", true) outs, err = job.Stdout.AddListTable() if err != nil { @@ -155,7 +153,7 @@ func TestRestartKillWait(t *testing.T) { } setTimeout(t, "Waiting on stopped container timedout", 5*time.Second, func() { - job = srv.Eng.Job("wait", outs.Data[0].Get("Id")) + job = eng.Job("wait", outs.Data[0].Get("Id")) if err := job.Run(); err != nil { t.Fatal(err) } @@ -164,7 +162,6 @@ func TestRestartKillWait(t *testing.T) { func TestCreateStartRestartStopStartKillRm(t *testing.T) { eng := NewTestEngine(t) - srv := mkServerFromEngine(eng, t) defer mkDaemonFromEngine(eng, t).Nuke() config, hostConfig, _, err := runconfig.Parse([]string{"-i", unitTestImageID, "/bin/cat"}, nil) @@ -174,7 +171,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) { id := createTestContainer(eng, config, t) - job := srv.Eng.Job("containers") + job := eng.Job("containers") job.SetenvBool("all", true) outs, err := job.Stdout.AddListTable() if err != nil { @@ -227,7 +224,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) { t.Fatal(err) } - job = srv.Eng.Job("containers") + job = eng.Job("containers") job.SetenvBool("all", true) outs, err = job.Stdout.AddListTable() if err != nil { diff --git a/integration/utils_test.go b/integration/utils_test.go index e44bda85a5..29741465a8 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -17,9 +17,9 @@ import ( "github.com/docker/docker/builtins" "github.com/docker/docker/daemon" + "github.com/docker/docker/daemonconfig" "github.com/docker/docker/engine" "github.com/docker/docker/runconfig" - "github.com/docker/docker/server" "github.com/docker/docker/utils" ) @@ -153,18 +153,6 @@ func getContainer(eng *engine.Engine, id string, t utils.Fataler) *daemon.Contai return c } -func mkServerFromEngine(eng *engine.Engine, t utils.Fataler) *server.Server { - iSrv := eng.Hack_GetGlobalVar("httpapi.server") - if iSrv == nil { - panic("Legacy server field not set in engine") - } - srv, ok := iSrv.(*server.Server) - if !ok { - panic("Legacy server field in engine does not cast to *server.Server") - } - return srv -} - func mkDaemonFromEngine(eng *engine.Engine, t utils.Fataler) *daemon.Daemon { iDaemon := eng.Hack_GetGlobalVar("httpapi.daemon") if iDaemon == nil { @@ -191,13 +179,22 @@ func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engin // Load default plugins builtins.Register(eng) // (This is manually copied and modified from main() until we have a more generic plugin system) - job := eng.Job("initserver") - job.Setenv("Root", root) - job.SetenvBool("AutoRestart", autorestart) - job.Setenv("ExecDriver", "native") - // TestGetEnabledCors and TestOptionsRoute require EnableCors=true - job.SetenvBool("EnableCors", true) - if err := job.Run(); err != nil { + cfg := &daemonconfig.Config{ + Root: root, + AutoRestart: autorestart, + ExecDriver: "native", + } + // FIXME: this should be initialized in NewDaemon or somewhere in daemonconfig. + // Currently it is copy-pasted from daemonMain() + if cfg.Mtu == 0 { + cfg.Mtu = daemonconfig.GetDefaultNetworkMtu() + } + cfg.DisableNetwork = cfg.BridgeIface == daemonconfig.DisableNetworkBridge + d, err := daemon.NewDaemon(cfg, eng) + if err != nil { + t.Fatal(err) + } + if err := d.Install(eng); err != nil { t.Fatal(err) } return eng diff --git a/server/MAINTAINERS b/server/MAINTAINERS deleted file mode 100644 index c00f916523..0000000000 --- a/server/MAINTAINERS +++ /dev/null @@ -1,3 +0,0 @@ -Solomon Hykes (@shykes) -Victor Vieux (@vieux) -buildfile.go: Tibor Vass (@tiborvass) diff --git a/server/init.go b/server/init.go deleted file mode 100644 index 14320678b5..0000000000 --- a/server/init.go +++ /dev/null @@ -1,62 +0,0 @@ -// DEPRECATION NOTICE. PLEASE DO NOT ADD ANYTHING TO THIS FILE. -// -// For additional commments see server/server.go -// -package server - -import ( - "github.com/docker/docker/daemon" - "github.com/docker/docker/daemonconfig" - "github.com/docker/docker/engine" -) - -func (srv *Server) handlerWrap(h engine.Handler) engine.Handler { - return func(job *engine.Job) engine.Status { - srv.tasks.Add(1) - defer srv.tasks.Done() - return h(job) - } -} - -// jobInitApi runs the remote api server `srv` as a daemon, -// Only one api server can run at the same time - this is enforced by a pidfile. -// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup. -func InitServer(job *engine.Job) engine.Status { - job.Logf("Creating server") - cfg := daemonconfig.ConfigFromJob(job) - srv, err := NewServer(job.Eng, cfg) - if err != nil { - return job.Error(err) - } - job.Eng.Hack_SetGlobalVar("httpapi.server", srv) - job.Eng.Hack_SetGlobalVar("httpapi.daemon", srv.daemon) - - for name, handler := range map[string]engine.Handler{} { - if err := job.Eng.Register(name, srv.handlerWrap(handler)); err != nil { - return job.Error(err) - } - } - // Install image-related commands from the image subsystem. - // See `graph/service.go` - if err := srv.daemon.Repositories().Install(job.Eng); err != nil { - return job.Error(err) - } - // Install daemon-related commands from the daemon subsystem. - // See `daemon/` - if err := srv.daemon.Install(job.Eng); err != nil { - return job.Error(err) - } - return engine.StatusOK -} - -func NewServer(eng *engine.Engine, config *daemonconfig.Config) (*Server, error) { - daemon, err := daemon.NewDaemon(config, eng) - if err != nil { - return nil, err - } - srv := &Server{ - Eng: eng, - daemon: daemon, - } - return srv, nil -} diff --git a/server/server.go b/server/server.go deleted file mode 100644 index 1b77e5efe1..0000000000 --- a/server/server.go +++ /dev/null @@ -1,36 +0,0 @@ -// DEPRECATION NOTICE. PLEASE DO NOT ADD ANYTHING TO THIS FILE. -// -// server/server.go is deprecated. We are working on breaking it up into smaller, cleaner -// pieces which will be easier to find and test. This will help make the code less -// redundant and more readable. -// -// Contributors, please don't add anything to server/server.go, unless it has the explicit -// goal of helping the deprecation effort. -// -// Maintainers, please refuse patches which add code to server/server.go. -// -// Instead try the following files: -// * For code related to local image management, try graph/ -// * For code related to image downloading, uploading, remote search etc, try registry/ -// * For code related to the docker daemon, try daemon/ -// * For small utilities which could potentially be useful outside of Docker, try pkg/ -// * For miscalleneous "util" functions which are docker-specific, try encapsulating them -// inside one of the subsystems above. If you really think they should be more widely -// available, are you sure you can't remove the docker dependencies and move them to -// pkg? In last resort, you can add them to utils/ (but please try not to). - -package server - -import ( - "sync" - - "github.com/docker/docker/daemon" - "github.com/docker/docker/engine" -) - -type Server struct { - sync.RWMutex - daemon *daemon.Daemon - Eng *engine.Engine - tasks sync.WaitGroup -}