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.

43 lines
973 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, collection 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. if collection != "" {
  24. values.Add("collection", collection)
  25. }
  26. jsonBlob, err := util.Post("http://"+server+"/dir/assign", values)
  27. glog.V(2).Info("assign result :", string(jsonBlob))
  28. if err != nil {
  29. return nil, err
  30. }
  31. var ret AssignResult
  32. err = json.Unmarshal(jsonBlob, &ret)
  33. if err != nil {
  34. return nil, err
  35. }
  36. if ret.Count <= 0 {
  37. return nil, errors.New(ret.Error)
  38. }
  39. return &ret, nil
  40. }