mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Use type ClusterStatusResult for writing and reading results
This commit is contained in:
parent
cb56322937
commit
7ad6cd35e8
|
@ -7,9 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClusterStatusResult struct {
|
type ClusterStatusResult struct {
|
||||||
IsLeader bool
|
IsLeader bool `json:"IsLeader,omitempty"`
|
||||||
Leader string
|
Leader string `json:"Leader,omitempty"`
|
||||||
Peers []string
|
Peers []string `json:"Peers,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListMasters(server string) ([]string, error) {
|
func ListMasters(server string) ([]string, error) {
|
||||||
|
|
|
@ -74,21 +74,21 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
||||||
option, err := ms.getVolumeGrowOption(r)
|
option, err := ms.getVolumeGrowOption(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusNotAcceptable)
|
w.WriteHeader(http.StatusNotAcceptable)
|
||||||
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
|
writeJsonQuiet(w, r, operation.AssignResult{Error: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ms.Topo.HasWriableVolume(option) {
|
if !ms.Topo.HasWriableVolume(option) {
|
||||||
if ms.Topo.FreeSpace() <= 0 {
|
if ms.Topo.FreeSpace() <= 0 {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
writeJsonQuiet(w, r, AssignResult{Error: "No free volumes left!"})
|
writeJsonQuiet(w, r, operation.AssignResult{Error: "No free volumes left!"})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
ms.vgLock.Lock()
|
ms.vgLock.Lock()
|
||||||
defer ms.vgLock.Unlock()
|
defer ms.vgLock.Unlock()
|
||||||
if !ms.Topo.HasWriableVolume(option) {
|
if !ms.Topo.HasWriableVolume(option) {
|
||||||
if _, err = ms.vg.AutomaticGrowByType(option, ms.Topo); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,9 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
fid, count, dn, err := ms.Topo.PickForWrite(requestedCount, option)
|
fid, count, dn, err := ms.Topo.PickForWrite(requestedCount, option)
|
||||||
if err == nil {
|
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 {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotAcceptable)
|
w.WriteHeader(http.StatusNotAcceptable)
|
||||||
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
|
writeJsonQuiet(w, r, operation.AssignResult{Error: err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package weed_server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/weed-fs/go/glog"
|
"code.google.com/p/weed-fs/go/glog"
|
||||||
|
"code.google.com/p/weed-fs/go/operation"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/goraft/raft"
|
"github.com/goraft/raft"
|
||||||
"io/ioutil"
|
"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) {
|
func (s *RaftServer) statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
m := make(map[string]interface{})
|
ret := operation.ClusterStatusResult{
|
||||||
m["IsLeader"] = s.topo.IsLeader()
|
IsLeader: s.topo.IsLeader(),
|
||||||
if leader, e := s.topo.Leader(); e == nil {
|
Peers: s.Peers(),
|
||||||
m["Leader"] = leader
|
|
||||||
} else {
|
|
||||||
m["Leader"] = ""
|
|
||||||
}
|
}
|
||||||
m["Peers"] = s.Peers()
|
if leader, e := s.topo.Leader(); e == nil {
|
||||||
writeJsonQuiet(w, r, m)
|
ret.Leader = leader
|
||||||
|
}
|
||||||
|
writeJsonQuiet(w, r, ret)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue