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.

85 lines
3.2 KiB

7 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package weed_server
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/chrislusf/seaweedfs/weed/security"
  5. "github.com/chrislusf/seaweedfs/weed/storage"
  6. "net/http"
  7. )
  8. type VolumeServer struct {
  9. MasterNodes []string
  10. currentMaster string
  11. pulseSeconds int
  12. dataCenter string
  13. rack string
  14. store *storage.Store
  15. guard *security.Guard
  16. needleMapKind storage.NeedleMapType
  17. FixJpgOrientation bool
  18. ReadRedirect bool
  19. }
  20. func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
  21. port int, publicUrl string,
  22. folders []string, maxCounts []int,
  23. needleMapKind storage.NeedleMapType,
  24. masterNodes []string, pulseSeconds int,
  25. dataCenter string, rack string,
  26. whiteList []string,
  27. fixJpgOrientation bool,
  28. readRedirect bool) *VolumeServer {
  29. vs := &VolumeServer{
  30. pulseSeconds: pulseSeconds,
  31. dataCenter: dataCenter,
  32. rack: rack,
  33. needleMapKind: needleMapKind,
  34. FixJpgOrientation: fixJpgOrientation,
  35. ReadRedirect: readRedirect,
  36. }
  37. vs.MasterNodes = masterNodes
  38. vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
  39. vs.guard = security.NewGuard(whiteList, "")
  40. handleStaticResources(adminMux)
  41. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  42. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  43. adminMux.HandleFunc("/admin/assign_volume", vs.guard.WhiteList(vs.assignVolumeHandler))
  44. adminMux.HandleFunc("/admin/vacuum/check", vs.guard.WhiteList(vs.vacuumVolumeCheckHandler))
  45. adminMux.HandleFunc("/admin/vacuum/compact", vs.guard.WhiteList(vs.vacuumVolumeCompactHandler))
  46. adminMux.HandleFunc("/admin/vacuum/commit", vs.guard.WhiteList(vs.vacuumVolumeCommitHandler))
  47. adminMux.HandleFunc("/admin/vacuum/cleanup", vs.guard.WhiteList(vs.vacuumVolumeCleanupHandler))
  48. adminMux.HandleFunc("/admin/delete_collection", vs.guard.WhiteList(vs.deleteCollectionHandler))
  49. adminMux.HandleFunc("/admin/sync/status", vs.guard.WhiteList(vs.getVolumeSyncStatusHandler))
  50. adminMux.HandleFunc("/admin/sync/index", vs.guard.WhiteList(vs.getVolumeIndexContentHandler))
  51. adminMux.HandleFunc("/admin/sync/data", vs.guard.WhiteList(vs.getVolumeDataContentHandler))
  52. adminMux.HandleFunc("/admin/volume/mount", vs.guard.WhiteList(vs.getVolumeMountHandler))
  53. adminMux.HandleFunc("/admin/volume/unmount", vs.guard.WhiteList(vs.getVolumeUnmountHandler))
  54. adminMux.HandleFunc("/admin/volume/delete", vs.guard.WhiteList(vs.getVolumeDeleteHandler))
  55. adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler))
  56. adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler))
  57. adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler))
  58. adminMux.HandleFunc("/delete", vs.guard.WhiteList(vs.batchDeleteHandler))
  59. adminMux.HandleFunc("/", vs.privateStoreHandler)
  60. if publicMux != adminMux {
  61. // separated admin and public port
  62. handleStaticResources(publicMux)
  63. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  64. }
  65. go vs.heartbeat()
  66. return vs
  67. }
  68. func (vs *VolumeServer) Shutdown() {
  69. glog.V(0).Infoln("Shutting down volume server...")
  70. vs.store.Close()
  71. glog.V(0).Infoln("Shut down successfully!")
  72. }
  73. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  74. return security.GenJwt(vs.guard.SecretKey, fileId)
  75. }