This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new b516ca13 [YUNIKORN-2204] Use ask unique id for allocation (#740)
b516ca13 is described below
commit b516ca13bf10df1e87a6350abe7ef39919ef6f07
Author: Manikandan R <[email protected]>
AuthorDate: Thu Nov 30 19:45:04 2023 +1100
[YUNIKORN-2204] Use ask unique id for allocation (#740)
Do not generate a new UUID for an allocation when it gets added. Re-use
the ask key which is the same as the K8s pod UID to improve on the
troubleshooting experience.
The new allocationID will be the ask key followed by the current repeat
counter, seperated by a dash '-'
The UUID is renamed to allocationID on the allocation. Scheduler
interface changes will follow. Replaced GetUUID with GetAllocationID in
already modified lines
Closes: #740
Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
pkg/scheduler/health_checker_test.go | 4 +-
pkg/scheduler/objects/allocation.go | 37 ++++--
pkg/scheduler/objects/allocation_ask.go | 7 ++
pkg/scheduler/objects/allocation_test.go | 11 +-
pkg/scheduler/objects/application.go | 7 +-
pkg/scheduler/objects/application_events_test.go | 12 +-
pkg/scheduler/objects/application_test.go | 140 ++++++++++-----------
pkg/scheduler/objects/node_collection_test.go | 9 +-
pkg/scheduler/objects/node_test.go | 57 +++++----
pkg/scheduler/objects/nodesorting_test.go | 7 +-
pkg/scheduler/objects/preemption_test.go | 14 +--
pkg/scheduler/objects/queue_test.go | 10 +-
.../objects/required_node_preemptor_test.go | 20 +--
pkg/scheduler/objects/utilities_test.go | 8 +-
pkg/scheduler/partition_test.go | 69 +++++-----
pkg/scheduler/tests/smoke_test.go | 4 +-
pkg/webservice/handlers_test.go | 27 ++--
17 files changed, 235 insertions(+), 208 deletions(-)
diff --git a/pkg/scheduler/health_checker_test.go
b/pkg/scheduler/health_checker_test.go
index a8043ed3..a3f97f2a 100644
--- a/pkg/scheduler/health_checker_test.go
+++ b/pkg/scheduler/health_checker_test.go
@@ -200,7 +200,7 @@ func TestGetSchedulerHealthStatusContext(t *testing.T) {
// add orphan allocation to a node
node := schedulerContext.partitions[partName].nodes.GetNode("node")
- alloc := objects.NewAllocation(allocID, "node", newAllocationAsk("key",
"appID", resources.NewResource()))
+ alloc := objects.NewAllocation("node", newAllocationAsk("key", "appID",
resources.NewResource()))
node.AddAllocation(alloc)
healthInfo = GetSchedulerHealthStatus(schedulerMetrics,
schedulerContext)
assert.Assert(t, !healthInfo.Healthy, "Scheduler should not be healthy")
@@ -216,7 +216,7 @@ func TestGetSchedulerHealthStatusContext(t *testing.T) {
assert.Assert(t, healthInfo.HealthChecks[9].Succeeded, "The orphan
allocation check on the node should be successful")
// remove the allocation from the node, so we will have an orphan
allocation assigned to the app
- node.RemoveAllocation(allocID)
+ node.RemoveAllocation("key-0")
healthInfo = GetSchedulerHealthStatus(schedulerMetrics,
schedulerContext)
assert.Assert(t, healthInfo.HealthChecks[9].Succeeded, "The orphan
allocation check on the node should be successful")
assert.Assert(t, !healthInfo.HealthChecks[10].Succeeded, "The orphan
allocation check on the app should not be successful")
diff --git a/pkg/scheduler/objects/allocation.go
b/pkg/scheduler/objects/allocation.go
index b81991a0..6d9eeb04 100644
--- a/pkg/scheduler/objects/allocation.go
+++ b/pkg/scheduler/objects/allocation.go
@@ -57,7 +57,7 @@ type Allocation struct {
taskGroupName string // task group this allocation belongs to
placeholder bool // is this a placeholder allocation
nodeID string
- uuid string
+ allocationID string
priority int32
tags map[string]string
allocatedResource *resources.Resource
@@ -77,7 +77,7 @@ type Allocation struct {
sync.RWMutex
}
-func NewAllocation(uuid, nodeID string, ask *AllocationAsk) *Allocation {
+func NewAllocation(nodeID string, ask *AllocationAsk) *Allocation {
var createTime time.Time
if ask.GetTag(siCommon.CreationTime) == "" {
createTime = time.Now()
@@ -92,7 +92,7 @@ func NewAllocation(uuid, nodeID string, ask *AllocationAsk)
*Allocation {
bindTime: time.Now(),
nodeID: nodeID,
partitionName:
common.GetPartitionNameWithoutClusterID(ask.GetPartitionName()),
- uuid: uuid,
+ allocationID: ask.allocationKey + "-" +
strconv.Itoa(ask.completedPendingAsk()),
tags: ask.GetTagsClone(),
priority: ask.GetPriority(),
allocatedResource: ask.GetAllocatedResource().Clone(),
@@ -103,14 +103,16 @@ func NewAllocation(uuid, nodeID string, ask
*AllocationAsk) *Allocation {
}
func newReservedAllocation(nodeID string, ask *AllocationAsk) *Allocation {
- alloc := NewAllocation("", nodeID, ask)
+ alloc := NewAllocation(nodeID, ask)
+ alloc.allocationID = ""
alloc.SetBindTime(time.Time{})
alloc.SetResult(Reserved)
return alloc
}
func newUnreservedAllocation(nodeID string, ask *AllocationAsk) *Allocation {
- alloc := NewAllocation("", nodeID, ask)
+ alloc := NewAllocation(nodeID, ask)
+ alloc.allocationID = ""
alloc.SetBindTime(time.Time{})
alloc.SetResult(Unreserved)
return alloc
@@ -152,7 +154,9 @@ func NewAllocationFromSI(alloc *si.Allocation) *Allocation {
createTime: time.Unix(creationTime, 0),
allocLog: make(map[string]*AllocationLogEntry),
}
- return NewAllocation(alloc.UUID, alloc.NodeID, ask)
+ newAlloc := NewAllocation(alloc.NodeID, ask)
+ newAlloc.allocationID = alloc.UUID
+ return newAlloc
}
// Convert the Allocation into a SI object. This is a limited set of values
that gets copied into the SI.
@@ -180,11 +184,11 @@ func (a *Allocation) String() string {
}
a.RLock()
defer a.RUnlock()
- uuid := a.uuid
+ allocationID := a.allocationID
if a.result == Reserved || a.result == Unreserved {
- uuid = "N/A"
+ allocationID = "N/A"
}
- return fmt.Sprintf("applicationID=%s, uuid=%s, allocationKey=%s,
Node=%s, result=%s", a.applicationID, uuid, a.allocationKey, a.nodeID,
a.result.String())
+ return fmt.Sprintf("applicationID=%s, uuid=%s, allocationKey=%s,
Node=%s, result=%s", a.applicationID, allocationID, a.allocationKey, a.nodeID,
a.result.String())
}
// GetAsk returns the ask associated with this allocation
@@ -290,9 +294,20 @@ func (a *Allocation) GetInstanceType() string {
return a.instType
}
-// GetUUID returns the uuid for this allocation
+// GetAllocationID returns the allocationID for this allocation
+func (a *Allocation) GetAllocationID() string {
+ return a.allocationID
+}
+
+// GetUUID returns the allocationID for this allocation
func (a *Allocation) GetUUID() string {
- return a.uuid
+ return a.allocationID
+}
+
+// SetAllocationID set the allocationID for this allocation
+// only for tests
+func (a *Allocation) SetAllocationID(allocationID string) {
+ a.allocationID = allocationID
}
// GetPriority returns the priority of this allocation
diff --git a/pkg/scheduler/objects/allocation_ask.go
b/pkg/scheduler/objects/allocation_ask.go
index d116b687..98b34f2b 100644
--- a/pkg/scheduler/objects/allocation_ask.go
+++ b/pkg/scheduler/objects/allocation_ask.go
@@ -291,3 +291,10 @@ func (aa *AllocationAsk) LessThan(other *AllocationAsk)
bool {
return aa.priority < other.priority
}
+
+// completedPendingAsk How many pending asks has been completed or processed
so far?
+func (aa *AllocationAsk) completedPendingAsk() int {
+ aa.RLock()
+ defer aa.RUnlock()
+ return int(aa.maxAllocations - aa.pendingAskRepeat)
+}
diff --git a/pkg/scheduler/objects/allocation_test.go
b/pkg/scheduler/objects/allocation_test.go
index ae6baa6c..ba16d402 100644
--- a/pkg/scheduler/objects/allocation_test.go
+++ b/pkg/scheduler/objects/allocation_test.go
@@ -50,10 +50,11 @@ func TestNewAlloc(t *testing.T) {
res, err := resources.NewResourceFromConf(map[string]string{"first":
"1"})
assert.NilError(t, err, "Resource creation failed")
ask := newAllocationAsk("ask-1", "app-1", res)
- alloc := NewAllocation("test-uuid", "node-1", ask)
+ alloc := NewAllocation("node-1", ask)
if alloc == nil {
t.Fatal("NewAllocation create failed while it should not")
}
+ assert.Equal(t, alloc.GetAllocationID(), "ask-1-0")
assert.Equal(t, alloc.GetResult(), Allocated, "New alloc should default
to result Allocated")
assert.Assert(t, resources.Equals(alloc.GetAllocatedResource(), res),
"Allocated resource not set correctly")
assert.Assert(t, !alloc.IsPlaceholder(), "ask should not have been a
placeholder")
@@ -62,7 +63,7 @@ func TestNewAlloc(t *testing.T) {
alloc.SetInstanceType(instType1)
assert.Equal(t, alloc.GetInstanceType(), instType1, "Instance type not
set as expected")
allocStr := alloc.String()
- expected := "applicationID=app-1, uuid=test-uuid, allocationKey=ask-1,
Node=node-1, result=Allocated"
+ expected := "applicationID=app-1, uuid=ask-1-0, allocationKey=ask-1,
Node=node-1, result=Allocated"
assert.Equal(t, allocStr, expected, "Strings should have been equal")
assert.Assert(t, !alloc.IsPlaceholderUsed(), fmt.Sprintf("Alloc should
not be placeholder replacement by default: got %t, expected %t",
alloc.IsPlaceholderUsed(), false))
created := alloc.GetCreateTime()
@@ -77,7 +78,7 @@ func TestNewAlloc(t *testing.T) {
tags[siCommon.CreationTime] = strconv.FormatInt(past, 10)
ask.tags = CloneAllocationTags(tags)
ask.createTime = time.Unix(past, 0)
- alloc = NewAllocation("test-uuid", "node-1", ask)
+ alloc = NewAllocation("node-1", ask)
assert.Equal(t, alloc.GetCreateTime(), ask.GetCreateTime(), "createTime
was not copied from the ask")
}
@@ -131,13 +132,13 @@ func TestSIFromAlloc(t *testing.T) {
assert.NilError(t, err, "Resource creation failed")
expectedSI := &si.Allocation{
AllocationKey: "ask-1",
- UUID: "test-uuid",
+ UUID: "ask-1-0",
NodeID: "node-1",
ApplicationID: "app-1",
ResourcePerAlloc: res.ToProto(),
}
ask := newAllocationAsk("ask-1", "app-1", res)
- alloc := NewAllocation("test-uuid", "node-1", ask)
+ alloc := NewAllocation("node-1", ask)
if alloc == nil {
t.Fatal("NewAllocation create failed while it should not")
}
diff --git a/pkg/scheduler/objects/application.go
b/pkg/scheduler/objects/application.go
index 4d494f9c..bb4b4f2e 100644
--- a/pkg/scheduler/objects/application.go
+++ b/pkg/scheduler/objects/application.go
@@ -667,7 +667,6 @@ func (sa *Application) AddAllocationAsk(ask *AllocationAsk)
error {
zap.String("ask", ask.GetAllocationKey()),
zap.Bool("placeholder", ask.IsPlaceholder()),
zap.Stringer("pendingDelta", delta))
-
sa.sortedRequests.insert(ask)
sa.appEvents.sendNewAskEvent(ask)
@@ -1133,7 +1132,7 @@ func (sa *Application)
tryPlaceholderAllocate(nodeIterator func() NodeIterator,
// got the node run same checks as for reservation (all
but fits)
// resource usage should not change anyway between
placeholder and real one at this point
if node != nil && node.preReserveConditions(request) {
- alloc := NewAllocation(common.GetNewUUID(),
node.NodeID, request)
+ alloc := NewAllocation(node.NodeID, request)
// double link to make it easier to find
// alloc (the real one) releases points to the
placeholder in the releases list
alloc.SetRelease(ph)
@@ -1175,7 +1174,7 @@ func (sa *Application)
tryPlaceholderAllocate(nodeIterator func() NodeIterator,
return true
}
// allocation worked: on a non placeholder node update
result and return
- alloc := NewAllocation(common.GetNewUUID(),
node.NodeID, reqFit)
+ alloc := NewAllocation(node.NodeID, reqFit)
// double link to make it easier to find
// alloc (the real one) releases points to the
placeholder in the releases list
alloc.SetRelease(phFit)
@@ -1471,7 +1470,7 @@ func (sa *Application) tryNode(node *Node, ask
*AllocationAsk) *Allocation {
}
// everything OK really allocate
- alloc := NewAllocation(common.GetNewUUID(), node.NodeID, ask)
+ alloc := NewAllocation(node.NodeID, ask)
if node.AddAllocation(alloc) {
if err :=
sa.queue.IncAllocatedResource(alloc.GetAllocatedResource(), false); err != nil {
log.Log(log.SchedApplication).Warn("queue update failed
unexpectedly",
diff --git a/pkg/scheduler/objects/application_events_test.go
b/pkg/scheduler/objects/application_events_test.go
index c960d105..e91633d1 100644
--- a/pkg/scheduler/objects/application_events_test.go
+++ b/pkg/scheduler/objects/application_events_test.go
@@ -125,7 +125,7 @@ func TestSendNewAllocationEvent(t *testing.T) {
appEvents.sendNewAllocationEvent(&Allocation{
applicationID: appID0,
allocationKey: aKey,
- uuid: aUUID,
+ allocationID: aUUID,
})
assert.Equal(t, 1, len(mock.events), "event was not generated")
assert.Equal(t, si.EventRecord_APP, mock.events[0].Type, "event type is
not expected")
@@ -188,7 +188,7 @@ func TestSendRemoveAllocationEvent(t *testing.T) {
name: "remove allocation cause of node
removal",
eventSystemMock: newEventSystemMock(),
terminationType:
si.TerminationType_UNKNOWN_TERMINATION_TYPE,
- allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, uuid: aUUID},
+ allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, allocationID: aUUID},
expectedEventCnt: 1,
expectedType: si.EventRecord_APP,
expectedChangeType: si.EventRecord_REMOVE,
@@ -200,7 +200,7 @@ func TestSendRemoveAllocationEvent(t *testing.T) {
name: "remove allocation cause of
resource manager cancel",
eventSystemMock: newEventSystemMock(),
terminationType: si.TerminationType_STOPPED_BY_RM,
- allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, uuid: aUUID},
+ allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, allocationID: aUUID},
expectedEventCnt: 1,
expectedType: si.EventRecord_APP,
expectedChangeType: si.EventRecord_REMOVE,
@@ -212,7 +212,7 @@ func TestSendRemoveAllocationEvent(t *testing.T) {
name: "remove allocation cause of
timeout",
eventSystemMock: newEventSystemMock(),
terminationType: si.TerminationType_TIMEOUT,
- allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, uuid: aUUID},
+ allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, allocationID: aUUID},
expectedEventCnt: 1,
expectedType: si.EventRecord_APP,
expectedChangeType: si.EventRecord_REMOVE,
@@ -224,7 +224,7 @@ func TestSendRemoveAllocationEvent(t *testing.T) {
name: "remove allocation cause of
preemption",
eventSystemMock: newEventSystemMock(),
terminationType:
si.TerminationType_PREEMPTED_BY_SCHEDULER,
- allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, uuid: aUUID},
+ allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, allocationID: aUUID},
expectedEventCnt: 1,
expectedType: si.EventRecord_APP,
expectedChangeType: si.EventRecord_REMOVE,
@@ -236,7 +236,7 @@ func TestSendRemoveAllocationEvent(t *testing.T) {
name: "remove allocation cause of
replacement",
eventSystemMock: newEventSystemMock(),
terminationType:
si.TerminationType_PLACEHOLDER_REPLACED,
- allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, uuid: aUUID},
+ allocation: &Allocation{applicationID:
appID0, allocationKey: aKey, allocationID: aUUID},
expectedEventCnt: 1,
expectedType: si.EventRecord_APP,
expectedChangeType: si.EventRecord_REMOVE,
diff --git a/pkg/scheduler/objects/application_test.go
b/pkg/scheduler/objects/application_test.go
index d52b86cd..48c05dec 100644
--- a/pkg/scheduler/objects/application_test.go
+++ b/pkg/scheduler/objects/application_test.go
@@ -688,12 +688,12 @@ func
TestRemovePlaceholderAllocationWithNoRealAllocation(t *testing.T) {
res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5})
ask := newAllocationAskRepeat(aKey, appID1, res, 2)
ask.placeholder = true
- allocInfo := NewAllocation("uuid-1", nodeID1, ask)
+ allocInfo := NewAllocation(nodeID1, ask)
app.AddAllocation(allocInfo)
err := app.handleApplicationEventWithLocking(RunApplication)
assert.NilError(t, err, "no error expected new to accepted")
- app.RemoveAllocation("uuid-1",
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
+ app.RemoveAllocation("alloc-1-0",
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
assert.Equal(t, app.stateMachine.Current(), Completing.String())
assertUserGroupResource(t, getTestUserGroup(), nil)
}
@@ -738,8 +738,7 @@ func TestStateChangeOnUpdate(t *testing.T) {
// app with ask should be accepted
assert.Assert(t, app.IsAccepted(), "Application did not change to
accepted state: %s", app.CurrentState())
// add an alloc
- uuid := "uuid-1"
- allocInfo := NewAllocation(uuid, nodeID1, ask)
+ allocInfo := NewAllocation(nodeID1, ask)
app.AddAllocation(allocInfo)
// app should be starting
assert.Assert(t, app.IsStarting(), "Application did not return starting
state after alloc: %s", app.CurrentState())
@@ -751,7 +750,7 @@ func TestStateChangeOnUpdate(t *testing.T) {
assert.Assert(t, app.IsStarting(), "Application should have stayed
same, changed unexpectedly: %s", app.CurrentState())
// remove the allocation, ask has been removed so nothing left
- app.RemoveAllocation(uuid, si.TerminationType_UNKNOWN_TERMINATION_TYPE)
+ app.RemoveAllocation(askID+"-0",
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
assert.Assert(t, app.IsCompleting(), "Application did not change as
expected: %s", app.CurrentState())
assertUserGroupResource(t, getTestUserGroup(), nil)
@@ -802,8 +801,7 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) {
// app with ask should be accepted
assert.Assert(t, app.IsAccepted(), "Application did not change to
accepted state: %s", app.CurrentState())
// add an alloc based on the placeholder ask
- uuid := "uuid-1"
- allocInfo := NewAllocation(uuid, nodeID1, ask)
+ allocInfo := NewAllocation(nodeID1, ask)
app.AddAllocation(allocInfo)
// app should be in the same state as it was before as it is a
placeholder allocation
assert.Assert(t, app.IsAccepted(), "Application did not return accepted
state after alloc: %s", app.CurrentState())
@@ -812,7 +810,7 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), res)
// first we have to remove the allocation itself
- alloc := app.RemoveAllocation(uuid,
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
+ alloc := app.RemoveAllocation(askID+"-0",
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
assert.Assert(t, alloc != nil, "Nil allocation was returned")
assert.Assert(t, app.IsAccepted(), "Application should have stayed in
Accepted, changed unexpectedly: %s", app.CurrentState())
// removing the ask should move the application into the waiting state,
because the allocation is only a placeholder allocation
@@ -839,7 +837,7 @@ func TestAllocations(t *testing.T) {
resMap := map[string]string{"memory": "100", "vcores": "10"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
if !resources.Equals(app.allocatedResource, res) {
t.Errorf("allocated resources is not updated correctly: %v",
app.allocatedResource)
@@ -850,16 +848,16 @@ func TestAllocations(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
// add more allocations to test the removals
- alloc = newAllocation(appID1, "uuid-2", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
- alloc = newAllocation(appID1, "uuid-3", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
allocs = app.GetAllAllocations()
assert.Equal(t, len(allocs), 3)
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
3))
// remove one of the 3
- if alloc = app.RemoveAllocation("uuid-2",
si.TerminationType_UNKNOWN_TERMINATION_TYPE); alloc == nil {
+ if alloc = app.RemoveAllocation(alloc.GetUUID(),
si.TerminationType_UNKNOWN_TERMINATION_TYPE); alloc == nil {
t.Error("returned allocations was nil allocation was not
removed")
}
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
@@ -896,7 +894,7 @@ func TestGangAllocChange(t *testing.T) {
var res *resources.Resource
res, err = resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
alloc.placeholder = true
app.AddAllocation(alloc)
assert.Assert(t, resources.Equals(app.allocatedPlaceholder, res),
"allocated placeholders resources is not updated correctly: %s",
app.allocatedPlaceholder.String())
@@ -905,7 +903,7 @@ func TestGangAllocChange(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), res)
// add second placeholder this should trigger state update
- alloc = newAllocation(appID1, "uuid-2", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
alloc.placeholder = true
app.AddAllocation(alloc)
assert.Assert(t, resources.Equals(app.allocatedPlaceholder, totalPH),
"allocated placeholders resources is not updated correctly: %s",
app.allocatedPlaceholder.String())
@@ -914,7 +912,7 @@ func TestGangAllocChange(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
// add a real alloc this should NOT trigger state update
- alloc = newAllocation(appID1, "uuid-3", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
alloc.SetResult(Replaced)
app.AddAllocation(alloc)
assert.Equal(t, len(app.GetAllAllocations()), 3)
@@ -922,7 +920,7 @@ func TestGangAllocChange(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
3))
// add a second real alloc this should trigger state update
- alloc = newAllocation(appID1, "uuid-4", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
alloc.SetResult(Replaced)
app.AddAllocation(alloc)
assert.Equal(t, len(app.GetAllAllocations()), 4)
@@ -943,7 +941,7 @@ func TestAllocChange(t *testing.T) {
resMap := map[string]string{"first": "2"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
// adding a normal allocation should change the state
app.AddAllocation(alloc)
assert.Assert(t, resources.Equals(app.allocatedResource, res),
"allocated resources is not updated correctly: %s",
app.allocatedResource.String())
@@ -952,7 +950,7 @@ func TestAllocChange(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), res)
// add a second real alloc this should trigger state update
- alloc = newAllocation(appID1, "uuid-2", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
assert.Equal(t, len(app.GetAllAllocations()), 2)
assert.Assert(t, app.IsRunning(), "app should have changed to running`
state")
@@ -1087,7 +1085,7 @@ func TestResourceUsageAggregation(t *testing.T) {
resMap := map[string]string{"memory": "100", "vcores": "10"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
alloc.SetInstanceType(instType1)
// Mock the time to be 3 seconds before
alloc.SetBindTime(time.Now().Add(-3 * time.Second))
@@ -1109,7 +1107,7 @@ func TestResourceUsageAggregation(t *testing.T) {
assertResourceUsage(t, appSummary, 0, 0)
// add more allocations to test the removals
- alloc = newAllocation(appID1, "uuid-2", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
alloc.SetInstanceType(instType1)
// Mock the time to be 3 seconds before
@@ -1118,7 +1116,7 @@ func TestResourceUsageAggregation(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
// remove one of the 2
- if alloc = app.RemoveAllocation("uuid-2",
si.TerminationType_UNKNOWN_TERMINATION_TYPE); alloc == nil {
+ if alloc = app.RemoveAllocation(alloc.GetUUID(),
si.TerminationType_UNKNOWN_TERMINATION_TYPE); alloc == nil {
t.Error("returned allocations was nil allocation was not
removed")
}
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
@@ -1127,7 +1125,7 @@ func TestResourceUsageAggregation(t *testing.T) {
appSummary.DoLogging()
assertResourceUsage(t, appSummary, 300, 30)
- alloc = newAllocation(appID1, "uuid-3", nodeID1, res)
+ alloc = newAllocation(appID1, nodeID1, res)
alloc.SetInstanceType(instType1)
app.AddAllocation(alloc)
allocs = app.GetAllAllocations()
@@ -1252,7 +1250,7 @@ func TestReplaceAllocation(t *testing.T) {
resMap := map[string]string{"memory": "100", "vcores": "10"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- ph := newPlaceholderAlloc(appID1, "uuid-1", nodeID1, res)
+ ph := newPlaceholderAlloc(appID1, nodeID1, res)
// add the placeholder to the app
app.AddAllocation(ph)
// add PlaceholderData
@@ -1270,7 +1268,7 @@ func TestReplaceAllocation(t *testing.T) {
t.Fatalf("placeholder allocation not updated as expected: got
%s, expected %s", app.allocatedPlaceholder, res)
}
assertUserGroupResource(t, getTestUserGroup(), res)
- alloc = app.ReplaceAllocation("uuid-1")
+ alloc = app.ReplaceAllocation(ph.GetUUID())
assert.Equal(t, alloc, nilAlloc, "placeholder without releases expected
nil to be returned got a real alloc: %s", alloc)
assert.Equal(t, app.placeholderData[""].Replaced, int64(0))
assertUserGroupResource(t, getTestUserGroup(), nil)
@@ -1282,10 +1280,10 @@ func TestReplaceAllocation(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), res)
// set the real one to replace the placeholder
- realAlloc := newAllocation(appID1, "uuid-2", nodeID1, res)
+ realAlloc := newAllocation(appID1, nodeID1, res)
realAlloc.SetResult(Replaced)
ph.AddRelease(realAlloc)
- alloc = app.ReplaceAllocation("uuid-1")
+ alloc = app.ReplaceAllocation(ph.GetUUID())
assert.Equal(t, alloc, ph, "returned allocation is not the placeholder")
assert.Assert(t, resources.IsZero(app.allocatedPlaceholder), "real
allocation counted as placeholder")
if !resources.Equals(app.allocatedResource, res) {
@@ -1304,13 +1302,13 @@ func TestReplaceAllocation(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
// set multiple real allocations to replace the placeholder
- realAlloc = newAllocation(appID1, "uuid-3", nodeID1, res)
+ realAlloc = newAllocation(appID1, nodeID1, res)
realAlloc.SetResult(Replaced)
ph.AddRelease(realAlloc)
- realAllocNoAdd := newAllocation(appID1, "not-added", nodeID1, res)
+ realAllocNoAdd := newAllocation(appID1, nodeID1, res)
realAllocNoAdd.SetResult(Replaced)
ph.AddRelease(realAlloc)
- alloc = app.ReplaceAllocation("uuid-1")
+ alloc = app.ReplaceAllocation(ph.GetUUID())
assert.Equal(t, alloc, ph, "returned allocation is not the placeholder")
assert.Assert(t, resources.IsZero(app.allocatedPlaceholder), "real
allocation counted as placeholder")
assert.Equal(t, app.placeholderData[""].Replaced, int64(2))
@@ -1334,9 +1332,9 @@ func TestReplaceAllocationTracking(t *testing.T) {
resMap := map[string]string{"memory": "100", "vcores": "10"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- ph1 := newPlaceholderAlloc(appID1, "uuid-1", nodeID1, res)
- ph2 := newPlaceholderAlloc(appID1, "uuid-2", nodeID1, res)
- ph3 := newPlaceholderAlloc(appID1, "uuid-3", nodeID1, res)
+ ph1 := newPlaceholderAlloc(appID1, nodeID1, res)
+ ph2 := newPlaceholderAlloc(appID1, nodeID1, res)
+ ph3 := newPlaceholderAlloc(appID1, nodeID1, res)
ph1.SetInstanceType(instType1)
ph2.SetInstanceType(instType1)
ph3.SetInstanceType(instType1)
@@ -1356,26 +1354,26 @@ func TestReplaceAllocationTracking(t *testing.T) {
ph3.SetBindTime(time.Now().Add(-10 * time.Second))
// replace placeholders
- realAlloc1 := newAllocation(appID1, "uuid-100", nodeID1, res)
+ realAlloc1 := newAllocation(appID1, nodeID1, res)
realAlloc1.SetResult(Replaced)
ph1.AddRelease(realAlloc1)
- alloc := app.ReplaceAllocation("uuid-1")
- app.RemoveAllocation("uuid-1", si.TerminationType_PLACEHOLDER_REPLACED)
- assert.Equal(t, "uuid-1", alloc.uuid)
+ alloc1 := app.ReplaceAllocation(ph1.GetUUID())
+ app.RemoveAllocation(ph1.GetUUID(),
si.TerminationType_PLACEHOLDER_REPLACED)
+ assert.Equal(t, ph1.GetUUID(), alloc1.GetUUID())
assert.Equal(t, true, app.HasPlaceholderAllocation())
- realAlloc2 := newAllocation(appID1, "uuid-200", nodeID1, res)
+ realAlloc2 := newAllocation(appID1, nodeID1, res)
realAlloc2.SetResult(Replaced)
ph2.AddRelease(realAlloc2)
- alloc = app.ReplaceAllocation("uuid-2")
- app.RemoveAllocation("uuid-2", si.TerminationType_PLACEHOLDER_REPLACED)
- assert.Equal(t, "uuid-2", alloc.uuid)
+ alloc2 := app.ReplaceAllocation(ph2.GetUUID())
+ app.RemoveAllocation(ph2.GetUUID(),
si.TerminationType_PLACEHOLDER_REPLACED)
+ assert.Equal(t, ph2.GetUUID(), alloc2.GetUUID())
assert.Equal(t, true, app.HasPlaceholderAllocation())
- realAlloc3 := newAllocation(appID1, "uuid-300", nodeID1, res)
+ realAlloc3 := newAllocation(appID1, nodeID1, res)
realAlloc3.SetResult(Replaced)
ph3.AddRelease(realAlloc3)
- alloc = app.ReplaceAllocation("uuid-3")
- app.RemoveAllocation("uuid-3", si.TerminationType_PLACEHOLDER_REPLACED)
- assert.Equal(t, "uuid-3", alloc.uuid)
+ alloc3 := app.ReplaceAllocation(ph3.GetUUID())
+ app.RemoveAllocation(ph3.GetUUID(),
si.TerminationType_PLACEHOLDER_REPLACED)
+ assert.Equal(t, ph3.GetUUID(), alloc3.GetUUID())
assert.Equal(t, false, app.HasPlaceholderAllocation())
// check placeholder resource usage
@@ -1426,12 +1424,12 @@ func runTimeoutPlaceholderTest(t *testing.T,
expectedState string, gangSchedulin
assert.DeepEqual(t, app.placeholderData[tg1].MinResource, res)
// add the placeholder to the app
- ph := newPlaceholderAlloc(appID1, "uuid-1", nodeID1, res)
+ ph := newPlaceholderAlloc(appID1, nodeID1, res)
app.AddAllocation(ph)
assertUserGroupResource(t, getTestUserGroup(), res)
assert.Assert(t, app.getPlaceholderTimer() != nil, "Placeholder timer
should be initiated after the first placeholder allocation")
// add a second one to check the filter
- ph = newPlaceholderAlloc(appID1, "uuid-2", nodeID1, res)
+ ph = newPlaceholderAlloc(appID1, nodeID1, res)
app.AddAllocation(ph)
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
err = common.WaitFor(10*time.Millisecond, 1*time.Second, func() bool {
@@ -1488,7 +1486,7 @@ func TestTimeoutPlaceholderAllocReleased(t *testing.T) {
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "Unexpected error when creating resource from
map")
// add the placeholders to the app: one released, one still available.
- ph := newPlaceholderAlloc(appID1, "released", nodeID1, res)
+ ph := newPlaceholderAlloc(appID1, nodeID1, res)
ph.SetReleased(true)
app.AddAllocation(ph)
// add PlaceholderData
@@ -1502,13 +1500,13 @@ func TestTimeoutPlaceholderAllocReleased(t *testing.T) {
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
assert.Assert(t, app.getPlaceholderTimer() != nil, "Placeholder timer
should be initiated after the first placeholder allocation")
- ph = newPlaceholderAlloc(appID1, "waiting", nodeID1, res)
+ ph = newPlaceholderAlloc(appID1, nodeID1, res)
app.AddAllocation(ph)
app.addPlaceholderDataWithLocking(ph.GetAsk())
assert.Equal(t, app.placeholderData[""].Count, int64(2))
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
- alloc := newAllocation(appID1, "real", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
assert.Assert(t, app.IsStarting(), "App should be in starting state
after the first allocation")
err = common.WaitFor(10*time.Millisecond, 1*time.Second, func() bool {
@@ -1523,7 +1521,7 @@ func TestTimeoutPlaceholderAllocReleased(t *testing.T) {
for _, event := range events {
if allocRelease, ok :=
event.(*rmevent.RMReleaseAllocationEvent); ok {
assert.Equal(t, len(allocRelease.ReleasedAllocations),
1, "one allocation should have been released")
- assert.Equal(t,
allocRelease.ReleasedAllocations[0].UUID, "waiting", "wrong placeholder
allocation released on timeout")
+ assert.Equal(t,
allocRelease.ReleasedAllocations[0].UUID, ph.allocationID, "wrong placeholder
allocation released on timeout")
found = true
}
if _, ok := event.(*rmevent.RMReleaseAllocationAskEvent); ok {
@@ -1551,18 +1549,18 @@ func TestTimeoutPlaceholderCompleting(t *testing.T) {
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "Unexpected error when creating resource from
map")
// add the placeholder to the app
- ph := newPlaceholderAlloc(appID1, "waiting", nodeID1, res)
+ ph := newPlaceholderAlloc(appID1, nodeID1, res)
app.AddAllocation(ph)
assert.Assert(t, app.getPlaceholderTimer() != nil, "Placeholder timer
should be initiated after the first placeholder allocation")
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
// add a real allocation as well
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
// move on to running
app.SetState(Running.String())
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
// remove allocation to trigger state change
- app.RemoveAllocation("uuid-1",
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
+ app.RemoveAllocation(alloc.GetUUID(),
si.TerminationType_UNKNOWN_TERMINATION_TYPE)
assert.Assert(t, app.IsCompleting(), "App should be in completing state
all allocs have been removed")
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
// make sure the placeholders time out
@@ -1598,12 +1596,12 @@ func TestAppTimersAfterAppRemoval(t *testing.T) {
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "Unexpected error when creating resource from
map")
// add the placeholder to the app
- ph := newPlaceholderAlloc(appID1, "waiting", nodeID1, res)
+ ph := newPlaceholderAlloc(appID1, nodeID1, res)
app.AddAllocation(ph)
assert.Assert(t, app.getPlaceholderTimer() != nil, "Placeholder timer
should be initiated after the first placeholder allocation")
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
1))
// add a real allocation as well
- alloc := newAllocation(appID1, "uuid-1", nodeID1, res)
+ alloc := newAllocation(appID1, nodeID1, res)
app.AddAllocation(alloc)
assertUserGroupResource(t, getTestUserGroup(), resources.Multiply(res,
2))
// move on to running
@@ -2107,14 +2105,14 @@ func TestAllocationEvents(t *testing.T) {
//nolint:funlen
resMap := map[string]string{"memory": "100", "vcores": "10"}
res, err := resources.NewResourceFromConf(resMap)
assert.NilError(t, err, "failed to create resource with error")
- alloc1 := newAllocation(appID1, "uuid-1", nodeID1, res)
- alloc2 := newAllocation(appID1, "uuid-2", nodeID1, res)
+ alloc1 := newAllocation(appID1, nodeID1, res)
+ alloc2 := newAllocation(appID1, nodeID1, res)
// add + remove
app.AddAllocation(alloc1)
app.AddAllocation(alloc2)
- app.RemoveAllocation("uuid-1", si.TerminationType_STOPPED_BY_RM)
- app.RemoveAllocation("uuid-2", si.TerminationType_PLACEHOLDER_REPLACED)
+ app.RemoveAllocation(alloc1.GetUUID(), si.TerminationType_STOPPED_BY_RM)
+ app.RemoveAllocation(alloc2.GetUUID(),
si.TerminationType_PLACEHOLDER_REPLACED)
noEvents := 0
err = common.WaitFor(10*time.Millisecond, time.Second, func() bool {
noEvents = eventSystem.Store.CountStoredEvents()
@@ -2127,28 +2125,28 @@ func TestAllocationEvents(t *testing.T) {
//nolint:funlen
assert.Equal(t, si.EventRecord_APP, records[1].Type)
assert.Equal(t, si.EventRecord_ADD, records[1].EventChangeType)
assert.Equal(t, si.EventRecord_APP_ALLOC, records[1].EventChangeDetail)
- assert.Equal(t, "uuid-1", records[1].ReferenceID)
+ assert.Equal(t, alloc1.GetUUID(), records[1].ReferenceID)
assert.Equal(t, "app-1", records[1].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[2].Type)
assert.Equal(t, si.EventRecord_ADD, records[2].EventChangeType)
assert.Equal(t, si.EventRecord_APP_ALLOC, records[2].EventChangeDetail)
- assert.Equal(t, "uuid-2", records[2].ReferenceID)
+ assert.Equal(t, alloc2.GetUUID(), records[2].ReferenceID)
assert.Equal(t, "app-1", records[2].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[3].Type)
assert.Equal(t, si.EventRecord_REMOVE, records[3].EventChangeType)
assert.Equal(t, si.EventRecord_ALLOC_CANCEL,
records[3].EventChangeDetail)
- assert.Equal(t, "uuid-1", records[3].ReferenceID)
+ assert.Equal(t, alloc1.GetUUID(), records[3].ReferenceID)
assert.Equal(t, "app-1", records[3].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[4].Type)
assert.Equal(t, si.EventRecord_REMOVE, records[4].EventChangeType)
assert.Equal(t, si.EventRecord_ALLOC_REPLACED,
records[4].EventChangeDetail)
- assert.Equal(t, "uuid-2", records[4].ReferenceID)
+ assert.Equal(t, alloc2.GetUUID(), records[4].ReferenceID)
assert.Equal(t, "app-1", records[4].ObjectID)
// add + replace
alloc1.placeholder = true
app.AddAllocation(alloc1)
- app.ReplaceAllocation("uuid-1")
+ app.ReplaceAllocation(alloc1.GetUUID())
noEvents = 0
err = common.WaitFor(10*time.Millisecond, time.Second, func() bool {
noEvents = eventSystem.Store.CountStoredEvents()
@@ -2160,12 +2158,12 @@ func TestAllocationEvents(t *testing.T) {
//nolint:funlen
assert.Equal(t, si.EventRecord_APP, records[0].Type)
assert.Equal(t, si.EventRecord_ADD, records[0].EventChangeType)
assert.Equal(t, si.EventRecord_APP_ALLOC, records[0].EventChangeDetail)
- assert.Equal(t, "uuid-1", records[0].ReferenceID)
+ assert.Equal(t, alloc1.GetUUID(), records[0].ReferenceID)
assert.Equal(t, "app-1", records[0].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[1].Type)
assert.Equal(t, si.EventRecord_REMOVE, records[1].EventChangeType)
assert.Equal(t, si.EventRecord_ALLOC_REPLACED,
records[1].EventChangeDetail)
- assert.Equal(t, "uuid-1", records[0].ReferenceID)
+ assert.Equal(t, alloc1.GetUUID(), records[0].ReferenceID)
assert.Equal(t, "app-1", records[0].ObjectID)
// add + remove all
@@ -2183,12 +2181,12 @@ func TestAllocationEvents(t *testing.T) {
//nolint:funlen
assert.Equal(t, si.EventRecord_APP, records[0].Type)
assert.Equal(t, si.EventRecord_ADD, records[0].EventChangeType)
assert.Equal(t, si.EventRecord_APP_ALLOC, records[0].EventChangeDetail)
- assert.Equal(t, "uuid-1", records[0].ReferenceID)
+ assert.Equal(t, alloc1.GetUUID(), records[0].ReferenceID)
assert.Equal(t, "app-1", records[0].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[1].Type)
assert.Equal(t, si.EventRecord_ADD, records[1].EventChangeType)
assert.Equal(t, si.EventRecord_APP_ALLOC, records[1].EventChangeDetail)
- assert.Equal(t, "uuid-2", records[1].ReferenceID)
+ assert.Equal(t, alloc2.GetUUID(), records[1].ReferenceID)
assert.Equal(t, "app-1", records[1].ObjectID)
assert.Equal(t, si.EventRecord_APP, records[2].Type)
assert.Equal(t, si.EventRecord_REMOVE, records[2].EventChangeType)
@@ -2200,8 +2198,8 @@ func TestAllocationEvents(t *testing.T) { //nolint:funlen
assert.Equal(t, si.EventRecord_ALLOC_CANCEL,
records[3].EventChangeDetail)
refIdsRemoved[records[3].ReferenceID]++
assert.Equal(t, "app-1", records[3].ObjectID)
- assert.Equal(t, 1, refIdsRemoved["uuid-1"])
- assert.Equal(t, 1, refIdsRemoved["uuid-2"])
+ assert.Equal(t, 1, refIdsRemoved[alloc1.GetUUID()])
+ assert.Equal(t, 1, refIdsRemoved[alloc2.GetUUID()])
}
func TestPlaceholderLargerEvent(t *testing.T) {
@@ -2223,7 +2221,7 @@ func TestPlaceholderLargerEvent(t *testing.T) {
assert.NilError(t, err, "queue create failed")
app.queue = queue
// smallerRes < res in the same task group, so delta will be -50 memory
- alloc1 := newAllocation(appID1, "uuid-1", nodeID1, smallerRes)
+ alloc1 := newAllocation(appID1, nodeID1, smallerRes)
alloc1.placeholder = true
alloc1.taskGroupName = "testGroup"
app.AddAllocation(alloc1)
diff --git a/pkg/scheduler/objects/node_collection_test.go
b/pkg/scheduler/objects/node_collection_test.go
index 3755cc05..c3abccd1 100644
--- a/pkg/scheduler/objects/node_collection_test.go
+++ b/pkg/scheduler/objects/node_collection_test.go
@@ -22,7 +22,6 @@ import (
"fmt"
"testing"
- "github.com/google/uuid"
"gotest.tools/v3/assert"
"github.com/apache/yunikorn-core/pkg/common/configs"
@@ -163,7 +162,7 @@ func TestSetNodeSortingPolicy(t *testing.T) {
for id := 0; id < len(nodesInfo); id++ {
node := newNode(nodesInfo[id].nodeID,
map[string]resources.Quantity{"vcore": resources.Quantity(defaultCapicity[0]),
"memory": resources.Quantity(defaultCapicity[1])})
res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore":
resources.Quantity(nodesInfo[id].allocatedVcore), "memory":
resources.Quantity(nodesInfo[id].allocatedMem)})
- alloc :=
newAllocation(fmt.Sprintf("test-app-%d", id+1), uuid.NewString(),
fmt.Sprintf("test-%d", id+1), res)
+ alloc :=
newAllocation(fmt.Sprintf("test-app-%d", id+1), fmt.Sprintf("test-%d", id+1),
res)
if ok := node.AddAllocation(alloc); !ok {
t.Error("Allocation error happen in
node.")
}
@@ -229,7 +228,7 @@ func TestGetNodeSortingPolicy(t *testing.T) {
for id := 1; id < len(nodeNames)+1; id++ {
node := newNode(nodeNames[id-1],
map[string]resources.Quantity{"vcore": resources.Quantity(6)})
res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore":
resources.Quantity(id)})
- alloc :=
newAllocation(fmt.Sprintf("test-app-%d", id+1), uuid.NewString(),
fmt.Sprintf("test-%d", id), res)
+ alloc :=
newAllocation(fmt.Sprintf("test-app-%d", id+1), fmt.Sprintf("test-%d", id), res)
node.AddAllocation(alloc)
if err := nc.AddNode(node); err != nil {
@@ -298,7 +297,7 @@ func TestGetFullNodeIterator(t *testing.T) {
}
} else {
res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore":
resources.Quantity(i)})
- alloc := newAllocation(fmt.Sprintf("test-app-%d", i),
uuid.NewString(), fmt.Sprintf("test-%d", i), res)
+ alloc := newAllocation(fmt.Sprintf("test-app-%d", i),
fmt.Sprintf("test-%d", i), res)
if ok := node.AddAllocation(alloc); !ok {
t.Error("Allocation error in node.")
}
@@ -347,7 +346,7 @@ func TestGetNodeIterator(t *testing.T) {
}
} else {
res :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore":
resources.Quantity(i)})
- alloc :=
newAllocation(fmt.Sprintf("test-app-%d", i), uuid.NewString(),
fmt.Sprintf("test-%d", i), res)
+ alloc :=
newAllocation(fmt.Sprintf("test-app-%d", i), fmt.Sprintf("test-%d", i), res)
if ok := node.AddAllocation(alloc); !ok
{
t.Error("Allocation error
happen in node.")
}
diff --git a/pkg/scheduler/objects/node_test.go
b/pkg/scheduler/objects/node_test.go
index 26d33c2f..bd103651 100644
--- a/pkg/scheduler/objects/node_test.go
+++ b/pkg/scheduler/objects/node_test.go
@@ -135,7 +135,8 @@ func TestPreAllocateCheck(t *testing.T) {
assert.Assert(t, !node.preAllocateCheck(resOther, ""), "unknown
resource type should not have fitted on node")
// set allocated resource
- node.AddAllocation(newAllocation(appID1, "UUID1", nodeID, resSmall))
+ alloc := newAllocation(appID1, nodeID, resSmall)
+ node.AddAllocation(alloc)
assert.Assert(t, node.preAllocateCheck(resSmall, ""), "small resource
should have fitted in available allocation")
assert.Assert(t, !node.preAllocateCheck(resNode, ""), "node resource
should not have fitted in available allocation")
@@ -390,12 +391,14 @@ func TestAddAllocation(t *testing.T) {
assert.Assert(t, !node.AddAllocation(nil), "nil allocation should not
have been added: %v", node)
// check alloc that does not match
unknown :=
resources.NewResourceFromMap(map[string]resources.Quantity{"unknown": 1})
- assert.Assert(t, !node.AddAllocation(newAllocation(appID1, "1",
nodeID1, unknown)), "unmatched resource type in allocation should not have been
added: %v", node)
+ alloc := newAllocation(appID1, nodeID1, unknown)
+ assert.Assert(t, !node.AddAllocation(alloc), "unmatched resource type
in allocation should not have been added: %v", node)
// allocate half of the resources available and check the calculation
half :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50,
"second": 100})
- assert.Assert(t, node.AddAllocation(newAllocation(appID1, "1", nodeID1,
half)), "add allocation 1 should not have failed")
- if node.GetAllocation("1") == nil {
+ alloc = newAllocation(appID1, nodeID1, half)
+ assert.Assert(t, node.AddAllocation(alloc), "add allocation 1 should
not have failed")
+ if node.GetAllocation(alloc.GetAllocationID()) == nil {
t.Fatal("failed to add allocations: allocation not returned")
}
if !resources.Equals(node.GetAllocatedResource(), half) {
@@ -410,8 +413,9 @@ func TestAddAllocation(t *testing.T) {
}
// second and check calculation
piece :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 25,
"second": 50})
- assert.Assert(t, node.AddAllocation(newAllocation(appID1, "2", nodeID1,
piece)), "add allocation 2 should not have failed")
- if node.GetAllocation("2") == nil {
+ alloc = newAllocation(appID1, nodeID1, piece)
+ assert.Assert(t, node.AddAllocation(alloc), "add allocation 2 should
not have failed")
+ if node.GetAllocation(alloc.GetAllocationID()) == nil {
t.Fatal("failed to add allocations: allocation not returned")
}
piece.AddTo(half)
@@ -436,8 +440,9 @@ func TestRemoveAllocation(t *testing.T) {
// allocate half of the resources available and check the calculation
half :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50,
"second": 100})
- node.AddAllocation(newAllocation(appID1, "1", nodeID1, half))
- if node.GetAllocation("1") == nil {
+ alloc1 := newAllocation(appID1, nodeID1, half)
+ node.AddAllocation(alloc1)
+ if node.GetAllocation(alloc1.GetAllocationID()) == nil {
t.Fatal("failed to add allocations: allocation not returned")
}
// check empty alloc
@@ -453,11 +458,12 @@ func TestRemoveAllocation(t *testing.T) {
// add second alloc and remove first check calculation
piece :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 25,
"second": 50})
- node.AddAllocation(newAllocation(appID1, "2", nodeID1, piece))
- if node.GetAllocation("2") == nil {
+ alloc2 := newAllocation(appID1, nodeID1, piece)
+ node.AddAllocation(alloc2)
+ if node.GetAllocation(alloc2.GetAllocationID()) == nil {
t.Fatal("failed to add allocations: allocation not returned")
}
- alloc := node.RemoveAllocation("1")
+ alloc := node.RemoveAllocation(alloc1.GetAllocationID())
if alloc == nil {
t.Error("allocation should have been removed but was not")
}
@@ -479,28 +485,26 @@ func TestNodeReplaceAllocation(t *testing.T) {
assert.Assert(t, resources.IsZero(node.GetAllocatedResource()), "failed
to initialize node")
// allocate half of the resources available and check the calculation
- phID := "ph-1"
half :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50,
"second": 100})
- ph := newPlaceholderAlloc(appID1, phID, nodeID1, half)
+ ph := newPlaceholderAlloc(appID1, nodeID1, half)
node.AddAllocation(ph)
- assert.Assert(t, node.GetAllocation(phID) != nil, "failed to add
placeholder allocation")
+ assert.Assert(t, node.GetAllocation(ph.GetAllocationID()) != nil,
"failed to add placeholder allocation")
assert.Assert(t, resources.Equals(node.GetAllocatedResource(), half),
"allocated resource not set correctly %v got %v", half,
node.GetAllocatedResource())
assert.Assert(t, resources.Equals(node.GetAvailableResource(), half),
"available resource not set correctly %v got %v", half,
node.GetAvailableResource())
- allocID := "real-1"
piece :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 25,
"second": 50})
- alloc := newAllocation(appID1, allocID, nodeID1, piece)
+ alloc := newAllocation(appID1, nodeID1, piece)
// calculate the delta: new allocation resource - placeholder (should
be negative!)
delta := resources.Sub(piece, half)
assert.Assert(t, delta.HasNegativeValue(), "expected negative values in
delta")
// swap and check the calculation
- node.ReplaceAllocation(phID, alloc, delta)
- assert.Assert(t, node.GetAllocation(allocID) != nil, "failed to replace
allocation: allocation not returned")
+ node.ReplaceAllocation(ph.GetAllocationID(), alloc, delta)
+ assert.Assert(t, node.GetAllocation(alloc.GetAllocationID()) != nil,
"failed to replace allocation: allocation not returned")
assert.Assert(t, resources.Equals(node.GetAllocatedResource(), piece),
"allocated resource not set correctly %v got %v", piece,
node.GetAllocatedResource())
assert.Assert(t, resources.Equals(node.GetAvailableResource(),
resources.Sub(node.GetCapacity(), piece)), "available resource not set
correctly %v got %v", resources.Sub(node.GetCapacity(), piece),
node.GetAvailableResource())
// clean up all should be zero
- assert.Assert(t, node.RemoveAllocation(allocID) != nil, "allocation
should have been removed but was not")
+ assert.Assert(t, node.RemoveAllocation(alloc.GetAllocationID()) != nil,
"allocation should have been removed but was not")
assert.Assert(t, resources.IsZero(node.GetAllocatedResource()),
"allocated resource not updated correctly")
assert.Assert(t, resources.Equals(node.GetAvailableResource(),
node.GetCapacity()), "available resource not set correctly %v got %v",
node.GetCapacity(), node.GetAvailableResource())
}
@@ -515,8 +519,9 @@ func TestGetAllocation(t *testing.T) {
if alloc != nil {
t.Fatalf("allocation should not have been found")
}
- node.AddAllocation(newAllocation(appID1, "1", nodeID1, nil))
- alloc = node.GetAllocation("1")
+ alloc = newAllocation(appID1, nodeID1, nil)
+ node.AddAllocation(alloc)
+ alloc = node.GetAllocation(alloc.GetAllocationID())
if alloc == nil {
t.Fatalf("allocation should have been found")
}
@@ -538,13 +543,15 @@ func TestGetAllocations(t *testing.T) {
if allocs == nil || len(allocs) != 0 {
t.Fatalf("allocation length should be 0 on new node")
}
+ alloc1 := newAllocation(appID1, nodeID1, nil)
+ alloc2 := newAllocation(appID1, nodeID1, nil)
// allocate
- node.AddAllocation(newAllocation(appID1, "1", nodeID1, nil))
- node.AddAllocation(newAllocation(appID1, "2", nodeID1, nil))
+ node.AddAllocation(alloc1)
+ node.AddAllocation(alloc2)
assert.Equal(t, 2, len(node.GetAllAllocations()), "allocation length
mismatch")
// This should not happen in real code just making sure the code does
do what is expected
- node.AddAllocation(newAllocation(appID1, "2", nodeID1, nil))
+ node.AddAllocation(alloc2)
assert.Equal(t, 2, len(node.GetAllAllocations()), "allocation length
mismatch")
}
@@ -712,7 +719,7 @@ func TestNodeEvents(t *testing.T) {
node.AddAllocation(&Allocation{
allocatedResource:
resources.NewResourceFromMap(map[string]resources.Quantity{"cpu": 1, "memory":
1}),
allocationKey: aKey,
- uuid: "uuid-0",
+ allocationID: "uuid-0",
})
assert.Equal(t, 1, len(mockEvents.events))
event = mockEvents.events[0]
diff --git a/pkg/scheduler/objects/nodesorting_test.go
b/pkg/scheduler/objects/nodesorting_test.go
index a046d2b9..35ba9063 100644
--- a/pkg/scheduler/objects/nodesorting_test.go
+++ b/pkg/scheduler/objects/nodesorting_test.go
@@ -21,7 +21,6 @@ package objects
import (
"testing"
- "github.com/google/uuid"
"gotest.tools/v3/assert"
"github.com/apache/yunikorn-core/pkg/common/configs"
@@ -171,11 +170,11 @@ func TestSortPolicyWeighting(t *testing.T) {
// add allocations
res1 :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 500,
"memory": 12000})
- alloc1 := newAllocation("test-app-1", uuid.NewString(), "test1", res1)
+ alloc1 := newAllocation("test-app-1", "test1", res1)
node1.AddAllocation(alloc1)
res2 :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 1500,
"memory": 4000})
- alloc2 := newAllocation("test-app-1", uuid.NewString(), "test2", res2)
+ alloc2 := newAllocation("test-app-1", "test2", res2)
node2.AddAllocation(alloc2)
// node1 w/ fair: 25% vcore, 75% memory => ((.25 * 4) + (.75 * 1)) / 5
= 0.35
@@ -262,7 +261,7 @@ func TestSortPolicy(t *testing.T) {
// add allocation to second node
half :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 1000,
"memory": 2000})
- alloc := newAllocation("test-app-1", uuid.NewString(), "test2", half)
+ alloc := newAllocation("test-app-1", "test2", half)
node2.AddAllocation(alloc)
// node2 should now be first as it is the highest-loaded
diff --git a/pkg/scheduler/objects/preemption_test.go
b/pkg/scheduler/objects/preemption_test.go
index a7641878..da8ed670 100644
--- a/pkg/scheduler/objects/preemption_test.go
+++ b/pkg/scheduler/objects/preemption_test.go
@@ -107,8 +107,8 @@ func TestCheckPreemptionQueueGuarantees(t *testing.T) {
assert.NilError(t, app1.AddAllocationAsk(ask1))
ask2 := newAllocationAsk("alloc2", appID1,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
assert.NilError(t, app1.AddAllocationAsk(ask2))
- app1.AddAllocation(NewAllocation("alloc1", "node1", ask1))
- app1.AddAllocation(NewAllocation("alloc2", "node1", ask2))
+ app1.AddAllocation(NewAllocation("node1", ask1))
+ app1.AddAllocation(NewAllocation("node1", ask2))
assert.NilError(t,
childQ1.IncAllocatedResource(ask1.GetAllocatedResource(), false))
assert.NilError(t,
childQ1.IncAllocatedResource(ask2.GetAllocatedResource(), false))
app2 := newApplication(appID2, "default", "root.parent.child2")
@@ -159,8 +159,8 @@ func
TestCheckPreemptionQueueGuaranteesWithNoGuaranteedResources(t *testing.T) {
assert.NilError(t, app1.AddAllocationAsk(ask1))
ask2 := newAllocationAsk("alloc2", appID1,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
assert.NilError(t, app1.AddAllocationAsk(ask2))
- app1.AddAllocation(NewAllocation("alloc1", "node1",
ask1))
- app1.AddAllocation(NewAllocation("alloc2", "node1",
ask2))
+ app1.AddAllocation(NewAllocation("node1", ask1))
+ app1.AddAllocation(NewAllocation("node1", ask2))
assert.NilError(t,
childQ1.IncAllocatedResource(ask1.GetAllocatedResource(), false))
assert.NilError(t,
childQ1.IncAllocatedResource(ask2.GetAllocatedResource(), false))
app2 := newApplication(appID2, "default",
"root.parent.child2")
@@ -196,10 +196,10 @@ func TestTryPreemption(t *testing.T) {
ask2 := newAllocationAsk("alloc2", appID1,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5, "pods":
1}))
ask2.createTime = time.Now()
assert.NilError(t, app1.AddAllocationAsk(ask2))
- alloc1 := NewAllocation("alloc1", "node1", ask1)
+ alloc1 := NewAllocation("node1", ask1)
app1.AddAllocation(alloc1)
assert.Check(t, node.AddAllocation(alloc1), "node alloc1 failed")
- alloc2 := NewAllocation("alloc2", "node1", ask2)
+ alloc2 := NewAllocation("node1", ask2)
assert.Check(t, node.AddAllocation(alloc2), "node alloc2 failed")
node.AddAllocation(alloc2)
assert.NilError(t,
childQ1.IncAllocatedResource(ask1.GetAllocatedResource(), false))
@@ -288,7 +288,7 @@ func allocForScore(originator bool, allowPreemptSelf bool)
*Allocation {
ask := NewAllocationAsk("alloc1", appID1, resources.NewResource())
ask.originator = originator
ask.allowPreemptSelf = allowPreemptSelf
- return NewAllocation("alloc1", nodeID1, ask)
+ return NewAllocation(nodeID1, ask)
}
type mockPreemption struct {
diff --git a/pkg/scheduler/objects/queue_test.go
b/pkg/scheduler/objects/queue_test.go
index 6044005f..d50a8e03 100644
--- a/pkg/scheduler/objects/queue_test.go
+++ b/pkg/scheduler/objects/queue_test.go
@@ -752,7 +752,7 @@ func TestSortAppsWithPlaceholderAllocations(t *testing.T) {
res, err := resources.NewResourceFromConf(map[string]string{"first":
"1"})
assert.NilError(t, err, "failed to create basic resource")
- alloc := newAllocation(appID1, "uuid-0", "node-0", res)
+ alloc := newAllocation(appID1, "node-0", res)
alloc.placeholder = true
// adding a placeholder allocation & pending request to "app1"
app1.AddAllocation(alloc)
@@ -764,7 +764,7 @@ func TestSortAppsWithPlaceholderAllocations(t *testing.T) {
assert.Equal(t, 1, len(phApps))
// adding a placeholder allocation & pending request to "app2"
- alloc2 := newAllocation(appID2, "uuid-1", "node-1", res)
+ alloc2 := newAllocation(appID2, "node-1", res)
alloc2.placeholder = true
app2.AddAllocation(alloc2)
err = app2.AddAllocationAsk(newAllocationAsk("ask-0", appID1, res))
@@ -1859,10 +1859,10 @@ func TestFindEligiblePreemptionVictims(t *testing.T) {
ask.pendingAskRepeat = 1
ask2 := createAllocationAsk("ask2", appID2, true, true, -1000, res)
ask2.pendingAskRepeat = 1
- alloc2 := NewAllocation("alloc-2", nodeID1, ask2)
+ alloc2 := NewAllocation(nodeID1, ask2)
ask3 := createAllocationAsk("ask3", appID2, true, true, -1000, res)
ask3.pendingAskRepeat = 1
- alloc3 := NewAllocation("alloc-3", nodeID1, ask3)
+ alloc3 := NewAllocation(nodeID1, ask3)
root, err := createRootQueue(map[string]string{siCommon.Memory: "1000"})
assert.NilError(t, err, "failed to create queue")
parent1, err := createManagedQueueGuaranteed(root, "parent1", true,
parentMax, parentGuar)
@@ -2648,7 +2648,7 @@ func TestQueueRunningAppsForSingleAllocationApp(t
*testing.T) {
err = app.AddAllocationAsk(ask)
assert.NilError(t, err, "failed to add ask")
- alloc := NewAllocation("alloc-1", nodeID1, ask)
+ alloc := NewAllocation(nodeID1, ask)
app.AddAllocation(alloc)
assert.Equal(t, app.CurrentState(), Starting.String(), "app state
should be starting")
assert.Equal(t, leaf.runningApps, uint64(1), "leaf should have 1 app
running")
diff --git a/pkg/scheduler/objects/required_node_preemptor_test.go
b/pkg/scheduler/objects/required_node_preemptor_test.go
index 90506452..9b852831 100644
--- a/pkg/scheduler/objects/required_node_preemptor_test.go
+++ b/pkg/scheduler/objects/required_node_preemptor_test.go
@@ -50,49 +50,49 @@ func prepareAllocationAsks(node *Node) {
// regular pods
ask1 := createAllocationAsk("ask1", "app1", true, false, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10}))
- node.AddAllocation(NewAllocation("1", node.NodeID, ask1))
+ node.AddAllocation(NewAllocation(node.NodeID, ask1))
ask2 := createAllocationAsk("ask2", "app1", true, false, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 8}))
ask2.createTime = createTime
- node.AddAllocation(NewAllocation("2", node.NodeID, ask2))
+ node.AddAllocation(NewAllocation(node.NodeID, ask2))
ask3 := createAllocationAsk("ask3", "app1", true, false, 15,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10}))
- node.AddAllocation(NewAllocation("3", node.NodeID, ask3))
+ node.AddAllocation(NewAllocation(node.NodeID, ask3))
ask4 := createAllocationAsk("ask4", "app1", true, false, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
ask4.createTime = createTime
- node.AddAllocation(NewAllocation("4", node.NodeID, ask4))
+ node.AddAllocation(NewAllocation(node.NodeID, ask4))
ask5 := createAllocationAsk("ask5", "app1", true, false, 5,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
- node.AddAllocation(NewAllocation("5", node.NodeID, ask5))
+ node.AddAllocation(NewAllocation(node.NodeID, ask5))
// opted out pods
ask6 := createAllocationAsk("ask6", "app1", false, false, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10}))
- node.AddAllocation(NewAllocation("6", node.NodeID, ask6))
+ node.AddAllocation(NewAllocation(node.NodeID, ask6))
ask7 := createAllocationAsk("ask7", "app1", false, false, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 8}))
ask7.createTime = createTime
- node.AddAllocation(NewAllocation("7", node.NodeID, ask7))
+ node.AddAllocation(NewAllocation(node.NodeID, ask7))
ask8 := createAllocationAsk("ask8", "app1", false, false, 15,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10}))
- node.AddAllocation(NewAllocation("8", node.NodeID, ask8))
+ node.AddAllocation(NewAllocation(node.NodeID, ask8))
// driver/owner pods
ask9 := createAllocationAsk("ask9", "app1", false, true, 10,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
ask9.createTime = createTime
- node.AddAllocation(NewAllocation("9", node.NodeID, ask9))
+ node.AddAllocation(NewAllocation(node.NodeID, ask9))
ask10 := createAllocationAsk("ask10", "app1", true, true, 5,
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 5}))
- node.AddAllocation(NewAllocation("10", node.NodeID, ask10))
+ node.AddAllocation(NewAllocation(node.NodeID, ask10))
}
// regular pods
diff --git a/pkg/scheduler/objects/utilities_test.go
b/pkg/scheduler/objects/utilities_test.go
index daec400c..91a16a6b 100644
--- a/pkg/scheduler/objects/utilities_test.go
+++ b/pkg/scheduler/objects/utilities_test.go
@@ -208,18 +208,18 @@ func newProto(nodeID string, totalResource,
occupiedResource *resources.Resource
}
// Create a new Allocation with a random ask key
-func newAllocation(appID, uuid, nodeID string, res *resources.Resource)
*Allocation {
+func newAllocation(appID, nodeID string, res *resources.Resource) *Allocation {
askKey := strconv.FormatInt((time.Now()).UnixNano(), 10)
ask := newAllocationAsk(askKey, appID, res)
- return NewAllocation(uuid, nodeID, ask)
+ return NewAllocation(nodeID, ask)
}
// Create a new Allocation with a random ask key
-func newPlaceholderAlloc(appID, uuid, nodeID string, res *resources.Resource)
*Allocation {
+func newPlaceholderAlloc(appID, nodeID string, res *resources.Resource)
*Allocation {
askKey := strconv.FormatInt((time.Now()).UnixNano(), 10)
ask := newAllocationAsk(askKey, appID, res)
ask.placeholder = true
- return NewAllocation(uuid, nodeID, ask)
+ return NewAllocation(nodeID, ask)
}
func newAllocationAsk(allocKey, appID string, res *resources.Resource)
*AllocationAsk {
diff --git a/pkg/scheduler/partition_test.go b/pkg/scheduler/partition_test.go
index e62923c4..4869f551 100644
--- a/pkg/scheduler/partition_test.go
+++ b/pkg/scheduler/partition_test.go
@@ -248,8 +248,8 @@ func TestAddNodeWithAllocations(t *testing.T) {
node := newNodeMaxResource(nodeID1, nodeRes)
// fail with an unknown app
- ask := newAllocationAsk("alloc-1", "unknown", appRes)
- alloc := objects.NewAllocation("alloc-1-uuid", nodeID1, ask)
+ ask := newAllocationAsk("alloc-1-uuid", "unknown", appRes)
+ alloc := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{alloc}
err = partition.AddNode(node, allocs)
if err == nil {
@@ -258,8 +258,12 @@ func TestAddNodeWithAllocations(t *testing.T) {
assert.Equal(t, partition.nodes.GetNodeCount(), 0, "error returned but
node still added to the partition (app)")
// fail with a broken alloc
- ask = newAllocationAsk("alloc-1", appID1, appRes)
- alloc = objects.NewAllocation("", nodeID1, ask)
+ ask = newAllocationAsk("alloc-1-uuid", appID1, appRes)
+ alloc = objects.NewAllocation(nodeID1, ask)
+ assert.Equal(t, alloc.GetAllocationID(), "alloc-1-uuid-0")
+ // reset uuid to empty
+ alloc.SetAllocationID("")
+ assert.Equal(t, alloc.GetAllocationID(), "")
allocs = []*objects.Allocation{alloc}
err = partition.AddNode(node, allocs)
if err == nil {
@@ -269,7 +273,7 @@ func TestAddNodeWithAllocations(t *testing.T) {
assertLimits(t, getTestUserGroup(), nil)
// fix the alloc add the node will work now
- alloc = objects.NewAllocation("alloc-1-uuid", nodeID1, ask)
+ alloc = objects.NewAllocation(nodeID1, ask)
allocs = []*objects.Allocation{alloc}
// add a node this must work
err = partition.AddNode(node, allocs)
@@ -317,8 +321,8 @@ func TestRemoveNodeWithAllocations(t *testing.T) {
node := newNodeMaxResource(nodeID1, nodeRes)
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 1000})
ask := newAllocationAsk("alloc-1", appID1, appRes)
- allocUUID := "alloc-1-uuid"
- alloc := objects.NewAllocation(allocUUID, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
+ allocUUID := alloc.GetAllocationID()
allocs := []*objects.Allocation{alloc}
err = partition.AddNode(node, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
@@ -329,10 +333,10 @@ func TestRemoveNodeWithAllocations(t *testing.T) {
// add broken allocations
ask = newAllocationAsk("alloc-na", "not-an-app", appRes)
- alloc = objects.NewAllocation("alloc-na-uuid", nodeID1, ask)
+ alloc = objects.NewAllocation(nodeID1, ask)
node.AddAllocation(alloc)
ask = newAllocationAsk("alloc-2", appID1, appRes)
- alloc = objects.NewAllocation("alloc-2-uuid", nodeID1, ask)
+ alloc = objects.NewAllocation(nodeID1, ask)
node.AddAllocation(alloc)
assertLimits(t, getTestUserGroup(), appRes)
@@ -363,7 +367,7 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
node1 := newNodeMaxResource(nodeID1, nodeRes)
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 1})
ask := newAllocationAskTG("placeholder", appID1, taskGroup, appRes,
true)
- ph := objects.NewAllocation(phID, nodeID1, ask)
+ ph := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{ph}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node1 to partition should not have failed")
@@ -384,7 +388,7 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
assertLimits(t, getTestUserGroup(), appRes)
// add real allocation that is replacing the placeholder
- alloc := objects.NewAllocation(allocID, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
alloc.SetRelease(ph)
// double link as if the replacement is ongoing
ph.SetRelease(alloc)
@@ -399,7 +403,7 @@ func TestRemoveNodeWithPlaceholders(t *testing.T) {
assert.Equal(t, 0, partition.GetTotalNodeCount(), "node list was not
updated, node was not removed")
assert.Equal(t, 1, len(released), "node removal did not release correct
allocation")
assert.Equal(t, 0, len(confirmed), "node removal should not have
confirmed allocation")
- assert.Equal(t, phID, released[0].GetUUID(), "uuid returned by release
not the same as the placeholder")
+ assert.Equal(t, ph.GetAllocationID(), released[0].GetAllocationID(),
"uuid returned by release not the same as the placeholder")
assert.Equal(t, 0, partition.getPhAllocationCount(), "number of active
placeholders")
allocs = app.GetAllAllocations()
assert.Equal(t, 0, len(allocs), "expected no allocations for the app")
@@ -418,14 +422,14 @@ func TestCalculateNodesResourceUsage(t *testing.T) {
assert.NilError(t, err)
occupiedResources :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
- alloc := objects.NewAllocation(allocID, nodeID1,
newAllocationAsk("key", "appID", occupiedResources))
+ alloc := objects.NewAllocation(nodeID1, newAllocationAsk("key",
"appID", occupiedResources))
node.AddAllocation(alloc)
usageMap := partition.calculateNodesResourceUsage()
assert.Equal(t, node.GetAvailableResource().Resources["first"],
resources.Quantity(50))
assert.Equal(t, usageMap["first"][4], 1)
occupiedResources =
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
- alloc = objects.NewAllocation(allocID, nodeID1, newAllocationAsk("key",
"appID", occupiedResources))
+ alloc = objects.NewAllocation(nodeID1, newAllocationAsk("key", "appID",
occupiedResources))
node.AddAllocation(alloc)
usageMap = partition.calculateNodesResourceUsage()
assert.Equal(t, node.GetAvailableResource().Resources["first"],
resources.Quantity(0))
@@ -470,7 +474,7 @@ func TestPlaceholderDataWithPlaceholderPreemption(t
*testing.T) {
phRes.MultiplyTo(7)
ask := newAllocationAskAll("ask-1", appID1, taskGroup, appRes, 0, 1,
false)
- alloc := objects.NewAllocation(allocID, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{alloc}
node1 := newNodeMaxResource(nodeID1, newRes)
@@ -596,7 +600,7 @@ func TestPlaceholderDataWithNodeRemoval(t *testing.T) {
// add a node with allocation: must have the correct app1 added already
ask := newAllocationAskAll("ask-1", appID1, taskGroup, appRes, 0, 1,
false)
- alloc := objects.NewAllocation(allocID, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{alloc}
node1 := newNodeMaxResource(nodeID1, newRes)
@@ -679,7 +683,7 @@ func TestPlaceholderDataWithRemoval(t *testing.T) {
// add a node with allocation: must have the correct app1 added already
ask := newAllocationAskAll("ask-1", appID1, taskGroup, appRes, 0, 1,
false)
- alloc := objects.NewAllocation(allocID, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{alloc}
node1 := newNodeMaxResource(nodeID1, newRes)
@@ -764,7 +768,7 @@ func TestRemoveNodeWithReplacement(t *testing.T) {
node1 := newNodeMaxResource(nodeID1, nodeRes)
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 1})
ask := newAllocationAskAll("placeholder", appID1, taskGroup, appRes, 0,
1, true)
- ph := objects.NewAllocation(phID, nodeID1, ask)
+ ph := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{ph}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node1 to partition should not have failed")
@@ -786,7 +790,7 @@ func TestRemoveNodeWithReplacement(t *testing.T) {
assert.Assert(t, resources.IsZero(app.GetPendingResource()), "app
should not have pending resources")
// add real allocation that is replacing the placeholder on the 2nd node
- alloc := objects.NewAllocation(allocID, nodeID2, ask)
+ alloc := objects.NewAllocation(nodeID2, ask)
alloc.SetRelease(ph)
alloc.SetResult(objects.Replaced)
node2.AddAllocation(alloc)
@@ -808,13 +812,13 @@ func TestRemoveNodeWithReplacement(t *testing.T) {
assert.Equal(t, 1, len(node2.GetAllAllocations()), "remaining node
should have allocation")
assert.Equal(t, 1, len(released), "node removal did not release correct
allocation")
assert.Equal(t, 1, len(confirmed), "node removal did not confirm
correct allocation")
- assert.Equal(t, phID, released[0].GetUUID(), "uuid returned by release
not the same as the placeholder")
- assert.Equal(t, allocID, confirmed[0].GetUUID(), "uuid returned by
confirmed not the same as the real allocation")
+ assert.Equal(t, ph.GetAllocationID(), released[0].GetAllocationID(),
"uuid returned by release not the same as the placeholder")
+ assert.Equal(t, alloc.GetAllocationID(),
confirmed[0].GetAllocationID(), "uuid returned by confirmed not the same as the
real allocation")
assert.Assert(t, resources.IsZero(app.GetPendingResource()), "app
should not have pending resources")
assert.Assert(t, !app.IsCompleting(), "app should not be COMPLETING
after confirming allocation")
allocs = app.GetAllAllocations()
assert.Equal(t, 1, len(allocs), "expected one allocation for the app
(real)")
- assert.Equal(t, allocID, allocs[0].GetUUID(), "uuid for the app is not
the same as the real allocation")
+ assert.Equal(t, alloc.GetAllocationID(), allocs[0].GetAllocationID(),
"uuid for the app is not the same as the real allocation")
assert.Equal(t, objects.Allocated, allocs[0].GetResult(), "allocation
state should be allocated")
assert.Equal(t, 0, allocs[0].GetReleaseCount(), "real allocation should
have no releases linked anymore")
assertLimits(t, getTestUserGroup(), appRes)
@@ -836,7 +840,7 @@ func TestRemoveNodeWithReal(t *testing.T) {
node1 := newNodeMaxResource(nodeID1, nodeRes)
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 1})
ask := newAllocationAskAll("placeholder", appID1, taskGroup, appRes, 0,
1, true)
- ph := objects.NewAllocation(phID, nodeID1, ask)
+ ph := objects.NewAllocation(nodeID1, ask)
allocs := []*objects.Allocation{ph}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node1 to partition should not have failed")
@@ -858,7 +862,7 @@ func TestRemoveNodeWithReal(t *testing.T) {
assert.Assert(t, resources.IsZero(app.GetPendingResource()), "app
should not have pending resources")
// add real allocation that is replacing the placeholder on the 2nd node
- alloc := objects.NewAllocation(allocID, nodeID2, ask)
+ alloc := objects.NewAllocation(nodeID2, ask)
alloc.SetRelease(ph)
alloc.SetResult(objects.Replaced)
node2.AddAllocation(alloc)
@@ -881,7 +885,7 @@ func TestRemoveNodeWithReal(t *testing.T) {
assert.Assert(t, resources.Equals(app.GetPendingResource(), appRes),
"app should have updated pending resources")
allocs = app.GetAllAllocations()
assert.Equal(t, 1, len(allocs), "expected one allocation for the app
(placeholder")
- assert.Equal(t, phID, allocs[0].GetUUID(), "uuid for the app is not the
same as the real allocation")
+ assert.Equal(t, ph.GetAllocationID(), allocs[0].GetAllocationID(),
"uuid for the app is not the same as the real allocation")
assert.Equal(t, 0, ph.GetReleaseCount(), "no inflight replacements
linked")
assertLimits(t, getTestUserGroup(), appRes)
}
@@ -1102,8 +1106,7 @@ func TestRemoveApp(t *testing.T) {
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 1000})
ask := newAllocationAsk("alloc-nr", appNotRemoved, appRes)
- uuid := "alloc-nr-uuid"
- alloc := objects.NewAllocation(uuid, nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
err = partition.addAllocation(alloc)
assert.NilError(t, err, "add allocation to partition should not have
failed")
assertLimits(t, getTestUserGroup(), appRes)
@@ -1130,7 +1133,7 @@ func TestRemoveApp(t *testing.T) {
assert.NilError(t, err, "add application to partition should not have
failed")
ask = newAllocationAsk("alloc-1", appID1, appRes)
- alloc = objects.NewAllocation("alloc-1-uuid", nodeID1, ask)
+ alloc = objects.NewAllocation(nodeID1, ask)
err = partition.addAllocation(alloc)
assert.NilError(t, err, "add allocation to partition should not have
failed")
assertLimits(t, getTestUserGroup(), resources.Multiply(appRes, 2))
@@ -1164,14 +1167,14 @@ func TestRemoveAppAllocs(t *testing.T) {
appRes :=
resources.NewResourceFromMap(map[string]resources.Quantity{"vcore": 1000})
ask := newAllocationAsk("alloc-nr", appNotRemoved, appRes)
- alloc := objects.NewAllocation("alloc-nr-uuid", nodeID1, ask)
+ alloc := objects.NewAllocation(nodeID1, ask)
err = partition.addAllocation(alloc)
assert.NilError(t, err, "add allocation to partition should not have
failed")
assertLimits(t, getTestUserGroup(), appRes)
ask = newAllocationAsk("alloc-1", appNotRemoved, appRes)
- uuid := "alloc-1-uuid"
- alloc = objects.NewAllocation(uuid, nodeID1, ask)
+ uuid := "alloc-1-0"
+ alloc = objects.NewAllocation(nodeID1, ask)
err = partition.addAllocation(alloc)
assert.NilError(t, err, "add allocation to partition should not have
failed")
assertLimits(t, getTestUserGroup(), resources.Multiply(appRes, 2))
@@ -1225,11 +1228,11 @@ func TestRemoveAllPlaceholderAllocs(t *testing.T) {
res, err := resources.NewResourceFromConf(map[string]string{"vcore":
"10"})
assert.NilError(t, err, "failed to create resource")
phAsk1 := newAllocationAskTG(phID, appID1, taskGroup, res, true)
- phAlloc1 := objects.NewAllocation("tg-alloc-1-uuid", nodeID1, phAsk1)
+ phAlloc1 := objects.NewAllocation(nodeID1, phAsk1)
err = partition.addAllocation(phAlloc1)
assert.NilError(t, err, "could not add allocation to partition")
phAsk2 := newAllocationAskTG(phID2, appID1, taskGroup, res, true)
- phAlloc2 := objects.NewAllocation("tg-alloc-2-uuid", nodeID1, phAsk2)
+ phAlloc2 := objects.NewAllocation(nodeID1, phAsk2)
err = partition.addAllocation(phAlloc2)
assert.NilError(t, err, "could not add allocation to partition")
partition.removeAllocation(&si.AllocationRelease{
diff --git a/pkg/scheduler/tests/smoke_test.go
b/pkg/scheduler/tests/smoke_test.go
index 759f364a..51346950 100644
--- a/pkg/scheduler/tests/smoke_test.go
+++ b/pkg/scheduler/tests/smoke_test.go
@@ -556,7 +556,7 @@ partitions:
ApplicationID: app1ID,
},
{
- AllocationKey: "alloc-1",
+ AllocationKey: "alloc-2",
ResourceAsk: &si.Resource{
Resources: map[string]*si.Quantity{
"memory": {Value: 10000000},
@@ -678,7 +678,7 @@ partitions:
ApplicationID: app1ID,
},
{
- AllocationKey: "alloc-1",
+ AllocationKey: "alloc-2",
ResourceAsk: &si.Resource{
Resources: map[string]*si.Quantity{
"memory": {Value: 10000000},
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index 0d976687..e6e70ea4 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -595,8 +595,8 @@ func TestGetClusterUtilJSON(t *testing.T) {
resAlloc2 :=
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory:
300, siCommon.CPU: 200})
ask1 := objects.NewAllocationAsk("alloc-1", appID, resAlloc1)
ask2 := objects.NewAllocationAsk("alloc-2", appID, resAlloc2)
- alloc1 := objects.NewAllocation("alloc-1-uuid", nodeID, ask1)
- alloc2 := objects.NewAllocation("alloc-2-uuid", nodeID, ask2)
+ alloc1 := objects.NewAllocation(nodeID, ask1)
+ alloc2 := objects.NewAllocation(nodeID, ask2)
allocs := []*objects.Allocation{alloc1, alloc2}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
@@ -661,10 +661,10 @@ func TestGetNodesUtilJSON(t *testing.T) {
resAlloc2 :=
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory:
300, siCommon.CPU: 500, "GPU": 5})
ask1 := objects.NewAllocationAsk("alloc-1", appID, resAlloc1)
ask2 := objects.NewAllocationAsk("alloc-2", appID, resAlloc2)
- allocs := []*objects.Allocation{objects.NewAllocation("alloc-1-uuid",
node1ID, ask1)}
+ allocs := []*objects.Allocation{objects.NewAllocation(node1ID, ask1)}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
- allocs = []*objects.Allocation{objects.NewAllocation("alloc-2-uuid",
node2ID, ask2)}
+ allocs = []*objects.Allocation{objects.NewAllocation(node2ID, ask2)}
err = partition.AddNode(node2, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
err = partition.AddNode(node3, nil)
@@ -750,7 +750,7 @@ func TestGetNodeUtilisation(t *testing.T) {
resAlloc :=
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
ask := objects.NewAllocationAsk("alloc-1", "app", resAlloc)
- alloc := objects.NewAllocation("alloc-1-uuid", node1ID, ask)
+ alloc := objects.NewAllocation(node1ID, ask)
assert.Assert(t, node1.AddAllocation(alloc), "unexpected failure adding
allocation to node")
rootQ := partition.GetQueue("root")
err = rootQ.IncAllocatedResource(resAlloc, false)
@@ -767,7 +767,7 @@ func TestGetNodeUtilisation(t *testing.T) {
// make second type dominant by using all
resAlloc =
resources.NewResourceFromMap(map[string]resources.Quantity{"second": 5})
ask = objects.NewAllocationAsk("alloc-2", "app", resAlloc)
- alloc = objects.NewAllocation("alloc-2-uuid", node2ID, ask)
+ alloc = objects.NewAllocation(node2ID, ask)
assert.Assert(t, node2.AddAllocation(alloc), "unexpected failure adding
allocation to node")
err = rootQ.IncAllocatedResource(resAlloc, false)
assert.NilError(t, err, "unexpected error returned setting allocated
resource on queue")
@@ -847,10 +847,10 @@ func TestPartitions(t *testing.T) {
resAlloc2 :=
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory:
200, siCommon.CPU: 300})
ask1 := objects.NewAllocationAsk("alloc-1", app6.ApplicationID,
resAlloc1)
ask2 := objects.NewAllocationAsk("alloc-2", app3.ApplicationID,
resAlloc2)
- allocs := []*objects.Allocation{objects.NewAllocation("alloc-1-uuid",
node1ID, ask1)}
+ allocs := []*objects.Allocation{objects.NewAllocation(node1ID, ask1)}
err := defaultPartition.AddNode(node1, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
- allocs = []*objects.Allocation{objects.NewAllocation("alloc-2-uuid",
node2ID, ask2)}
+ allocs = []*objects.Allocation{objects.NewAllocation(node2ID, ask2)}
err = defaultPartition.AddNode(node2, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
@@ -999,10 +999,10 @@ func TestGetPartitionNodes(t *testing.T) {
resAlloc2 :=
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory:
300, siCommon.CPU: 500})
ask1 := objects.NewAllocationAsk("alloc-1", appID, resAlloc1)
ask2 := objects.NewAllocationAsk("alloc-2", appID, resAlloc2)
- allocs := []*objects.Allocation{objects.NewAllocation("alloc-1-uuid",
node1ID, ask1)}
+ allocs := []*objects.Allocation{objects.NewAllocation(node1ID, ask1)}
err = partition.AddNode(node1, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
- allocs = []*objects.Allocation{objects.NewAllocation("alloc-2-uuid",
node2ID, ask2)}
+ allocs = []*objects.Allocation{objects.NewAllocation(node2ID, ask2)}
err = partition.AddNode(node2, allocs)
assert.NilError(t, err, "add node to partition should not have failed")
@@ -1029,13 +1029,13 @@ func TestGetPartitionNodes(t *testing.T) {
if node.NodeID == node1ID {
assert.Equal(t, node.NodeID, node1ID)
assert.Equal(t, "alloc-1",
node.Allocations[0].AllocationKey)
- assert.Equal(t, "alloc-1-uuid",
node.Allocations[0].UUID)
+ assert.Equal(t, "alloc-1-0", node.Allocations[0].UUID)
assert.DeepEqual(t, attributesOfnode1, node.Attributes)
assert.DeepEqual(t, map[string]int64{"memory": 50,
"vcore": 30}, node.Utilized)
} else {
assert.Equal(t, node.NodeID, node2ID)
assert.Equal(t, "alloc-2",
node.Allocations[0].AllocationKey)
- assert.Equal(t, "alloc-2-uuid",
node.Allocations[0].UUID)
+ assert.Equal(t, "alloc-2-0", node.Allocations[0].UUID)
assert.DeepEqual(t, attributesOfnode2, node.Attributes)
assert.DeepEqual(t, map[string]int64{"memory": 30,
"vcore": 50}, node.Utilized)
}
@@ -1702,8 +1702,7 @@ func prepareUserAndGroupContext(t *testing.T) {
assert.NilError(t, err, "ask should have been added to app")
// add an alloc
- uuid := "uuid-1"
- allocInfo := objects.NewAllocation(uuid, "node-1", ask)
+ allocInfo := objects.NewAllocation("node-1", ask)
app.AddAllocation(allocInfo)
assert.Assert(t, app.IsStarting(), "Application did not return starting
state after alloc: %s", app.CurrentState())
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]