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.

87 lines
2.7 KiB

  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. SeedMasterNodes []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. v.SetDefault("jwt.signing.expires_after_seconds", 10)
  38. expiresAfterSec := v.GetInt("jwt.signing.expires_after_seconds")
  39. enableUiAccess := v.GetBool("access.ui")
  40. vs := &VolumeServer{
  41. pulseSeconds: pulseSeconds,
  42. dataCenter: dataCenter,
  43. rack: rack,
  44. needleMapKind: needleMapKind,
  45. FixJpgOrientation: fixJpgOrientation,
  46. ReadRedirect: readRedirect,
  47. grpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "volume"),
  48. compactionBytePerSecond: int64(compactionMBPerSecond) * 1024 * 1024,
  49. }
  50. vs.SeedMasterNodes = masterNodes
  51. vs.store = storage.NewStore(vs.grpcDialOption, port, ip, publicUrl, folders, maxCounts, vs.needleMapKind)
  52. vs.guard = security.NewGuard(whiteList, signingKey, expiresAfterSec)
  53. handleStaticResources(adminMux)
  54. if signingKey == "" || enableUiAccess {
  55. // only expose the volume server details for safe environments
  56. adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler)
  57. adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler))
  58. adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler))
  59. adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler))
  60. adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler))
  61. }
  62. adminMux.HandleFunc("/", vs.privateStoreHandler)
  63. if publicMux != adminMux {
  64. // separated admin and public port
  65. handleStaticResources(publicMux)
  66. publicMux.HandleFunc("/", vs.publicReadOnlyHandler)
  67. }
  68. go vs.heartbeat()
  69. return vs
  70. }
  71. func (vs *VolumeServer) Shutdown() {
  72. glog.V(0).Infoln("Shutting down volume server...")
  73. vs.store.Close()
  74. glog.V(0).Infoln("Shut down successfully!")
  75. }