master_client.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. IsAdd: true,
  21. CreatedAtNs: node.CreatedAtNs,
  22. })
  23. }
  24. return err
  25. }); grpcErr != nil {
  26. glog.V(0).Infof("connect to %s: %v", master, grpcErr)
  27. }
  28. return
  29. }