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.

99 lines
3.5 KiB

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