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.

61 lines
1.4 KiB

  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/mq/balancer"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandMqTopicList{})
  11. }
  12. type commandMqTopicList struct {
  13. }
  14. func (c *commandMqTopicList) Name() string {
  15. return "mq.topic.list"
  16. }
  17. func (c *commandMqTopicList) Help() string {
  18. return `print out all topics`
  19. }
  20. func (c *commandMqTopicList) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
  21. brokerBalancer, err := findBrokerBalancer(commandEnv)
  22. if err != nil {
  23. return err
  24. }
  25. //pb.WithBrokerGrpcClient(false, brokerBalancer, commandEnv.option.GrpcDialOption, func(client pb.SeaweedMessagingClient) error {
  26. // resp, err := client.ListTopics(context.Background(), &pb.ListTopicsRequest{})
  27. // if err != nil {
  28. // return err
  29. // }
  30. // for _, topic := range resp.Topics {
  31. // fmt.Fprintf(writer, "%s\n", topic)
  32. // }
  33. // return nil
  34. //})
  35. fmt.Fprintf(writer, "current balancer: %s\n", brokerBalancer)
  36. return nil
  37. }
  38. func findBrokerBalancer(commandEnv *CommandEnv) (brokerBalancer string, err error) {
  39. err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  40. resp, err := client.FindLockOwner(context.Background(), &filer_pb.FindLockOwnerRequest{
  41. Name: balancer.LockBrokerBalancer,
  42. })
  43. if err != nil {
  44. return err
  45. }
  46. brokerBalancer = resp.Owner
  47. return nil
  48. })
  49. return
  50. }