in pkg/scheduler/objects/application.go [643:700]
func (sa *Application) UpdateAllocationResources(alloc *Allocation) error {
sa.Lock()
defer sa.Unlock()
if alloc == nil {
return fmt.Errorf("alloc cannot be nil when updating resources for app %s", sa.ApplicationID)
}
if resources.IsZero(alloc.GetAllocatedResource()) {
return fmt.Errorf("cannot update alloc with zero resources on app %s: %v", sa.ApplicationID, alloc)
}
existing := sa.requests[alloc.GetAllocationKey()]
if existing == nil {
return fmt.Errorf("existing alloc not found when updating resources on app %s: %v", sa.ApplicationID, alloc)
}
newResource := alloc.GetAllocatedResource().Clone()
existingResource := existing.GetAllocatedResource().Clone()
delta := resources.Sub(newResource, existingResource)
if resources.IsZero(delta) {
return nil
}
delta.Prune()
if existing.IsAllocated() {
// update allocated resources
sa.allocatedResource = resources.Add(sa.allocatedResource, delta)
sa.allocatedResource.Prune()
sa.queue.IncAllocatedResource(delta)
// update user usage
sa.incUserResourceUsage(delta)
log.Log(log.SchedApplication).Info("updated allocated resources for application",
zap.String("appID", sa.ApplicationID),
zap.String("user", sa.user.User),
zap.String("alloc", existing.GetAllocationKey()),
zap.Bool("placeholder", existing.IsPlaceholder()),
zap.Stringer("existingResources", existingResource),
zap.Stringer("updatedResources", newResource),
zap.Stringer("delta", delta))
} else {
// update pending resources
sa.pending = resources.Add(sa.pending, delta)
sa.pending.Prune()
sa.queue.incPendingResource(delta)
log.Log(log.SchedApplication).Info("updated pending resources for application",
zap.String("appID", sa.ApplicationID),
zap.String("user", sa.user.User),
zap.String("alloc", existing.GetAllocationKey()),
zap.Bool("placeholder", existing.IsPlaceholder()),
zap.Stringer("existingResources", existingResource),
zap.Stringer("updatedResources", newResource),
zap.Stringer("delta", delta))
}
// update the allocation itself
existing.SetAllocatedResource(newResource)
return nil
}