yangwwei commented on a change in pull request #145: URL: https://github.com/apache/incubator-yunikorn-core/pull/145#discussion_r427732222
########## File path: pkg/scheduler/scheduling_application.go ########## @@ -633,3 +668,44 @@ func (sa *SchedulingApplication) recoverOnNode(node *SchedulingNode, ask *schedu zap.Error(err)) } } + +// Application status methods reflecting the underlying app object state +// link back to the underlying app object to prevent out of sync states +func (sa *SchedulingApplication) isAccepted() bool { + return sa.ApplicationInfo.IsAccepted() +} + +func (sa *SchedulingApplication) isStarting() bool { + return sa.ApplicationInfo.IsStarting() +} + +func (sa *SchedulingApplication) isNew() bool { + return sa.ApplicationInfo.IsNew() +} + +func (sa *SchedulingApplication) isWaiting() bool { + return sa.ApplicationInfo.IsWaiting() +} + +// Move the app state to running after allocation has been recovered. +// Since we do not add allocations in the normal way states will not change during recovery. +// There could also be multiple nodes that recover the app and +// This moves via starting directly to running. +func (sa *SchedulingApplication) finishRecovery() { + // no need to do anything if we are already running + if sa.ApplicationInfo.IsRunning() { + return + } + // this is the first recovered allocation: move to starting this cannot fail + if sa.ApplicationInfo.IsAccepted() { + // ignore the errors explicitly and marked as nolint + //nolint: errcheck + _ = sa.ApplicationInfo.HandleApplicationEvent(cache.StartApplication) + _ = sa.ApplicationInfo.HandleApplicationEvent(cache.RunApplication) + } + // log unexpected state + if !sa.ApplicationInfo.IsRunning() { + log.Logger().Warn("State of recovered app is not the expected RUNNING state", + zap.String("state", sa.ApplicationInfo.GetApplicationState())) + } +} Review comment: Similarly, can we handle a `FinishRecoveryEvent` in 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