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.

97 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. "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,
  31. enableBytesCache bool) *VolumeServer {
  32. vs := &VolumeServer{
  33. pulseSeconds: pulseSeconds,
  34. dataCenter: dataCenter,
  35. rack: rack,
  36. needleMapKind: needleMapKind,
  37. FixJpgOrientation: fixJpgOrientation,
  38. ReadRedirect: readRedirect,
  39. }
  40. vs.SetMasterNode(masterNode)
  41. vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
  42. storage.EnableBytesCache = enableBytesCache
  43. vs.guard = security.NewGuard(whiteList, "")
  44. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  45. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  46. adminMux.HandleFunc("/admin/assign_volume", vs.guard.WhiteList(vs.assignVolumeHandler))
  47. adminMux.HandleFunc("/admin/vacuum/check", vs.guard.WhiteList(vs.vacuumVolumeCheckHandler))
  48. adminMux.HandleFunc("/admin/vacuum/compact", vs.guard.WhiteList(vs.vacuumVolumeCompactHandler))
  49. adminMux.HandleFunc("/admin/vacuum/commit", vs.guard.WhiteList(vs.vacuumVolumeCommitHandler))
  50. adminMux.HandleFunc("/admin/delete_collection", vs.guard.WhiteList(vs.deleteCollectionHandler))
  51. adminMux.HandleFunc("/admin/sync/status", vs.guard.WhiteList(vs.getVolumeSyncStatusHandler))
  52. adminMux.HandleFunc("/admin/sync/index", vs.guard.WhiteList(vs.getVolumeIndexContentHandler))
  53. adminMux.HandleFunc("/admin/sync/data", vs.guard.WhiteList(vs.getVolumeDataContentHandler))
  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", vs.faviconHandler)
  62. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  63. }
  64. go vs.heartbeat()
  65. return vs
  66. }
  67. func (vs *VolumeServer) GetMasterNode() string {
  68. vs.mnLock.RLock()
  69. defer vs.mnLock.RUnlock()
  70. return vs.masterNode
  71. }
  72. func (vs *VolumeServer) SetMasterNode(masterNode string) {
  73. vs.mnLock.Lock()
  74. defer vs.mnLock.Unlock()
  75. vs.masterNode = masterNode
  76. }
  77. func (vs *VolumeServer) Shutdown() {
  78. glog.V(0).Infoln("Shutting down volume server...")
  79. vs.store.Close()
  80. glog.V(0).Infoln("Shut down successfully!")
  81. }
  82. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  83. return security.GenJwt(vs.guard.SecretKey, fileId)
  84. }