list_masters.go 774 B

1234567891011121314151617181920212223242526272829303132
  1. package operation
  2. import (
  3. "encoding/json"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/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) (leader string, peers []string, err 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. peers = ret.Peers
  24. if ret.IsLeader {
  25. peers = append(peers, ret.Leader)
  26. }
  27. return ret.Leader, peers, nil
  28. }