2021-11-03 14:38:45 +08:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-12 17:11:25 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2021-11-03 14:38:45 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
2022-01-12 17:11:25 +08:00
|
|
|
"math/rand"
|
2021-11-03 14:38:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) {
|
|
|
|
resp := &master_pb.ListClusterNodesResponse{}
|
|
|
|
|
|
|
|
clusterNodes := ms.Cluster.ListClusterNode(req.ClientType)
|
|
|
|
|
|
|
|
for _, node := range clusterNodes {
|
|
|
|
resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{
|
2022-01-12 17:11:25 +08:00
|
|
|
Address: string(node.Address),
|
|
|
|
Version: node.Version,
|
2021-11-07 05:23:35 +08:00
|
|
|
IsLeader: ms.Cluster.IsOneLeader(node.Address),
|
2021-11-03 14:38:45 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
2022-01-12 17:11:25 +08:00
|
|
|
|
|
|
|
func (ms *MasterServer) GetOneFiler() pb.ServerAddress {
|
|
|
|
|
|
|
|
clusterNodes := ms.Cluster.ListClusterNode(cluster.FilerType)
|
|
|
|
|
|
|
|
var filers []pb.ServerAddress
|
|
|
|
for _, node := range clusterNodes {
|
|
|
|
if ms.Cluster.IsOneLeader(node.Address) {
|
|
|
|
filers = append(filers, node.Address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(filers) > 0 {
|
|
|
|
return filers[rand.Intn(len(filers))]
|
|
|
|
}
|
|
|
|
return "localhost:8888"
|
|
|
|
}
|