more error handling
This commit is contained in:
@@ -77,6 +77,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if topo.GetVolumeLayout(rt).GetActiveVolumeCount() <= 0 {
|
if topo.GetVolumeLayout(rt).GetActiveVolumeCount() <= 0 {
|
||||||
if topo.FreeSpace() <= 0 {
|
if topo.FreeSpace() <= 0 {
|
||||||
writeJson(w, r, map[string]string{"error": "No free volumes left!"})
|
writeJson(w, r, map[string]string{"error": "No free volumes left!"})
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
vg.GrowByType(rt, topo)
|
vg.GrowByType(rt, topo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func assign(count int) (*AssignResult, error) {
|
|||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upload(filename string, server string, fid string) (int) {
|
func upload(filename string, server string, fid string) (int, error) {
|
||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
fmt.Println("Start uploading file:", filename)
|
fmt.Println("Start uploading file:", filename)
|
||||||
}
|
}
|
||||||
@@ -69,15 +69,19 @@ func upload(filename string, server string, fid string) (int) {
|
|||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
fmt.Println("Failed to open file:", filename)
|
fmt.Println("Failed to open file:", filename)
|
||||||
}
|
}
|
||||||
panic(err.Error())
|
return 0, err
|
||||||
}
|
}
|
||||||
ret, _ := operation.Upload("http://"+server+"/"+fid, filename, fh)
|
ret, e := operation.Upload("http://"+server+"/"+fid, filename, fh)
|
||||||
return ret.Size
|
if e != nil {
|
||||||
|
return 0, e
|
||||||
|
}
|
||||||
|
return ret.Size, e
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubmitResult struct {
|
type SubmitResult struct {
|
||||||
Fid string "fid"
|
Fid string "fid"
|
||||||
Size int "size"
|
Size int "size"
|
||||||
|
Error string "error"
|
||||||
}
|
}
|
||||||
|
|
||||||
func submit(files []string) []SubmitResult {
|
func submit(files []string) []SubmitResult {
|
||||||
@@ -92,7 +96,11 @@ func submit(files []string) []SubmitResult {
|
|||||||
if index > 0 {
|
if index > 0 {
|
||||||
fid = fid + "_" + strconv.Itoa(index)
|
fid = fid + "_" + strconv.Itoa(index)
|
||||||
}
|
}
|
||||||
results[index].Size = upload(file, ret.PublicUrl, fid)
|
results[index].Size, err = upload(file, ret.PublicUrl, fid)
|
||||||
|
if err != nil {
|
||||||
|
fid = ""
|
||||||
|
results[index].Error = err.Error()
|
||||||
|
}
|
||||||
results[index].Fid = fid
|
results[index].Fid = fid
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJson(w, r, ne)
|
writeJson(w, r, ne)
|
||||||
} else {
|
} else {
|
||||||
ret := store.Write(volumeId, needle)
|
ret := store.Write(volumeId, needle)
|
||||||
|
errorStatus := ""
|
||||||
if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
|
if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
|
||||||
if r.FormValue("type") != "standard" {
|
if r.FormValue("type") != "standard" {
|
||||||
if distributedOperation(volumeId, func(location operation.Location) bool {
|
if distributedOperation(volumeId, func(location operation.Location) bool {
|
||||||
@@ -142,16 +143,19 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
} else {
|
} else {
|
||||||
ret = 0
|
ret = 0
|
||||||
|
errorStatus = "Failed to write to replicas for volume " + volumeId.String()
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
errorStatus = "Failed to write to local disk"
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
m := make(map[string]uint32)
|
m := make(map[string]interface{})
|
||||||
m["size"] = ret
|
m["size"] = ret
|
||||||
|
m["error"] = errorStatus
|
||||||
writeJson(w, r, m)
|
writeJson(w, r, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UploadResult struct {
|
type UploadResult struct {
|
||||||
Size int
|
Size int
|
||||||
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
|
func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
|
||||||
@@ -38,5 +40,8 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
|
|||||||
log.Println("failing to read upload resonse", uploadUrl, resp_body)
|
log.Println("failing to read upload resonse", uploadUrl, resp_body)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if ret.Error != ""{
|
||||||
|
return nil, errors.New(ret.Error)
|
||||||
|
}
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user