Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 17 additions & 42 deletions internal/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/clock"
"k8s.io/utils/ptr"

"github.com/armadaproject/armada/internal/common/armadacontext"
"github.com/armadaproject/armada/internal/common/constants"
Expand Down Expand Up @@ -800,10 +801,7 @@ func AppendEventSequencesFromPreemptedJobs(eventSequences []*armadaevents.EventS
if run == nil {
return nil, errors.Errorf("attempting to generate preempted eventSequences for job %s with no associated runs", jctx.JobId)
}
var requestor string
if requestorPtr := run.PreemptUser(); requestorPtr != nil {
requestor = *requestorPtr
}
requestor := ptr.Deref(run.PreemptUser(), "")
eventSequences = append(eventSequences, &armadaevents.EventSequence{
Queue: jctx.Job.Queue(),
JobSetName: jctx.Job.Jobset(),
Expand Down Expand Up @@ -984,10 +982,7 @@ func AppendEventSequencesFromReconciliationFailureJobs(eventSequences []*armadae
if run == nil {
return nil, errors.Errorf("attempting to generate reconciliation preemption eventSequences for job %s with no associated runs", jobInfo.Job.Id())
}
var requestor string
if requestorPtr := run.PreemptUser(); requestorPtr != nil {
requestor = *requestorPtr
}
requestor := ptr.Deref(run.PreemptUser(), "")
es := &armadaevents.EventSequence{
Queue: jobInfo.Job.Queue(),
JobSetName: jobInfo.Job.Jobset(),
Expand Down Expand Up @@ -1186,7 +1181,6 @@ func (s *Scheduler) buildQueueRetryPolicyMap(ctx *armadacontext.Context) map[str
// If there are no state changes it returns nil.
func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, job *jobdb.Job, jobRunErrors map[string]*armadaevents.Error, queueRetryPolicies map[string]string, txn *jobdb.Txn) (*armadaevents.EventSequence, error) {
var events []*armadaevents.EventSequence_Event
var sequenceUserId string

// Is the job already in a terminal state? If so then don't send any more messages
if job.InTerminalState() {
Expand All @@ -1197,18 +1191,14 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo

if job.RequestedPriority() != job.Priority() {
job = job.WithPriority(job.RequestedPriority())
if reprioritiseUserPtr := job.ReprioritiseUser(); reprioritiseUserPtr != nil {
if sequenceUserId == "" {
sequenceUserId = *reprioritiseUserPtr
}
}
requestor := ptr.Deref(job.ReprioritiseUser(), "")
jobReprioritised := &armadaevents.EventSequence_Event{
Created: s.now(),
Event: &armadaevents.EventSequence_Event_ReprioritisedJob{
ReprioritisedJob: &armadaevents.ReprioritisedJob{
JobId: job.Id(),
Priority: job.Priority(),
Requestor: sequenceUserId,
Requestor: requestor,
},
},
}
Expand All @@ -1217,13 +1207,7 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo

// Has the job been requested cancelled. If so, cancel the job
if job.CancelRequested() {
var cancelUser string
if cancelUserPtr := job.CancelUser(); cancelUserPtr != nil {
cancelUser = *cancelUserPtr
}
if sequenceUserId == "" {
sequenceUserId = cancelUser
}
requestor := ptr.Deref(job.CancelUser(), "")
var cancelReason string
if cancelReasonPtr := job.CancelReason(); cancelReasonPtr != nil {
cancelReason = *cancelReasonPtr
Expand All @@ -1238,7 +1222,7 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
JobRunCancelled: &armadaevents.JobRunCancelled{
RunId: lastRun.Id(),
JobId: job.Id(),
Requestor: cancelUser,
Requestor: requestor,
Reason: cancelReason,
},
},
Expand All @@ -1250,28 +1234,25 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
Event: &armadaevents.EventSequence_Event_CancelledJob{
CancelledJob: &armadaevents.CancelledJob{
JobId: job.Id(),
Requestor: cancelUser,
Requestor: requestor,
},
},
}
events = append(events, cancel)
} else if job.CancelByJobsetRequested() {
job = job.WithQueued(false).WithoutTerminal().WithCancelled(true)
var cancelUser string
if cancelUserPtr := job.CancelUser(); cancelUserPtr != nil {
cancelUser = *cancelUserPtr
}
if sequenceUserId == "" {
sequenceUserId = cancelUser
}
requestor := ptr.Deref(job.CancelUser(), "")
var cancelReason string
if cancelReasonPtr := job.CancelReason(); cancelReasonPtr != nil {
cancelReason = *cancelReasonPtr
}
cancelRequest := &armadaevents.EventSequence_Event{
Created: s.now(),
Event: &armadaevents.EventSequence_Event_CancelJob{
CancelJob: &armadaevents.CancelJob{JobId: job.Id()},
CancelJob: &armadaevents.CancelJob{
JobId: job.Id(),
Requestor: requestor,
},
},
}
events = append(events, cancelRequest)
Expand All @@ -1286,7 +1267,7 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
JobRunCancelled: &armadaevents.JobRunCancelled{
RunId: lastRun.Id(),
JobId: job.Id(),
Requestor: cancelUser,
Requestor: requestor,
Reason: cancelReason,
},
},
Expand All @@ -1298,7 +1279,8 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
Event: &armadaevents.EventSequence_Event_CancelledJob{
CancelledJob: &armadaevents.CancelledJob{
JobId: job.Id(),
Requestor: cancelUser,
Requestor: requestor,
Reason: cancelReason,
},
},
}
Expand Down Expand Up @@ -1499,13 +1481,7 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
if lastRun.PreemptReason() != nil && *lastRun.PreemptReason() != "" {
reason = *lastRun.PreemptReason()
}
var requestor string
if requestorPtr := lastRun.PreemptUser(); requestorPtr != nil {
requestor = *requestorPtr
if sequenceUserId == "" {
sequenceUserId = requestor
}
}
requestor := ptr.Deref(lastRun.PreemptUser(), "")
events = append(events, createEventsForPreemptedJob(job.Id(), lastRun.Id(), "", reason, requestor, s.clock.Now())...)
s.metrics.ReportJobPreemptedWithType(job, schedulercontext.PreemptedViaApi)
}
Expand All @@ -1524,7 +1500,6 @@ func (s *Scheduler) generateUpdateMessagesFromJob(ctx *armadacontext.Context, jo
return &armadaevents.EventSequence{
Queue: job.Queue(),
JobSetName: job.Jobset(),
UserId: sequenceUserId,
Events: events,
Comment thread
greptile-apps[bot] marked this conversation as resolved.
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions internal/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,8 @@ func subtractEventsFromOutstandingEventsByType(eventSequences []*armadaevents.Ev

requestor := eventSequence.UserId
switch e := event.Event.(type) {
case *armadaevents.EventSequence_Event_CancelJob:
requestor = e.CancelJob.Requestor
case *armadaevents.EventSequence_Event_CancelledJob:
requestor = e.CancelledJob.Requestor
case *armadaevents.EventSequence_Event_ReprioritisedJob:
Expand Down Expand Up @@ -3155,7 +3157,6 @@ func TestCycleConsistency(t *testing.T) {
{
Queue: queuedJobA.Queue,
JobSetName: queuedJobA.JobSet,
UserId: "cancel-user-a",
Events: []*armadaevents.EventSequence_Event{
{
Created: &types.Timestamp{},
Expand Down Expand Up @@ -3185,13 +3186,13 @@ func TestCycleConsistency(t *testing.T) {
{
Queue: queuedJobA.Queue,
JobSetName: queuedJobA.JobSet,
UserId: "cancel-user-a",
Events: []*armadaevents.EventSequence_Event{
{
Created: &types.Timestamp{},
Event: &armadaevents.EventSequence_Event_CancelJob{
CancelJob: &armadaevents.CancelJob{
JobId: queuedJobA.JobID,
JobId: queuedJobA.JobID,
Requestor: "cancel-user-a",
},
},
},
Expand Down Expand Up @@ -3229,7 +3230,6 @@ func TestCycleConsistency(t *testing.T) {
{
Queue: queuedJobA.Queue,
JobSetName: queuedJobA.JobSet,
UserId: "cancel-user-a",
Events: []*armadaevents.EventSequence_Event{
{
Created: &types.Timestamp{},
Expand Down Expand Up @@ -3275,13 +3275,13 @@ func TestCycleConsistency(t *testing.T) {
{
Queue: queuedJobA.Queue,
JobSetName: queuedJobA.JobSet,
UserId: "cancel-user-a",
Events: []*armadaevents.EventSequence_Event{
{
Created: &types.Timestamp{},
Event: &armadaevents.EventSequence_Event_CancelJob{
CancelJob: &armadaevents.CancelJob{
JobId: queuedJobA.JobID,
JobId: queuedJobA.JobID,
Requestor: "cancel-user-a",
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion internal/server/event/conversion/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func FromInternalPreemptionRequested(userId string, queueName string, jobSetName
}

func FromInternalCancel(userId string, queueName string, jobSetName string, time time.Time, e *armadaevents.CancelJob) ([]*api.EventMessage, error) {
requestor := userId
if e.Requestor != "" {
requestor = e.Requestor
}
return []*api.EventMessage{
{
Events: &api.EventMessage_Cancelling{
Expand All @@ -137,7 +141,7 @@ func FromInternalCancel(userId string, queueName string, jobSetName string, time
JobSetId: jobSetName,
Queue: queueName,
Created: protoutil.ToTimestamp(time),
Requestor: userId,
Requestor: requestor,
},
},
},
Expand Down
Loading
Loading