Files
seaweedfs/go/operation/allocate_volume.go

34 lines
799 B
Go
Raw Normal View History

2012-09-20 18:02:56 -07: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-26 22:54:22 -08:00
"encoding/json"
"errors"
"net/url"
2012-09-20 18:02:56 -07:00
)
type AllocateVolumeResult struct {
2013-01-17 00:56:56 -08:00
Error string
2012-09-20 18:02:56 -07:00
}
2013-11-12 02:21:22 -08:00
func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, collection string, repType storage.ReplicationType) error {
2013-01-17 00:56:56 -08:00
values := make(url.Values)
values.Add("volume", vid.String())
2013-11-12 02:21:22 -08:00
values.Add("collection", collection)
2014-02-06 11:44:18 -08:00
values.Add("replication", repType.String())
jsonBlob, err := util.Post("http://"+dn.PublicUrl+"/admin/assign_volume", values)
2013-01-17 00:56:56 -08: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-20 18:02:56 -07:00
}