chia7712 commented on code in PR #900:
URL: https://github.com/apache/yunikorn-core/pull/900#discussion_r1665897870


##########
pkg/scheduler/objects/application_state.go:
##########
@@ -90,141 +90,150 @@ func (as applicationState) String() string {
        return [...]string{"New", "Accepted", "Running", "Rejected", 
"Completing", "Completed", "Failing", "Failed", "Expired", "Resuming"}[as]
 }
 
-func NewAppState() *fsm.FSM {
-       return fsm.NewFSM(
-               New.String(), fsm.Events{
-                       {
-                               Name: RejectApplication.String(),
-                               Src:  []string{New.String()},
-                               Dst:  Rejected.String(),
-                       }, {
-                               Name: RunApplication.String(),
-                               Src:  []string{New.String(), Resuming.String()},
-                               Dst:  Accepted.String(),
-                       }, {
-                               Name: RunApplication.String(),
-                               Src:  []string{Accepted.String(), 
Running.String(), Completing.String()},
-                               Dst:  Running.String(),
-                       }, {
-                               Name: CompleteApplication.String(),
-                               Src:  []string{Accepted.String(), 
Running.String()},
-                               Dst:  Completing.String(),
-                       }, {
-                               Name: CompleteApplication.String(),
-                               Src:  []string{Completing.String()},
-                               Dst:  Completed.String(),
-                       }, {
-                               Name: FailApplication.String(),
-                               Src:  []string{New.String(), Accepted.String(), 
Running.String()},
-                               Dst:  Failing.String(),
-                       }, {
-                               Name: FailApplication.String(),
-                               Src:  []string{Failing.String()},
-                               Dst:  Failed.String(),
-                       }, {
-                               Name: ResumeApplication.String(),
-                               Src:  []string{New.String(), Accepted.String()},
-                               Dst:  Resuming.String(),
-                       }, {
-                               Name: ExpireApplication.String(),
-                               Src:  []string{Completed.String(), 
Failed.String(), Rejected.String()},
-                               Dst:  Expired.String(),
-                       },
-               },
-               fsm.Callbacks{
-                       // The state machine is tightly tied to the Application 
object.
-                       //
-                       // The first argument must always be an Application and 
if there is a second,
-                       // that must be a string. If this precondition is not 
met, a runtime panic
-                       // will occur.
-                       "enter_state": func(_ context.Context, event 
*fsm.Event) {
-                               app := event.Args[0].(*Application) 
//nolint:errcheck
-                               log.Log(log.SchedFSM).Info("Application state 
transition",
-                                       zap.String("appID", app.ApplicationID),
-                                       zap.String("source", event.Src),
-                                       zap.String("destination", event.Dst),
-                                       zap.String("event", event.Event))
-
-                               eventInfo := ""
-                               if len(event.Args) == 2 {
-                                       eventInfo = event.Args[1].(string) 
//nolint:errcheck
-                                       app.OnStateChange(event, eventInfo)
-                               } else {
-                                       app.OnStateChange(event, "")
-                               }
-                               eventDetails, ok := stateEvents[event.Dst]
-                               if !ok {
-                                       log.Log(log.SchedFSM).Error("event 
details not found",
-                                               zap.String("state", event.Dst))
-                                       return
-                               }
-                               if app.sendStateChangeEvents {
-                                       
app.appEvents.SendStateChangeEvent(app.ApplicationID, eventDetails, eventInfo)
-                               }
-                       },
-                       "leave_state": func(_ context.Context, event 
*fsm.Event) {
-                               event.Args[0].(*Application).clearStateTimer() 
//nolint:errcheck
-                       },
-                       fmt.Sprintf("enter_%s", Completing.String()): func(_ 
context.Context, event *fsm.Event) {
-                               app := event.Args[0].(*Application) 
//nolint:errcheck
-                               app.setStateTimer(completingTimeout, 
app.stateMachine.Current(), CompleteApplication)
-                       },
-                       fmt.Sprintf("leave_%s", New.String()): func(_ 
context.Context, event *fsm.Event) {
-                               if event.Dst != Rejected.String() {
-                                       app := event.Args[0].(*Application) 
//nolint:errcheck
-                                       
metrics.GetQueueMetrics(app.queuePath).IncQueueApplicationsAccepted()
-                                       
metrics.GetSchedulerMetrics().IncTotalApplicationsAccepted()
-                               }
-                       },
-                       fmt.Sprintf("enter_%s", Rejected.String()): func(_ 
context.Context, event *fsm.Event) {
-                               app := event.Args[0].(*Application) 
//nolint:errcheck
-                               
metrics.GetQueueMetrics(app.queuePath).IncQueueApplicationsRejected()
-                               
metrics.GetSchedulerMetrics().IncTotalApplicationsRejected()
-                               app.setStateTimer(terminatedTimeout, 
app.stateMachine.Current(), ExpireApplication)
-                               app.finishedTime = time.Now()
-                               app.cleanupTrackedResource()
-                               // No rejected message when use 
app.HandleApplicationEvent(RejectApplication)
-                               if len(event.Args) == 2 {
-                                       app.rejectedMessage = 
event.Args[1].(string) //nolint:errcheck
-                               }
-                       },
-                       fmt.Sprintf("enter_%s", Running.String()): func(_ 
context.Context, event *fsm.Event) {
-                               if event.Src != Running.String() {
-                                       app := event.Args[0].(*Application) 
//nolint:errcheck
-                                       app.startTime = time.Now()
-                                       
app.queue.incRunningApps(app.ApplicationID)
-                                       
metrics.GetQueueMetrics(app.queuePath).IncQueueApplicationsRunning()
-                                       
metrics.GetSchedulerMetrics().IncTotalApplicationsRunning()
-                               }
-                       },
-                       fmt.Sprintf("leave_%s", Running.String()): func(_ 
context.Context, event *fsm.Event) {
-                               if event.Dst != Running.String() {
-                                       app := event.Args[0].(*Application) 
//nolint:errcheck
-                                       app.queue.decRunningApps()
-                                       
metrics.GetQueueMetrics(app.queuePath).DecQueueApplicationsRunning()
-                                       
metrics.GetSchedulerMetrics().DecTotalApplicationsRunning()
-                               }
-                       },
-                       fmt.Sprintf("enter_%s", Completed.String()): func(_ 
context.Context, event *fsm.Event) {
+//nolint:funlen

Review Comment:
   this is unnecessary now, right?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to