Use type ClusterStatusResult for writing and reading results

This commit is contained in:
Chris Lu 2014-04-15 09:30:08 -07:00
parent cb56322937
commit 7ad6cd35e8
3 changed files with 16 additions and 16 deletions

View file

@ -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) {

View file

@ -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()})
}
}

View file

@ -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()
if leader, e := s.topo.Leader(); e == nil {
m["Leader"] = leader
} else {
m["Leader"] = ""
ret := operation.ClusterStatusResult{
IsLeader: s.topo.IsLeader(),
Peers: s.Peers(),
}
m["Peers"] = s.Peers()
writeJsonQuiet(w, r, m)
if leader, e := s.topo.Leader(); e == nil {
ret.Leader = leader
}
writeJsonQuiet(w, r, ret)
}