2014-04-13 16:29:52 +08:00
|
|
|
package topology
|
2012-09-21 09:02:56 +08:00
|
|
|
|
|
|
|
import (
|
2013-02-27 14:54:22 +08:00
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
2015-02-21 01:12:02 +08:00
|
|
|
"fmt"
|
2013-02-27 14:54:22 +08:00
|
|
|
"net/url"
|
2014-10-27 02:34:55 +08:00
|
|
|
|
2016-06-03 09:09:14 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2012-09-21 09:02:56 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type AllocateVolumeResult struct {
|
2013-01-17 16:56:56 +08:00
|
|
|
Error string
|
2012-09-21 09:02:56 +08:00
|
|
|
}
|
|
|
|
|
2014-09-21 03:38:59 +08:00
|
|
|
func AllocateVolume(dn *DataNode, vid storage.VolumeId, option *VolumeGrowOption) error {
|
2013-01-17 16:56:56 +08:00
|
|
|
values := make(url.Values)
|
|
|
|
values.Add("volume", vid.String())
|
2014-09-21 03:38:59 +08:00
|
|
|
values.Add("collection", option.Collection)
|
|
|
|
values.Add("replication", option.ReplicaPlacement.String())
|
|
|
|
values.Add("ttl", option.Ttl.String())
|
2015-03-09 16:10:01 +08:00
|
|
|
jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
|
2013-01-17 16:56:56 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var ret AllocateVolumeResult
|
|
|
|
if err := json.Unmarshal(jsonBlob, &ret); err != nil {
|
2015-02-21 01:12:02 +08:00
|
|
|
return fmt.Errorf("Invalid JSON result for %s: %s", "/admin/assign_volum", string(jsonBlob))
|
2013-01-17 16:56:56 +08:00
|
|
|
}
|
|
|
|
if ret.Error != "" {
|
|
|
|
return errors.New(ret.Error)
|
|
|
|
}
|
|
|
|
return nil
|
2012-09-21 09:02:56 +08:00
|
|
|
}
|