Skip to content

Commit e8abbe3

Browse files
author
smothiki
committed
feat(mesos): change docker cmd format and make ExecstartPre statements onle liners
fix(style): fix go vet erorrs for mesos
1 parent 57e9be7 commit e8abbe3

32 files changed

Lines changed: 181 additions & 76 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ publisher/Godeps/
4444
publisher/image/bin/publisher
4545
router/Godeps/
4646
swarm/image/bin/
47+
mesos/**/bin/
48+
mesos/**/bindata/
49+
mesos/Dockerfile
50+
mesos/marathon-assembly.jar
4751

4852
# coverage reports
4953
.coverage

controller/scheduler/mesos_marathon.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import re
22
import time
3+
34
from django.conf import settings
45
from marathon import MarathonClient
56
from marathon.models import MarathonApp
6-
from .states import JobState
77
from docker import Client
8+
9+
from .states import JobState
810
from .fleet import FleetHTTPClient
911

1012
# turn down standard marathon logging
1113

1214
MATCH = re.compile(
1315
'(?P<app>[a-z0-9-]+)_?(?P<version>v[0-9]+)?\.?(?P<c_type>[a-z-_]+)?.(?P<c_num>[0-9]+)')
1416
RETRIES = 3
17+
POLL_ATTEMPTS = 30
18+
POLL_WAIT = 100
1519

1620

1721
class MarathonHTTPClient(object):
@@ -47,24 +51,23 @@ def create(self, name, image, command='', **kwargs):
4751
cpu = kwargs.get('cpu', {}).get(l['c_type'])
4852
if cpu:
4953
c = cpu
50-
cpu = kwargs.get('cpu', {}).get(l['c_type'])
51-
self.client.create_app(app_id,
52-
MarathonApp(cmd="docker run --name "+name+" -P "+image+" "+command,
53-
mem=m, cpus=c))
54+
cmd = "docker run --name {name} -P {image} {command}".format(**locals())
55+
self.client.create_app(app_id, MarathonApp(cmd=cmd, mem=m, cpus=c))
5456
self.client.scale_app(app_id, 0, force=True)
55-
for _ in xrange(30):
57+
for _ in xrange(POLL_ATTEMPTS):
5658
if self.client.get_app(self._app_id(name)).tasks_running == 0:
5759
return
5860
time.sleep(1)
5961

6062
def start(self, name):
6163
"""Start a container"""
6264
self.client.scale_app(self._app_id(name), 1, force=True)
63-
for _ in xrange(30):
65+
for _ in xrange(POLL_ATTEMPTS):
6466
if self.client.get_app(self._app_id(name)).tasks_running == 1:
65-
return
67+
break
6668
time.sleep(1)
67-
raise RuntimeError("App Not Started")
69+
host = self.client.get_app(self._app_id(name)).tasks[0].host
70+
self._waitforcontainer(host, name)
6871

6972
def stop(self, name):
7073
"""Stop a container"""
@@ -79,21 +82,33 @@ def destroy(self, name):
7982
except:
8083
self.client.delete_app(self._app_id(name), force=True)
8184

82-
def _delete_container(self, host, name):
85+
def _get_container_state(self, host, name):
8386
docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version='1.17')
8487
try:
85-
if docker_cli.inspect_container(name)['State']:
86-
docker_cli.remove_container(name, force=True)
88+
if docker_cli.inspect_container(name)['State']['Running']:
89+
return JobState.up
8790
except:
88-
pass
91+
return JobState.destroyed
92+
93+
def _waitforcontainer(self, host, name):
94+
for _ in xrange(POLL_WAIT):
95+
if self._get_container_state(host, name) == JobState.up:
96+
return
97+
time.sleep(1)
98+
raise RuntimeError("App container Not Started")
99+
100+
def _delete_container(self, host, name):
101+
docker_cli = Client("tcp://{}:2375".format(host), timeout=1200, version='1.17')
102+
if docker_cli.inspect_container(name)['State']:
103+
docker_cli.remove_container(name, force=True)
89104

90105
def run(self, name, image, entrypoint, command): # noqa
91106
"""Run a one-off command"""
92107
return self.fleet.run(name, image, entrypoint, command)
93108

94109
def state(self, name):
95110
try:
96-
for _ in xrange(30):
111+
for _ in xrange(POLL_ATTEMPTS):
97112
if self.client.get_app(self._app_id(name)).tasks_running == 1:
98113
return JobState.up
99114
elif self.client.get_app(self._app_id(name)).tasks_running == 0:

