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.

34 lines
792 B

  1. package topology
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "net/url"
  6. "github.com/chrislusf/weed-fs/go/storage"
  7. "github.com/chrislusf/weed-fs/go/util"
  8. )
  9. type AllocateVolumeResult struct {
  10. Error string
  11. }
  12. func AllocateVolume(dn *DataNode, vid storage.VolumeId, option *VolumeGrowOption) error {
  13. values := make(url.Values)
  14. values.Add("volume", vid.String())
  15. values.Add("collection", option.Collection)
  16. values.Add("replication", option.ReplicaPlacement.String())
  17. values.Add("ttl", option.Ttl.String())
  18. jsonBlob, err := util.Post("http://"+dn.PublicUrl+"/admin/assign_volume", values)
  19. if err != nil {
  20. return err
  21. }
  22. var ret AllocateVolumeResult
  23. if err := json.Unmarshal(jsonBlob, &ret); err != nil {
  24. return err
  25. }
  26. if ret.Error != "" {
  27. return errors.New(ret.Error)
  28. }
  29. return nil
  30. }