|
@ -1,7 +1,6 @@ |
|
|
package main |
|
|
package main |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"bytes" |
|
|
|
|
|
"code.google.com/p/weed-fs/go/operation" |
|
|
"code.google.com/p/weed-fs/go/operation" |
|
|
"code.google.com/p/weed-fs/go/replication" |
|
|
"code.google.com/p/weed-fs/go/replication" |
|
|
"code.google.com/p/weed-fs/go/storage" |
|
|
"code.google.com/p/weed-fs/go/storage" |
|
@ -100,46 +99,8 @@ func freezeVolumeHandler(w http.ResponseWriter, r *http.Request) { |
|
|
} |
|
|
} |
|
|
debug("freeze volume =", r.FormValue("volume"), ", error =", err) |
|
|
debug("freeze volume =", r.FormValue("volume"), ", error =", err) |
|
|
} |
|
|
} |
|
|
func submitForClientHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
m := make(map[string]interface{}) |
|
|
|
|
|
if r.Method != "POST" { |
|
|
|
|
|
m["error"] = "Only submit via POST!" |
|
|
|
|
|
writeJsonQuiet(w, r, m) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debug("parsing upload file...") |
|
|
|
|
|
fname, data, mimeType, isGzipped, lastModified, pe := storage.ParseUpload(r) |
|
|
|
|
|
if pe != nil { |
|
|
|
|
|
writeJsonError(w, r, pe) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debug("assigning file id for", fname) |
|
|
|
|
|
assignResult, ae := Assign(*masterNode, 1) |
|
|
|
|
|
if ae != nil { |
|
|
|
|
|
writeJsonError(w, r, ae) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
url := "http://" + assignResult.PublicUrl + "/" + assignResult.Fid |
|
|
|
|
|
if lastModified != 0 { |
|
|
|
|
|
url = url + "?ts=" + strconv.FormatUint(lastModified, 10) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debug("upload file to store", url) |
|
|
|
|
|
uploadResult, err := operation.Upload(url, fname, bytes.NewReader(data), isGzipped, mimeType) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
writeJsonError(w, r, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m["fileName"] = fname |
|
|
|
|
|
m["fid"] = assignResult.Fid |
|
|
|
|
|
m["fileUrl"] = assignResult.PublicUrl + "/" + assignResult.Fid |
|
|
|
|
|
m["size"] = uploadResult.Size |
|
|
|
|
|
writeJsonQuiet(w, r, m) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
func submitFromVolumeServerHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
submitForClientHandler(w, r, *masterNode) |
|
|
} |
|
|
} |
|
|
func storeHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func storeHandler(w http.ResponseWriter, r *http.Request) { |
|
|
switch r.Method { |
|
|
switch r.Method { |
|
@ -376,7 +337,7 @@ func runVolume(cmd *Command, args []string) bool { |
|
|
store = storage.NewStore(*vport, *ip, *publicUrl, folders, maxCounts) |
|
|
store = storage.NewStore(*vport, *ip, *publicUrl, folders, maxCounts) |
|
|
defer store.Close() |
|
|
defer store.Close() |
|
|
http.HandleFunc("/", storeHandler) |
|
|
http.HandleFunc("/", storeHandler) |
|
|
http.HandleFunc("/submit", submitForClientHandler) |
|
|
|
|
|
|
|
|
http.HandleFunc("/submit", submitFromVolumeServerHandler) |
|
|
http.HandleFunc("/status", statusHandler) |
|
|
http.HandleFunc("/status", statusHandler) |
|
|
http.HandleFunc("/admin/assign_volume", assignVolumeHandler) |
|
|
http.HandleFunc("/admin/assign_volume", assignVolumeHandler) |
|
|
http.HandleFunc("/admin/vacuum_volume_check", vacuumVolumeCheckHandler) |
|
|
http.HandleFunc("/admin/vacuum_volume_check", vacuumVolumeCheckHandler) |
|
|