seaweedfs/go/operation/allocate_volume.go

33 lines
742 B
Go
Raw Normal View History

2012-09-21 01:02:56 +00:00
package operation
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/topology"
"code.google.com/p/weed-fs/go/util"
2013-02-27 06:54:22 +00:00
"encoding/json"
"errors"
"net/url"
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 *topology.DataNode, vid storage.VolumeId, repType storage.ReplicationType) error {
2013-01-17 08:56:56 +00:00
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
2012-09-21 01:02:56 +00:00
}