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.

40 lines
889 B

  1. package operation
  2. import (
  3. "code.google.com/p/weed-fs/go/glog"
  4. "code.google.com/p/weed-fs/go/util"
  5. "encoding/json"
  6. "errors"
  7. "net/url"
  8. "strconv"
  9. )
  10. type AssignResult struct {
  11. Fid string `json:"fid"`
  12. Url string `json:"url"`
  13. PublicUrl string `json:"publicUrl"`
  14. Count int
  15. Error string `json:"error"`
  16. }
  17. func Assign(server string, count int, replication string) (*AssignResult, error) {
  18. values := make(url.Values)
  19. values.Add("count", strconv.Itoa(count))
  20. if replication != "" {
  21. values.Add("replication", replication)
  22. }
  23. jsonBlob, err := util.Post("http://"+server+"/dir/assign", values)
  24. glog.V(2).Info("assign result :", string(jsonBlob))
  25. if err != nil {
  26. return nil, err
  27. }
  28. var ret AssignResult
  29. err = json.Unmarshal(jsonBlob, &ret)
  30. if err != nil {
  31. return nil, err
  32. }
  33. if ret.Count <= 0 {
  34. return nil, errors.New(ret.Error)
  35. }
  36. return &ret, nil
  37. }