deisctl/cmd/mesos.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func InstallMesos(b backend.Backend) error {
3434
func installMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
3535

3636
outchan <- fmt.Sprintf("Zookeeper...")
37-
b.Create([]string{"mesos-zk"}, wg, outchan, errchan)
37+
b.Create([]string{"zookeeper"}, wg, outchan, errchan)
3838
wg.Wait()
3939

4040
outchan <- fmt.Sprintf("Mesos Master...")
@@ -85,7 +85,7 @@ func uninstallMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan
8585
wg.Wait()
8686

8787
outchan <- fmt.Sprintf("Zookeeper...")
88-
b.Destroy([]string{"mesos-zk"}, wg, outchan, errchan)
88+
b.Destroy([]string{"zookeeper"}, wg, outchan, errchan)
8989
wg.Wait()
9090

9191
return nil
@@ -116,7 +116,7 @@ func StartMesos(b backend.Backend) error {
116116
func startMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
117117

118118
outchan <- fmt.Sprintf("Zookeeper...")
119-
b.Start([]string{"mesos-zk"}, wg, outchan, errchan)
119+
b.Start([]string{"zookeeper"}, wg, outchan, errchan)
120120
wg.Wait()
121121

122122
outchan <- fmt.Sprintf("Mesos Master...")
@@ -169,6 +169,6 @@ func stopMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan strin
169169
wg.Wait()
170170

171171
outchan <- fmt.Sprintf("Zookeeper...")
172-
b.Stop([]string{"mesos-zk"}, wg, outchan, errchan)
172+
b.Stop([]string{"zookeeper"}, wg, outchan, errchan)
173173
wg.Wait()
174174
}

deisctl/units/deis-mesos-marathon.service

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ ExecStartPre=/bin/sh -c "etcdctl set /deis/scheduler/mesos/marathon $COREOS_PRIV
1313
ExecStartPre=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-marathon` && docker history $IMAGE >/dev/null 2>&1 || docker pull $IMAGE"
1414
ExecStartPre=-/usr/bin/docker kill deis-mesos-marathon
1515
ExecStartPre=-/usr/bin/docker rm deis-mesos-marathon
16-
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-marathon` && docker run \
17-
--name=coreos-mesos-marathon \
18-
--net=host \
19-
-e HOST=$COREOS_PRIVATE_IPV4 \
20-
$IMAGE"
16+
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-marathon` && docker run --name=deis-mesos-marathon --net=host -e HOST=$COREOS_PRIVATE_IPV4 $IMAGE"
2117
ExecStop=-/usr/bin/docker stop deis-mesos-marathon
2218

2319
[Install]

deisctl/units/deis-mesos-master.service

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ ExecStartPre=-/usr/bin/docker kill deis-mesos-master
1212
ExecStartPre=-/usr/bin/docker rm deis-mesos-master
1313
ExecStartPre=/bin/sh -c "docker inspect deis-mesos-master-data >/dev/null 2>&1 || docker run --name deis-mesos-master-data -v /tmp/mesos-master alpine:3.1 /bin/true"
1414
ExecStartPre=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-master` && docker history $IMAGE >/dev/null 2>&1 || docker pull $IMAGE"
15-
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-master` && docker run \
16-
--volumes-from=deis-mesos-master-data \
17-
--name=deis-mesos-master \
18-
--privileged \
19-
--net=host \
20-
-e HOST=$COREOS_PRIVATE_IPV4 \
21-
$IMAGE"
15+
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-master` && docker run --volumes-from=deis-mesos-master-data --name=deis-mesos-master --privileged --net=host -e HOST=$COREOS_PRIVATE_IPV4 $IMAGE"
2216
ExecStop=-/usr/bin/docker stop deis-mesos-master
2317

2418
[Install]

deisctl/units/deis-mesos-slave.service

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@ TimeoutStartSec=0
1111
ExecStartPre=-/usr/bin/docker kill deis-mesos-slave
1212
ExecStartPre=-/usr/bin/docker rm deis-mesos-slave
1313
ExecStartPre=/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-slave` && docker history $IMAGE >/dev/null 2>&1 || docker pull $IMAGE"
14-
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-slave` && docker run \
15-
--name=deis-mesos-slave \
16-
--net=host \
17-
--privileged \
18-
-e HOST=$COREOS_PRIVATE_IPV4 \
19-
-v /sys:/sys \
20-
-v /usr/bin/docker:/usr/bin/docker:ro \
21-
-v /var/run/docker.sock:/var/run/docker.sock \
22-
-v /lib64/libdevmapper.so.1.02:/lib/libdevmapper.so.1.02:ro \
23-
$IMAGE"
24-
ExecStop=/usr/bin/docker stop coreos-mesos-slave
14+
ExecStart=/usr/bin/sh -c "IMAGE=`/run/deis/bin/get_image /deis/mesos-slave` && docker run --name=deis-mesos-slave --net=host --privileged -e HOST=$COREOS_PRIVATE_IPV4 -v /sys:/sys -v /usr/bin/docker:/usr/bin/docker:ro -v /var/run/docker.sock:/var/run/docker.sock -v /lib64/libdevmapper.so.1.02:/lib/libdevmapper.so.1.02:ro $IMAGE"
15+
ExecStop=/usr/bin/docker stop deis-mesos-slave
2516

2617
[Install]
2718
WantedBy=multi-user.target

docs/customizing_deis/choosing-a-scheduler.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ to `enable the remote API`_.
103103
**Known Issues**
104104

105105
- It is not yet possible to change the default affinity filter.
106-
- If swarm can't create all the containers requested during scale, deis rolls back the scale operation.
107106

108107
To test the Swarm Scheduler backend, first install and start the swarm components:
109108

mesos/Makefile

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include ../includes.mk
2+
13
REPO = deis
24
MESOS = 0.22.1-1.0.ubuntu1404
35
MESOS_VERSION = v1.9.0
@@ -13,56 +15,108 @@ GOLINT = golint
1315
GOTEST = $(GO) test -cover -race -v
1416
GOVET = $(GO) vet
1517

16-
GO_PACKAGES = pkg/boot pkg/confd pkg/etcd pkg/fleet pkg/log pkg/net
18+
COMPONENT = $(notdir $(repo_path))
19+
GO_PACKAGES = pkg/boot pkg/confd pkg/etcd pkg/fleet pkg/log pkg/net pkg/os pkg/types
1720
GO_PACKAGES_REPO_PATH = $(addprefix $(repo_path)/,$(GO_PACKAGES))
1821

19-
build: test-style zookeeper-go build-tools mesos-template mesos-master mesos-slave mesos-marathon zookeeper
22+
MASTER_IMAGE = $(IMAGE_PREFIX)mesos-master:$(BUILD_TAG)
23+
MASTER_DEV_IMAGE = $(REGISTRY)$(MASTER_IMAGE)
24+
MARATHON_IMAGE = $(IMAGE_PREFIX)mesos-marathon:$(BUILD_TAG)
25+
MARATHON_DEV_IMAGE = $(REGISTRY)$(MARATHON_IMAGE)
26+
SLAVE_IMAGE = $(IMAGE_PREFIX)mesos-slave:$(BUILD_TAG)
27+
SLAVE_DEV_IMAGE = $(REGISTRY)$(SLAVE_IMAGE)
28+
ZOOKEEPER_IMAGE = $(IMAGE_PREFIX)zookeeper:$(BUILD_TAG)
29+
ZOOKEEPER_DEV_IMAGE = $(REGISTRY)$(ZOOKEEPER_IMAGE)
30+
31+
build: test-style zookeeper-go mesos-template mesos-master mesos-slave mesos-marathon zookeeper
32+
33+
install: check-deisctl
34+
deisctl install $(COMPONENT)
35+
36+
uninstall: check-deisctl
37+
deisctl uninstall $(COMPONENT)
38+
39+
start: check-deisctl
40+
deisctl start $(COMPONENT)
41+
42+
stop: check-deisctl
43+
deisctl stop $(COMPONENT)
44+
45+
restart: stop start
46+
47+
run: install start
2048

21-
mesos-go:
49+
dev-release: push set-image
50+
51+
push: check-registry
52+
docker tag -f $(MASTER_IMAGE) $(MASTER_DEV_IMAGE)
53+
docker push $(MASTER_DEV_IMAGE)
54+
docker tag -f $(SLAVE_IMAGE) $(SLAVE_DEV_IMAGE)
55+
docker push $(SLAVE_DEV_IMAGE)
56+
docker tag -f $(MARATHON_IMAGE) $(MARATHON_DEV_IMAGE)
57+
docker push $(MARATHON_DEV_IMAGE)
58+
docker tag -f $(ZOOKEEPER_IMAGE) $(ZOOKEEPER_DEV_IMAGE)
59+
docker push $(ZOOKEEPER_DEV_IMAGE)
60+
61+
set-image: check-deisctl
62+
deisctl config mesos-master set image=$(MASTER_DEV_IMAGE)
63+
deisctl config mesos-slave set image=$(SLAVE_DEV_IMAGE)
64+
deisctl config mesos-marathon set image=$(MARATHON_DEV_IMAGE)
65+
deisctl config zookeeper set image=$(ZOOKEEPER_DEV_IMAGE)
66+
67+
release:
68+
docker push $(MASTER_IMAGE)
69+
docker push $(SLAVE_IMAGE)
70+
docker push $(MARATHON_IMAGE)
71+
docker push $(ZOOKEEPER_IMAGE)
72+
73+
deploy: build dev-release restart
74+
75+
setup-gotools:
76+
go get -u github.com/jteeuwen/go-bindata/...
77+
78+
mesos-go: setup-gotools
2279
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o bin/master-boot pkg/boot/mesos/master/main.go
2380
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o bin/slave-boot pkg/boot/mesos/slave/main.go
24-
go-bindata -pkg bindata -o pkg/boot/mesos/marathon/bindata/bindata.go pkg/boot/mesos/marathon/bash/; \
81+
go-bindata -pkg bindata -o bindata/marathon/bindata.go pkg/boot/mesos/marathon/bash/; \
2582
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o bin/marathon-boot pkg/boot/mesos/marathon/main.go
2683

2784
mesos-template:
2885
sed "s/#VERSION#/$(MESOS)/g" template > Dockerfile
29-
docker build -t $(REPO)/$@:$(MESOS_VERSION) .
86+
docker build -t $(IMAGE_PREFIX)$@:$(MESOS_VERSION) .
3087
rm -f Dockerfile
3188

3289
mesos-master: mesos-go mesos-template
3390
sed "s/#VERSION#/$(MESOS_VERSION)/g" master > Dockerfile
34-
docker build -t $(REPO)/$@:$(MESOS_VERSION) .
91+
docker build -t $(IMAGE_PREFIX)$@:$(BUILD_TAG) .
3592
rm -f Dockerfile
3693

3794
mesos-slave: mesos-go mesos-template
3895
sed "s/#VERSION#/$(MESOS_VERSION)/g" slave > Dockerfile
39-
docker build -t $(REPO)/$@:$(MESOS_VERSION) .
96+
docker build -t $(IMAGE_PREFIX)$@:$(BUILD_TAG) .
4097
rm -f Dockerfile
4198

4299
build-mesos-marathon: mesos-template
43100
sed "s/#MARATHON_VERSION#/$(MARATHON_VERSION)/;s/#VERSION#/$(MESOS_VERSION)/" build-marathon > Dockerfile
44-
docker build -t $(REPO)/$@:$(MESOS_VERSION) .
101+
docker build -t $(IMAGE_PREFIX)$@:$(BUILD_TAG) .
45102
rm -f Dockerfile
46103

47-
mesos-marathon: build-mesos-marathon mesos-go
104+
mesos-marathon: mesos-go build-mesos-marathon
48105
cp marathon Dockerfile
49-
docker cp `docker create $(REPO)/build-mesos-marathon:$(MESOS_VERSION) /bin/bash`:/marathon/target/marathon-assembly-$(MARATHON_VERSION).jar .
106+
docker cp `docker create $(IMAGE_PREFIX)build-mesos-marathon:$(BUILD_TAG) /bin/bash`:/marathon/target/marathon-assembly-$(MARATHON_VERSION).jar .
50107
mv marathon-assembly-$(MARATHON_VERSION).jar marathon-assembly.jar
51108
sed "s/#MARATHON_VERSION#/$(MARATHON_VERSION)/;s/#VERSION#/$(MESOS_VERSION)/" marathon > Dockerfile
52-
docker build -t $(REPO)/$@:$(MESOS_VERSION) .
109+
docker build -t $(IMAGE_PREFIX)$@:$(BUILD_TAG) .
53110
rm -f Dockerfile
54111

55112
zookeeper: zookeeper-go
56-
docker build -t $(REPO)/$@:$(ZOOKEEPER_VERSION) zookeeper/.
113+
docker build -t $(IMAGE_PREFIX)$@:$(BUILD_TAG) zookeeper/.
57114

58115
zookeeper-go:
59116
echo "Building..."
60-
go-bindata -pkg bindata -o pkg/boot/zookeeper/bindata/bindata.go pkg/boot/zookeeper/bash/; \
117+
go-bindata -pkg bindata -o bindata/zookeeper/bindata.go pkg/boot/zookeeper/bash/; \
61118
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -ldflags '-s' -o zookeeper/bin/boot pkg/boot/zookeeper/main/boot.go
62119

63-
build-tools:
64-
echo "Building tools..."
65-
66120
test: mesos-go zookeeper-go
67121
@$(GOFMT) -timeout 10s $(GO_PACKAGES)
68122

mesos/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Mesos with Marathon Framework
2+
3+
[Marathon Framework](https://github.com/mesosphere/marathon) components for use as
4+
an optional scheduler in Deis, the open source PaaS.
5+
6+
## Usage
7+
8+
Please consult the [Mesos with Marathon framework](http://docs.deis.io/en/latest/customizing_deis/choosing-a-scheduler/#mesos-with-marathon-framework)
9+
for instructions on installing and activating Mesos with Marathon Framework in Deis.
10+
11+
## License
12+
13+
© 2015 Engine Yard, Inc.
14+
15+
Licensed under the Apache License, Version 2.0 (the "License"); you may
16+
not use this file except in compliance with the License. You may obtain
17+
a copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>
18+
19+
Unless required by applicable law or agreed to in writing, software
20+
distributed under the License is distributed on an "AS IS" BASIS,
21+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
See the License for the specific language governing permissions and
23+
limitations under the License.

0 commit comments

Comments
 (0)