1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #3175 from vieux/engine-job-stop

Move stop to job
This commit is contained in:
Guillaume J. Charmes 2013-12-13 14:15:58 -08:00
commit aaa1c48d24
5 changed files with 32 additions and 20 deletions

11
api.go
View file

@ -678,17 +678,12 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *
if err := parseForm(r); err != nil {
return err
}
t, err := strconv.Atoi(r.Form.Get("t"))
if err != nil || t < 0 {
t = 10
}
if vars == nil {
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
if err := srv.ContainerStop(name, t); err != nil {
job := srv.Eng.Job("stop", vars["name"])
job.Setenv("t", r.Form.Get("t"))
if err := job.Run(); err != nil {
return err
}
w.WriteHeader(http.StatusNoContent)

View file

@ -24,7 +24,7 @@ type Job struct {
Eng *Engine
Name string
Args []string
env *Env
env *Env
Stdout *Output
Stderr *Output
Stdin *Input

View file

@ -168,7 +168,7 @@ func Tail(src io.Reader, n int, dst *[]string) {
// AddEnv starts a new goroutine which will decode all subsequent data
// as a stream of json-encoded objects, and point `dst` to the last
// decoded object.
// The result `env` can be queried using the type-neutral Env interface.
// The result `env` can be queried using the type-neutral Env interface.
// It is not safe to query `env` until the Output is closed.
func (o *Output) AddEnv() (dst *Env, err error) {
src, err := o.AddPipe()
@ -185,9 +185,8 @@ func (o *Output) AddEnv() (dst *Env, err error) {
if err != nil {
return
}
*dst= *env
*dst = *env
}
}()
return dst, nil
}

View file

@ -129,8 +129,9 @@ func TestCreateRmVolumes(t *testing.T) {
t.Fatal(err)
}
err = srv.ContainerStop(id, 1)
if err != nil {
job = eng.Job("stop", id)
job.SetenvInt("t", 1)
if err := job.Run(); err != nil {
t.Fatal(err)
}
@ -188,7 +189,9 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
t.Fatal(err)
}
if err := srv.ContainerStop(id, 15); err != nil {
job = eng.Job("stop", id)
job.SetenvInt("t", 15)
if err := job.Run(); err != nil {
t.Fatal(err)
}

View file

@ -79,6 +79,10 @@ func jobInitApi(job *engine.Job) engine.Status {
job.Error(err)
return engine.StatusErr
}
if err := job.Eng.Register("stop", srv.ContainerStop); err != nil {
job.Error(err)
return engine.StatusErr
}
if err := job.Eng.Register("start", srv.ContainerStart); err != nil {
job.Error(err)
return engine.StatusErr
@ -1727,16 +1731,27 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
return engine.StatusOK
}
func (srv *Server) ContainerStop(name string, t int) error {
func (srv *Server) ContainerStop(job *engine.Job) engine.Status {
if len(job.Args) != 1 {
job.Errorf("Usage: %s CONTAINER\n", job.Name)
return engine.StatusErr
}
name := job.Args[0]
t := job.GetenvInt("t")
if t == -1 {
t = 10
}
if container := srv.runtime.Get(name); container != nil {
if err := container.Stop(t); err != nil {
return fmt.Errorf("Cannot stop container %s: %s", name, err)
if err := container.Stop(int(t)); err != nil {
job.Errorf("Cannot stop container %s: %s\n", name, err)
return engine.StatusErr
}
srv.LogEvent("stop", container.ID, srv.runtime.repositories.ImageName(container.Image))
} else {
return fmt.Errorf("No such container: %s", name)
job.Errorf("No such container: %s\n", name)
return engine.StatusErr
}
return nil
return engine.StatusOK
}
func (srv *Server) ContainerWait(job *engine.Job) engine.Status {