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.

111 lines
3.3 KiB

7 years ago
7 years ago
7 years ago
  1. package weed_server
  2. import (
  3. "fmt"
  4. "net/http"
  5. "path/filepath"
  6. "strconv"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/stats"
  9. "github.com/chrislusf/seaweedfs/weed/storage"
  10. "github.com/chrislusf/seaweedfs/weed/util"
  11. )
  12. func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
  13. m := make(map[string]interface{})
  14. m["Version"] = util.VERSION
  15. m["Volumes"] = vs.store.Status()
  16. writeJsonQuiet(w, r, http.StatusOK, m)
  17. }
  18. func (vs *VolumeServer) assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
  19. var err error
  20. preallocate := int64(0)
  21. if r.FormValue("preallocate") != "" {
  22. preallocate, err = strconv.ParseInt(r.FormValue("preallocate"), 10, 64)
  23. if err != nil {
  24. glog.V(0).Infof("ignoring invalid int64 value for preallocate = %v", r.FormValue("preallocate"))
  25. }
  26. }
  27. err = vs.store.AddVolume(
  28. r.FormValue("volume"),
  29. r.FormValue("collection"),
  30. vs.needleMapKind,
  31. r.FormValue("replication"),
  32. r.FormValue("ttl"),
  33. preallocate,
  34. )
  35. if err == nil {
  36. writeJsonQuiet(w, r, http.StatusAccepted, map[string]string{"error": ""})
  37. } else {
  38. writeJsonError(w, r, http.StatusNotAcceptable, err)
  39. }
  40. glog.V(2).Infof("assign volume = %s, collection = %s , replication = %s, error = %v",
  41. r.FormValue("volume"), r.FormValue("collection"), r.FormValue("replication"), err)
  42. }
  43. func (vs *VolumeServer) deleteCollectionHandler(w http.ResponseWriter, r *http.Request) {
  44. err := vs.store.DeleteCollection(r.FormValue("collection"))
  45. if err == nil {
  46. writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
  47. } else {
  48. writeJsonError(w, r, http.StatusInternalServerError, err)
  49. }
  50. glog.V(2).Infof("deleting collection = %s, error = %v", r.FormValue("collection"), err)
  51. }
  52. func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
  53. m := make(map[string]interface{})
  54. m["Version"] = util.VERSION
  55. var ds []*stats.DiskStatus
  56. for _, loc := range vs.store.Locations {
  57. if dir, e := filepath.Abs(loc.Directory); e == nil {
  58. ds = append(ds, stats.NewDiskStatus(dir))
  59. }
  60. }
  61. m["DiskStatuses"] = ds
  62. writeJsonQuiet(w, r, http.StatusOK, m)
  63. }
  64. func (vs *VolumeServer) getVolume(volumeParameterName string, r *http.Request) (*storage.Volume, error) {
  65. vid, err := vs.getVolumeId(volumeParameterName, r)
  66. if err != nil {
  67. return nil, err
  68. }
  69. v := vs.store.GetVolume(vid)
  70. if v == nil {
  71. return nil, fmt.Errorf("Not Found Volume Id %d", vid)
  72. }
  73. return v, nil
  74. }
  75. func (vs *VolumeServer) getVolumeMountHandler(w http.ResponseWriter, r *http.Request) {
  76. vid, err := vs.getVolumeId("volume", r)
  77. if err != nil {
  78. writeJsonError(w, r, http.StatusNotFound, err)
  79. return
  80. }
  81. vs.store.MountVolume(vid)
  82. writeJsonQuiet(w, r, http.StatusOK, "Volume mounted")
  83. }
  84. func (vs *VolumeServer) getVolumeUnmountHandler(w http.ResponseWriter, r *http.Request) {
  85. vid, err := vs.getVolumeId("volume", r)
  86. if err != nil {
  87. writeJsonError(w, r, http.StatusNotFound, err)
  88. return
  89. }
  90. vs.store.UnmountVolume(vid)
  91. writeJsonQuiet(w, r, http.StatusOK, "Volume unmounted")
  92. }
  93. func (vs *VolumeServer) getVolumeDeleteHandler(w http.ResponseWriter, r *http.Request) {
  94. vid, err := vs.getVolumeId("volume", r)
  95. if err != nil {
  96. writeJsonError(w, r, http.StatusNotFound, err)
  97. return
  98. }
  99. vs.store.DeleteVolume(vid)
  100. writeJsonQuiet(w, r, http.StatusOK, "Volume deleted")
  101. }