yangwwei commented on a change in pull request #145: URL: https://github.com/apache/incubator-yunikorn-core/pull/145#discussion_r427721780
########## File path: pkg/scheduler/scheduling_application.go ########## @@ -207,10 +224,28 @@ func (sa *SchedulingApplication) addAllocationAsk(ask *schedulingAllocationAsk) oldAskResource = resources.Multiply(oldAsk.AllocatedResource, int64(oldAsk.getPendingAskRepeat())) } - delta.SubFrom(oldAskResource) + // Check if we need to change state based on the ask added, there are two cases: + // 1) first ask added on a new app: state is New + // 2) all asks and allocation have been removed: state is Waiting + // Accept the app and get it scheduling (again) + if sa.isNew() { + if err := sa.ApplicationInfo.HandleApplicationEvent(cache.AcceptApplication); err != nil { + log.Logger().Debug("Application state change failed while adding first ask", + zap.String("currentState", sa.ApplicationInfo.GetApplicationState()), + zap.Error(err)) + } + } + if sa.isWaiting() { + if err := sa.ApplicationInfo.HandleApplicationEvent(cache.RunApplication); err != nil { + log.Logger().Debug("Application state change failed while adding new ask", + zap.String("currentState", sa.ApplicationInfo.GetApplicationState()), + zap.Error(err)) + } + } Review comment: Similar to the comments I had for the `addAllocation`, I think we can achieve this by leveraging the state machine. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org