From 3aefea0fe2c508c6a9222148acf4ef754f3fc5b0 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 10 Oct 2012 01:10:05 -0700 Subject: [PATCH] show volume status --- weed-fs/src/cmd/weed/master.go | 8 ++++++++ weed-fs/src/pkg/topology/topology.go | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go index 08134f3bf..b84e1d4b1 100644 --- a/weed-fs/src/cmd/weed/master.go +++ b/weed-fs/src/cmd/weed/master.go @@ -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 { if *mMaxCpu < 1 { *mMaxCpu = runtime.NumCPU() @@ -156,6 +163,7 @@ func runMaster(cmd *Command, args []string) bool { http.HandleFunc("/dir/join", dirJoinHandler) http.HandleFunc("/dir/status", dirStatusHandler) http.HandleFunc("/vol/grow", volumeGrowHandler) + http.HandleFunc("/vol/status", volumeStatusHandler) topo.StartRefreshWritableVolumes() diff --git a/weed-fs/src/pkg/topology/topology.go b/weed-fs/src/pkg/topology/topology.go index 28340233c..836a5cc69 100644 --- a/weed-fs/src/pkg/topology/topology.go +++ b/weed-fs/src/pkg/topology/topology.go @@ -162,3 +162,30 @@ func (t *Topology) ToMap() interface{} { m["layouts"] = layouts 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 +}