aboutsummaryrefslogtreecommitdiff
path: root/weed/operation/allocate_volume.go
blob: 1e016abf760cd261f7ff8ad1f79642e80b3e7de1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package operation

import (
	"encoding/json"
	"errors"
	"net/url"
	"weed/storage"
	"weed/topology"
	"weed/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())
	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
}