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.

65 lines
2.2 KiB

  1. package weed_server
  2. import (
  3. "net/http"
  4. "path/filepath"
  5. "github.com/chrislusf/weed-fs/go/glog"
  6. "github.com/chrislusf/weed-fs/go/stats"
  7. "github.com/chrislusf/weed-fs/go/util"
  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"), r.FormValue("ttl"))
  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) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  48. m := make(map[string]interface{})
  49. m["Version"] = util.VERSION
  50. ds := make([]*stats.DiskStatus, 0)
  51. for _, loc := range vs.store.Locations {
  52. if dir, e := filepath.Abs(loc.Directory); e == nil {
  53. ds = append(ds, stats.NewDiskStatus(dir))
  54. }
  55. }
  56. m["DiskStatues"] = ds
  57. writeJsonQuiet(w, r, m)
  58. }