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.

58 lines
1.8 KiB

11 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/chrislusf/weed-fs/go/filer"
  6. "github.com/chrislusf/weed-fs/go/filer/cassandra_store"
  7. "github.com/chrislusf/weed-fs/go/filer/embedded_filer"
  8. "github.com/chrislusf/weed-fs/go/filer/flat_namespace"
  9. "github.com/chrislusf/weed-fs/go/filer/redis_store"
  10. "github.com/chrislusf/weed-fs/go/glog"
  11. )
  12. type FilerServer struct {
  13. port string
  14. master string
  15. collection string
  16. defaultReplication string
  17. redirectOnRead bool
  18. filer filer.Filer
  19. }
  20. func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
  21. replication string, redirectOnRead bool,
  22. cassandra_server string, cassandra_keyspace string,
  23. redis_server string, redis_database int,
  24. ) (fs *FilerServer, err error) {
  25. fs = &FilerServer{
  26. master: master,
  27. collection: collection,
  28. defaultReplication: replication,
  29. redirectOnRead: redirectOnRead,
  30. port: ":" + strconv.Itoa(port),
  31. }
  32. if cassandra_server != "" {
  33. cassandra_store, err := cassandra_store.NewCassandraStore(cassandra_keyspace, cassandra_server)
  34. if err != nil {
  35. glog.Fatalf("Can not connect to cassandra server %s with keyspace %s: %v", cassandra_server, cassandra_keyspace, err)
  36. }
  37. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, cassandra_store)
  38. } else if redis_server != "" {
  39. redis_store := redis_store.NewRedisStore(redis_server, redis_database)
  40. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, redis_store)
  41. } else {
  42. if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
  43. glog.Fatalf("Can not start filer in dir %s : %v", err)
  44. return
  45. }
  46. r.HandleFunc("/admin/mv", fs.moveHandler)
  47. }
  48. r.HandleFunc("/", fs.filerHandler)
  49. return fs, nil
  50. }