-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #930 from bbklab/fix-launch-tasks
fix the mess of launch tasks logic
- Loading branch information
Showing
6 changed files
with
276 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
package mesos | ||
|
||
import ( | ||
//"github.com/Dataman-Cloud/swan/mesos/filter" | ||
"github.com/Dataman-Cloud/swan/types" | ||
) | ||
|
||
type Filter interface { | ||
Filter(config *types.TaskConfig, agents []*Agent) []*Agent | ||
Filter(config *types.TaskConfig, replicas int, agents []*Agent) ([]*Agent, error) | ||
} | ||
|
||
//func NewFilter() []Filter { | ||
// filters := []Filter{ | ||
// filter.NewResourceFilter(), | ||
// } | ||
// | ||
// return filters | ||
//} | ||
|
||
func ApplyFilters(filters []Filter, config *types.TaskConfig, agents []*Agent) []*Agent { | ||
// the returned agents contains at least one proper agent | ||
func ApplyFilters(filters []Filter, config *types.TaskConfig, replicas int, agents []*Agent) ([]*Agent, error) { | ||
accepted := agents | ||
|
||
var err error | ||
for _, filter := range filters { | ||
accepted = filter.Filter(config, accepted) | ||
accepted, err = filter.Filter(config, replicas, accepted) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return accepted | ||
return accepted, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,42 @@ | ||
package filter | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/Dataman-Cloud/swan/mesos" | ||
"github.com/Dataman-Cloud/swan/types" | ||
) | ||
|
||
var ( | ||
errResourceNotEnough = errors.New("resource not enough") | ||
) | ||
|
||
type resourceFilter struct { | ||
} | ||
|
||
func NewResourceFilter() *resourceFilter { | ||
return &resourceFilter{} | ||
} | ||
|
||
func (f *resourceFilter) Filter(config *types.TaskConfig, agents []*mesos.Agent) []*mesos.Agent { | ||
// multiplicate with replicas to calculate total resource requirments | ||
func (f *resourceFilter) Filter(config *types.TaskConfig, replicas int, agents []*mesos.Agent) ([]*mesos.Agent, error) { | ||
candidates := make([]*mesos.Agent, 0) | ||
|
||
for _, agent := range agents { | ||
cpus, mem, disk, ports := agent.Resources() | ||
|
||
if cpus >= config.CPUs && | ||
mem >= config.Mem && | ||
disk >= config.Disk && | ||
len(ports) >= len(config.PortMappings) { | ||
var ( | ||
cpus, mem, disk, ports = agent.Resources() // avaliable agent resources | ||
cpusReq = config.CPUs * float64(replicas) // total resources requirements ... | ||
memReq = config.Mem * float64(replicas) | ||
diskReq = config.Disk * float64(replicas) | ||
portsReq = len(config.PortMappings) * replicas // FIXME LATER | ||
) | ||
if cpus >= cpusReq && mem >= memReq && disk >= diskReq && len(ports) >= portsReq { | ||
candidates = append(candidates, agent) | ||
} | ||
} | ||
|
||
return candidates | ||
if len(candidates) == 0 { | ||
return nil, errResourceNotEnough | ||
} | ||
return candidates, nil | ||
} |
Oops, something went wrong.