-
Notifications
You must be signed in to change notification settings - Fork 129
/
common.go
61 lines (57 loc) · 1.74 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package scheduler
import (
"fmt"
"golang.org/x/exp/maps"
armadamaps "github.com/armadaproject/armada/internal/common/maps"
armadaslices "github.com/armadaproject/armada/internal/common/slices"
schedulercontext "github.com/armadaproject/armada/internal/scheduler/context"
"github.com/armadaproject/armada/internal/scheduler/interfaces"
"github.com/armadaproject/armada/internal/scheduler/schedulerobjects"
)
// JobsSummary returns a string giving an overview of the provided jobs meant for logging.
// For example: "affected queues [A, B]; resources {A: {cpu: 1}, B: {cpu: 2}}; jobs [jobAId, jobBId]".
func JobsSummary(jctxs []*schedulercontext.JobSchedulingContext) string {
if len(jctxs) == 0 {
return ""
}
jobsByQueue := armadaslices.MapAndGroupByFuncs(
jctxs,
func(jctx *schedulercontext.JobSchedulingContext) string {
return jctx.Job.GetQueue()
},
func(jctx *schedulercontext.JobSchedulingContext) interfaces.LegacySchedulerJob {
return jctx.Job
},
)
resourcesByQueue := armadamaps.MapValues(
jobsByQueue,
func(jobs []interfaces.LegacySchedulerJob) schedulerobjects.ResourceList {
rv := schedulerobjects.NewResourceListWithDefaultSize()
for _, job := range jobs {
rv.AddV1ResourceList(job.GetResourceRequirements().Requests)
}
return rv
},
)
jobIdsByQueue := armadamaps.MapValues(
jobsByQueue,
func(jobs []interfaces.LegacySchedulerJob) []string {
rv := make([]string, len(jobs))
for i, job := range jobs {
rv[i] = job.GetId()
}
return rv
},
)
return fmt.Sprintf(
"affected queues %v; resources %v; jobs %v",
maps.Keys(jobsByQueue),
armadamaps.MapValues(
resourcesByQueue,
func(rl schedulerobjects.ResourceList) string {
return rl.CompactString()
},
),
jobIdsByQueue,
)
}