in pkg/mgmapi/clusterstatus.go [141:190]
func (cs ClusterStatus) GetNodesGroupedByNodegroup() [][]int {
// Map to store the nodes based on nodegroup
nodesInNodeGroupMap := make(map[int][]int)
for nodeId, node := range cs {
if !node.IsDataNode() {
// not a data node
continue
}
nodegroup := node.NodeGroup
if !node.IsConnected {
if nodegroup == NodeGroupNewDisconnectedDataNode {
// node is not inducted into cluster yet
continue
}
// data node not connected
debug.Panic("should be called only when the cluster is healthy")
return nil
}
if nodegroup == NodeGroupNewConnectedDataNode {
// ignore new connected data nodes without a nodegroup
continue
}
// append the node id to the map based on nodegroup
nodesInNodeGroupMap[nodegroup] = append(nodesInNodeGroupMap[nodegroup], nodeId)
}
// The map has the required node ids grouped under node groups
// but nothing is sorted yet. Sort the output based on node groups
// and then the sort the node ids under them
nodeGroupIds := make([]int, 0, len(nodesInNodeGroupMap))
for ng, nodeIdsInNodegroup := range nodesInNodeGroupMap {
nodeGroupIds = append(nodeGroupIds, ng)
// sort the node ids
sort.Ints(nodeIdsInNodegroup)
}
// sort the node group
sort.Ints(nodeGroupIds)
// Copy out the sorted output in an [][]int and return
nodesGroupedByNodegroup := make([][]int, 0, len(nodesInNodeGroupMap))
for ng := range nodeGroupIds {
nodesGroupedByNodegroup = append(nodesGroupedByNodegroup, nodesInNodeGroupMap[ng])
}
return nodesGroupedByNodegroup
}