aboutsummaryrefslogtreecommitdiff
path: root/go/operation/list_masters.go
blob: 05235aed024ecad737a556f3ddfbf0c726e6d4be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package operation

import (
	"code.google.com/p/weed-fs/go/glog"
	"code.google.com/p/weed-fs/go/util"
	"encoding/json"
)

type ClusterStatusResult struct {
	IsLeader bool
	Leader   string
	Peers    []string
}

func ListMasters(server string) ([]string, error) {
	jsonBlob, err := util.Get("http://" + server + "/cluster/status")
	glog.V(2).Info("list masters result :", string(jsonBlob))
	if err != nil {
		return nil, err
	}
	var ret ClusterStatusResult
	err = json.Unmarshal(jsonBlob, &ret)
	if err != nil {
		return nil, err
	}
	return ret.Peers, nil
}