Skip to content

Commit

Permalink
[YUNIKORN-2597] Improve error messages in Context (apache#829)
Browse files Browse the repository at this point in the history
Closes: apache#829

Signed-off-by: Peter Bacsko <[email protected]>
  • Loading branch information
pbacsko committed May 2, 2024
1 parent a1b8480 commit 6f601c0
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions pkg/cache/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"errors"
"fmt"
"reflect"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1294,41 +1295,70 @@ func (ctx *Context) HandleContainerStateUpdate(request *si.UpdateContainerSchedu
func (ctx *Context) ApplicationEventHandler() func(obj interface{}) {
return func(obj interface{}) {
if event, ok := obj.(events.ApplicationEvent); ok {
app := ctx.GetApplication(event.GetApplicationID())
appID := event.GetApplicationID()
app := ctx.GetApplication(appID)
if app == nil {
log.Log(log.ShimContext).Error("failed to handle application event",
zap.String("reason", "application not exist"))
log.Log(log.ShimContext).Error("failed to handle application event, application does not exist",
zap.String("applicationID", appID))
return
}

if app.canHandle(event) {
if err := app.handle(event); err != nil {
log.Log(log.ShimContext).Error("failed to handle application event",
zap.String("event", event.GetEvent()),
zap.String("applicationID", appID),
zap.Error(err))
}
return
}

log.Log(log.ShimContext).Error("application event cannot be handled in the current state",
zap.String("applicationID", appID),
zap.String("event", event.GetEvent()),
zap.String("state", app.sm.Current()))
return
}

log.Log(log.ShimContext).Error("could not handle application event",
zap.String("type", reflect.TypeOf(obj).Name()))
}
}

func (ctx *Context) TaskEventHandler() func(obj interface{}) {
return func(obj interface{}) {
if event, ok := obj.(events.TaskEvent); ok {
task := ctx.getTask(event.GetApplicationID(), event.GetTaskID())
appID := event.GetApplicationID()
taskID := event.GetTaskID()
task := ctx.getTask(appID, taskID)
if task == nil {
log.Log(log.ShimContext).Error("failed to handle application event")
log.Log(log.ShimContext).Error("failed to handle task event, task does not exist",
zap.String("applicationID", appID),
zap.String("taskID", taskID))
return
}

if task.canHandle(event) {
if err := task.handle(event); err != nil {
log.Log(log.ShimContext).Error("failed to handle task event",
zap.String("applicationID", task.applicationID),
zap.String("taskID", task.taskID),
zap.String("applicationID", appID),
zap.String("taskID", taskID),
zap.String("event", event.GetEvent()),
zap.Error(err))
}
return
}

log.Log(log.ShimContext).Error("task event cannot be handled in the current state",
zap.String("applicationID", appID),
zap.String("taskID", taskID),
zap.String("event", event.GetEvent()),
zap.String("state", task.sm.Current()))
return
}

log.Log(log.ShimContext).Error("could not handle task event",
zap.String("type", reflect.TypeOf(obj).Name()))
}
}

Expand Down

0 comments on commit 6f601c0

Please sign in to comment.