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.

89 lines
2.6 KiB

10 years ago
10 years ago
  1. package weed_server
  2. import (
  3. "google.golang.org/grpc"
  4. "net/http"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/security"
  7. "github.com/chrislusf/seaweedfs/weed/storage"
  8. "github.com/spf13/viper"
  9. )
  10. type VolumeServer struct {
  11. MasterNodes []string
  12. currentMaster string
  13. pulseSeconds int
  14. dataCenter string
  15. rack string
  16. store *storage.Store
  17. guard *security.Guard
  18. grpcDialOption grpc.DialOption
  19. needleMapKind storage.NeedleMapType
  20. FixJpgOrientation bool
  21. ReadRedirect bool
  22. compactionBytePerSecond int64
  23. }
  24. func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
  25. port int, publicUrl string,
  26. folders []string, maxCounts []int,
  27. needleMapKind storage.NeedleMapType,
  28. masterNodes []string, pulseSeconds int,
  29. dataCenter string, rack string,
  30. whiteList []string,
  31. fixJpgOrientation bool,
  32. readRedirect bool,
  33. compactionMBPerSecond int,
  34. ) *VolumeServer {
  35. v := viper.GetViper()
  36. signingKey := v.GetString("jwt.signing.key")
  37. enableUiAccess := v.GetBool("access.ui")
  38. vs := &VolumeServer{
  39. pulseSeconds: pulseSeconds,
  40. dataCenter: dataCenter,
  41. rack: rack,
  42. needleMapKind: needleMapKind,
  43. FixJpgOrientation: fixJpgOrientation,
  44. ReadRedirect: readRedirect,
  45. grpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "volume"),
  46. compactionBytePerSecond: int64(compactionMBPerSecond) * 1024 * 1024,
  47. }
  48. vs.MasterNodes = masterNodes
  49. vs.store = storage.NewStore(port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
  50. vs.guard = security.NewGuard(whiteList, signingKey)
  51. handleStaticResources(adminMux)
  52. if signingKey == "" || enableUiAccess {
  53. // only expose the volume server details for safe environments
  54. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  55. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  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. }
  60. adminMux.HandleFunc("/", vs.privateStoreHandler)
  61. if publicMux != adminMux {
  62. // separated admin and public port
  63. handleStaticResources(publicMux)
  64. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  65. }
  66. go vs.heartbeat()
  67. return vs
  68. }
  69. func (vs *VolumeServer) Shutdown() {
  70. glog.V(0).Infoln("Shutting down volume server...")
  71. vs.store.Close()
  72. glog.V(0).Infoln("Shut down successfully!")
  73. }
  74. func (vs *VolumeServer) jwt(fileId string) security.EncodedJwt {
  75. return security.GenJwt(vs.guard.SigningKey, fileId)
  76. }