Skip to content

Commit 8eb6956

Browse files
committed
ADD: mesos attribute support.
1 parent e28ab67 commit 8eb6956

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ services:
166166
port:
167167
deploy:
168168
runtime: "runcvm"
169+
attributes:
170+
- "gpus: True"
171+
- "airflow: True"
169172
placement:
170173
constraints:
171174
- "node.hostname==localhost"

api/compose.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,33 @@ func (e *API) mapComposeServiceToMesosTask(vars map[string]string, name string,
6666
cmd.Uris = e.getURIs()
6767
cmd.Arguments = e.getArguments()
6868

69-
7069
// set healthcheck if it's configured
7170
e.setHealthCheck(cmd)
7271

7372
// set the docker constraints
7473
e.setConstraints(cmd)
7574

75+
// set mesos attributes
76+
e.setAttributes(cmd)
77+
7678
// store/update the mesos task in db
7779
e.Redis.SaveTaskRedis(cmd)
7880
}
7981

82+
// set mesos attributes
83+
func (e *API) setAttributes(cmd *cfg.Command) {
84+
if len(e.Service.Deploy.Placement.Attributes) > 0 {
85+
for _, attribute := range e.Service.Deploy.Placement.Attributes {
86+
if strings.Contains(attribute, ":") {
87+
attr := strings.Split(attribute, ":")
88+
if len(attr) >= 2 {
89+
cmd.Attributes = append(cmd.Attributes, &mesosproto.Label{Key: util.StringToPointer(attr[0]), Value: &attr[1]})
90+
}
91+
}
92+
}
93+
}
94+
}
95+
8096
// Set the Runtime (https://github.com/newsnowlabs/runcvm)
8197
func (e *API) getRuntime(cmd *cfg.Command) []*mesosproto.Parameter {
8298
param := cmd.DockerParameter

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- ADD: Support for AMD and NVIDIA GPUs.
1111
- ADD: Mesos Framework GPU Capabilities to get GPU offers from mesos.
1212
- ADD: Runtime support for docker container (https://github.com/newsnowlabs/runcvm)
13+
- ADD: Support for Mesos attributes
1314

1415
## v1.1.3
1516

docs/example/mesos-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ services:
7474
deploy:
7575
runtime: "runcvm"
7676
placement:
77+
attributes:
78+
- "gpus: True"
79+
- "airflow: True"
7780
constraints:
7881
- "node.hostname==localhost"
7982
- "node.platform.os==linux"

docs/src/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ services:
8888
deploy:
8989
runtime: "runcvm"
9090
placement:
91+
attributes:
92+
- "gpus: True"
93+
- "airflow: True"
9194
constraints:
9295
- "node.hostname==localhost"
9396
- "node.platform.os==linux"

scheduler/handle_offers.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ func (e *Scheduler) getOffer(offers *mesosproto.Event_Offers, cmd *cfg.Command)
138138
continue
139139
}
140140

141-
// if the ressources of this offer does not matched what the command need, the skip
141+
// if the attributes of this offer does not matched what the command need, then skip
142+
if !e.matchAttributes(cmd, offer) {
143+
logrus.WithField("func", "scheduler.getOffer").Debug("Could not found any matched attributes, get next offer")
144+
continue
145+
}
146+
147+
// if the ressources of this offer does not matched what the command need, then skip
142148
if !e.Mesos.IsRessourceMatched(offer.Resources, cmd) {
143149
logrus.WithField("func", "scheduler.getOffer").Debug("Could not found any matched ressources, get next offer")
144150
continue
@@ -155,6 +161,22 @@ func (e *Scheduler) getOffer(offers *mesosproto.Event_Offers, cmd *cfg.Command)
155161
return offerret, offerIds
156162
}
157163

164+
// search matched mesos attributes. if cmd does not has any attributes,
165+
// then the result would be true.
166+
func (e *Scheduler) matchAttributes(cmd *cfg.Command, offer *mesosproto.Offer) bool {
167+
if len(cmd.Attributes) <= 0 {
168+
return true
169+
}
170+
171+
ret := false;
172+
for _, attribute := range cmd.Attributes {
173+
if strings.EqualFold("true", e.getAttributes(*attribute.Key, offer)) {
174+
ret = ret && true
175+
}
176+
}
177+
return ret
178+
}
179+
158180
// search matched mesos attributes
159181
func (e *Scheduler) getAttributes(name string, offer *mesosproto.Offer) string {
160182
for _, attribute := range offer.Attributes {

types/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type Deploy struct {
133133

134134
// Placement - The docker-compose placement
135135
type Placement struct {
136+
Attributes []string `yaml:"attributes"`
136137
Constraints []string `yaml:"constraints"`
137138
}
138139

@@ -222,6 +223,7 @@ type Command struct {
222223
EnableHealthCheck bool
223224
Health *mesosproto.HealthCheck
224225
MesosAgent MesosSlaves
226+
Attributes []*mesosproto.Label
225227
}
226228

227229
// State will have the state of all tasks stated by this framework

0 commit comments

Comments
 (0)