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.

88 lines
2.4 KiB

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