aboutsummaryrefslogtreecommitdiff
path: root/weed/server/master_grpc_server_cluster.go
blob: a5c82627adf56bf111b0141020baf13dcaf17ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package weed_server

import (
	"context"
	"github.com/chrislusf/seaweedfs/weed/cluster"
	"github.com/chrislusf/seaweedfs/weed/pb"
	"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
	"math/rand"
)

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{
			Address:  string(node.Address),
			Version:  node.Version,
			IsLeader: ms.Cluster.IsOneLeader(node.Address),
		})
	}
	return resp, nil
}

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"
}