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.

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