chenyulin0719 commented on code in PR #762:
URL: https://github.com/apache/yunikorn-core/pull/762#discussion_r1436106056


##########
pkg/webservice/handlers.go:
##########
@@ -418,6 +420,80 @@ func getNodesUtilJSON(partition 
*scheduler.PartitionContext, name string) *dao.N
        }
 }
 
+func getNodeUtilisations(w http.ResponseWriter, r *http.Request) {
+       writeHeaders(w)
+       var result []*dao.PartitionNodesUtilDAOInfo
+       for _, part := range schedulerContext.GetPartitionMapClone() {
+               partitionNodesUtilJSON := getPartitionNodesUtilJSON(part)
+               result = append(result, partitionNodesUtilJSON)
+       }
+
+       if err := json.NewEncoder(w).Encode(result); err != nil {
+               buildJSONErrorResponse(w, err.Error(), 
http.StatusInternalServerError)
+       }
+}
+
+// getPartitionNodesUtilJSON retrieves the utilization of all resource types 
for nodes within a specific partition.
+func getPartitionNodesUtilJSON(partition *scheduler.PartitionContext) 
*dao.PartitionNodesUtilDAOInfo {
+       type UtilizationBucket struct {
+               NodeCount []int      // 10 buckets, each bucket contains number 
of nodes
+               NodeList  [][]string // 10 buckets, each bucket contains node 
name list
+       }
+       resourceBuckets := make(map[string]*UtilizationBucket) // key is 
resource type, value is UtilizationBucket
+
+       // put nodes to buckets
+       for _, node := range partition.GetNodes() {
+               capacity := node.GetCapacity()
+               resourceAllocated := node.GetAllocatedResource()
+               absUsedCapacity := resources.CalculateAbsUsedCapacity(capacity, 
resourceAllocated)

Review Comment:
    Call CalculateAbsUsedCapacity() once per node



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to