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.

41 lines
1.3 KiB

  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.FilerGroup(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, node.Address),
  18. CreatedAtNs: node.CreatedTs.UnixNano(),
  19. })
  20. }
  21. return resp, nil
  22. }
  23. func (ms *MasterServer) GetOneFiler(filerGroup cluster.FilerGroup) pb.ServerAddress {
  24. clusterNodes := ms.Cluster.ListClusterNode(filerGroup, cluster.FilerType)
  25. var filers []pb.ServerAddress
  26. for _, node := range clusterNodes {
  27. if ms.Cluster.IsOneLeader(filerGroup, node.Address) {
  28. filers = append(filers, node.Address)
  29. }
  30. }
  31. if len(filers) > 0 {
  32. return filers[rand.Intn(len(filers))]
  33. }
  34. return "localhost:8888"
  35. }