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.

69 lines
2.1 KiB

  1. package weed_server
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/replication"
  5. "code.google.com/p/weed-fs/go/sequence"
  6. "code.google.com/p/weed-fs/go/topology"
  7. "github.com/gorilla/mux"
  8. "path"
  9. "sync"
  10. )
  11. type MasterServer struct {
  12. port int
  13. metaFolder string
  14. volumeSizeLimitMB uint
  15. pulseSeconds int
  16. defaultRepType string
  17. garbageThreshold string
  18. whiteList []string
  19. version string
  20. topo *topology.Topology
  21. vg *replication.VolumeGrowth
  22. vgLock sync.Mutex
  23. }
  24. func NewMasterServer(r *mux.Router, version string, port int, metaFolder string,
  25. volumeSizeLimitMB uint,
  26. pulseSeconds int,
  27. confFile string,
  28. defaultRepType string,
  29. garbageThreshold string,
  30. whiteList []string) *MasterServer {
  31. ms := &MasterServer{
  32. version: version,
  33. volumeSizeLimitMB: volumeSizeLimitMB,
  34. pulseSeconds: pulseSeconds,
  35. defaultRepType: defaultRepType,
  36. garbageThreshold: garbageThreshold,
  37. whiteList: whiteList,
  38. }
  39. //if len(*etcdCluster) == 0 {
  40. seq := sequence.NewFileSequencer(path.Join(metaFolder, "weed.seq"))
  41. //} else {
  42. // seq = sequence.NewEtcdSequencer(*etcdCluster)
  43. //}
  44. var e error
  45. if ms.topo, e = topology.NewTopology("topo", confFile, seq,
  46. uint64(volumeSizeLimitMB)*1024*1024, pulseSeconds); e != nil {
  47. glog.Fatalf("cannot create topology:%s", e)
  48. }
  49. ms.vg = replication.NewDefaultVolumeGrowth()
  50. glog.V(0).Infoln("Volume Size Limit is", volumeSizeLimitMB, "MB")
  51. r.HandleFunc("/dir/assign", secure(ms.whiteList, ms.dirAssignHandler))
  52. r.HandleFunc("/dir/lookup", secure(ms.whiteList, ms.dirLookupHandler))
  53. r.HandleFunc("/dir/join", secure(ms.whiteList, ms.dirJoinHandler))
  54. r.HandleFunc("/dir/status", secure(ms.whiteList, ms.dirStatusHandler))
  55. r.HandleFunc("/vol/grow", secure(ms.whiteList, ms.volumeGrowHandler))
  56. r.HandleFunc("/vol/status", secure(ms.whiteList, ms.volumeStatusHandler))
  57. r.HandleFunc("/vol/vacuum", secure(ms.whiteList, ms.volumeVacuumHandler))
  58. r.HandleFunc("/submit", secure(ms.whiteList, ms.submitFromMasterServerHandler))
  59. r.HandleFunc("/", ms.redirectHandler)
  60. ms.topo.StartRefreshWritableVolumes(garbageThreshold)
  61. return ms
  62. }