當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mesos.SchedulerDriver類代碼示例

本文整理匯總了Golang中github.com/mesosphere/mesos-go/mesos.SchedulerDriver的典型用法代碼示例。如果您正苦於以下問題:Golang SchedulerDriver類的具體用法?Golang SchedulerDriver怎麽用?Golang SchedulerDriver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SchedulerDriver類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

func (self *ResMan) Run(master string) {
	frameworkIdStr := FRAMEWORK_ID
	frameworkId := &mesos.FrameworkID{Value: &frameworkIdStr}
	driver := mesos.SchedulerDriver{
		Master: master,
		Framework: mesos.FrameworkInfo{
			Name:            proto.String("TyrantFramework"),
			User:            proto.String(""),
			FailoverTimeout: failoverTimeout,
			Id:              frameworkId,
		},

		Scheduler: &mesos.Scheduler{
			ResourceOffers: self.OnResourceOffers,
			StatusUpdate:   self.OnStatusUpdate,
			Error:          self.OnError,
			Disconnected:   self.OnDisconnected,
			Registered:     self.OnRegister,
			Reregistered:   self.OnReregister,
		},
	}

	driver.Init()
	defer driver.Destroy()
	go self.EventLoop()

	driver.Start()
	<-self.exit
	log.Debug("exit")
	driver.Stop(false)
}
開發者ID:ngaut,項目名稱:tyrant,代碼行數:31,代碼來源:scheduler.go

示例2: runTaskUsingOffer

func (self *ResMan) runTaskUsingOffer(driver *mesos.SchedulerDriver, offer mesos.Offer,
	ts []*Task) (launchCount int) {
	cpus, mem := extraCpuMem(offer)
	var tasks []mesos.TaskInfo
	for i := 0; i < len(ts) && cpus > CPU_UNIT && mem > MEM_UNIT; i++ {
		t := ts[i]
		log.Debugf("Launching task: %s\n", t.Tid)
		job := t.job
		executor := &mesos.ExecutorInfo{
			Command: &mesos.CommandInfo{
				//Value: proto.String(job.Executor + ` "` + job.ExecutorFlags + `"`),
				Value: proto.String(fmt.Sprintf(`%s "%s"`, job.Executor,
					base64.StdEncoding.EncodeToString([]byte(job.ExecutorFlags)))),
			},
			Name:   proto.String("shell executor (Go)"),
			Source: proto.String("go_test"),
		}

		executorId := self.genExtorId(t.Tid)
		executor.ExecutorId = &mesos.ExecutorID{Value: proto.String(executorId)}
		log.Debug(*executor.Command.Value)

		urls := splitTrim(job.Uris)
		taskUris := make([]*mesos.CommandInfo_URI, len(urls))
		for i, _ := range urls {
			taskUris[i] = &mesos.CommandInfo_URI{Value: &urls[i]}
		}
		executor.Command.Uris = taskUris

		task := mesos.TaskInfo{
			Name: proto.String(job.Name),
			TaskId: &mesos.TaskID{
				Value: proto.String(t.Tid),
			},
			SlaveId:  offer.SlaveId,
			Executor: executor,
			Resources: []*mesos.Resource{
				mesos.ScalarResource("cpus", CPU_UNIT),
				mesos.ScalarResource("mem", MEM_UNIT),
			},
		}

		tasks = append(tasks, task)
		t.state = taskRuning

		t.LastUpdate = time.Now()
		t.SlaveId = offer.GetSlaveId().GetValue()
		self.running.Add(t.Tid, t)
		log.Debugf("remove %+v from ready queue", t.Tid)
		self.ready.Del(t.Tid)
		cpus -= CPU_UNIT
		mem -= MEM_UNIT
	}

	if len(tasks) == 0 {
		return 0
	}

	log.Debugf("%+v", tasks)

	filters := mesos.Filters{RefuseSeconds: &refuseSeconds}
	driver.LaunchTasks(offer.Id, tasks, filters)

	return len(tasks)
}
開發者ID:ngaut,項目名稱:tyrant,代碼行數:65,代碼來源:scheduler.go

