Skip to content

Commit

Permalink
[YUNIKORN-2599] Certain shim events are not handled by the state mach…
Browse files Browse the repository at this point in the history
…ine (#830)

Closes: #830

Signed-off-by: Chia-Ping Tsai <[email protected]>
  • Loading branch information
pbacsko authored and chia7712 committed May 9, 2024
1 parent b7499e1 commit 04d951e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
3 changes: 1 addition & 2 deletions pkg/cache/application_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ const (
KilledApplication
ReleaseAppAllocation
ReleaseAppAllocationAsk
AppStateChange
ResumingApplication
AppTaskCompleted
)

func (ae ApplicationEventType) String() string {
return [...]string{"SubmitApplication", "RecoverApplication", "AcceptApplication", "TryReserve", "UpdateReservation", "RunApplication", "RejectApplication", "CompleteApplication", "FailApplication", "KillApplication", "KilledApplication", "ReleaseAppAllocation", "ReleaseAppAllocationAsk", "AppStateChange", "ResumingApplication", "AppTaskCompleted"}[ae]
return [...]string{"SubmitApplication", "AcceptApplication", "TryReserve", "UpdateReservation", "RunApplication", "RejectApplication", "CompleteApplication", "FailApplication", "KillApplication", "KilledApplication", "ReleaseAppAllocation", "ReleaseAppAllocationAsk", "ResumingApplication", "AppTaskCompleted"}[ae]
}

// ------------------------
Expand Down
19 changes: 19 additions & 0 deletions pkg/cache/application_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package cache
import (
"testing"

"gotest.tools/v3/assert"

"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)

Expand Down Expand Up @@ -887,3 +889,20 @@ func TestNewResumingApplicationEvent(t *testing.T) {
})
}
}

func TestApplicationEventsAsString(t *testing.T) {
assert.Equal(t, SubmitApplication.String(), "SubmitApplication")
assert.Equal(t, AcceptApplication.String(), "AcceptApplication")
assert.Equal(t, TryReserve.String(), "TryReserve")
assert.Equal(t, UpdateReservation.String(), "UpdateReservation")
assert.Equal(t, RunApplication.String(), "RunApplication")
assert.Equal(t, RejectApplication.String(), "RejectApplication")
assert.Equal(t, CompleteApplication.String(), "CompleteApplication")
assert.Equal(t, FailApplication.String(), "FailApplication")
assert.Equal(t, KillApplication.String(), "KillApplication")
assert.Equal(t, KilledApplication.String(), "KilledApplication")
assert.Equal(t, ReleaseAppAllocation.String(), "ReleaseAppAllocation")
assert.Equal(t, ReleaseAppAllocationAsk.String(), "ReleaseAppAllocationAsk")
assert.Equal(t, ResumingApplication.String(), "ResumingApplication")
assert.Equal(t, AppTaskCompleted.String(), "AppTaskCompleted")
}
5 changes: 3 additions & 2 deletions pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,9 @@ func (ctx *Context) notifyTaskComplete(appID, taskID string) {
zap.String("taskID", taskID))
ev := NewSimpleTaskEvent(appID, taskID, CompleteTask)
dispatcher.Dispatch(ev)
appEv := NewSimpleApplicationEvent(appID, AppTaskCompleted)
dispatcher.Dispatch(appEv)
if app.GetApplicationState() == ApplicationStates().Resuming {
dispatcher.Dispatch(NewSimpleApplicationEvent(appID, AppTaskCompleted))
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/cache/scheduler_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,12 @@ func (callback *AsyncRMCallback) UpdateApplication(response *si.ApplicationRespo
if app != nil && app.GetApplicationState() == ApplicationStates().Reserving {
ev := NewResumingApplicationEvent(updated.ApplicationID)
dispatcher.Dispatch(ev)

// handle status update
dispatcher.Dispatch(NewApplicationStatusChangeEvent(updated.ApplicationID, AppStateChange, updated.State))
}
default:
if updated.State == ApplicationStates().Failing || updated.State == ApplicationStates().Failed {
ev := NewFailApplicationEvent(updated.ApplicationID, updated.Message)
dispatcher.Dispatch(ev)
}
// handle status update
dispatcher.Dispatch(NewApplicationStatusChangeEvent(updated.ApplicationID, AppStateChange, updated.State))
}
}
return nil
Expand Down
12 changes: 12 additions & 0 deletions pkg/cache/task_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,15 @@ func TestGetAllocateTaskEventArgs(t *testing.T) {
err = events.GetEventArgsAsStrings(nil, args)
assert.Assert(t, err != nil)
}

func TestTaskEventsAsString(t *testing.T) {
assert.Equal(t, InitTask.String(), "InitTask")
assert.Equal(t, SubmitTask.String(), "SubmitTask")
assert.Equal(t, TaskAllocated.String(), "TaskAllocated")
assert.Equal(t, TaskRejected.String(), "TaskRejected")
assert.Equal(t, TaskBound.String(), "TaskBound")
assert.Equal(t, CompleteTask.String(), "CompleteTask")
assert.Equal(t, TaskFail.String(), "TaskFail")
assert.Equal(t, KillTask.String(), "KillTask")
assert.Equal(t, TaskKilled.String(), "TaskKilled")
}

0 comments on commit 04d951e

Please sign in to comment.