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.

96 lines
2.7 KiB

7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "os"
  5. "github.com/chrislusf/seaweedfs/weed/stats"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "google.golang.org/grpc"
  8. "github.com/chrislusf/seaweedfs/weed/filer2"
  9. _ "github.com/chrislusf/seaweedfs/weed/filer2/cassandra"
  10. _ "github.com/chrislusf/seaweedfs/weed/filer2/leveldb"
  11. _ "github.com/chrislusf/seaweedfs/weed/filer2/memdb"
  12. _ "github.com/chrislusf/seaweedfs/weed/filer2/mysql"
  13. _ "github.com/chrislusf/seaweedfs/weed/filer2/postgres"
  14. _ "github.com/chrislusf/seaweedfs/weed/filer2/redis"
  15. "github.com/chrislusf/seaweedfs/weed/glog"
  16. "github.com/chrislusf/seaweedfs/weed/notification"
  17. _ "github.com/chrislusf/seaweedfs/weed/notification/aws_sqs"
  18. _ "github.com/chrislusf/seaweedfs/weed/notification/gocdk_pub_sub"
  19. _ "github.com/chrislusf/seaweedfs/weed/notification/google_pub_sub"
  20. _ "github.com/chrislusf/seaweedfs/weed/notification/kafka"
  21. _ "github.com/chrislusf/seaweedfs/weed/notification/log"
  22. "github.com/chrislusf/seaweedfs/weed/security"
  23. "github.com/spf13/viper"
  24. )
  25. type FilerOption struct {
  26. Masters []string
  27. Collection string
  28. DefaultReplication string
  29. RedirectOnRead bool
  30. DisableDirListing bool
  31. MaxMB int
  32. DirListingLimit int
  33. DataCenter string
  34. DefaultLevelDbDir string
  35. DisableHttp bool
  36. MetricsAddress string
  37. MetricsIntervalSec int
  38. Port int
  39. }
  40. type FilerServer struct {
  41. option *FilerOption
  42. secret security.SigningKey
  43. filer *filer2.Filer
  44. grpcDialOption grpc.DialOption
  45. }
  46. func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
  47. fs = &FilerServer{
  48. option: option,
  49. grpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "filer"),
  50. }
  51. if len(option.Masters) == 0 {
  52. glog.Fatal("master list is required!")
  53. }
  54. fs.filer = filer2.NewFiler(option.Masters, fs.grpcDialOption)
  55. go fs.filer.KeepConnectedToMaster()
  56. v := viper.GetViper()
  57. if !util.LoadConfiguration("filer", false) {
  58. v.Set("leveldb.enabled", true)
  59. v.Set("leveldb.dir", option.DefaultLevelDbDir)
  60. _, err := os.Stat(option.DefaultLevelDbDir)
  61. if os.IsNotExist(err) {
  62. os.MkdirAll(option.DefaultLevelDbDir, 0755)
  63. }
  64. }
  65. util.LoadConfiguration("notification", false)
  66. fs.filer.LoadConfiguration(v)
  67. notification.LoadConfiguration(v.Sub("notification"))
  68. handleStaticResources(defaultMux)
  69. if !option.DisableHttp {
  70. defaultMux.HandleFunc("/", fs.filerHandler)
  71. }
  72. if defaultMux != readonlyMux {
  73. readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
  74. }
  75. go stats.LoopPushingMetric("filer", stats.SourceName(option.Port), stats.FilerGather,
  76. func() (addr string, intervalSeconds int) {
  77. return option.MetricsAddress, option.MetricsIntervalSec
  78. })
  79. return fs, nil
  80. }