You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by wi...@apache.org on 2024/02/26 09:26:59 UTC
(yunikorn-core) branch branch-1.5 updated (3148d2b8 -> 381bc9a8)
This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a change to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
from 3148d2b8 [YUNIKORN-2413] Initialism fixes for allocationId, clusterId (#806)
new d24a25a2 [YUNIKORN-2042] REST API for specific queue (#687)
new 381bc9a8 [YUNIKORN-2030] headroom check for reserved allocations (#793)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pkg/scheduler/objects/application.go | 23 ++++----
pkg/scheduler/objects/application_test.go | 33 ++++++++++++
pkg/scheduler/objects/queue.go | 16 ++++--
pkg/scheduler/objects/queue_test.go | 20 +++----
pkg/scheduler/objects/utilities_test.go | 1 +
pkg/scheduler/partition.go | 2 +-
pkg/webservice/dao/queue_info.go | 1 +
pkg/webservice/handlers.go | 30 +++++++++++
pkg/webservice/handlers_test.go | 90 ++++++++++++++++++++++++++-----
pkg/webservice/routes.go | 6 +++
10 files changed, 184 insertions(+), 38 deletions(-)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org
(yunikorn-core) 01/02: [YUNIKORN-2042] REST API for specific queue (#687)
Posted by wi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
commit d24a25a2a3331fef70bfb95dbd6a45b675cf2127
Author: steinsgateted <st...@gmail.com>
AuthorDate: Mon Feb 26 20:09:07 2024 +1100
[YUNIKORN-2042] REST API for specific queue (#687)
Expose a REST API for specific queue:
/ws/v1/partition/%s/queue/%s
/ws/v1/partition/%s/queue/%s?aubtree
The call takes one query parameter "subtree" if provided the whole tree
of queues rooted at the level requested in the call will be returned. If
"subtree" is not set only the queue requested will be returned
Closes: #687
Signed-off-by: Wilfred Spiegelenburg <wi...@apache.org>
(cherry picked from commit e9805c956bb806437dcf103c0350af3756cc8ba1)
---
pkg/scheduler/objects/queue.go | 16 ++++---
pkg/scheduler/objects/queue_test.go | 20 ++++-----
pkg/scheduler/partition.go | 2 +-
pkg/webservice/dao/queue_info.go | 1 +
pkg/webservice/handlers.go | 30 +++++++++++++
pkg/webservice/handlers_test.go | 90 +++++++++++++++++++++++++++++++------
pkg/webservice/routes.go | 6 +++
7 files changed, 136 insertions(+), 29 deletions(-)
diff --git a/pkg/scheduler/objects/queue.go b/pkg/scheduler/objects/queue.go
index ebf70e29..43c66e8b 100644
--- a/pkg/scheduler/objects/queue.go
+++ b/pkg/scheduler/objects/queue.go
@@ -624,17 +624,23 @@ func (sq *Queue) CheckAdminAccess(user security.UserGroup) bool {
}
// GetPartitionQueueDAOInfo returns the queue hierarchy as an object for a REST call.
-func (sq *Queue) GetPartitionQueueDAOInfo() dao.PartitionQueueDAOInfo {
+// Exclude is true, which means that returns the specified queue object, but does not return the children of the specified queue.
+func (sq *Queue) GetPartitionQueueDAOInfo(exclude bool) dao.PartitionQueueDAOInfo {
queueInfo := dao.PartitionQueueDAOInfo{}
- childes := sq.GetCopyOfChildren()
- queueInfo.Children = make([]dao.PartitionQueueDAOInfo, 0, len(childes))
- for _, child := range childes {
- queueInfo.Children = append(queueInfo.Children, child.GetPartitionQueueDAOInfo())
+ children := sq.GetCopyOfChildren()
+ if !exclude {
+ queueInfo.Children = make([]dao.PartitionQueueDAOInfo, 0, len(children))
+ for _, child := range children {
+ queueInfo.Children = append(queueInfo.Children, child.GetPartitionQueueDAOInfo(false))
+ }
}
// we have held the read lock so following method should not take lock again.
sq.RLock()
defer sq.RUnlock()
+ for _, child := range children {
+ queueInfo.ChildrenNames = append(queueInfo.ChildrenNames, child.QueuePath)
+ }
queueInfo.QueueName = sq.QueuePath
queueInfo.Status = sq.stateMachine.Current()
queueInfo.PendingResource = sq.pending.DAOMap()
diff --git a/pkg/scheduler/objects/queue_test.go b/pkg/scheduler/objects/queue_test.go
index 4c9e3303..7c46484e 100644
--- a/pkg/scheduler/objects/queue_test.go
+++ b/pkg/scheduler/objects/queue_test.go
@@ -1685,7 +1685,7 @@ func TestGetPartitionQueueDAOInfo(t *testing.T) {
// test properties
root.properties = getProperties()
- assert.DeepEqual(t, root.properties, root.GetPartitionQueueDAOInfo().Properties)
+ assert.DeepEqual(t, root.properties, root.GetPartitionQueueDAOInfo(false).Properties)
// test template
root.template, err = template.FromConf(&configs.ChildTemplate{
@@ -1697,23 +1697,23 @@ func TestGetPartitionQueueDAOInfo(t *testing.T) {
},
})
assert.NilError(t, err)
- assert.Equal(t, root.template.GetMaxApplications(), root.GetPartitionQueueDAOInfo().TemplateInfo.MaxApplications)
- assert.DeepEqual(t, root.template.GetProperties(), root.GetPartitionQueueDAOInfo().TemplateInfo.Properties)
- assert.DeepEqual(t, root.template.GetMaxResource().DAOMap(), root.template.GetMaxResource().DAOMap())
- assert.DeepEqual(t, root.template.GetGuaranteedResource().DAOMap(), root.template.GetGuaranteedResource().DAOMap())
+ assert.Equal(t, root.template.GetMaxApplications(), root.GetPartitionQueueDAOInfo(false).TemplateInfo.MaxApplications)
+ assert.DeepEqual(t, root.template.GetProperties(), root.GetPartitionQueueDAOInfo(false).TemplateInfo.Properties)
+ assert.DeepEqual(t, root.template.GetMaxResource().DAOMap(), root.GetPartitionQueueDAOInfo(false).TemplateInfo.MaxResource)
+ assert.DeepEqual(t, root.template.GetGuaranteedResource().DAOMap(), root.GetPartitionQueueDAOInfo(false).TemplateInfo.GuaranteedResource)
// test resources
root.maxResource = getResource(t)
root.guaranteedResource = getResource(t)
- assert.DeepEqual(t, root.GetMaxResource().DAOMap(), root.GetPartitionQueueDAOInfo().MaxResource)
- assert.DeepEqual(t, root.GetGuaranteedResource().DAOMap(), root.GetPartitionQueueDAOInfo().GuaranteedResource)
- assert.DeepEqual(t, root.getHeadRoom().DAOMap(), root.GetPartitionQueueDAOInfo().HeadRoom)
+ assert.DeepEqual(t, root.GetMaxResource().DAOMap(), root.GetPartitionQueueDAOInfo(false).MaxResource)
+ assert.DeepEqual(t, root.GetGuaranteedResource().DAOMap(), root.GetPartitionQueueDAOInfo(false).GuaranteedResource)
+ assert.DeepEqual(t, root.getHeadRoom().DAOMap(), root.GetPartitionQueueDAOInfo(false).HeadRoom)
// test allocatingAcceptedApps
root.allocatingAcceptedApps = getAllocatingAcceptedApps()
assert.Equal(t, len(root.allocatingAcceptedApps), 2, "allocatingAcceptedApps size")
- assert.Equal(t, len(root.GetPartitionQueueDAOInfo().AllocatingAcceptedApps), 1, "AllocatingAcceptedApps size")
- assert.Equal(t, root.GetPartitionQueueDAOInfo().AllocatingAcceptedApps[0], appID1)
+ assert.Equal(t, len(root.GetPartitionQueueDAOInfo(false).AllocatingAcceptedApps), 1, "AllocatingAcceptedApps size")
+ assert.Equal(t, root.GetPartitionQueueDAOInfo(false).AllocatingAcceptedApps[0], appID1)
}
func getAllocatingAcceptedApps() map[string]bool {
diff --git a/pkg/scheduler/partition.go b/pkg/scheduler/partition.go
index ec84c9f0..c318c6b8 100644
--- a/pkg/scheduler/partition.go
+++ b/pkg/scheduler/partition.go
@@ -477,7 +477,7 @@ func (pc *PartitionContext) getQueueInternal(name string) *objects.Queue {
// Get the queue info for the whole queue structure to pass to the webservice
func (pc *PartitionContext) GetPartitionQueues() dao.PartitionQueueDAOInfo {
- partitionQueueDAOInfo := pc.root.GetPartitionQueueDAOInfo()
+ partitionQueueDAOInfo := pc.root.GetPartitionQueueDAOInfo(false)
partitionQueueDAOInfo.Partition = common.GetPartitionNameWithoutClusterID(pc.Name)
return partitionQueueDAOInfo
}
diff --git a/pkg/webservice/dao/queue_info.go b/pkg/webservice/dao/queue_info.go
index 2c2ee250..8f137dca 100644
--- a/pkg/webservice/dao/queue_info.go
+++ b/pkg/webservice/dao/queue_info.go
@@ -40,6 +40,7 @@ type PartitionQueueDAOInfo struct {
Parent string `json:"parent,omitempty"`
TemplateInfo *TemplateInfo `json:"template,omitempty"`
Children []PartitionQueueDAOInfo `json:"children,omitempty"`
+ ChildrenNames []string `json:"childrenNames,omitempty"`
AbsUsedCapacity map[string]int64 `json:"absUsedCapacity,omitempty"`
MaxRunningApps uint64 `json:"maxRunningApps,omitempty"`
RunningApps uint64 `json:"runningApps,omitempty"`
diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go
index 2d633460..a10bac53 100644
--- a/pkg/webservice/handlers.go
+++ b/pkg/webservice/handlers.go
@@ -642,6 +642,36 @@ func getPartitionQueues(w http.ResponseWriter, r *http.Request) {
}
}
+func getPartitionQueue(w http.ResponseWriter, r *http.Request) {
+ writeHeaders(w)
+ vars := httprouter.ParamsFromContext(r.Context())
+ if vars == nil {
+ buildJSONErrorResponse(w, MissingParamsName, http.StatusBadRequest)
+ return
+ }
+ partition := vars.ByName("partition")
+ partitionContext := schedulerContext.GetPartitionWithoutClusterID(partition)
+ if partitionContext == nil {
+ buildJSONErrorResponse(w, PartitionDoesNotExists, http.StatusNotFound)
+ return
+ }
+ queueName := vars.ByName("queue")
+ queueErr := validateQueue(queueName)
+ if queueErr != nil {
+ buildJSONErrorResponse(w, queueErr.Error(), http.StatusBadRequest)
+ return
+ }
+ queue := partitionContext.GetQueue(queueName)
+ if queue == nil {
+ buildJSONErrorResponse(w, QueueDoesNotExists, http.StatusNotFound)
+ return
+ }
+ queueDao := queue.GetPartitionQueueDAOInfo(r.URL.Query().Has("subtree"))
+ if err := json.NewEncoder(w).Encode(queueDao); err != nil {
+ buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError)
+ }
+}
+
func getPartitionNodes(w http.ResponseWriter, r *http.Request) {
writeHeaders(w)
vars := httprouter.ParamsFromContext(r.Context())
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index 9cf7633c..0442619a 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -1147,20 +1147,80 @@ func TestGetPartitionQueuesHandler(t *testing.T) {
assert.Equal(t, child.Properties[configs.ApplicationSortPolicy], policies.FifoSortPolicy.String())
assert.Assert(t, child.TemplateInfo == nil)
- // Partition not exists
+ // test partition not exists
req, err = http.NewRequest("GET", "/ws/v1/partition/default/queues", strings.NewReader(""))
req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "notexists"}}))
- assert.NilError(t, err, "Get Queues for PartitionQueues Handler request failed")
+ assert.NilError(t, err)
resp = &MockResponseWriter{}
getPartitionQueues(resp, req)
assertPartitionNotExists(t, resp)
// test params name missing
req, err = http.NewRequest("GET", "/ws/v1/partition/default/queues", strings.NewReader(""))
- assert.NilError(t, err, "Get Queues for PartitionQueues Handler request failed")
+ assert.NilError(t, err)
resp = &MockResponseWriter{}
getPartitionQueues(resp, req)
assertParamsMissing(t, resp)
+
+ // test specific queue
+ var partitionQueueDao1 dao.PartitionQueueDAOInfo
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a?subtree", strings.NewReader(""))
+ req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "default"}, httprouter.Param{Key: "queue", Value: "root.a"}}))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ err = json.Unmarshal(resp.outputBytes, &partitionQueueDao1)
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, partitionQueueDao1.QueueName, "root.a")
+ assert.Equal(t, len(partitionQueueDao1.Children), 0)
+ assert.Equal(t, len(partitionQueueDao1.ChildrenNames), 1)
+ assert.Equal(t, partitionQueueDao1.ChildrenNames[0], "root.a.a1")
+
+ // test hierarchy queue
+ var partitionQueueDao2 dao.PartitionQueueDAOInfo
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a", strings.NewReader(""))
+ req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "default"}, httprouter.Param{Key: "queue", Value: "root.a"}}))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ err = json.Unmarshal(resp.outputBytes, &partitionQueueDao2)
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, partitionQueueDao2.QueueName, "root.a")
+ assert.Equal(t, len(partitionQueueDao2.Children), 1)
+ assert.Equal(t, len(partitionQueueDao2.ChildrenNames), 1)
+ assert.Equal(t, partitionQueueDao2.Children[0].QueueName, "root.a.a1")
+ assert.Equal(t, partitionQueueDao2.ChildrenNames[0], "root.a.a1")
+
+ // test partition not exists
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a", strings.NewReader(""))
+ req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "notexists"}}))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ assertPartitionNotExists(t, resp)
+
+ // test params name missing
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a", strings.NewReader(""))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ assertParamsMissing(t, resp)
+
+ // test invalid queue name
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a", strings.NewReader(""))
+ req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "default"}, httprouter.Param{Key: "queue", Value: "root.notexists@"}}))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ assertQueueInvalid(t, resp, "root.notexists@", "notexists@")
+
+ // test queue is not exists
+ req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.a", strings.NewReader(""))
+ req = req.WithContext(context.WithValue(req.Context(), httprouter.ParamsKey, httprouter.Params{httprouter.Param{Key: "partition", Value: "default"}, httprouter.Param{Key: "queue", Value: "notexists"}}))
+ assert.NilError(t, err)
+ resp = &MockResponseWriter{}
+ getPartitionQueue(resp, req)
+ assertQueueNotExists(t, resp)
}
func TestGetClusterInfo(t *testing.T) {
@@ -1485,12 +1545,12 @@ func TestGetPartitionApplicationsByStateHandler(t *testing.T) {
// test disallow state
checkIllegalGetAppsRequest(t, "/ws/v1/partition/default/applications/Accepted", httprouter.Params{
httprouter.Param{Key: "partition", Value: partitionNameWithoutClusterID},
- httprouter.Param{Key: "state", Value: "Accepted"}}, assertAppStateAllow)
+ httprouter.Param{Key: "state", Value: "Accepted"}}, assertAppStateNotAllow)
// test disallow active state
checkIllegalGetAppsRequest(t, "/ws/v1/partition/default/applications/Active?status=invalid", httprouter.Params{
httprouter.Param{Key: "partition", Value: partitionNameWithoutClusterID},
- httprouter.Param{Key: "state", Value: "Active"}}, assertActiveStateAllow)
+ httprouter.Param{Key: "state", Value: "Active"}}, assertActiveStateNotAllow)
// test missing params name
checkIllegalGetAppsRequest(t, "/ws/v1/partition/default/applications/Active", nil, assertParamsMissing)
@@ -1598,12 +1658,7 @@ func TestGetApplicationHandler(t *testing.T) {
assert.NilError(t, err, "Get Application Handler request failed")
resp5 := &MockResponseWriter{}
getApplication(resp5, req5)
- var errInfo dao.YAPIError
- err = json.Unmarshal(resp5.outputBytes, &errInfo)
- assert.NilError(t, err, unmarshalError)
- assert.Equal(t, http.StatusBadRequest, resp5.statusCode, statusCodeError)
- assert.Equal(t, errInfo.Message, "problem in queue query parameter parsing as queue param root.test.test123@ contains invalid queue name test123@. Queue name must only have alphanumeric characters, - or _, and be no longer than 64 characters", jsonMessageError)
- assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
+ assertQueueInvalid(t, resp5, "root.test.test123@", "test123@")
// test missing params name
req, err = http.NewRequest("GET", "/ws/v1/partition/default/queue/root.default/application/app-1", strings.NewReader(""))
@@ -1640,6 +1695,15 @@ func assertQueueNotExists(t *testing.T, resp *MockResponseWriter) {
assert.Equal(t, errInfo.StatusCode, http.StatusNotFound)
}
+func assertQueueInvalid(t *testing.T, resp *MockResponseWriter, invalidQueuePath string, invalidQueueName string) {
+ var errInfo dao.YAPIError
+ err := json.Unmarshal(resp.outputBytes, &errInfo)
+ assert.NilError(t, err, unmarshalError)
+ assert.Equal(t, http.StatusBadRequest, resp.statusCode, statusCodeError)
+ assert.Equal(t, errInfo.Message, "problem in queue query parameter parsing as queue param "+invalidQueuePath+" contains invalid queue name "+invalidQueueName+". Queue name must only have alphanumeric characters, - or _, and be no longer than 64 characters", jsonMessageError)
+ assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
+}
+
func assertApplicationNotExists(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
@@ -1708,7 +1772,7 @@ func assertNodeIDNotExists(t *testing.T, resp *MockResponseWriter) {
assert.Equal(t, errInfo.StatusCode, http.StatusNotFound)
}
-func assertAppStateAllow(t *testing.T, resp *MockResponseWriter) {
+func assertAppStateNotAllow(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, unmarshalError)
@@ -1717,7 +1781,7 @@ func assertAppStateAllow(t *testing.T, resp *MockResponseWriter) {
assert.Equal(t, errInfo.StatusCode, http.StatusBadRequest)
}
-func assertActiveStateAllow(t *testing.T, resp *MockResponseWriter) {
+func assertActiveStateNotAllow(t *testing.T, resp *MockResponseWriter) {
var errInfo dao.YAPIError
err := json.Unmarshal(resp.outputBytes, &errInfo)
assert.NilError(t, err, unmarshalError)
diff --git a/pkg/webservice/routes.go b/pkg/webservice/routes.go
index ba549315..f3653b25 100644
--- a/pkg/webservice/routes.go
+++ b/pkg/webservice/routes.go
@@ -98,6 +98,12 @@ var webRoutes = routes{
"/ws/v1/partition/:partition/queues",
getPartitionQueues,
},
+ route{
+ "Scheduler",
+ "GET",
+ "/ws/v1/partition/:partition/queue/:queue",
+ getPartitionQueue,
+ },
route{
"Scheduler",
"GET",
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org
(yunikorn-core) 02/02: [YUNIKORN-2030] headroom check for reserved allocations (#793)
Posted by wi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
wilfreds pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
commit 381bc9a8a64d4fac99e37d04de6be4e436adf1a9
Author: Yongjun Zhang <yo...@pinterest.com>
AuthorDate: Mon Feb 26 20:12:25 2024 +1100
[YUNIKORN-2030] headroom check for reserved allocations (#793)
During the allocation cycle for reservations we fall back to trying all
reservations on all nodes for an application. During this fallback a
headroom check was missing which caused queue update failures to be
logged.
The allocation did not succeed but it caused scheduling delays and log
spew.
Closes: #793
Signed-off-by: Wilfred Spiegelenburg <wi...@apache.org>
(cherry picked from commit 908d1cb07083b989230a9a18bb0b66180122fb73)
---
pkg/scheduler/objects/application.go | 23 ++++++++++++---------
pkg/scheduler/objects/application_test.go | 33 +++++++++++++++++++++++++++++++
pkg/scheduler/objects/utilities_test.go | 1 +
3 files changed, 48 insertions(+), 9 deletions(-)
diff --git a/pkg/scheduler/objects/application.go b/pkg/scheduler/objects/application.go
index cde6fbd9..a064d321 100644
--- a/pkg/scheduler/objects/application.go
+++ b/pkg/scheduler/objects/application.go
@@ -1223,6 +1223,12 @@ func (sa *Application) tryPlaceholderAllocate(nodeIterator func() NodeIterator,
return allocResult
}
+// check ask against both user headRoom and queue headRoom
+func (sa *Application) checkHeadRooms(ask *AllocationAsk, userHeadroom *resources.Resource, headRoom *resources.Resource) bool {
+ // check if this fits in the users' headroom first, if that fits check the queues' headroom
+ return userHeadroom.FitInMaxUndef(ask.GetAllocatedResource()) && headRoom.FitInMaxUndef(ask.GetAllocatedResource())
+}
+
// Try a reserved allocation of an outstanding reservation
func (sa *Application) tryReservedAllocate(headRoom *resources.Resource, nodeIterator func() NodeIterator) *Allocation {
sa.Lock()
@@ -1250,13 +1256,8 @@ func (sa *Application) tryReservedAllocate(headRoom *resources.Resource, nodeIte
alloc := newUnreservedAllocation(reserve.nodeID, unreserveAsk)
return alloc
}
- // check if this fits in the users' headroom first, if that fits check the queues' headroom
- if !userHeadroom.FitInMaxUndef(ask.GetAllocatedResource()) {
- continue
- }
- // check if this fits in the queue's headroom
- if !headRoom.FitInMaxUndef(ask.GetAllocatedResource()) {
+ if !sa.checkHeadRooms(ask, userHeadroom, headRoom) {
continue
}
@@ -1280,12 +1281,16 @@ func (sa *Application) tryReservedAllocate(headRoom *resources.Resource, nodeIte
// lets try this on all other nodes
for _, reserve := range sa.reservations {
// Other nodes cannot be tried if the ask has a required node
- if reserve.ask.GetRequiredNode() != "" {
+ ask := reserve.ask
+ if ask.GetRequiredNode() != "" {
continue
}
iterator := nodeIterator()
if iterator != nil {
- alloc := sa.tryNodesNoReserve(reserve.ask, iterator, reserve.nodeID)
+ if !sa.checkHeadRooms(ask, userHeadroom, headRoom) {
+ continue
+ }
+ alloc := sa.tryNodesNoReserve(ask, iterator, reserve.nodeID)
// have a candidate return it, including the node that was reserved
if alloc != nil {
return alloc
@@ -1490,7 +1495,7 @@ func (sa *Application) tryNode(node *Node, ask *AllocationAsk) *Allocation {
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",
+ log.Log(log.SchedApplication).DPanic("queue update failed unexpectedly",
zap.Error(err))
// revert the node update
node.RemoveAllocation(alloc.GetAllocationID())
diff --git a/pkg/scheduler/objects/application_test.go b/pkg/scheduler/objects/application_test.go
index bc055ee6..04439672 100644
--- a/pkg/scheduler/objects/application_test.go
+++ b/pkg/scheduler/objects/application_test.go
@@ -2601,6 +2601,39 @@ func TestGetRateLimitedAppLog(t *testing.T) {
assert.Check(t, l != nil)
}
+func TestTryAllocateWithReservedHeadRoomChecking(t *testing.T) {
+ defer func() {
+ if r := recover(); r != nil {
+ t.Fatalf("reserved headroom test regression: %v", r)
+ }
+ }()
+
+ res, err := resources.NewResourceFromConf(map[string]string{"memory": "2G"})
+ assert.NilError(t, err, "failed to create basic resource")
+ var headRoom *resources.Resource
+ headRoom, err = resources.NewResourceFromConf(map[string]string{"memory": "1G"})
+ assert.NilError(t, err, "failed to create basic resource")
+
+ app := newApplication(appID1, "default", "root")
+ ask := newAllocationAsk(aKey, appID1, res)
+ var queue *Queue
+ queue, err = createRootQueue(map[string]string{"memory": "1G"})
+ assert.NilError(t, err, "queue create failed")
+ app.queue = queue
+ err = app.AddAllocationAsk(ask)
+ assert.NilError(t, err, "ask should have been added to app")
+
+ node1 := newNodeRes(nodeID1, res)
+ node2 := newNodeRes(nodeID2, res)
+ // reserve that works
+ err = app.Reserve(node1, ask)
+ assert.NilError(t, err, "reservation should not have failed")
+
+ iter := getNodeIteratorFn(node1, node2)
+ alloc := app.tryReservedAllocate(headRoom, iter)
+ assert.Assert(t, alloc == nil, "Alloc is expected to be nil due to insufficient headroom")
+}
+
func TestUpdateRunnableStatus(t *testing.T) {
app := newApplication(appID0, "default", "root.unknown")
assert.Assert(t, app.runnableInQueue)
diff --git a/pkg/scheduler/objects/utilities_test.go b/pkg/scheduler/objects/utilities_test.go
index e66e4e98..577e26ff 100644
--- a/pkg/scheduler/objects/utilities_test.go
+++ b/pkg/scheduler/objects/utilities_test.go
@@ -42,6 +42,7 @@ const (
aKey = "alloc-1"
aAllocationID = "alloc-allocationid-1"
nodeID1 = "node-1"
+ nodeID2 = "node-2"
instType1 = "itype-1"
)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org