예제 #1
0
func (s *_MesosScheduler) createTask(o *mesos.Offer,
	job Jobber, t _Tasker, available_cpus float64) *mesos.TaskInfo {
	jobId := job.getId()
	taskId := t.getId()
	tried := t.getTried()
	tid := fmt.Sprintf("%d:%d:%d", jobId, taskId, tried)
	var buff bytes.Buffer
	gw := gzip.NewWriter(&buff)
	var encoder = gob.NewEncoder(gw)
	jobTask := &SimpleJobTask{t}
	if err := encoder.Encode(jobTask); err != nil {
		glog.Fatal(err)
	}
	gw.Close()

	task := &mesos.TaskInfo{
		Name: proto.String(fmt.Sprintf("task %s", tid)),
		TaskId: &mesos.TaskID{
			Value: proto.String(tid),
		},
		Data:     buff.Bytes(),
		SlaveId:  o.SlaveId,
		Executor: s.executor,
	}
	cpus := math.Min(t.getCpus(), available_cpus)
	mem := t.getMem()
	task.Resources = []*mesos.Resource{
		mesos.ScalarResource("cpus", cpus),
		mesos.ScalarResource("mem", mem),
	}

	glog.Infof(" %s createTask :cpus : %#v, mem: %#v", tid, cpus, mem)
	return task
}
예제 #2
0
파일: main.go 프로젝트: luffyhwl/gopark
func main() {
	taskLimit := 1000
	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()

	executable := false
	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,
					Executable: &executable},
			},
		},
		Name:   proto.String("Test Executor (Go)"),
		Source: proto.String("go_test"),
	}
	str1 := "abcd"
	fmt.Println(str1)
	i := 0
	str := ""
	for i < 100000 {
		str = str + str1
		i = i + 1
	}

	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++
					tt := &Data{str}
					var buf bytes.Buffer
					enc := gob.NewEncoder(&buf)
					if err := enc.Encode(tt); err != nil {
						panic(err)
					}
					datas := buf.Bytes()

					fmt.Printf("Launching task: %d data:%d\n", taskId, len(datas))

					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,
							Data:     datas,
							Resources: []*mesos.Resource{
								mesos.ScalarResource("cpus", 1),
								mesos.ScalarResource("mem", 128),
							},
						},
					}

					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)
}