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.

84 lines
3.2 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/security"
  6. "github.com/chrislusf/seaweedfs/weed/storage"
  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. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  41. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  42. adminMux.HandleFunc("/admin/assign_volume", vs.guard.WhiteList(vs.assignVolumeHandler))
  43. adminMux.HandleFunc("/admin/vacuum/check", vs.guard.WhiteList(vs.vacuumVolumeCheckHandler))
  44. adminMux.HandleFunc("/admin/vacuum/compact", vs.guard.WhiteList(vs.vacuumVolumeCompactHandler))
  45. adminMux.HandleFunc("/admin/vacuum/commit", vs.guard.WhiteList(vs.vacuumVolumeCommitHandler))
  46. adminMux.HandleFunc("/admin/vacuum/cleanup", vs.guard.WhiteList(vs.vacuumVolumeCleanupHandler))
  47. adminMux.HandleFunc("/admin/delete_collection", vs.guard.WhiteList(vs.deleteCollectionHandler))
  48. adminMux.HandleFunc("/admin/sync/status", vs.guard.WhiteList(vs.getVolumeSyncStatusHandler))
  49. adminMux.HandleFunc("/admin/sync/index", vs.guard.WhiteList(vs.getVolumeIndexContentHandler))
  50. adminMux.HandleFunc("/admin/sync/data", vs.guard.WhiteList(vs.getVolumeDataContentHandler))
  51. adminMux.HandleFunc("/admin/volume/mount", vs.guard.WhiteList(vs.getVolumeMountHandler))
  52. adminMux.HandleFunc("/admin/volume/unmount", vs.guard.WhiteList(vs.getVolumeUnmountHandler))
  53. adminMux.HandleFunc("/admin/volume/delete", vs.guard.WhiteList(vs.getVolumeDeleteHandler))
  54. adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler))
  55. adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler))
  56. adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler))
  57. adminMux.HandleFunc("/delete", vs.guard.WhiteList(vs.batchDeleteHandler))
  58. adminMux.HandleFunc("/", vs.privateStoreHandler)
  59. if publicMux != adminMux {
  60. // separated admin and public port
  61. publicMux.HandleFunc("/favicon.ico", faviconHandler)
  62. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  63. }
  64. go vs.heartbeat()
  65. return vs
  66. }
  67. func (vs *VolumeServer) Shutdown() {
  68. glog.V(0).Infoln("Shutting down volume server...")
  69. vs.store.Close()
  70. glog.V(0).Infoln("Shut down successfully!")
  71. }
  72. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  73. return security.GenJwt(vs.guard.SecretKey, fileId)
  74. }