2014-02-15 01:10:49 +00:00
|
|
|
package replication
|
2012-09-21 01:02:56 +00:00
|
|
|
|
|
|
|
import (
|
2013-02-10 11:49:51 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
|
2014-03-03 06:16:54 +00:00
|
|
|
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, collection string, rp *storage.ReplicaPlacement) error {
|
2013-01-17 08:56:56 +00:00
|
|
|
values := make(url.Values)
|
|
|
|
values.Add("volume", vid.String())
|
2013-11-12 10:21:22 +00:00
|
|
|
values.Add("collection", collection)
|
2014-03-03 06:16:54 +00:00
|
|
|
values.Add("replication", rp.String())
|
2013-12-03 06:58:27 +00:00
|
|
|
jsonBlob, err := util.Post("http://"+dn.PublicUrl+"/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 err
|
|
|
|
}
|
|
|
|
if ret.Error != "" {
|
|
|
|
return errors.New(ret.Error)
|
|
|
|
}
|
|
|
|
return nil
|
2012-09-21 01:02:56 +00:00
|
|
|
}
|