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.1 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. clusterNodes := ms.Cluster.ListClusterNode(req.ClientType)
  12. for _, node := range clusterNodes {
  13. resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{
  14. Address: string(node.Address),
  15. Version: node.Version,
  16. IsLeader: ms.Cluster.IsOneLeader(node.Address),
  17. })
  18. }
  19. return resp, nil
  20. }
  21. func (ms *MasterServer) GetOneFiler() pb.ServerAddress {
  22. clusterNodes := ms.Cluster.ListClusterNode(cluster.FilerType)
  23. var filers []pb.ServerAddress
  24. for _, node := range clusterNodes {
  25. if ms.Cluster.IsOneLeader(node.Address) {
  26. filers = append(filers, node.Address)
  27. }
  28. }
  29. if len(filers) > 0 {
  30. return filers[rand.Intn(len(filers))]
  31. }
  32. return "localhost:8888"
  33. }