You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. package weed_server
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/cluster"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  7. "math/rand"
  8. )
  9. func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) {
  10. resp := &master_pb.ListClusterNodesResponse{}
  11. filerGroup := cluster.FilerGroupName(req.FilerGroup)
  12. clusterNodes := ms.Cluster.ListClusterNode(filerGroup, req.ClientType)
  13. for _, node := range clusterNodes {
  14. resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{
  15. Address: string(node.Address),
  16. Version: node.Version,
  17. IsLeader: ms.Cluster.IsOneLeader(filerGroup, req.ClientType, node.Address),
  18. CreatedAtNs: node.CreatedTs.UnixNano(),
  19. DataCenter: string(node.DataCenter),
  20. Rack: string(node.Rack),
  21. })
  22. }
  23. return resp, nil
  24. }
  25. func (ms *MasterServer) GetOneFiler(filerGroup cluster.FilerGroupName) pb.ServerAddress {
  26. clusterNodes := ms.Cluster.ListClusterNode(filerGroup, cluster.FilerType)
  27. var filers []pb.ServerAddress
  28. for _, node := range clusterNodes {
  29. if ms.Cluster.IsOneLeader(filerGroup, cluster.FilerType, node.Address) {
  30. filers = append(filers, node.Address)
  31. }
  32. }
  33. if len(filers) > 0 {
  34. return filers[rand.Intn(len(filers))]
  35. }
  36. return "localhost:8888"
  37. }