Skip to content

Commit 59cb432

Browse files
committed
OrderJob Elastic
1 parent 3a32110 commit 59cb432

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

pkg/scheduler/plugins/elastic/elastic.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ func JobOrderFn(l, r interface{}) int {
2929
lv := l.(*podgroup_info.PodGroupInfo)
3030
rv := r.(*podgroup_info.PodGroupInfo)
3131

32-
lvAllocatedCount := int32(lv.GetActiveAllocatedTasksCount())
33-
rvAllocatedCount := int32(rv.GetActiveAllocatedTasksCount())
32+
lvBelowMinAvailable, lvAboveMinAvailable, lvExactlyAtMinAvailable := minAvailableState(lv)
33+
rvBelowMinAvailable, rvAboveMinAvailable, rvExactlyAtMinAvailable := minAvailableState(rv)
3434

35-
if lvAllocatedCount < lv.GetDefaultMinAvailable() && rvAllocatedCount >= rv.GetDefaultMinAvailable() {
35+
if lvBelowMinAvailable && !rvBelowMinAvailable {
3636
return -1
3737
}
3838

39-
if lvAllocatedCount == lv.GetDefaultMinAvailable() && rvAllocatedCount > rv.GetDefaultMinAvailable() {
39+
if lvExactlyAtMinAvailable && rvAboveMinAvailable {
4040
return -1
4141
}
4242

43-
if lvAllocatedCount >= lv.GetDefaultMinAvailable() && rvAllocatedCount < rv.GetDefaultMinAvailable() {
43+
if !lvBelowMinAvailable && rvBelowMinAvailable {
4444
return 1
4545
}
4646

47-
if lvAllocatedCount > lv.GetDefaultMinAvailable() && rvAllocatedCount == rv.GetDefaultMinAvailable() {
47+
if lvAboveMinAvailable && rvExactlyAtMinAvailable {
4848
return 1
4949
}
5050

@@ -53,4 +53,23 @@ func JobOrderFn(l, r interface{}) int {
5353
return 0
5454
}
5555

56+
func minAvailableState(pgi *podgroup_info.PodGroupInfo) (bool, bool, bool) {
57+
underMinAvailable := false
58+
aboveMinAvailable := true
59+
exactlyAtMinAvailable := true
60+
for _, subGroup := range pgi.SubGroups {
61+
numAllocatedTasks := int32(subGroup.GetNumActiveAllocatedTasks())
62+
if numAllocatedTasks < subGroup.GetMinAvailable() {
63+
underMinAvailable = true
64+
aboveMinAvailable = false
65+
}
66+
if numAllocatedTasks == subGroup.GetMinAvailable() {
67+
aboveMinAvailable = false
68+
} else {
69+
exactlyAtMinAvailable = false
70+
}
71+
}
72+
return underMinAvailable, aboveMinAvailable, exactlyAtMinAvailable
73+
}
74+
5675
func (pp *elasticPlugin) OnSessionClose(_ *framework.Session) {}

pkg/scheduler/plugins/elastic/elastic_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestJobOrderFn(t *testing.T) {
6060
},
6161
lPods: []*pod_info.PodInfo{
6262
{
63+
UID: "pod-a-1",
6364
Name: "pod-a-1",
6465
Status: pod_status.Running,
6566
ResReq: resource_info.EmptyResourceRequirements(),
@@ -74,6 +75,7 @@ func TestJobOrderFn(t *testing.T) {
7475
},
7576
rPods: []*pod_info.PodInfo{
7677
{
78+
UID: "pod-a-2",
7779
Name: "pod-a-2",
7880
Status: pod_status.Running,
7981
ResReq: resource_info.EmptyResourceRequirements(),
@@ -94,6 +96,7 @@ func TestJobOrderFn(t *testing.T) {
9496
},
9597
lPods: []*pod_info.PodInfo{
9698
{
99+
UID: "pod-a-1",
97100
Name: "pod-a-1",
98101
Status: pod_status.Allocated,
99102
ResReq: resource_info.EmptyResourceRequirements(),
@@ -108,6 +111,7 @@ func TestJobOrderFn(t *testing.T) {
108111
},
109112
rPods: []*pod_info.PodInfo{
110113
{
114+
UID: "pod-a-2",
111115
Name: "pod-a-2",
112116
Status: pod_status.Running,
113117
ResReq: resource_info.EmptyResourceRequirements(),
@@ -128,6 +132,7 @@ func TestJobOrderFn(t *testing.T) {
128132
},
129133
lPods: []*pod_info.PodInfo{
130134
{
135+
UID: "pod-a-1",
131136
Name: "pod-a-1",
132137
Status: pod_status.Bound,
133138
ResReq: resource_info.EmptyResourceRequirements(),
@@ -142,6 +147,7 @@ func TestJobOrderFn(t *testing.T) {
142147
},
143148
rPods: []*pod_info.PodInfo{
144149
{
150+
UID: "pod-a-2",
145151
Name: "pod-a-2",
146152
Status: pod_status.Running,
147153
ResReq: resource_info.EmptyResourceRequirements(),
@@ -162,6 +168,7 @@ func TestJobOrderFn(t *testing.T) {
162168
},
163169
lPods: []*pod_info.PodInfo{
164170
{
171+
UID: "pod-a-1",
165172
Name: "pod-a-1",
166173
Status: pod_status.Releasing,
167174
ResReq: resource_info.EmptyResourceRequirements(),
@@ -176,6 +183,7 @@ func TestJobOrderFn(t *testing.T) {
176183
},
177184
rPods: []*pod_info.PodInfo{
178185
{
186+
UID: "pod-a-2",
179187
Name: "pod-a-2",
180188
Status: pod_status.Running,
181189
ResReq: resource_info.EmptyResourceRequirements(),
@@ -196,6 +204,7 @@ func TestJobOrderFn(t *testing.T) {
196204
},
197205
lPods: []*pod_info.PodInfo{
198206
{
207+
UID: "pod-a-1",
199208
Name: "pod-a-1",
200209
Status: pod_status.Running,
201210
ResReq: resource_info.EmptyResourceRequirements(),
@@ -222,6 +231,7 @@ func TestJobOrderFn(t *testing.T) {
222231
},
223232
lPods: []*pod_info.PodInfo{
224233
{
234+
UID: "pod-a-1",
225235
Name: "pod-a-1",
226236
Status: pod_status.Running,
227237
ResReq: resource_info.EmptyResourceRequirements(),
@@ -236,11 +246,13 @@ func TestJobOrderFn(t *testing.T) {
236246
},
237247
rPods: []*pod_info.PodInfo{
238248
{
249+
UID: "pod-a-2",
239250
Name: "pod-a-2",
240251
Status: pod_status.Running,
241252
ResReq: resource_info.EmptyResourceRequirements(),
242253
},
243254
{
255+
UID: "pod-b-2",
244256
Name: "pod-b-2",
245257
Status: pod_status.Running,
246258
ResReq: resource_info.EmptyResourceRequirements(),
@@ -261,6 +273,7 @@ func TestJobOrderFn(t *testing.T) {
261273
},
262274
lPods: []*pod_info.PodInfo{
263275
{
276+
UID: "pod-a-1",
264277
Name: "pod-a-1",
265278
Status: pod_status.Running,
266279
ResReq: resource_info.EmptyResourceRequirements(),
@@ -275,16 +288,19 @@ func TestJobOrderFn(t *testing.T) {
275288
},
276289
rPods: []*pod_info.PodInfo{
277290
{
291+
UID: "pod-a-2",
278292
Name: "pod-a-2",
279293
Status: pod_status.Running,
280294
ResReq: resource_info.EmptyResourceRequirements(),
281295
},
282296
{
297+
UID: "pod-b-2",
283298
Name: "pod-b-2",
284299
Status: pod_status.Running,
285300
ResReq: resource_info.EmptyResourceRequirements(),
286301
},
287302
{
303+
UID: "pod-b-3",
288304
Name: "pod-b-3",
289305
Status: pod_status.Running,
290306
ResReq: resource_info.EmptyResourceRequirements(),
@@ -305,6 +321,7 @@ func TestJobOrderFn(t *testing.T) {
305321
},
306322
lPods: []*pod_info.PodInfo{
307323
{
324+
UID: "pod-a-1",
308325
Name: "pod-a-1",
309326
Status: pod_status.Running,
310327
ResReq: resource_info.EmptyResourceRequirements(),
@@ -319,11 +336,13 @@ func TestJobOrderFn(t *testing.T) {
319336
},
320337
rPods: []*pod_info.PodInfo{
321338
{
339+
UID: "pod-a-2",
322340
Name: "pod-a-2",
323341
Status: pod_status.Running,
324342
ResReq: resource_info.EmptyResourceRequirements(),
325343
},
326344
{
345+
UID: "pod-b-2",
327346
Name: "pod-b-2",
328347
Status: pod_status.Running,
329348
ResReq: resource_info.EmptyResourceRequirements(),
@@ -344,6 +363,7 @@ func TestJobOrderFn(t *testing.T) {
344363
},
345364
lPods: []*pod_info.PodInfo{
346365
{
366+
UID: "pod-a-1",
347367
Name: "pod-a-1",
348368
Status: pod_status.Running,
349369
ResReq: resource_info.EmptyResourceRequirements(),
@@ -358,11 +378,13 @@ func TestJobOrderFn(t *testing.T) {
358378
},
359379
rPods: []*pod_info.PodInfo{
360380
{
381+
UID: "pod-a-2",
361382
Name: "pod-a-2",
362383
Status: pod_status.Running,
363384
ResReq: resource_info.EmptyResourceRequirements(),
364385
},
365386
{
387+
UID: "pod-b-2",
366388
Name: "pod-b-2",
367389
Status: pod_status.Running,
368390
ResReq: resource_info.EmptyResourceRequirements(),
@@ -383,11 +405,13 @@ func TestJobOrderFn(t *testing.T) {
383405
},
384406
lPods: []*pod_info.PodInfo{
385407
{
408+
UID: "pod-a-1",
386409
Name: "pod-a-1",
387410
Status: pod_status.Running,
388411
ResReq: resource_info.EmptyResourceRequirements(),
389412
},
390413
{
414+
UID: "pod-a-2",
391415
Name: "pod-a-2",
392416
Status: pod_status.Running,
393417
ResReq: resource_info.EmptyResourceRequirements(),
@@ -402,6 +426,7 @@ func TestJobOrderFn(t *testing.T) {
402426
},
403427
rPods: []*pod_info.PodInfo{
404428
{
429+
UID: "pod-a-2",
405430
Name: "pod-a-2",
406431
Status: pod_status.Running,
407432
ResReq: resource_info.EmptyResourceRequirements(),
@@ -422,11 +447,13 @@ func TestJobOrderFn(t *testing.T) {
422447
},
423448
lPods: []*pod_info.PodInfo{
424449
{
450+
UID: "pod-a-1",
425451
Name: "pod-a-1",
426452
Status: pod_status.Running,
427453
ResReq: resource_info.EmptyResourceRequirements(),
428454
},
429455
{
456+
UID: "pod-a-2",
430457
Name: "pod-a-2",
431458
Status: pod_status.Running,
432459
ResReq: resource_info.EmptyResourceRequirements(),
@@ -441,6 +468,7 @@ func TestJobOrderFn(t *testing.T) {
441468
},
442469
rPods: []*pod_info.PodInfo{
443470
{
471+
UID: "pod-a-2",
444472
Name: "pod-a-2",
445473
Status: pod_status.Running,
446474
ResReq: resource_info.EmptyResourceRequirements(),

0 commit comments

Comments
 (0)