本文整理汇总了Golang中github.com/mesos/mesos-go/mesosutil.FilterResources函数的典型用法代码示例。如果您正苦于以下问题:Golang FilterResources函数的具体用法?Golang FilterResources怎么用?Golang FilterResources使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FilterResources函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ResourceOffers
func (sched *ExampleScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
for _, offer := range offers {
cpuResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == "cpus"
})
cpus := 0.0
for _, res := range cpuResources {
cpus += res.GetScalar().GetValue()
}
memResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == "mem"
})
mems := 0.0
for _, res := range memResources {
mems += res.GetScalar().GetValue()
}
log.Infoln("Received Offer <", offer.Id.GetValue(), "> with cpus=", cpus, " mem=", mems)
remainingCpus := cpus
remainingMems := mems
var tasks []*mesos.TaskInfo
for sched.tasksLaunched < sched.totalTasks &&
CPUS_PER_TASK <= remainingCpus &&
MEM_PER_TASK <= remainingMems {
sched.tasksLaunched++
taskId := &mesos.TaskID{
Value: proto.String(strconv.Itoa(sched.tasksLaunched)),
}
task := &mesos.TaskInfo{
Name: proto.String("go-task-" + taskId.GetValue()),
TaskId: taskId,
SlaveId: offer.SlaveId,
Executor: sched.executor,
Resources: []*mesos.Resource{
util.NewScalarResource("cpus", CPUS_PER_TASK),
util.NewScalarResource("mem", MEM_PER_TASK),
},
}
log.Infof("Prepared task: %s with offer %s for launch\n", task.GetName(), offer.Id.GetValue())
tasks = append(tasks, task)
remainingCpus -= CPUS_PER_TASK
remainingMems -= MEM_PER_TASK
}
log.Infoln("Launching ", len(tasks), "tasks for offer", offer.Id.GetValue())
driver.LaunchTasks([]*mesos.OfferID{offer.Id}, tasks, &mesos.Filters{RefuseSeconds: proto.Float64(1)})
}
}
开发者ID:Ima8,项目名称:kubernetes,代码行数:55,代码来源:example_scheduler.go
示例2: ResourceOffers
func (sched *ReflexScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
for _, offer := range offers {
// CPUs
cpuResources := util.FilterResources(
offer.Resources,
func(res *mesos.Resource) bool {
return res.GetName() == "cpus"
},
)
cpus := 0.0
for _, res := range cpuResources {
cpus += res.GetScalar().GetValue()
}
// Mem
memResources := util.FilterResources(
offer.Resources,
func(res *mesos.Resource) bool {
return res.GetName() == "mem"
},
)
mem := 0.0
for _, res := range memResources {
mem += res.GetScalar().GetValue()
}
logrus.WithFields(logrus.Fields{
"cpus": cpus,
"mem": mem,
}).Debug("got offer")
for _, pair := range sched.waitingPairs {
if pair.InProgress {
continue
}
task := pair.Task
if cpus >= task.CPU && mem >= task.Mem {
logrus.WithField("task", task).Info("would have launched a task")
}
}
driver.DeclineOffer(offer.GetId(), new(mesos.Filters))
}
}
开发者ID:asteris-llc,项目名称:reflex,代码行数:45,代码来源:scheduler.go
示例3: resourcesHaveVolume
func resourcesHaveVolume(resources []*mesos.Resource, persistenceId string) bool {
filtered := util.FilterResources(resources, func(res *mesos.Resource) bool {
return res.GetName() == "disk" &&
res.Reservation != nil &&
res.Disk != nil &&
res.Disk.Persistence.GetId() == persistenceId
})
return len(filtered) > 0
}
开发者ID:cebufooddroid,项目名称:mesos-go,代码行数:9,代码来源:main.go
示例4: ResourceOffers
func (sched *Scheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
for _, offer := range offers {
taskId := &mesos.TaskID{
Value: proto.String(fmt.Sprintf("basicdocker-task-%d", time.Now().Unix())),
}
ports := util.FilterResources(
offer.Resources,
func(res *mesos.Resource) bool {
return res.GetName() == "ports"
},
)
if len(ports) > 0 && len(ports[0].GetRanges().GetRange()) > 0 {
} else {
return
}
task := &mesos.TaskInfo{
Name: proto.String(taskId.GetValue()),
TaskId: taskId,
SlaveId: offer.SlaveId,
Container: &mesos.ContainerInfo{
Type: mesos.ContainerInfo_DOCKER.Enum(),
Volumes: nil,
Hostname: nil,
Docker: &mesos.ContainerInfo_DockerInfo{
Image: &DOCKER_IMAGE_DEFAULT,
Network: mesos.ContainerInfo_DockerInfo_BRIDGE.Enum(),
},
},
Command: &mesos.CommandInfo{
Shell: proto.Bool(true),
Value: proto.String("set -x ; /bin/date ; /bin/hostname ; sleep 200 ; echo done"),
},
Executor: nil,
Resources: []*mesos.Resource{
util.NewScalarResource("cpus", getOfferCpu(offer)),
util.NewScalarResource("mem", getOfferMem(offer)),
util.NewRangesResource("ports", []*mesos.Value_Range{
util.NewValueRange(
*ports[0].GetRanges().GetRange()[0].Begin,
*ports[0].GetRanges().GetRange()[0].Begin+1,
),
}),
},
}
log.Infof("Prepared task: %s with offer %s for launch\n", task.GetName(), offer.Id.GetValue())
var tasks []*mesos.TaskInfo = []*mesos.TaskInfo{task}
log.Infoln("Launching ", len(tasks), " tasks for offer", offer.Id.GetValue())
driver.LaunchTasks([]*mesos.OfferID{offer.Id}, tasks, &mesos.Filters{RefuseSeconds: proto.Float64(1)})
sched.tasksLaunched++
time.Sleep(time.Second)
}
}
开发者ID:spacejam,项目名称:mesos-docker-sched-example,代码行数:56,代码来源:sched.go
示例5: getScalarResources
func getScalarResources(offer *mesos.Offer, resourceName string) float64 {
resources := 0.0
filteredResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == resourceName
})
for _, res := range filteredResources {
resources += res.GetScalar().GetValue()
}
return resources
}
开发者ID:elodina,项目名称:syscol,代码行数:10,代码来源:scheduler.go
示例6: getPersistenceIds
func getPersistenceIds(resources []*mesos.Resource) []string {
filtered := util.FilterResources(resources, func(res *mesos.Resource) bool {
return res.GetName() == "disk" && res.Reservation != nil && res.Disk != nil
})
val := []string{}
for _, res := range filtered {
val = append(val, res.Disk.Persistence.GetId())
}
return val
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:10,代码来源:offer.go
示例7: FilterReservedVolumes
func FilterReservedVolumes(immutableResources []*mesos.Resource) []*mesos.Resource {
return util.FilterResources(immutableResources, func(res *mesos.Resource) bool {
if res.Reservation != nil &&
res.Disk != nil &&
res.GetName() == "disk" {
return true
}
return false
})
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:10,代码来源:utils.go
示例8: ScalarResourceVal
func ScalarResourceVal(name string, resources []*mesos.Resource) float64 {
scalarResources := util.FilterResources(resources, func(res *mesos.Resource) bool {
return res.GetType() == mesos.Value_SCALAR && res.GetName() == name
})
sum := 0.0
for _, res := range scalarResources {
sum += res.GetScalar().GetValue()
}
return sum
}
开发者ID:lucmichalski,项目名称:taurus,代码行数:10,代码来源:util.go
示例9: getRangeResources
func getRangeResources(offer *mesos.Offer, resourceName string) []*mesos.Value_Range {
resources := make([]*mesos.Value_Range, 0)
filteredResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == resourceName
})
for _, res := range filteredResources {
resources = append(resources, res.GetRanges().GetRange()...)
}
return resources
}
开发者ID:stealthly,项目名称:edge-test,代码行数:10,代码来源:scheduler.go
示例10: portIter
func portIter(resources []*mesos.Resource) chan int64 {
ports := make(chan int64)
go func() {
defer close(ports)
for _, resource := range util.FilterResources(resources, func(res *mesos.Resource) bool { return res.GetName() == "ports" }) {
for _, port := range common.RangesToArray(resource.GetRanges().GetRange()) {
ports <- port
}
}
}()
return ports
}
开发者ID:sargun,项目名称:riak-mesos,代码行数:12,代码来源:riak_node.go
示例11: getOfferScalar
func getOfferScalar(offer *mesos.Offer, name string) float64 {
resources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == name
})
value := 0.0
for _, res := range resources {
value += res.GetScalar().GetValue()
}
return value
}
开发者ID:mehiar,项目名称:mesos-framework,代码行数:12,代码来源:utils.go
示例12: TestBadCPUAsk
func TestBadCPUAsk(t *testing.T) {
assert := assert.New(t)
offer2 := generateResourceOffer()
offer := generateResourceOffer()
askFun := AskForCPU(3.1)
newOffer, _, success := askFun(offer)
assert.Equal(false, success)
assert.Equal(offer, offer2)
cpuResources := util.FilterResources(newOffer, func(res *mesos.Resource) bool {
return res.GetName() == "cpus"
})
assert.Equal(3.0, cpuResources[0].Scalar.GetValue())
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:13,代码来源:utils_test.go
示例13: getPorts
func getPorts(resources []*mesos.Resource, withReservation bool) []int64 {
filtered := util.FilterResources(resources, func(res *mesos.Resource) bool {
if withReservation {
return res.GetName() == "ports" && res.Reservation != nil
}
return res.GetName() == "ports" && res.Reservation == nil
})
val := []int64{}
for _, res := range filtered {
val = append(val, RangesToArray(res.GetRanges().GetRange())...)
}
return val
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:13,代码来源:offer.go
示例14: getResource
func getResource(name string, resources []*mesos.Resource, withReservation bool) float64 {
filtered := util.FilterResources(resources, func(res *mesos.Resource) bool {
if withReservation {
return res.GetName() == name && res.Reservation != nil
}
return res.GetName() == name && res.Reservation == nil
})
val := 0.0
for _, res := range filtered {
val += res.GetScalar().GetValue()
}
return val
}
开发者ID:cebufooddroid,项目名称:mesos-go,代码行数:13,代码来源:main.go
示例15: TestGoodPortAsk
func TestGoodPortAsk(t *testing.T) {
rand.Seed(10)
assert := assert.New(t)
offer := generateResourceOffer()
askFun := AskForPorts(100)
remaining, resourceAsk, success := askFun(offer)
assert.Equal(true, success)
assert.Equal(util.NewRangesResource("ports", []*mesos.Value_Range{util.NewValueRange(31105, 31204)}), resourceAsk)
remainingPorts := util.FilterResources(remaining, func(res *mesos.Resource) bool {
return res.GetName() == "ports"
})
assert.Equal([]*mesos.Resource{util.NewRangesResource("ports", []*mesos.Value_Range{util.NewValueRange(31000, 31104), util.NewValueRange(31205, 32000)})}, remainingPorts)
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:14,代码来源:utils_test.go
示例16: TestGoodMemoryAsk
func TestGoodMemoryAsk(t *testing.T) {
assert := assert.New(t)
offer2 := generateResourceOffer()
offer := generateResourceOffer()
askFun := AskForMemory(100)
newOffer, resourceAsk, success := askFun(offer)
assert.Equal(true, success)
assert.Equal(util.NewScalarResource("mem", 100), resourceAsk)
assert.Equal(offer, offer2)
cpuResources := util.FilterResources(newOffer, func(res *mesos.Resource) bool {
return res.GetName() == "mem"
})
assert.Equal(1885.0, cpuResources[0].Scalar.GetValue())
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:14,代码来源:utils_test.go
示例17: TestTotalCPUAsk
func TestTotalCPUAsk(t *testing.T) {
assert := assert.New(t)
offer2 := generateResourceOffer()
offer := generateResourceOffer()
askFun := AskForCPU(3)
newOffer, resourceAsk, success := askFun(offer)
assert.Equal(true, success)
assert.Equal(util.NewScalarResource("cpus", 3), resourceAsk)
assert.Equal(offer, offer2)
cpuResources := util.FilterResources(newOffer, func(res *mesos.Resource) bool {
return res.GetName() == "cpus"
})
assert.Equal(0.0, cpuResources[0].Scalar.GetValue())
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:14,代码来源:utils_test.go
示例18: parseOffer
func parseOffer(offer *mesos.Offer) OfferResources {
getResources := func(resourceName string) []*mesos.Resource {
return util.FilterResources(
offer.Resources,
func(res *mesos.Resource) bool {
return res.GetName() == resourceName
},
)
}
cpuResources := getResources("cpus")
cpus := 0.0
for _, res := range cpuResources {
cpus += res.GetScalar().GetValue()
}
memResources := getResources("mem")
mems := 0.0
for _, res := range memResources {
mems += res.GetScalar().GetValue()
}
portResources := getResources("ports")
ports := make([]*mesos.Value_Range, 0, 10)
for _, res := range portResources {
ranges := res.GetRanges()
ports = append(ports, ranges.GetRange()...)
}
diskResources := getResources("disk")
disk := 0.0
for _, res := range diskResources {
disk += res.GetScalar().GetValue()
}
return OfferResources{
cpus: cpus,
mems: mems,
disk: disk,
ports: ports,
}
}
开发者ID:puppetizeme,项目名称:etcd-mesos,代码行数:42,代码来源:scheduler.go
示例19: AcceptOffers
func (driver *MesosSchedulerDriver) AcceptOffers(offerIds []*mesos.OfferID, operations []*mesos.Offer_Operation, filters *mesos.Filters) (mesos.Status, error) {
driver.eventLock.Lock()
defer driver.eventLock.Unlock()
if stat := driver.status; stat != mesos.Status_DRIVER_RUNNING {
return stat, fmt.Errorf("Unable to AcceptOffers, expected driver status %s, but got %s", mesos.Status_DRIVER_RUNNING, stat)
}
if !driver.connected {
err := fmt.Errorf("Not connected to master.")
for _, operation := range operations {
if *operation.Type == mesos.Offer_Operation_LAUNCH {
for _, task := range operation.Launch.TaskInfos {
driver.pushLostTask(task, "Unable to launch tasks: "+err.Error())
}
}
}
log.Errorf("Failed to send LaunchTask message: %v\n", err)
return driver.status, err
}
okOperations := make([]*mesos.Offer_Operation, 0, len(operations))
for _, offerId := range offerIds {
for _, operation := range operations {
// Keep only the slave PIDs where we run tasks so we can send
// framework messages directly.
if !driver.cache.containsOffer(offerId) {
log.Warningf("Attempting to accept offers with unknown offer %s\n", offerId.GetValue())
continue
}
// Validate
switch *operation.Type {
case mesos.Offer_Operation_LAUNCH:
tasks := []*mesos.TaskInfo{}
// Set TaskInfo.executor.framework_id, if it's missing.
for _, task := range operation.Launch.TaskInfos {
newTask := *task
if newTask.Executor != nil && newTask.Executor.FrameworkId == nil {
newTask.Executor.FrameworkId = driver.frameworkInfo.Id
}
tasks = append(tasks, &newTask)
}
for _, task := range tasks {
if driver.cache.getOffer(offerId).offer.SlaveId.Equal(task.SlaveId) {
// cache the tasked slave, for future communication
pid := driver.cache.getOffer(offerId).slavePid
driver.cache.putSlavePid(task.SlaveId, pid)
} else {
log.Warningf("Attempting to launch task %s with the wrong slaveId offer %s\n", task.TaskId.GetValue(), task.SlaveId.GetValue())
}
}
operation.Launch.TaskInfos = tasks
okOperations = append(okOperations, operation)
case mesos.Offer_Operation_RESERVE:
// Only send reserved resources
filtered := util.FilterResources(operation.Reserve.Resources, func(res *mesos.Resource) bool { return res.Reservation != nil })
operation.Reserve.Resources = filtered
okOperations = append(okOperations, operation)
case mesos.Offer_Operation_UNRESERVE:
// Only send reserved resources
filtered := util.FilterResources(operation.Unreserve.Resources, func(res *mesos.Resource) bool { return res.Reservation != nil })
operation.Unreserve.Resources = filtered
okOperations = append(okOperations, operation)
case mesos.Offer_Operation_CREATE:
// Only send reserved resources disks with volumes
filtered := util.FilterResources(operation.Create.Volumes, func(res *mesos.Resource) bool {
return res.Reservation != nil && res.Disk != nil && res.GetName() == "disk"
})
operation.Create.Volumes = filtered
okOperations = append(okOperations, operation)
case mesos.Offer_Operation_DESTROY:
// Only send reserved resources disks with volumes
filtered := util.FilterResources(operation.Destroy.Volumes, func(res *mesos.Resource) bool {
return res.Reservation != nil && res.Disk != nil && res.GetName() == "disk"
})
operation.Destroy.Volumes = filtered
okOperations = append(okOperations, operation)
}
}
driver.cache.removeOffer(offerId) // if offer
}
// Accept Offers
message := &mesos.Call{
FrameworkId: driver.frameworkInfo.Id,
Type: mesos.Call_ACCEPT.Enum(),
Accept: &mesos.Call_Accept{
OfferIds: offerIds,
Operations: okOperations,
Filters: filters,
},
}
if err := driver.send(driver.masterPid, message); err != nil {
for _, operation := range operations {
if *operation.Type == mesos.Offer_Operation_LAUNCH {
for _, task := range operation.Launch.TaskInfos {
//.........这里部分代码省略.........
开发者ID:cbbs,项目名称:swarm,代码行数:101,代码来源:scheduler.go
示例20: ResourceOffers
func (sched *SdcScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
if sched.tasksLaunched >= sched.totalTasks {
log.Info("decline all of the offers since all of our tasks are already launched")
log.Infoln("sched.totalTasks ", sched.totalTasks)
log.Infoln("sched.tasksFinished ", sched.tasksFinished)
log.Infoln("sched.tasksLaunched ", sched.tasksLaunched)
// cmdQueueからCommand.Argumentsをpopする
// 将来的に外部のキューから取得できるように置き換える
if sched.totalTasks == 0 && sched.tasksFinished == 0 && sched.tasksLaunched == 0 && cmdQueue.Len() != 0 {
execinfo := cmdQueue.Remove(cmdQueue.Front()).(*mesos.ExecutorInfo)
log.Infoln("execinfo ", execinfo.Command.Arguments)
sched.totalTasks = len(execinfo.Command.Arguments)
sched.executor.Command.Arguments = execinfo.Command.Arguments
}
if sched.totalTasks == 0 && sched.tasksFinished == 0 && sched.tasksLaunched == 0 {
ids := make([]*mesos.OfferID, len(offers))
for i, offer := range offers {
ids[i] = offer.Id
}
driver.LaunchTasks(ids, []*mesos.TaskInfo{}, &mesos.Filters{RefuseSeconds: proto.Float64(5)})
return
}
}
log.Info("prepare pass args: ", sched.executor.Command.Arguments)
cmds := sched.executor.Command.Arguments
for _, v := range cmds {
fmt.Println("v = ", v)
}
// [/bin/cat /var/tmp/1.txt /var/tmp/2.txt /var/tmp/3.txt | /bin/grep abe > /var/tmp/grep-result.txt]
//
// rebuild args
// 1. /bin/cat /var/tmp/1.txt >> /var/tmp/intermediate.txt
// 2. /bin/cat /var/tmp/2.txt >> /var/tmp/intermediate.txt
// 3. /bin/cat /var/tmp/3.txt >> /var/tmp/intermediate.txt
// 4. /bin/cat /var/tmp/intermediate.txt | /bin/grep abe > /var/tmp/grep-result.txt
// 5. /bin/rm /var/tmp/intermediate.txt
for _, offer := range offers {
cpuResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == "cpus"
})
cpus := 0.0
for _, res := range cpuResources {
cpus += res.GetScalar().GetValue()
}
memResources := util.FilterResources(offer.Resources, func(res *mesos.Resource) bool {
return res.GetName() == "mem"
})
mems := 0.0
for _, res := range memResources {
mems += res.GetScalar().GetValue()
}
log.Infoln("Received Offer <", offer.Id.GetValue(), "> with cpus=", cpus, " mem=", mems)
remainingCpus := cpus
remainingMems := mems
var tasks []*mesos.TaskInfo
// $ cat 1.txt 2.txt. 3.txt | wc -lの場合
// 先に、後ろのタスクを上げておく必要がある?
//
// コンセプト実装はシンプルに中間ファイル方式で行く
// 遅いけど
for sched.tasksLaunched < sched.totalTasks &&
CPUS_PER_TASK <= remainingCpus &&
MEM_PER_TASK <= remainingMems {
sched.tasksLaunched++
taskId := &mesos.TaskID{
Value: proto.String(strconv.Itoa(sched.tasksLaunched)),
}
// executionidの書き換え
sched.executor.ExecutorId = util.NewExecutorID(taskId.GetValue())
log.Infof("sched.tasksLaunched = %d\n", sched.tasksLaunched)
log.Infof("sched.totalTasks = %d\n", sched.totalTasks)
log.Infof("sched.executor.Command.Value = %s\n", sched.executor.Command.GetValue())
log.Infof("sched.executor.GetExecutorId() = %s\n", sched.executor.GetExecutorId())
// sched.executor.Command.Arguments で書き換えても保持されている
// 値はポインタなので、LaunchTasksするときに、複数のタスクでまとめられているので、
// 値は最後に上書きされた物になる
// そこで、Argumentsがタスクごとにまとめられないように個別にオブジェクトを生成してタスクを
// 起動する
exec := &mesos.ExecutorInfo{
ExecutorId: sched.executor.GetExecutorId(),
Name: proto.String(sched.executor.GetName()),
Source: proto.String(sched.executor.GetSource()),
Command: &mesos.CommandInfo{
//.........这里部分代码省略.........
开发者ID:hirolovesbeer,项目名称:sdc,代码行数:101,代码来源:main.go
注:本文中的github.com/mesos/mesos-go/mesosutil.FilterResources函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论