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.

36 lines
951 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. values.Add("preallocate", fmt.Sprintf("%d", option.Prealloacte))
  20. jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
  21. if err != nil {
  22. return err
  23. }
  24. var ret AllocateVolumeResult
  25. if err := json.Unmarshal(jsonBlob, &ret); err != nil {
  26. return fmt.Errorf("Invalid JSON result for %s: %s", "/admin/assign_volum", string(jsonBlob))
  27. }
  28. if ret.Error != "" {
  29. return errors.New(ret.Error)
  30. }
  31. return nil
  32. }