diff --git a/scheduler/service_sched.go b/scheduler/service_sched.go index 9e8025cef..d3ed24ce0 100644 --- a/scheduler/service_sched.go +++ b/scheduler/service_sched.go @@ -189,7 +189,7 @@ func (s *ServiceScheduler) computePlacements(job *structs.Job, place []allocTupl NodeID: option.Node.ID, JobID: job.ID, Job: job, - Resources: nil, // TODO: size + Resources: stack.TaskGroupSize(), Metrics: ctx.Metrics(), Status: structs.AllocStatusPending, } diff --git a/scheduler/stack.go b/scheduler/stack.go index bb5798d92..178d9d80a 100644 --- a/scheduler/stack.go +++ b/scheduler/stack.go @@ -15,6 +15,10 @@ type Stack interface { // This must be called in between calls to Select. SetTaskGroup(tg *structs.TaskGroup) + // TaskGroupSize returns the size of the task group. + // This is only valid after calling SetTaskGroup + TaskGroupSize() *structs.Resources + // Select is used to select a node for the task group Select() *RankedNode } @@ -34,6 +38,8 @@ type ServiceStack struct { BinPack *BinPackIterator Limit *LimitIterator MaxScore *MaxScoreIterator + + size *structs.Resources } // NewServiceStack constructs a stack used for selecting service placements @@ -99,6 +105,9 @@ func (s *ServiceStack) SetTaskGroup(tg *structs.TaskGroup) { size.Add(task.Resources) } + // Store the size + s.size = size + // Update the parameters of iterators s.TaskGroupDrivers.SetDrivers(drivers) s.TaskGroupConstraint.SetConstraints(constr) @@ -108,6 +117,10 @@ func (s *ServiceStack) SetTaskGroup(tg *structs.TaskGroup) { s.MaxScore.Reset() } +func (s *ServiceStack) TaskGroupSize() *structs.Resources { + return s.size +} + func (s *ServiceStack) Select() *RankedNode { return s.MaxScore.Next() }