From 79b0a581327b0153acb869570eae20fa1a1e8faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=8D=E6=99=93=E6=A0=8B?= Date: Thu, 23 Jun 2016 11:19:09 +0800 Subject: [PATCH] add options params for the Assign func --- weed/operation/assign_file_id.go | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go index acc2d3034..a893e836b 100644 --- a/weed/operation/assign_file_id.go +++ b/weed/operation/assign_file_id.go @@ -19,7 +19,13 @@ type AssignResult struct { Error string `json:"error,omitempty"` } -func Assign(server string, count uint64, replication string, collection string, ttl string) (*AssignResult, error) { +/* +options params meaning: +options[0] main data Center +options[1] main rack +options[2] main data node +*/ +func Assign(server string, count uint64, replication string, collection string, ttl string, options ...string) (*AssignResult, error) { values := make(url.Values) values.Add("count", strconv.FormatUint(count, 10)) if replication != "" { @@ -31,6 +37,31 @@ func Assign(server string, count uint64, replication string, collection string, if ttl != "" { values.Add("ttl", ttl) } + + var dataCenter, rack, dataNode string + switch len(options) { + case 1: + dataCenter = options[0] + case 2: + dataCenter = options[0] + rack = options[1] + case 3: + dataCenter = options[0] + rack = options[1] + dataNode = options[2] + default: + } + + if dataCenter != "" { + values.Add("dataCenter", dataCenter) + } + if rack != "" { + values.Add("rack", rack) + } + if dataNode != "" { + values.Add("dataNode", dataNode) + } + jsonBlob, err := util.Post("http://"+server+"/dir/assign", values) glog.V(2).Info("assign result :", string(jsonBlob)) if err != nil {