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.

42 lines
1.2 KiB

7 years ago
  1. package wdclient
  2. import (
  3. "context"
  4. "code.uber.internal/fraud/alpine/.gen/proto/go/fraud/alpine"
  5. )
  6. type SeaweedClient struct {
  7. ctx context.Context
  8. Master string
  9. ClientName string
  10. ClusterListener *clusterlistener.ClusterListener
  11. }
  12. // NewSeaweedClient creates a SeaweedFS client which contains a listener for the Seaweed system topology changes
  13. func NewSeaweedClient(ctx context.Context, clientName, master string) *SeaweedClient {
  14. c := &SeaweedClient{
  15. ctx: ctx,
  16. Master: master,
  17. ClusterListener: clusterlistener.NewClusterListener(clientName),
  18. ClientName: clientName,
  19. }
  20. c.ClusterListener.StartListener(ctx, c.Master)
  21. conn, err := grpc.Dial(c.Master, grpc.WithInsecure())
  22. if err != nil {
  23. glog.Fatalf("%s fail to dial %v: %v", c.ClientName, c.Master, err)
  24. }
  25. c.MasterClient = pb.NewAlpineMasterClient(conn)
  26. return c
  27. }
  28. // NewClusterClient create a lightweight client to access a specific cluster
  29. // TODO The call will block if the keyspace is not created in this data center.
  30. func (c *SeaweedClient) NewClusterClient(keyspace string) (clusterClient *ClusterClient) {
  31. return &ClusterClient{
  32. keyspace: keyspace,
  33. }
  34. }