show volume status

This commit is contained in:
Chris Lu 2012-10-10 01:10:05 -07:00
parent 1d0be87e0e
commit 3aefea0fe2
2 changed files with 35 additions and 0 deletions

View file

@ -143,6 +143,13 @@ func volumeGrowHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
func volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = VERSION
m["Volumes"] = topo.ToVolumeMap()
writeJson(w, r, m)
}
func runMaster(cmd *Command, args []string) bool { func runMaster(cmd *Command, args []string) bool {
if *mMaxCpu < 1 { if *mMaxCpu < 1 {
*mMaxCpu = runtime.NumCPU() *mMaxCpu = runtime.NumCPU()
@ -156,6 +163,7 @@ func runMaster(cmd *Command, args []string) bool {
http.HandleFunc("/dir/join", dirJoinHandler) http.HandleFunc("/dir/join", dirJoinHandler)
http.HandleFunc("/dir/status", dirStatusHandler) http.HandleFunc("/dir/status", dirStatusHandler)
http.HandleFunc("/vol/grow", volumeGrowHandler) http.HandleFunc("/vol/grow", volumeGrowHandler)
http.HandleFunc("/vol/status", volumeStatusHandler)
topo.StartRefreshWritableVolumes() topo.StartRefreshWritableVolumes()

View file

@ -162,3 +162,30 @@ func (t *Topology) ToMap() interface{} {
m["layouts"] = layouts m["layouts"] = layouts
return m return m
} }
func (t *Topology) ToVolumeMap() interface{} {
m := make(map[string]interface{})
m["Max"] = t.GetMaxVolumeCount()
m["Free"] = t.FreeSpace()
dcs := make(map[NodeId]interface{})
for _, c := range t.Children() {
dc := c.(*DataCenter)
racks := make(map[NodeId]interface{})
for _, r := range dc.Children() {
rack := r.(*Rack)
dataNodes := make(map[NodeId]interface{})
for _, d := range rack.Children() {
dn := d.(*DataNode)
var volumes []interface{}
for _, v := range dn.volumes {
volumes = append(volumes, v)
}
dataNodes[d.Id()] = volumes
}
racks[r.Id()] = dataNodes
}
dcs[dc.Id()] = racks
}
m["DataCenters"] = dcs
return m
}