This is an automated email from the ASF dual-hosted git repository.

manirajv06 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 568247d1 [YUNIKORN-3234] Remove node-utilization redirect from routes 
(#1092)
568247d1 is described below

commit 568247d1435b0d0275d28f50c55b959c587024fc
Author: Wilfred Spiegelenburg <[email protected]>
AuthorDate: Wed Jun 10 13:25:40 2026 +0530

    [YUNIKORN-3234] Remove node-utilization redirect from routes (#1092)
    
    The deprecated "/ws/v1/scheduler/node-utilization" was replaced with
    "/ws/v1/scheduler/node-utilizations" as part of YuniKorn 1.5.
    
    Removal of the code and redirect as part of YuniKorn 1.9.
    
    Closes: #1092
    
    Signed-off-by: mani <[email protected]>
---
 pkg/webservice/handlers.go      |  69 --------------------
 pkg/webservice/handlers_test.go | 139 ----------------------------------------
 pkg/webservice/routes.go        |   8 ---
 3 files changed, 216 deletions(-)

diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go
index f5cf9e44..2698b525 100644
--- a/pkg/webservice/handlers.go
+++ b/pkg/webservice/handlers.go
@@ -456,75 +456,6 @@ func getNodesDAO(entries []*objects.Node) 
[]*dao.NodeDAOInfo {
        return nodesDAO
 }
 
-// getNodeUtilisation loads the node utilisation based on the dominant 
resource used
-// for the default partition. Dominant resource is defined as the highest 
utilised resource
-// type on the root queue based on the registered resources.
-// Only check the default partition
-// Deprecated - To be removed in next major release. Replaced with 
getNodesUtilisations
-func getNodeUtilisation(w http.ResponseWriter, r *http.Request) {
-       writeHeaders(w, r.Method)
-       partitionContext := 
schedulerContext.Load().GetPartitionWithoutClusterID(configs.DefaultPartition)
-       if partitionContext == nil {
-               buildJSONErrorResponse(w, PartitionDoesNotExists, 
http.StatusInternalServerError)
-               return
-       }
-       // calculate the dominant resource based on root queue usage and size
-       rootQ := partitionContext.GetQueue(configs.RootQueue)
-       rootMax := rootQ.GetMaxResource()
-       // if no nodes have been registered return an empty object
-       nodesDao := &dao.NodesUtilDAOInfo{}
-       if !resources.IsZero(rootMax) {
-               // if nothing is used we get an empty dominant resource and 
return an empty object
-               rootUsed := rootQ.GetAllocatedResource()
-               dominant := rootUsed.DominantResourceType(rootMax)
-               nodesDao = getNodesUtilJSON(partitionContext, dominant)
-       }
-       if err := json.NewEncoder(w).Encode(nodesDao); err != nil {
-               buildJSONErrorResponse(w, err.Error(), 
http.StatusInternalServerError)
-       }
-}
-
-// getNodesUtilJSON loads the nodes utilisation for a partition for a specific 
resource type.
-// Deprecated - To be removed in next major release. Replaced with 
getPartitionNodesUtilJSON
-func getNodesUtilJSON(partition *scheduler.PartitionContext, name string) 
*dao.NodesUtilDAOInfo {
-       mapResult := make([]int, 10)
-       mapName := make([][]string, 10)
-       var v float64
-       var nodeUtil []*dao.NodeUtilDAOInfo
-       var idx int
-       for _, node := range partition.GetNodes() {
-               // check resource exist or not: only count if node advertises 
the resource
-               total := node.GetCapacity()
-               if _, ok := total.Resources[name]; !ok {
-                       continue
-               }
-               resourceAllocated := node.GetAllocatedResource()
-               // if resource exist in node, record the bucket it should go 
into,
-               // otherwise none is used, and it should end up in the 0 bucket
-               if _, ok := resourceAllocated.Resources[name]; ok {
-                       v = float64(resources.CalculateAbsUsedCapacity(total, 
resourceAllocated).Resources[name])
-                       idx = int(math.Dim(math.Ceil(v/10), 1))
-               } else {
-                       idx = 0
-               }
-               mapResult[idx]++
-               mapName[idx] = append(mapName[idx], node.NodeID)
-       }
-       // put number of nodes and node name to different buckets
-       for k := 0; k < 10; k++ {
-               util := &dao.NodeUtilDAOInfo{
-                       BucketName: fmt.Sprintf("%d", k*10) + "-" + 
fmt.Sprintf("%d", (k+1)*10) + "%",
-                       NumOfNodes: int64(mapResult[k]),
-                       NodeNames:  mapName[k],
-               }
-               nodeUtil = append(nodeUtil, util)
-       }
-       return &dao.NodesUtilDAOInfo{
-               ResourceType: name,
-               NodesUtil:    nodeUtil,
-       }
-}
-
 func getNodeUtilisations(w http.ResponseWriter, r *http.Request) {
        writeHeaders(w, r.Method)
        var result []*dao.PartitionNodesUtilDAOInfo
diff --git a/pkg/webservice/handlers_test.go b/pkg/webservice/handlers_test.go
index db305793..2ff1f76a 100644
--- a/pkg/webservice/handlers_test.go
+++ b/pkg/webservice/handlers_test.go
@@ -687,145 +687,6 @@ func ContainsObj(slice interface{}, contains interface{}) 
bool {
        return false
 }
 
-func TestGetNodesUtilJSON(t *testing.T) {
-       partition := setup(t, configDefault, 1)
-
-       // create test application
-       app := newApplication("app1", partition.Name, queueName, rmID, 
security.UserGroup{})
-       err := partition.AddApplication(app)
-       assert.NilError(t, err, "add application to partition should not have 
failed")
-
-       // create test nodes
-       nodeRes := 
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory: 
1000, siCommon.CPU: 1000}).ToProto()
-       node1 := objects.NewNode(&si.NodeInfo{NodeID: "node-1", 
SchedulableResource: nodeRes})
-       nodeRes2 := 
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory: 
1000, siCommon.CPU: 1000, "GPU": 10}).ToProto()
-       node2 := objects.NewNode(&si.NodeInfo{NodeID: "node-2", 
SchedulableResource: nodeRes2})
-       nodeCPU := 
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.CPU: 
1000}).ToProto()
-       node3 := objects.NewNode(&si.NodeInfo{NodeID: "node-3", 
SchedulableResource: nodeCPU})
-
-       // create test allocations
-       resAlloc1 := 
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory: 
500, siCommon.CPU: 300})
-       resAlloc2 := 
resources.NewResourceFromMap(map[string]resources.Quantity{siCommon.Memory: 
300, siCommon.CPU: 500, "GPU": 5})
-       alloc1 := newAlloc("alloc-1", app.ApplicationID, node1.NodeID, 
resAlloc1)
-       allocs := []*objects.Allocation{alloc1}
-       err = partition.AddNode(node1)
-       assert.NilError(t, err, "add node to partition should not have failed")
-       _, allocCreated, err := partition.UpdateAllocation(allocs[0])
-       assert.NilError(t, err, "add alloc-1 should not have failed")
-       assert.Check(t, allocCreated)
-       alloc2 := newAlloc("alloc-2", app.ApplicationID, node2.NodeID, 
resAlloc2)
-       allocs = []*objects.Allocation{alloc2}
-       err = partition.AddNode(node2)
-       assert.NilError(t, err, "add node to partition should not have failed")
-       _, allocCreated, err = partition.UpdateAllocation(allocs[0])
-       assert.NilError(t, err, "add alloc-2 should not have failed")
-       assert.Check(t, allocCreated)
-       err = partition.AddNode(node3)
-       assert.NilError(t, err, "add node to partition should not have failed")
-
-       // two nodes advertise memory: must show up in the list
-       result := getNodesUtilJSON(partition, siCommon.Memory)
-       subResult := result.NodesUtil
-       assert.Equal(t, result.ResourceType, siCommon.Memory)
-       assert.Equal(t, subResult[2].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[4].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[2].NodeNames[0], node2.NodeID)
-       assert.Equal(t, subResult[4].NodeNames[0], node1.NodeID)
-
-       // three nodes advertise cpu: must show up in the list
-       result = getNodesUtilJSON(partition, siCommon.CPU)
-       subResult = result.NodesUtil
-       assert.Equal(t, result.ResourceType, siCommon.CPU)
-       assert.Equal(t, subResult[0].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[0].NodeNames[0], node3.NodeID)
-       assert.Equal(t, subResult[2].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[2].NodeNames[0], node1.NodeID)
-       assert.Equal(t, subResult[4].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[4].NodeNames[0], node2.NodeID)
-
-       // one node advertise GPU: must show up in the list
-       result = getNodesUtilJSON(partition, "GPU")
-       subResult = result.NodesUtil
-       assert.Equal(t, result.ResourceType, "GPU")
-       assert.Equal(t, subResult[4].NumOfNodes, int64(1))
-       assert.Equal(t, subResult[4].NodeNames[0], node2.NodeID)
-
-       result = getNodesUtilJSON(partition, "non-exist")
-       subResult = result.NodesUtil
-       assert.Equal(t, result.ResourceType, "non-exist")
-       assert.Equal(t, subResult[0].NumOfNodes, int64(0))
-       assert.Equal(t, len(subResult[0].NodeNames), 0)
-}
-
-func TestGetNodeUtilisation(t *testing.T) {
-       NewWebApp(&scheduler.ClusterContext{}, nil)
-
-       // var req *http.Request
-       req, err := http.NewRequest("GET", "/ws/v1/scheduler/node-utilization", 
strings.NewReader(""))
-       assert.NilError(t, err, "Get node utilisation Handler request failed")
-       req = req.WithContext(context.TODO())
-       resp := &MockResponseWriter{}
-
-       getNodeUtilisation(resp, req)
-       var errInfo dao.YAPIError
-       err = json.Unmarshal(resp.outputBytes, &errInfo)
-       assert.NilError(t, err, "getNodeUtilisation should have returned and 
error")
-
-       partition := setup(t, configDefault, 1)
-       utilisation := &dao.NodesUtilDAOInfo{}
-       err = json.Unmarshal(resp.outputBytes, utilisation)
-       assert.NilError(t, err, "getNodeUtilisation should have returned an 
empty object")
-       assert.Equal(t, utilisation.ResourceType, "", "unexpected type 
returned")
-       assert.Equal(t, len(utilisation.NodesUtil), 0, "no nodes should be 
returned")
-       assert.Assert(t, confirmNodeCount(utilisation.NodesUtil, 0), 
"unexpected number of nodes returned should be 0")
-
-       // create test nodes
-       node1 := addNode(t, partition, "node-1", 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10}))
-       node2 := addNode(t, partition, "node-2", 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10, 
"second": 5}))
-
-       // get nodes utilization
-       resp = &MockResponseWriter{}
-       getNodeUtilisation(resp, req)
-       utilisation = &dao.NodesUtilDAOInfo{}
-       err = json.Unmarshal(resp.outputBytes, utilisation)
-       assert.NilError(t, err, "getNodeUtilisation should have returned an 
object")
-       assert.Equal(t, utilisation.ResourceType, "", "unexpected type 
returned")
-       assert.Equal(t, len(utilisation.NodesUtil), 10, "empty usage: 
unexpected bucket count returned")
-       assert.Assert(t, confirmNodeCount(utilisation.NodesUtil, 0), 
"unexpected number of nodes returned should be 0")
-
-       resAlloc := 
resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
-       alloc := newAlloc("alloc-1", "app", node1.NodeID, resAlloc)
-       assert.Assert(t, node1.TryAddAllocation(alloc), "unexpected failure 
adding allocation to node")
-       rootQ := partition.GetQueue("root")
-       err = rootQ.TryIncAllocatedResource(resAlloc)
-       assert.NilError(t, err, "unexpected error returned setting allocated 
resource on queue")
-       // get nodes utilization
-       resp = &MockResponseWriter{}
-       getNodeUtilisation(resp, req)
-       utilisation = &dao.NodesUtilDAOInfo{}
-       err = json.Unmarshal(resp.outputBytes, utilisation)
-       assert.NilError(t, err, "getNodeUtilisation should have returned an 
object")
-       assert.Equal(t, utilisation.ResourceType, "first", "expected first as 
type returned")
-       assert.Equal(t, len(utilisation.NodesUtil), 10, "empty usage: 
unexpected bucket count returned")
-       assert.Assert(t, confirmNodeCount(utilisation.NodesUtil, 2), 
"unexpected number of nodes returned should be 2")
-
-       // make second type dominant by using all
-       resAlloc = 
resources.NewResourceFromMap(map[string]resources.Quantity{"second": 5})
-       alloc = newAlloc("alloc-2", "app", node2.NodeID, resAlloc)
-       assert.Assert(t, node2.TryAddAllocation(alloc), "unexpected failure 
adding allocation to node")
-       err = rootQ.TryIncAllocatedResource(resAlloc)
-       assert.NilError(t, err, "unexpected error returned setting allocated 
resource on queue")
-       // get nodes utilization
-       resp = &MockResponseWriter{}
-       getNodeUtilisation(resp, req)
-       utilisation = &dao.NodesUtilDAOInfo{}
-       err = json.Unmarshal(resp.outputBytes, utilisation)
-       assert.NilError(t, err, "getNodeUtilisation should have returned an 
object")
-       assert.Equal(t, utilisation.ResourceType, "second", "expected second as 
type returned")
-       assert.Equal(t, len(utilisation.NodesUtil), 10, "empty usage: 
unexpected bucket count returned")
-       assert.Assert(t, confirmNodeCount(utilisation.NodesUtil, 1), 
"unexpected number of nodes returned should be 1")
-}
-
 func addNode(t *testing.T, partition *scheduler.PartitionContext, nodeId 
string, resource *resources.Resource) *objects.Node {
        nodeRes := resource.ToProto()
        node := objects.NewNode(&si.NodeInfo{NodeID: nodeId, 
SchedulableResource: nodeRes})
diff --git a/pkg/webservice/routes.go b/pkg/webservice/routes.go
index 50c5e20a..6ecce4f9 100644
--- a/pkg/webservice/routes.go
+++ b/pkg/webservice/routes.go
@@ -274,14 +274,6 @@ var webRoutes = routes{
 
        // Deprecated REST calls
        //
-       // Replaced with /ws/v1/scheduler/node-utilizations as part of YuniKorn 
1.5
-       // Remove as part of YuniKorn 1.8
-       route{
-               Name:        "Scheduler",
-               Method:      "GET",
-               Pattern:     "/ws/v1/scheduler/node-utilization",
-               HandlerFunc: getNodeUtilisation,
-       },
        // Permanently moved to the debug endpoint as part of YuniKorn 1.7
        // Remove redirect in YuniKorn 1.10
        route{


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to