You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. package weed_server
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/stats"
  5. "code.google.com/p/weed-fs/go/util"
  6. "net/http"
  7. "path/filepath"
  8. )
  9. func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
  10. m := make(map[string]interface{})
  11. m["Version"] = util.VERSION
  12. m["Volumes"] = vs.store.Status()
  13. writeJsonQuiet(w, r, m)
  14. }
  15. func (vs *VolumeServer) assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
  16. err := vs.store.AddVolume(r.FormValue("volume"), r.FormValue("collection"), r.FormValue("replication"))
  17. if err == nil {
  18. writeJsonQuiet(w, r, map[string]string{"error": ""})
  19. } else {
  20. writeJsonQuiet(w, r, map[string]string{"error": err.Error()})
  21. }
  22. glog.V(2).Infoln("assign volume =", r.FormValue("volume"), ", collection =", r.FormValue("collection"), ", replication =", r.FormValue("replication"), ", error =", err)
  23. }
  24. func (vs *VolumeServer) deleteCollectionHandler(w http.ResponseWriter, r *http.Request) {
  25. if "benchmark" != r.FormValue("collection") {
  26. glog.V(0).Infoln("deleting collection =", r.FormValue("collection"), "!!!")
  27. return
  28. }
  29. err := vs.store.DeleteCollection(r.FormValue("collection"))
  30. if err == nil {
  31. writeJsonQuiet(w, r, map[string]string{"error": ""})
  32. } else {
  33. writeJsonQuiet(w, r, map[string]string{"error": err.Error()})
  34. }
  35. glog.V(2).Infoln("deleting collection =", r.FormValue("collection"), ", error =", err)
  36. }
  37. func (vs *VolumeServer) freezeVolumeHandler(w http.ResponseWriter, r *http.Request) {
  38. //TODO: notify master that this volume will be read-only
  39. err := vs.store.FreezeVolume(r.FormValue("volume"))
  40. if err == nil {
  41. writeJsonQuiet(w, r, map[string]interface{}{"error": ""})
  42. } else {
  43. writeJsonQuiet(w, r, map[string]string{"error": err.Error()})
  44. }
  45. glog.V(2).Infoln("freeze volume =", r.FormValue("volume"), ", error =", err)
  46. }
  47. func (vs *VolumeServer) submitFromVolumeServerHandler(w http.ResponseWriter, r *http.Request) {
  48. submitForClientHandler(w, r, vs.masterNode)
  49. }
  50. func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  51. m := make(map[string]interface{})
  52. m["Version"] = util.VERSION
  53. ds := make([]*stats.DiskStatus, 0)
  54. for _, loc := range vs.store.Locations {
  55. if dir, e := filepath.Abs(loc.Directory); e == nil {
  56. ds = append(ds, stats.NewDiskStatus(dir))
  57. }
  58. }
  59. m["DiskStatues"] = ds
  60. writeJsonQuiet(w, r, m)
  61. }