示例3: main


//.........這裏部分代碼省略.........
		return task
	}

	maxTasksForOffer := func(offer mesos.Offer) int {
		// TODO(nnielsen): Parse offer resources.
		count := 0

		var cpus float64 = 0
		var mem float64 = 0

		for _, resource := range offer.Resources {
			if resource.GetName() == "cpus" {
				cpus = *resource.GetScalar().Value
			}

			if resource.GetName() == "mem" {
				mem = *resource.GetScalar().Value
			}
		}

		for cpus >= TASK_CPUS && mem >= TASK_MEM {
			count++
			cpus -= TASK_CPUS
			mem -= TASK_MEM
		}

		return count
	}

	printQueueStatistics := func() {
		// TODO(nnielsen): Print queue lengths.
	}

	driver := mesos.SchedulerDriver{
		Master: *master,
		Framework: mesos.FrameworkInfo{
			Name: proto.String("RENDLER"),
			User: proto.String(""),
		},

		Scheduler: &mesos.Scheduler{

			Registered: func(
				driver *mesos.SchedulerDriver,
				frameworkId mesos.FrameworkID,
				masterInfo mesos.MasterInfo) {
				log.Printf("Registered")
			},

			ResourceOffers: func(driver *mesos.SchedulerDriver, offers []mesos.Offer) {
				printQueueStatistics()

				for _, offer := range offers {
					if shuttingDown {
						fmt.Println("Shutting down: declining offer on [", offer.Hostname, "]")
						driver.DeclineOffer(offer.Id)
						continue
					}

					tasks := []mesos.TaskInfo{}

					for i := 0; i < maxTasksForOffer(offer)/2; i++ {
						if crawlQueue.Front() != nil {
							url := crawlQueue.Front().Value.(string)
							crawlQueue.Remove(crawlQueue.Front())
							task := makeCrawlTask(url, offer)
開發者ID:karya0,項目名稱:RENDLER,代碼行數:67,代碼來源:main.go

示例4: main


//.........這裏部分代碼省略.........
		for {
			cluster.Update()
			time.Sleep(updateInterval)
		}
	}()

	slaves := list.New()
	for _, slave := range cluster.Sample.Slaves {
		slaveHostname := slave.Hostname + ":" + strconv.Itoa(slave.Port)
		slaves.PushBack(slaveHostname)
	}

	// TODO(nnielsen): Move this and callbacks to dedicated scheduler package / struct.
	taskToSlave := make(map[string]string)

	scheduleTask := func(offer mesos.Offer) *mesos.TaskInfo {
		slave := slaves.Front()
		if slave == nil {
			return nil
		}

		glog.V(2).Infof("Scheduling slave '%s'", slave.Value.(string))

		slaves.Remove(slave)

		task := "angstrom-task-" + strconv.Itoa(taskId)
		taskToSlave[task] = slave.Value.(string)

		return &mesos.TaskInfo{
			Name: proto.String("angstrom-task"),
			TaskId: &mesos.TaskID{
				Value: proto.String(task),
			},
			SlaveId:  offer.SlaveId,
			Executor: executor,
			Data:     []byte("{\"slave\": \"" + slave.Value.(string) + "\"}"),
			Resources: []*mesos.Resource{
				mesos.ScalarResource("cpus", 0.5),
				mesos.ScalarResource("mem", 32),
			},
		}
	}

	driver := mesos.SchedulerDriver{
		Master: *master,
		Framework: mesos.FrameworkInfo{
			Name: proto.String("Angstrom metrics"),
			User: proto.String(""),
		},

		Scheduler: &mesos.Scheduler{
			ResourceOffers: func(driver *mesos.SchedulerDriver, offers []mesos.Offer) {
				for _, offer := range offers {
					taskId++

					tasks := make([]mesos.TaskInfo, 0)

					task := scheduleTask(offer)
					if task != nil {
						glog.V(2).Infof("Launching on offer %v", offer.Id)

						tasks = append(tasks, *task)
						driver.LaunchTasks(offer.Id, tasks)
					} else {
						glog.V(2).Infof("Declining offer %v", offer.Id)
						driver.DeclineOffer(offer.Id)
					}

				}
			},

			FrameworkMessage: func(driver *mesos.SchedulerDriver, _executorId mesos.ExecutorID, slaveId mesos.SlaveID, data string) {
				var target []payload.StatisticsInfo
				err := json.Unmarshal([]byte(data), &target)
				if err != nil {
					return
				}

				cluster.AddSlaveSamples(slaveId, target)
			},

			StatusUpdate: func(driver *mesos.SchedulerDriver, status mesos.TaskStatus) {
				// TODO(nnielsen): Readd slave task to queue in case of any terminal state.
				if *status.State == mesos.TaskState_TASK_RUNNING {
				} else if *status.State == mesos.TaskState_TASK_FINISHED {
				}
			},
		},
	}

	driver.Init()
	defer driver.Destroy()
	driver.Start()

	endpoints.Initialize(defaultPort, *angstromPath, cluster)

	glog.V(2).Infof("Waiting for threads to join")

	driver.Join()
}
開發者ID:nqn,項目名稱:angstrom,代碼行數:101,代碼來源:main.go

示例5: main

func main() {
	taskLimit := 5
	taskId := 0
	exit := make(chan bool)
	localExecutor, _ := executorPath()

	master := flag.String("master", "localhost:5050", "Location of leading Mesos master")
	executorUri := flag.String("executor-uri", localExecutor, "URI of executor executable")
	flag.Parse()

	executor := &mesos.ExecutorInfo{
		ExecutorId: &mesos.ExecutorID{Value: proto.String("default")},
		Command: &mesos.CommandInfo{
			Value: proto.String("./example_executor"),
			Uris: []*mesos.CommandInfo_URI{
				&mesos.CommandInfo_URI{Value: executorUri},
			},
		},
		Name:   proto.String("Test Executor (Go)"),
		Source: proto.String("go_test"),
	}

	driver := mesos.SchedulerDriver{
		Master: *master,
		Framework: mesos.FrameworkInfo{
			Name: proto.String("GoFramework"),
			User: proto.String(""),
		},

		Scheduler: &mesos.Scheduler{
			ResourceOffers: func(driver *mesos.SchedulerDriver, offers []mesos.Offer) {
				for _, offer := range offers {
					taskId++
					fmt.Printf("Launching task: %d\n", taskId)

					tasks := []mesos.TaskInfo{
						mesos.TaskInfo{
							Name: proto.String("go-task"),
							TaskId: &mesos.TaskID{
								Value: proto.String("go-task-" + strconv.Itoa(taskId)),
							},
							SlaveId:  offer.SlaveId,
							Executor: executor,
							Resources: []*mesos.Resource{
								mesos.ScalarResource("cpus", 1),
								mesos.ScalarResource("mem", 512),
							},
						},
					}

					driver.LaunchTasks(offer.Id, tasks)
				}
			},

			StatusUpdate: func(driver *mesos.SchedulerDriver, status mesos.TaskStatus) {
				fmt.Println("Received task status: " + *status.Message)

				if *status.State == mesos.TaskState_TASK_FINISHED {
					taskLimit--
					if taskLimit <= 0 {
						exit <- true
					}
				}
			},
		},
	}

	driver.Init()
	defer driver.Destroy()

	driver.Start()
	<-exit
	driver.Stop(false)
}
開發者ID:tomzhang,項目名稱:mesos-go,代碼行數:74,代碼來源:main.go


注:本文中的github.com/mesosphere/mesos-go/mesos.SchedulerDriver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。