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.

32 lines
734 B

  1. package operation
  2. import (
  3. "encoding/json"
  4. "github.com/chrislusf/seaweedfs/go/glog"
  5. "github.com/chrislusf/seaweedfs/go/util"
  6. )
  7. type ClusterStatusResult struct {
  8. IsLeader bool `json:"IsLeader,omitempty"`
  9. Leader string `json:"Leader,omitempty"`
  10. Peers []string `json:"Peers,omitempty"`
  11. }
  12. func ListMasters(server string) ([]string, error) {
  13. jsonBlob, err := util.Get("http://" + server + "/cluster/status")
  14. glog.V(2).Info("list masters result :", string(jsonBlob))
  15. if err != nil {
  16. return nil, err
  17. }
  18. var ret ClusterStatusResult
  19. err = json.Unmarshal(jsonBlob, &ret)
  20. if err != nil {
  21. return nil, err
  22. }
  23. masters := ret.Peers
  24. if ret.IsLeader {
  25. masters = append(masters, ret.Leader)
  26. }
  27. return masters, nil
  28. }