From 5a529d4c4a1f1f457a2505bdfe7fc1f2d41e836f Mon Sep 17 00:00:00 2001 From: Isabel Jimenez Date: Tue, 5 Jan 2016 13:16:57 -0500 Subject: [PATCH] Adding help for new flag offer_refuse_seconds and renaming Signed-off-by: Isabel Jimenez --- cli/help.go | 3 ++- cluster/mesos/cluster.go | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cli/help.go b/cli/help.go index 1493f585c8..bf71388471 100644 --- a/cli/help.go +++ b/cli/help.go @@ -48,7 +48,8 @@ Options: {{printf "\t * mesos.port=\tport to bind on [$SWARM_MESOS_PORT]"}} {{printf "\t * mesos.offertimeout=30s\ttimeout for offers [$SWARM_MESOS_OFFER_TIMEOUT]"}} {{printf "\t * mesos.tasktimeout=5s\ttimeout for task creation [$SWARM_MESOS_TASK_TIMEOUT]"}} - {{printf "\t * mesos.user=\tframework user [$SWARM_MESOS_USER]"}}{{end}}{{ end }} + {{printf "\t * mesos.user=\tframework user [$SWARM_MESOS_USER]"}} + {{printf "\t * mesos.offerrefusetimeout=5s\tseconds to consider unused resources refused [$SWARM_MESOS_OFFER_REFUSE_TIMEOUT]"}}{{end}}{{ end }} ` } diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index 09e04ae861..21bffc94e6 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -9,7 +9,6 @@ import ( "io" "os" "sort" - "strconv" "sync" "time" @@ -37,7 +36,7 @@ type Cluster struct { TLSConfig *tls.Config options *cluster.DriverOpts offerTimeout time.Duration - refuseSeconds *float64 + refuseTimeout time.Duration taskCreationTimeout time.Duration pendingTasks *queue.Queue engineOpts *cluster.EngineOpts @@ -49,6 +48,7 @@ const ( defaultDockerEngineTLSPort = "2376" dockerPortAttribute = "docker_port" defaultOfferTimeout = 30 * time.Second + defaultRefuseTimeout = 5 * time.Second defaultTaskCreationTimeout = 5 * time.Second ) @@ -75,6 +75,7 @@ func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, master st offerTimeout: defaultOfferTimeout, taskCreationTimeout: defaultTaskCreationTimeout, engineOpts: engineOptions, + refuseTimeout: defaultRefuseTimeout, } cluster.pendingTasks = queue.NewQueue() @@ -128,12 +129,12 @@ func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, master st cluster.offerTimeout = d } - if refuseSeconds, ok := options.String("mesos.offer_refuse_seconds", "SWARM_MESOS_OFFER_REFUSE_SECONDS"); ok { - d, err := strconv.ParseFloat(refuseSeconds, 64); + if refuseTimeout, ok := options.String("mesos.offerrefusetimeout", "SWARM_MESOS_OFFER_REFUSE_TIMEOUT"); ok { + d, err := time.ParseDuration(refuseTimeout) if err != nil { return nil, err } - cluster.refuseSeconds = &d; + cluster.refuseTimeout = d } driver, err := mesosscheduler.NewMesosSchedulerDriver(driverConfig) @@ -480,11 +481,9 @@ func (c *Cluster) scheduleTask(t *task) bool { t.build(n.ID, c.agents[n.ID].offers) - // Set Mesos refuse seconds by environment variables. - offerFilters := &mesosproto.Filters{}; - if c.refuseSeconds != nil { - offerFilters.RefuseSeconds = c.refuseSeconds; - } + offerFilters := &mesosproto.Filters{} + refuseSeconds := c.refuseTimeout.Seconds() + offerFilters.RefuseSeconds = &refuseSeconds if _, err := c.driver.LaunchTasks(offerIDs, []*mesosproto.TaskInfo{&t.TaskInfo}, offerFilters); err != nil { // TODO: Do not erase all the offers, only the one used