in pkg/webservice/handlers.go [533:591]
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 {
v := float64(absValue)
idx = int(math.Dim(math.Ceil(v/10), 1))
}
// create resource bucket if not exist
if _, ok := resourceBuckets[resourceType]; !ok {
resourceBuckets[resourceType] = &UtilizationBucket{
NodeCount: make([]int, 10),
NodeList: make([][]string, 10),
}
}
resourceBuckets[resourceType].NodeCount[idx]++
resourceBuckets[resourceType].NodeList[idx] = append(resourceBuckets[resourceType].NodeList[idx], node.NodeID)
}
}
// build result
var nodesUtilList []*dao.NodesUtilDAOInfo
for resourceType, bucket := range resourceBuckets {
var nodesUtil []*dao.NodeUtilDAOInfo
for k := 0; k < 10; k++ {
util := &dao.NodeUtilDAOInfo{
BucketName: fmt.Sprintf("%d", k*10) + "-" + fmt.Sprintf("%d", (k+1)*10) + "%",
NumOfNodes: int64(bucket.NodeCount[k]),
NodeNames: bucket.NodeList[k],
}
nodesUtil = append(nodesUtil, util)
}
nodeUtilization := &dao.NodesUtilDAOInfo{
ResourceType: resourceType,
NodesUtil: nodesUtil,
}
nodesUtilList = append(nodesUtilList, nodeUtilization)
}
return &dao.PartitionNodesUtilDAOInfo{
ClusterID: partition.RmID,
Partition: common.GetPartitionNameWithoutClusterID(partition.Name),
NodesUtilList: nodesUtilList,
}
}