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.

35 lines
885 B

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