Browse Source

error handling

pull/2/head
Chris Lu 12 years ago
parent
commit
59ca65da3c
  1. 21
      weed-fs/src/cmd/weed/master.go
  2. 16
      weed-fs/src/cmd/weed/volume.go

21
weed-fs/src/cmd/weed/master.go

@ -45,17 +45,18 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
if commaSep > 0 { if commaSep > 0 {
vid = vid[0:commaSep] vid = vid[0:commaSep]
} }
volumeId, _ := storage.NewVolumeId(vid)
machines := topo.Lookup(volumeId)
if machines != nil {
ret := []map[string]string{}
for _, dn := range *machines {
ret = append(ret, map[string]string{"url": dn.Ip + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl})
volumeId, err := storage.NewVolumeId(vid)
if err == nil {
machines := topo.Lookup(volumeId)
if machines != nil {
ret := []map[string]string{}
for _, dn := range *machines {
ret = append(ret, map[string]string{"url": dn.Ip + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl})
}
writeJson(w, r, map[string]interface{}{"locations": ret})
} else {
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
} }
writeJson(w, r, map[string]interface{}{"locations": ret})
} else {
log.Println("Invalid volume id", volumeId)
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
} }
} }

16
weed-fs/src/cmd/weed/volume.go

@ -65,21 +65,29 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
func GetHandler(w http.ResponseWriter, r *http.Request) { func GetHandler(w http.ResponseWriter, r *http.Request) {
n := new(storage.Needle) n := new(storage.Needle)
vid, fid, ext := parseURLPath(r.URL.Path) vid, fid, ext := parseURLPath(r.URL.Path)
volumeId, _ := storage.NewVolumeId(vid)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
if *IsDebug {
log.Println("parsing error:", err, r.URL.Path)
}
return
}
n.ParsePath(fid) n.ParsePath(fid)
if *IsDebug { if *IsDebug {
log.Println("volume", volumeId, "reading", n) log.Println("volume", volumeId, "reading", n)
} }
if !store.HasVolume(volumeId) { if !store.HasVolume(volumeId) {
lookupResult, err := operation.Lookup(*server, volumeId)
lookupResult, err := operation.Lookup(*masterNode, volumeId)
if *IsDebug { if *IsDebug {
log.Println("volume", volumeId, "found on", lookupResult, "error", err) log.Println("volume", volumeId, "found on", lookupResult, "error", err)
} }
if err == nil { if err == nil {
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently) http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
} else { } else {
log.Println("lookup error:", err)
if *IsDebug {
log.Println("lookup error:", err, r.URL.Path)
}
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
return return
@ -90,7 +98,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
log.Println("read bytes", count, "error", e) log.Println("read bytes", count, "error", e)
} }
if e != nil || count <= 0 { if e != nil || count <= 0 {
log.Println("read error:", e)
log.Println("read error:", e)
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }

Loading…
Cancel
Save