From d571b7e39eb6167b938a7704289b4c3b88c378af Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 2 Sep 2015 20:33:25 -0700 Subject: [PATCH] Revert "prevent double starts with mesos" This reverts commit 9a93dcf46bf2a223248c735f2e5bf06b0b87852a. Signed-off-by: Victor Vieux --- api/handlers.go | 19 +--------------- api/primary.go | 4 ++-- cluster/cluster.go | 3 --- cluster/engine.go | 5 ----- cluster/mesos/cluster.go | 17 -------------- cluster/swarm/cluster.go | 12 ---------- test/integration/mesos/api/events.bats | 2 +- test/integration/mesos/api/log.bats | 31 -------------------------- 8 files changed, 4 insertions(+), 89 deletions(-) delete mode 100644 test/integration/mesos/api/log.bats diff --git a/api/handlers.go b/api/handlers.go index bbb5e057f3..7fc93b9c42 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -717,25 +717,8 @@ func postBuild(c *context, w http.ResponseWriter, r *http.Request) { } } -// POST /containers/{name:.*}/start -func postContainersStart(c *context, w http.ResponseWriter, r *http.Request) { - _, container, err := getContainerFromVars(c, mux.Vars(r)) - if err != nil { - httpError(w, err.Error(), http.StatusNotFound) - return - } - - if err = c.cluster.StartContainer(container); err != nil { - if strings.HasPrefix(err.Error(), "Conflict") { - httpError(w, err.Error(), http.StatusConflict) - } else { - httpError(w, err.Error(), http.StatusInternalServerError) - } - } -} - // POST /containers/{name:.*}/rename -func postContainersRename(c *context, w http.ResponseWriter, r *http.Request) { +func postRenameContainer(c *context, w http.ResponseWriter, r *http.Request) { _, container, err := getContainerFromVars(c, mux.Vars(r)) if err != nil { httpError(w, err.Error(), http.StatusNotFound) diff --git a/api/primary.go b/api/primary.go index d46c62ba74..60283e9bba 100644 --- a/api/primary.go +++ b/api/primary.go @@ -60,9 +60,9 @@ var routes = map[string]map[string]handler{ "/containers/{name:.*}/kill": proxyContainerAndForceRefresh, "/containers/{name:.*}/pause": proxyContainerAndForceRefresh, "/containers/{name:.*}/unpause": proxyContainerAndForceRefresh, - "/containers/{name:.*}/rename": postContainersRename, + "/containers/{name:.*}/rename": postRenameContainer, "/containers/{name:.*}/restart": proxyContainerAndForceRefresh, - "/containers/{name:.*}/start": postContainersStart, + "/containers/{name:.*}/start": proxyContainerAndForceRefresh, "/containers/{name:.*}/stop": proxyContainerAndForceRefresh, "/containers/{name:.*}/wait": proxyContainerAndForceRefresh, "/containers/{name:.*}/resize": proxyContainer, diff --git a/cluster/cluster.go b/cluster/cluster.go index 7a4e1ffa9f..e6c74eaa8f 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -31,9 +31,6 @@ type Cluster interface { // cluster.Containers().Get(IDOrName) Container(IDOrName string) *Container - // Start a container - StartContainer(container *Container) error - // Pull images // `callback` can be called multiple time // `where` is where it is being pulled diff --git a/cluster/engine.go b/cluster/engine.go index 1b2a857cfd..5b6d175166 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -433,11 +433,6 @@ func (e *Engine) Create(config *ContainerConfig, name string, pullImage bool) (* return container, err } -// StartContainer a container from the engine. -func (e *Engine) StartContainer(container *Container, config *dockerclient.HostConfig) error { - return e.client.StartContainer(container.Id, config) -} - // RemoveContainer a container from the engine. func (e *Engine) RemoveContainer(container *Container, force bool) error { if err := e.client.RemoveContainer(container.Id, force, true); err != nil { diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index 90df777c0f..35ac783bfe 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -284,23 +284,6 @@ func (c *Cluster) Import(source string, repository string, tag string, imageRead } -// StartContainer start a container -func (c *Cluster) StartContainer(container *cluster.Container) error { - c.RLock() - defer c.RUnlock() - - if container, _ := container.Refresh(); container != nil { - // As mesos garbage collect containers, we only allow starting on a "Created" containers - if container.Info.State.Running == false && container.Info.State.FinishedAt.IsZero() { - if err := container.Engine.StartContainer(container, nil); err != nil { - _, err = container.Refresh() - return err - } - } - } - return nil -} - // RenameContainer Rename a container func (c *Cluster) RenameContainer(container *cluster.Container, newName string) error { //FIXME this doesn't work as the next refreshcontainer will erase this change (this change is in-memory only) diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index 8463761407..45c38182ab 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -552,18 +552,6 @@ func (c *Cluster) RANDOMENGINE() (*cluster.Engine, error) { return nil, nil } -// StartContainer start a container -func (c *Cluster) StartContainer(container *cluster.Container) error { - c.RLock() - defer c.RUnlock() - - if err := container.Engine.StartContainer(container, nil); err != nil { - return err - } - _, err := container.Refresh() - return err -} - // RenameContainer rename a container func (c *Cluster) RenameContainer(container *cluster.Container, newName string) error { c.RLock() diff --git a/test/integration/mesos/api/events.bats b/test/integration/mesos/api/events.bats index 625bf1bebe..59a6b68ff6 100644 --- a/test/integration/mesos/api/events.bats +++ b/test/integration/mesos/api/events.bats @@ -19,7 +19,7 @@ function teardown() { local events_pid="$!" # This should emit 3 events: create, start, die. - docker_swarm run -d -m 20m --name test_container -e constraint:node==node-0 busybox true + docker_swarm run -m 20m --name test_container -e constraint:node==node-0 busybox true # events might take a little big to show up, wait until we get the last one. retry 5 0.5 grep -q "die" "$log_file" diff --git a/test/integration/mesos/api/log.bats b/test/integration/mesos/api/log.bats deleted file mode 100644 index 6363bffb8b..0000000000 --- a/test/integration/mesos/api/log.bats +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bats - -load ../mesos_helpers - -function teardown() { - swarm_manage_cleanup - stop_mesos - stop_docker -} - -@test "mesos - docker logs" { - start_docker_with_busybox 2 - start_mesos - swarm_manage --cluster-driver mesos-experimental 127.0.0.1:$MESOS_MASTER_PORT - - # run a container with echo command - docker_swarm run -d -m 20m --name test_container busybox /bin/sh -c "echo hello world; echo hello docker; echo hello swarm" - - # make sure container exists - run docker_swarm ps -l - [ "${#lines[@]}" -eq 2 ] - [[ "${lines[1]}" == *"test_container"* ]] - - # verify - run docker_swarm logs test_container - [ "$status" -eq 0 ] - [ "${#lines[@]}" -eq 3 ] - [[ "${lines[0]}" == *"hello world"* ]] - [[ "${lines[1]}" == *"hello docker"* ]] - [[ "${lines[2]}" == *"hello swarm"* ]] -}