Browse Source

Use type ClusterStatusResult for writing and reading results

pull/2/head
Chris Lu 11 years ago
parent
commit
7ad6cd35e8
  1. 6
      go/operation/list_masters.go
  2. 10
      go/weed/weed_server/master_server_handlers.go
  3. 14
      go/weed/weed_server/raft_server_handlers.go

6
go/operation/list_masters.go

@ -7,9 +7,9 @@ import (
)
type ClusterStatusResult struct {
IsLeader bool
Leader string
Peers []string
IsLeader bool `json:"IsLeader,omitempty"`
Leader string `json:"Leader,omitempty"`
Peers []string `json:"Peers,omitempty"`
}
func ListMasters(server string) ([]string, error) {

10
go/weed/weed_server/master_server_handlers.go

@ -74,21 +74,21 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
option, err := ms.getVolumeGrowOption(r)
if err != nil {
w.WriteHeader(http.StatusNotAcceptable)
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
writeJsonQuiet(w, r, operation.AssignResult{Error: err.Error()})
return
}
if !ms.Topo.HasWriableVolume(option) {
if ms.Topo.FreeSpace() <= 0 {
w.WriteHeader(http.StatusNotFound)
writeJsonQuiet(w, r, AssignResult{Error: "No free volumes left!"})
writeJsonQuiet(w, r, operation.AssignResult{Error: "No free volumes left!"})
return
} else {
ms.vgLock.Lock()
defer ms.vgLock.Unlock()
if !ms.Topo.HasWriableVolume(option) {
if _, err = ms.vg.AutomaticGrowByType(option, ms.Topo); err != nil {
writeJsonQuiet(w, r, AssignResult{Error: "Cannot grow volume group! " + err.Error()})
writeJsonQuiet(w, r, operation.AssignResult{Error: "Cannot grow volume group! " + err.Error()})
return
}
}
@ -96,9 +96,9 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
}
fid, count, dn, err := ms.Topo.PickForWrite(requestedCount, option)
if err == nil {
writeJsonQuiet(w, r, AssignResult{Fid: fid, Url: dn.Url(), PublicUrl: dn.PublicUrl, Count: count})
writeJsonQuiet(w, r, operation.AssignResult{Fid: fid, Url: dn.Url(), PublicUrl: dn.PublicUrl, Count: count})
} else {
w.WriteHeader(http.StatusNotAcceptable)
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
writeJsonQuiet(w, r, operation.AssignResult{Error: err.Error()})
}
}

14
go/weed/weed_server/raft_server_handlers.go

@ -2,6 +2,7 @@ package weed_server
import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"encoding/json"
"github.com/goraft/raft"
"io/ioutil"
@ -51,13 +52,12 @@ func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request)
}
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["IsLeader"] = s.topo.IsLeader()
ret := operation.ClusterStatusResult{
IsLeader: s.topo.IsLeader(),
Peers: s.Peers(),
}
if leader, e := s.topo.Leader(); e == nil {
m["Leader"] = leader
} else {
m["Leader"] = ""
ret.Leader = leader
}
m["Peers"] = s.Peers()
writeJsonQuiet(w, r, m)
writeJsonQuiet(w, r, ret)
}
Loading…
Cancel
Save