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


##########
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)

Review Comment:
   ```go
   result = append(result, getPartitionNodesUtilJSON(part))
   ```
   
   how about this style?



##########
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)
+
+               // append to bucket based on resource type, only count if node 
advertises the resource
+               for resourceType := range capacity.Resources {
+                       idx := 0
+                       if absValue, ok := 
absUsedCapacity.Resources[resourceType]; ok {

Review Comment:
   what if the keys of `absUsedCapacity` are not equal to `capacity`? the `idx` 
is always 0 



-- 
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