Example #1
0
// Schedule implementation
func (scheduler *FCFSScheduler) Schedule(offers []*mesosproto.Offer) (*registry.Task, *mesosproto.Offer, bool) {
	log.Debugf("Schedule tasks, current registry len: %v", scheduler.Queue.Len())

	// get first task
	job := scheduler.Queue.Front().Value.(*registry.Job)
	task := job.FirstTask()

	for _, offer := range offers {
		if resource.ResourcesMatch(task, offer) && resource.ConstraintsMatch(task, offer) {
			job.PopFirstTask()
			return task, offer, true
		}
	}

	return nil, nil, false
}
Example #2
0
// Schedule implementation
func (scheduler *DRFScheduler) Schedule(offers []*mesosproto.Offer) (*registry.Task, *mesosproto.Offer, bool) {
	log.Debugf("Schedule tasks, current registry len: %v", scheduler.Heap.Len())
	if !scheduler.init {
		log.Debugf("Init DRF Heap, current waiting queue len: %d", len(scheduler.Queue))
		scheduler.totalResource = getTotalResource(offers)
		scheduler.init = true
		heap.Init(scheduler.Heap)
		for _, job := range scheduler.Queue {
			scheduler.AddJob(job)
		}
		return nil, nil, false
	}

	// get first task
	element := heap.Pop(scheduler.Heap).(*structure.DRFElement)
	job := element.Job
	if job.IsFinished() {
		return nil, nil, false
	}
	task := job.FirstTask()

	// search suitable offer for first task of this job
	for _, offer := range offers {
		if resource.ResourcesMatch(task, offer) && resource.ConstraintsMatch(task, offer) {
			job.PopFirstTask()
			if !job.IsFinished() {
				scheduler.AddJob(job)
			}
			return task, offer, true
		}
	}

	if !job.IsFinished() {
		scheduler.AddJob(job)
	}

	return nil, nil, false
}