seaweedfs/go/topology/allocate_volume.go

36 lines
882 B
Go
Raw Normal View History

package topology
2012-09-21 01:02:56 +00:00
import (
2013-02-27 06:54:22 +00:00
"encoding/json"
"errors"
"fmt"
2013-02-27 06:54:22 +00:00
"net/url"
"github.com/chrislusf/weed-fs/go/storage"
"github.com/chrislusf/weed-fs/go/util"
2012-09-21 01:02:56 +00:00
)
type AllocateVolumeResult struct {
2013-01-17 08:56:56 +00:00
Error string
2012-09-21 01:02:56 +00:00
}
func AllocateVolume(dn *DataNode, vid storage.VolumeId, option *VolumeGrowOption) error {
2013-01-17 08:56:56 +00:00
values := make(url.Values)
values.Add("volume", vid.String())
values.Add("collection", option.Collection)
values.Add("replication", option.ReplicaPlacement.String())
values.Add("ttl", option.Ttl.String())
jsonBlob, err := util.Post("http://"+dn.AdminUrl()+"/admin/assign_volume", values)
2013-01-17 08:56:56 +00:00
if err != nil {
return err
}
var ret AllocateVolumeResult
if err := json.Unmarshal(jsonBlob, &ret); err != nil {
return fmt.Errorf("Invalid JSON result for %s: %s", "/admin/assign_volum", string(jsonBlob))
2013-01-17 08:56:56 +00:00
}
if ret.Error != "" {
return errors.New(ret.Error)
}
return nil
2012-09-21 01:02:56 +00:00
}