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.

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