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.

73 lines
2.0 KiB

7 years ago
  1. package weed_server
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/stats"
  5. "github.com/chrislusf/seaweedfs/weed/storage"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "net/http"
  8. "path/filepath"
  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) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  17. m := make(map[string]interface{})
  18. m["Version"] = util.VERSION
  19. var ds []*stats.DiskStatus
  20. for _, loc := range vs.store.Locations {
  21. if dir, e := filepath.Abs(loc.Directory); e == nil {
  22. ds = append(ds, stats.NewDiskStatus(dir))
  23. }
  24. }
  25. m["DiskStatuses"] = ds
  26. writeJsonQuiet(w, r, http.StatusOK, m)
  27. }
  28. // TODO delete this when volume sync is all moved to grpc
  29. func (vs *VolumeServer) getVolume(volumeParameterName string, r *http.Request) (*storage.Volume, error) {
  30. vid, err := vs.getVolumeId(volumeParameterName, r)
  31. if err != nil {
  32. return nil, err
  33. }
  34. v := vs.store.GetVolume(vid)
  35. if v == nil {
  36. return nil, fmt.Errorf("Not Found Volume Id %d", vid)
  37. }
  38. return v, nil
  39. }
  40. func (vs *VolumeServer) getVolumeMountHandler(w http.ResponseWriter, r *http.Request) {
  41. vid, err := vs.getVolumeId("volume", r)
  42. if err != nil {
  43. writeJsonError(w, r, http.StatusNotFound, err)
  44. return
  45. }
  46. vs.store.MountVolume(vid)
  47. writeJsonQuiet(w, r, http.StatusOK, "Volume mounted")
  48. }
  49. func (vs *VolumeServer) getVolumeUnmountHandler(w http.ResponseWriter, r *http.Request) {
  50. vid, err := vs.getVolumeId("volume", r)
  51. if err != nil {
  52. writeJsonError(w, r, http.StatusNotFound, err)
  53. return
  54. }
  55. vs.store.UnmountVolume(vid)
  56. writeJsonQuiet(w, r, http.StatusOK, "Volume unmounted")
  57. }
  58. func (vs *VolumeServer) getVolumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
  59. vid, err := vs.getVolumeId("volume", r)
  60. if err != nil {
  61. writeJsonError(w, r, http.StatusNotFound, err)
  62. return
  63. }
  64. vs.store.DeleteVolume(vid)
  65. writeJsonQuiet(w, r, http.StatusOK, "Volume deleted")
  66. }