From 63a7f0acb51874744c4d64291ca249fbd9b1bb94 Mon Sep 17 00:00:00 2001 From: Pradyumna Kaushik Date: Sun, 18 Dec 2016 14:30:29 -0500 Subject: [PATCH] Moved the check for fitting tasks into a different function. --- schedulers/pistoncapper.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/schedulers/pistoncapper.go b/schedulers/pistoncapper.go index 699bc0f..9590553 100644 --- a/schedulers/pistoncapper.go +++ b/schedulers/pistoncapper.go @@ -69,6 +69,18 @@ func NewPistonCapper(tasks []def.Task, ignoreWatts bool) *PistonCapper { return s } +// check whether task fits the offer or not. +func (s *PistonCapper) takeOffer(offerWatts float64, offerCPU float64, offerRAM float64, totalWatts float64, totalCPU float64, + totalRAM float64, task def.Task) bool { + if (s.ignoreWatts || (offerWatts >= (totalWatts + task.Watts))) && + (offerCPU >= (totalCPU + task.CPU)) && + (offerRAM >= (totalRAM + task.RAM)) { + return true + } else { + return false + } +} + // mutex var mutex sync.Mutex @@ -248,9 +260,7 @@ func (s *PistonCapper) ResourceOffers(driver sched.SchedulerDriver, offers []*me for *task.Instances > 0 { // Does the task fit - if (s.ignoreWatts || (offerWatts >= (totalWatts + task.Watts))) && - (offerCPU >= (totalCPU + task.CPU)) && - (offerRAM >= (totalRAM + task.RAM)) { + if s.takeOffer(offerWatts, offerCPU, offerRAM, totalWatts, totalCPU, totalRAM, task) { // Start piston capping if haven't started yet if !s.isCapping {