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.

83 lines
2.4 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. "github.com/spf13/viper"
  8. )
  9. type VolumeServer struct {
  10. MasterNodes []string
  11. currentMaster string
  12. pulseSeconds int
  13. dataCenter string
  14. rack string
  15. store *storage.Store
  16. guard *security.Guard
  17. needleMapKind storage.NeedleMapType
  18. FixJpgOrientation bool
  19. ReadRedirect bool
  20. }
  21. func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
  22. port int, publicUrl string,
  23. folders []string, maxCounts []int,
  24. needleMapKind storage.NeedleMapType,
  25. masterNodes []string, pulseSeconds int,
  26. dataCenter string, rack string,
  27. whiteList []string,
  28. fixJpgOrientation bool,
  29. readRedirect bool) *VolumeServer {
  30. LoadConfiguration("security", false)
  31. v := viper.GetViper()
  32. signingKey := v.GetString("jwt.signing.key")
  33. enableUiAccess := v.GetBool("access.ui")
  34. vs := &VolumeServer{
  35. pulseSeconds: pulseSeconds,
  36. dataCenter: dataCenter,
  37. rack: rack,
  38. needleMapKind: needleMapKind,
  39. FixJpgOrientation: fixJpgOrientation,
  40. ReadRedirect: readRedirect,
  41. }
  42. vs.MasterNodes = masterNodes
  43. vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
  44. vs.guard = security.NewGuard(whiteList, signingKey)
  45. handleStaticResources(adminMux)
  46. if signingKey == "" || enableUiAccess {
  47. // only expose the volume server details for safe environments
  48. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  49. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  50. adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler))
  51. adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler))
  52. adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler))
  53. }
  54. adminMux.HandleFunc("/", vs.privateStoreHandler)
  55. if publicMux != adminMux {
  56. // separated admin and public port
  57. handleStaticResources(publicMux)
  58. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  59. }
  60. go vs.heartbeat()
  61. return vs
  62. }
  63. func (vs *VolumeServer) Shutdown() {
  64. glog.V(0).Infoln("Shutting down volume server...")
  65. vs.store.Close()
  66. glog.V(0).Infoln("Shut down successfully!")
  67. }
  68. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  69. return security.GenJwt(vs.guard.SigningKey, fileId)
  70. }