add more error handling, adjust volume size to 32G
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@32 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
@@ -29,6 +29,10 @@ var (
|
||||
func statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeJson(w, r, store.Status())
|
||||
}
|
||||
func addVolumeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
store.AddVolume(r.FormValue("volume"))
|
||||
writeJson(w, r, store.Status())
|
||||
}
|
||||
func storeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
@@ -133,6 +137,7 @@ func main() {
|
||||
defer store.Close()
|
||||
http.HandleFunc("/", storeHandler)
|
||||
http.HandleFunc("/status", statusHandler)
|
||||
http.HandleFunc("/add_volume", addVolumeHandler)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
|
||||
@@ -27,16 +27,22 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vid = vid[0:commaSep]
|
||||
}
|
||||
volumeId, _ := strconv.Atoui64(vid)
|
||||
machine := mapper.Get(uint32(volumeId))
|
||||
writeJson(w, r, machine.Server)
|
||||
}
|
||||
func dirWriteHandler(w http.ResponseWriter, r *http.Request) {
|
||||
_, machine := mapper.PickForWrite()
|
||||
writeJson(w, r, machine)
|
||||
machine, e := mapper.Get(uint32(volumeId))
|
||||
if e == nil {
|
||||
writeJson(w, r, machine.Server)
|
||||
} else {
|
||||
log.Println("Invalid volume id", volumeId)
|
||||
writeJson(w, r, map[string]string{"error": "volume id " + strconv.Uitoa64(volumeId) + " not found"})
|
||||
}
|
||||
}
|
||||
func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fid, machine := mapper.PickForWrite()
|
||||
writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url})
|
||||
fid, machine, err := mapper.PickForWrite()
|
||||
if err == nil {
|
||||
writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url})
|
||||
} else {
|
||||
log.Println(err)
|
||||
writeJson(w, r, map[string]string{"error": err.String()})
|
||||
}
|
||||
}
|
||||
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||
s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port")
|
||||
@@ -71,7 +77,6 @@ func main() {
|
||||
mapper = directory.NewMapper(*metaFolder, "directory")
|
||||
http.HandleFunc("/dir/assign", dirAssignHandler)
|
||||
http.HandleFunc("/dir/lookup", dirLookupHandler)
|
||||
http.HandleFunc("/dir/write", dirWriteHandler)
|
||||
http.HandleFunc("/dir/join", dirJoinHandler)
|
||||
http.HandleFunc("/dir/status", dirStatusHandler)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user