master_client.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package cluster
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/glog"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  7. "google.golang.org/grpc"
  8. )
  9. func ListExistingPeerUpdates(master pb.ServerAddress, grpcDialOption grpc.DialOption, filerGroup string, clientType string) (existingNodes []*master_pb.ClusterNodeUpdate) {
  10. if grpcErr := pb.WithMasterClient(false, master, grpcDialOption, false, func(client master_pb.SeaweedClient) error {
  11. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  12. ClientType: clientType,
  13. FilerGroup: filerGroup,
  14. })
  15. glog.V(0).Infof("the cluster has %d %s\n", len(resp.ClusterNodes), clientType)
  16. for _, node := range resp.ClusterNodes {
  17. existingNodes = append(existingNodes, &master_pb.ClusterNodeUpdate{
  18. NodeType: FilerType,
  19. Address: node.Address,
  20. IsLeader: node.IsLeader,
  21. IsAdd: true,
  22. CreatedAtNs: node.CreatedAtNs,
  23. })
  24. }
  25. return err
  26. }); grpcErr != nil {
  27. glog.V(0).Infof("connect to %s: %v", master, grpcErr)
  28. }
  29. return
  30. }