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.

31 lines
723 B

  1. package operation
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/util"
  5. "encoding/json"
  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. }