2012-09-21 01:02:56 +00:00
|
|
|
package operation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"net/url"
|
|
|
|
"pkg/storage"
|
|
|
|
"pkg/topology"
|
|
|
|
"pkg/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())
|
2012-09-26 08:55:56 +00:00
|
|
|
jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
|
2012-09-21 01:02: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
|
|
|
|
}
|