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.

53 lines
1.5 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/glog"
  10. )
  11. type FilerServer struct {
  12. port string
  13. master string
  14. collection string
  15. defaultReplication string
  16. redirectOnRead bool
  17. filer filer.Filer
  18. }
  19. func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
  20. replication string, redirectOnRead bool,
  21. cassandra_server string, cassandra_keyspace string,
  22. ) (fs *FilerServer, err error) {
  23. fs = &FilerServer{
  24. master: master,
  25. collection: collection,
  26. defaultReplication: replication,
  27. redirectOnRead: redirectOnRead,
  28. port: ":" + strconv.Itoa(port),
  29. }
  30. if cassandra_server == "" {
  31. if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
  32. glog.Fatalf("Can not start filer in dir %s : %v", err)
  33. return
  34. }
  35. r.HandleFunc("/admin/mv", fs.moveHandler)
  36. } else {
  37. cassandra_store, err := cassandra_store.NewCassandraStore(cassandra_keyspace, cassandra_server)
  38. if err != nil {
  39. glog.Fatalf("Can not connect to cassandra server %s with keyspace %s: %v", cassandra_server, cassandra_keyspace, err)
  40. }
  41. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, cassandra_store)
  42. }
  43. r.HandleFunc("/", fs.filerHandler)
  44. return fs, nil
  45. }