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.

67 lines
2.0 KiB

  1. package weed_server
  2. import (
  3. "net/http"
  4. "path/filepath"
  5. "strconv"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/stats"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. )
  10. func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
  11. m := make(map[string]interface{})
  12. m["Version"] = util.VERSION
  13. m["Volumes"] = vs.store.Status()
  14. writeJsonQuiet(w, r, http.StatusOK, m)
  15. }
  16. func (vs *VolumeServer) assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
  17. var err error
  18. preallocate := int64(0)
  19. if r.FormValue("preallocate") != "" {
  20. preallocate, err = strconv.ParseInt(r.FormValue("preallocate"), 10, 64)
  21. if err != nil {
  22. glog.V(0).Infoln("ignoring invalid int64 value for preallocate = %v", r.FormValue("preallocate"))
  23. }
  24. }
  25. err = vs.store.AddVolume(
  26. r.FormValue("volume"),
  27. r.FormValue("collection"),
  28. vs.needleMapKind,
  29. r.FormValue("replication"),
  30. r.FormValue("ttl"),
  31. preallocate,
  32. )
  33. if err == nil {
  34. writeJsonQuiet(w, r, http.StatusAccepted, map[string]string{"error": ""})
  35. } else {
  36. writeJsonError(w, r, http.StatusNotAcceptable, err)
  37. }
  38. glog.V(2).Infoln("assign volume = %s, collection = %s , replication = %s, error = %v",
  39. r.FormValue("volume"), r.FormValue("collection"), r.FormValue("replication"), err)
  40. }
  41. func (vs *VolumeServer) deleteCollectionHandler(w http.ResponseWriter, r *http.Request) {
  42. err := vs.store.DeleteCollection(r.FormValue("collection"))
  43. if err == nil {
  44. writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
  45. } else {
  46. writeJsonError(w, r, http.StatusInternalServerError, err)
  47. }
  48. glog.V(2).Infof("deleting collection = %s, error = %v", r.FormValue("collection"), err)
  49. }
  50. func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  51. m := make(map[string]interface{})
  52. m["Version"] = util.VERSION
  53. var ds []*stats.DiskStatus
  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["DiskStatuses"] = ds
  60. writeJsonQuiet(w, r, http.StatusOK, m)
  61. }