This commit is contained in:
Chris Lu 2012-09-26 02:29:16 -07:00
parent d63c5231ac
commit 5d86b50782
4 changed files with 8 additions and 3 deletions

View file

@ -83,7 +83,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
} }
fid, count, dn, err := topo.PickForWrite(rt, c) fid, count, dn, err := topo.PickForWrite(rt, c)
if err == nil { if err == nil {
writeJson(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "count": count}) writeJson(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "publicUrl":dn.PublicUrl, "count": count})
} else { } else {
writeJson(w, r, map[string]string{"error": err.Error()}) writeJson(w, r, map[string]string{"error": err.Error()})
} }

View file

@ -30,7 +30,7 @@ var cmdVolume = &Command{
var ( var (
vport = cmdVolume.Flag.Int("port", 8080, "http listen port") vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
volumeFolder = cmdVolume.Flag.String("dir", "/tmp", "directory to store data files") volumeFolder = cmdVolume.Flag.String("dir", "/tmp", "directory to store data files")
ip = cmdVolume.Flag.String("ip", "", "ip or server name") ip = cmdVolume.Flag.String("ip", "localhost", "ip or server name")
publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible <ip|server_name>:<port>") publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible <ip|server_name>:<port>")
masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location") masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location")
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats") vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
@ -229,6 +229,10 @@ func runVolume(cmd *Command, args []string) bool {
perm := fileInfo.Mode().Perm() perm := fileInfo.Mode().Perm()
log.Println("Volume Folder permission:", perm) log.Println("Volume Folder permission:", perm)
if *publicUrl == "" {
*publicUrl = *ip + ":" + strconv.Itoa(*vport)
}
store = storage.NewStore(*vport, *ip, *publicUrl, *volumeFolder, *maxVolumeCount) store = storage.NewStore(*vport, *ip, *publicUrl, *volumeFolder, *maxVolumeCount)
defer store.Close() defer store.Close()
http.HandleFunc("/", storeHandler) http.HandleFunc("/", storeHandler)

View file

@ -15,6 +15,7 @@ type UploadResult struct {
} }
func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) { func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
println("uploading to", uploadUrl)
body_buf := bytes.NewBufferString("") body_buf := bytes.NewBufferString("")
body_writer := multipart.NewWriter(body_buf) body_writer := multipart.NewWriter(body_buf)
file_writer, err := body_writer.CreateFormFile("file", filename) file_writer, err := body_writer.CreateFormFile("file", filename)
@ -31,6 +32,7 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
return nil, err return nil, err
} }
var ret UploadResult var ret UploadResult
println("upload response to", uploadUrl, resp_body)
err = json.Unmarshal(resp_body, &ret) err = json.Unmarshal(resp_body, &ret)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())

View file

@ -89,7 +89,6 @@ func (n *Needle) Append(w io.Writer) uint32 {
w.Write(n.Data) w.Write(n.Data)
rest := 8 - ((n.Size + 16 + 4) % 8) rest := 8 - ((n.Size + 16 + 4) % 8)
util.Uint32toBytes(header[0:4], n.Checksum.Value()) util.Uint32toBytes(header[0:4], n.Checksum.Value())
println("writing checksum", n.Checksum.Value(), "=>", util.BytesToUint32(header[0:4]), "for", n.Id)
w.Write(header[0 : rest+4]) w.Write(header[0 : rest+4])
return n.Size return n.Size
} }