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.

73 lines
2.1 KiB

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. handleStaticResources(adminMux)
  41. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  42. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  43. adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler))
  44. adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler))
  45. adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler))
  46. adminMux.HandleFunc("/", vs.privateStoreHandler)
  47. if publicMux != adminMux {
  48. // separated admin and public port
  49. handleStaticResources(publicMux)
  50. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  51. }
  52. go vs.heartbeat()
  53. return vs
  54. }
  55. func (vs *VolumeServer) Shutdown() {
  56. glog.V(0).Infoln("Shutting down volume server...")
  57. vs.store.Close()
  58. glog.V(0).Infoln("Shut down successfully!")
  59. }
  60. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  61. return security.GenJwt(vs.guard.SecretKey, fileId)
  62. }