seaweedfs/weed/operation/allocate_volume.go
2013-02-10 03:31:40 -08:00

33 lines
748 B
Go

package operation
import (
"encoding/json"
"errors"
"net/url"
"code.google.com/p/weed-fs/weed/storage"
"code.google.com/p/weed-fs/weed/topology"
"code.google.com/p/weed-fs/weed/util"
)
type AllocateVolumeResult struct {
Error string
}
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage.ReplicationType) error {
values := make(url.Values)
values.Add("volume", vid.String())
values.Add("replicationType", repType.String())
jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
if err != nil {
return err
}
var ret AllocateVolumeResult
if err := json.Unmarshal(jsonBlob, &ret); err != nil {
return err
}
if ret.Error != "" {
return errors.New(ret.Error)
}
return nil
}