diff options
| author | Chris Lu <chris.lu@gmail.com> | 2012-09-03 19:18:02 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2012-09-03 19:18:02 -0700 |
| commit | fbe828e48648df0c0adeca240853d110bb04f4d8 (patch) | |
| tree | 8fb7e1806ed28b2fee54b52ac95257ca4acdd1f1 /weed-fs/src/cmd | |
| parent | 09542d82b422242216c7f717f22aaf2b73d65b72 (diff) | |
| download | seaweedfs-fbe828e48648df0c0adeca240853d110bb04f4d8.tar.xz seaweedfs-fbe828e48648df0c0adeca240853d110bb04f4d8.zip | |
reformatting
Diffstat (limited to 'weed-fs/src/cmd')
| -rw-r--r-- | weed-fs/src/cmd/weed/master.go | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go index d94526675..6d44913a3 100644 --- a/weed-fs/src/cmd/weed/master.go +++ b/weed-fs/src/cmd/weed/master.go @@ -1,87 +1,87 @@ package main import ( - "pkg/directory" - "encoding/json" - "log" - "net/http" - "pkg/storage" - "strconv" - "strings" + "encoding/json" + "log" + "net/http" + "pkg/directory" + "pkg/storage" + "strconv" + "strings" ) func init() { - cmdMaster.Run = runMaster // break init cycle - IsDebug = cmdMaster.Flag.Bool("debug", false, "enable debug mode") + cmdMaster.Run = runMaster // break init cycle + IsDebug = cmdMaster.Flag.Bool("debug", false, "enable debug mode") } var cmdMaster = &Command{ - UsageLine: "master -port=9333", - Short: "start a master server", - Long: `start a master server to provide volume=>location mapping service + UsageLine: "master -port=9333", + Short: "start a master server", + Long: `start a master server to provide volume=>location mapping service and sequence number of file ids `, } var ( - mport = cmdMaster.Flag.Int("port", 9333, "http listen port") - metaFolder = cmdMaster.Flag.String("mdir", "/tmp", "data directory to store mappings") - capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold") - mapper *directory.Mapper - volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes") + mport = cmdMaster.Flag.Int("port", 9333, "http listen port") + metaFolder = cmdMaster.Flag.String("mdir", "/tmp", "data directory to store mappings") + capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold") + mapper *directory.Mapper + volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes") ) func dirLookupHandler(w http.ResponseWriter, r *http.Request) { - vid := r.FormValue("volumeId") - commaSep := strings.Index(vid, ",") - if commaSep > 0 { - vid = vid[0:commaSep] - } - volumeId, _ := storage.NewVolumeId(vid) - machine, e := mapper.Get(volumeId) - if e == nil { - writeJson(w, r, machine.Server) - } else { - log.Println("Invalid volume id", volumeId) - writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found"}) - } + vid := r.FormValue("volumeId") + commaSep := strings.Index(vid, ",") + if commaSep > 0 { + vid = vid[0:commaSep] + } + volumeId, _ := storage.NewVolumeId(vid) + machine, e := mapper.Get(volumeId) + if e == nil { + writeJson(w, r, map[string]string{"url": machine.Url, "publicUrl": machine.PublicUrl}) + } else { + log.Println("Invalid volume id", volumeId) + writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found"}) + } } func dirAssignHandler(w http.ResponseWriter, r *http.Request) { - c:=r.FormValue("count") - fid, count, machine, err := mapper.PickForWrite(c) - if err == nil { - writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url, "publicUrl":machine.PublicUrl, "count":strconv.Itoa(count)}) - } else { - writeJson(w, r, map[string]string{"error": err.Error()}) - } + c := r.FormValue("count") + fid, count, machine, err := mapper.PickForWrite(c) + if err == nil { + writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url, "publicUrl": machine.PublicUrl, "count": strconv.Itoa(count)}) + } else { + writeJson(w, r, map[string]string{"error": err.Error()}) + } } func dirJoinHandler(w http.ResponseWriter, r *http.Request) { - s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port") - publicUrl := r.FormValue("publicUrl") - volumes := new([]storage.VolumeInfo) - json.Unmarshal([]byte(r.FormValue("volumes")), volumes) - if *IsDebug { - log.Println(s, "volumes", r.FormValue("volumes")) - } - mapper.Add(*directory.NewMachine(s, publicUrl, *volumes)) + s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port") + publicUrl := r.FormValue("publicUrl") + volumes := new([]storage.VolumeInfo) + json.Unmarshal([]byte(r.FormValue("volumes")), volumes) + if *IsDebug { + log.Println(s, "volumes", r.FormValue("volumes")) + } + mapper.Add(*directory.NewMachine(s, publicUrl, *volumes)) } func dirStatusHandler(w http.ResponseWriter, r *http.Request) { - writeJson(w, r, mapper) + writeJson(w, r, mapper) } func runMaster(cmd *Command, args []string) bool { - log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB") - mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024) - http.HandleFunc("/dir/assign", dirAssignHandler) - http.HandleFunc("/dir/lookup", dirLookupHandler) - http.HandleFunc("/dir/join", dirJoinHandler) - http.HandleFunc("/dir/status", dirStatusHandler) + log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB") + mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024) + http.HandleFunc("/dir/assign", dirAssignHandler) + http.HandleFunc("/dir/lookup", dirLookupHandler) + http.HandleFunc("/dir/join", dirJoinHandler) + http.HandleFunc("/dir/status", dirStatusHandler) - log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport)) - e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil) - if e != nil { - log.Fatal("Fail to start:", e) - } - return true + log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport)) + e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil) + if e != nil { + log.Fatal("Fail to start:", e) + } + return true } |
