From 6f54992d4eb07d4be4e529570ac186bb3b76fb05 Mon Sep 17 00:00:00 2001 From: Peter Bacsko Date: Tue, 22 Oct 2024 16:41:16 +0200 Subject: [PATCH] [YUNIKORN-2942] Expose foreign allocations tags on the REST interface (#988) Closes: #988 Signed-off-by: Peter Bacsko --- pkg/webservice/dao/allocation_info.go | 13 +++++++------ pkg/webservice/handlers.go | 1 + pkg/webservice/handlers_test.go | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/webservice/dao/allocation_info.go b/pkg/webservice/dao/allocation_info.go index e399cbdfd..0de1191db 100644 --- a/pkg/webservice/dao/allocation_info.go +++ b/pkg/webservice/dao/allocation_info.go @@ -36,10 +36,11 @@ type AllocationDAOInfo struct { } type ForeignAllocationDAOInfo struct { - AllocationKey string `json:"allocationKey"` // no omitempty, allocation key should not be empty - AllocationTime int64 `json:"allocationTime,omitempty"` - ResourcePerAlloc map[string]int64 `json:"resource,omitempty"` - Priority string `json:"priority,omitempty"` - NodeID string `json:"nodeId,omitempty"` - Preemptable bool `json:"preemptable,omitempty"` + AllocationKey string `json:"allocationKey"` // no omitempty, allocation key should not be empty + AllocationTags map[string]string `json:"allocationTags,omitempty"` + AllocationTime int64 `json:"allocationTime,omitempty"` + ResourcePerAlloc map[string]int64 `json:"resource,omitempty"` + Priority string `json:"priority,omitempty"` + NodeID string `json:"nodeId,omitempty"` + Preemptable bool `json:"preemptable,omitempty"` } diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go index 8e455a712..1180b32ee 100644 --- a/pkg/webservice/handlers.go +++ b/pkg/webservice/handlers.go @@ -258,6 +258,7 @@ func getForeignAllocationDAO(alloc *objects.Allocation) *dao.ForeignAllocationDA allocTime := alloc.GetCreateTime().UnixNano() allocDAO := &dao.ForeignAllocationDAOInfo{ AllocationKey: alloc.GetAllocationKey(), + AllocationTags: alloc.GetTagsClone(), AllocationTime: allocTime, ResourcePerAlloc: alloc.GetAllocatedResource().DAOMap(), Priority: strconv.Itoa(int(alloc.GetPriority())), diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go index bba72166e..e3465b891 100644 --- a/pkg/webservice/handlers_test.go +++ b/pkg/webservice/handlers_test.go @@ -1490,6 +1490,12 @@ func assertForeignAllocation(t *testing.T, key, priority, nodeID string, expecte resFromInfo := resources.NewResourceFromMap(resMap) assert.Assert(t, resources.Equals(resFromInfo, expectedRes)) assert.Equal(t, preemptable, info.Preemptable) + assert.Equal(t, 1, len(info.AllocationTags)) + if info.AllocationKey == "foreign-1" { + assert.Equal(t, siCommon.AllocTypeDefault, info.AllocationTags[siCommon.Foreign]) + } else { + assert.Equal(t, siCommon.AllocTypeStatic, info.AllocationTags[siCommon.Foreign]) + } } // addApp Add app to the given partition and assert the app count, state etc