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.

95 lines
3.2 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "strconv"
  6. "time"
  7. "github.com/chrislusf/weed-fs/go/glog"
  8. "github.com/chrislusf/weed-fs/go/util"
  9. "github.com/chrislusf/weed-fs/go/weed/weed_server"
  10. )
  11. var (
  12. f FilerOptions
  13. )
  14. type FilerOptions struct {
  15. master *string
  16. port *int
  17. collection *string
  18. defaultReplicaPlacement *string
  19. dir *string
  20. redirectOnRead *bool
  21. cassandra_server *string
  22. cassandra_keyspace *string
  23. redis_server *string
  24. redis_database *int
  25. }
  26. func init() {
  27. cmdFiler.Run = runFiler // break init cycle
  28. f.master = cmdFiler.Flag.String("master", "localhost:9333", "master server location")
  29. f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this collection")
  30. f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port")
  31. f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
  32. f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified")
  33. f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
  34. f.cassandra_server = cmdFiler.Flag.String("cassandra.server", "", "host[:port] of the cassandra server")
  35. f.cassandra_keyspace = cmdFiler.Flag.String("cassandra.keyspace", "seaweed", "keyspace of the cassandra server")
  36. f.redis_server = cmdFiler.Flag.String("redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379")
  37. f.redis_database = cmdFiler.Flag.Int("redis.database", 0, "the database on the redis server")
  38. }
  39. var cmdFiler = &Command{
  40. UsageLine: "filer -port=8888 -dir=/tmp -master=<ip:port>",
  41. Short: "start a file server that points to a master server",
  42. Long: `start a file server which accepts REST operation for any files.
  43. //create or overwrite the file, the directories /path/to will be automatically created
  44. POST /path/to/file
  45. //get the file content
  46. GET /path/to/file
  47. //create or overwrite the file, the filename in the multipart request will be used
  48. POST /path/to/
  49. //return a json format subdirectory and files listing
  50. GET /path/to/
  51. Current <fullpath~fileid> mapping metadata store is local embedded leveldb.
  52. It should be highly scalable to hundreds of millions of files on a modest machine.
  53. Future we will ensure it can avoid of being SPOF.
  54. `,
  55. }
  56. func runFiler(cmd *Command, args []string) bool {
  57. if err := util.TestFolderWritable(*f.dir); err != nil {
  58. glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)
  59. }
  60. r := http.NewServeMux()
  61. _, nfs_err := weed_server.NewFilerServer(r, *f.port, *f.master, *f.dir, *f.collection,
  62. *f.defaultReplicaPlacement, *f.redirectOnRead,
  63. *f.cassandra_server, *f.cassandra_keyspace,
  64. *f.redis_server, *f.redis_database,
  65. )
  66. if nfs_err != nil {
  67. glog.Fatalf(nfs_err.Error())
  68. }
  69. glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
  70. filerListener, e := util.NewListener(
  71. ":"+strconv.Itoa(*f.port),
  72. time.Duration(10)*time.Second,
  73. )
  74. if e != nil {
  75. glog.Fatalf(e.Error())
  76. }
  77. if e := http.Serve(filerListener, r); e != nil {
  78. glog.Fatalf("Filer Fail to serve:%s", e.Error())
  79. }
  80. return true
  81. }