diff options
Diffstat (limited to 'go/operation')
| -rw-r--r-- | go/operation/allocate_volume.go | 33 | ||||
| -rw-r--r-- | go/operation/list_masters.go | 27 | ||||
| -rw-r--r-- | go/operation/lookup_volume_id.go | 14 |
3 files changed, 34 insertions, 40 deletions
diff --git a/go/operation/allocate_volume.go b/go/operation/allocate_volume.go deleted file mode 100644 index 3f96583e5..000000000 --- a/go/operation/allocate_volume.go +++ /dev/null @@ -1,33 +0,0 @@ -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" - "encoding/json" - "errors" - "net/url" -) - -type AllocateVolumeResult struct { - Error string -} - -func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, collection string, repType storage.ReplicationType) error { - values := make(url.Values) - values.Add("volume", vid.String()) - values.Add("collection", collection) - values.Add("replication", repType.String()) - jsonBlob, err := util.Post("http://"+dn.PublicUrl+"/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 -} diff --git a/go/operation/list_masters.go b/go/operation/list_masters.go new file mode 100644 index 000000000..05235aed0 --- /dev/null +++ b/go/operation/list_masters.go @@ -0,0 +1,27 @@ +package operation + +import ( + "code.google.com/p/weed-fs/go/glog" + "code.google.com/p/weed-fs/go/util" + "encoding/json" +) + +type ClusterStatusResult struct { + IsLeader bool + Leader string + Peers []string +} + +func ListMasters(server string) ([]string, error) { + jsonBlob, err := util.Get("http://" + server + "/cluster/status") + glog.V(2).Info("list masters result :", string(jsonBlob)) + if err != nil { + return nil, err + } + var ret ClusterStatusResult + err = json.Unmarshal(jsonBlob, &ret) + if err != nil { + return nil, err + } + return ret.Peers, nil +} diff --git a/go/operation/lookup_volume_id.go b/go/operation/lookup_volume_id.go index cd1d3b1bd..6e6035fae 100644 --- a/go/operation/lookup_volume_id.go +++ b/go/operation/lookup_volume_id.go @@ -1,12 +1,12 @@ package operation import ( - "code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/util" "encoding/json" "errors" _ "fmt" "net/url" + "strings" ) type Location struct { @@ -18,9 +18,9 @@ type LookupResult struct { Error string `json:"error"` } -func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) { +func Lookup(server string, vid string) (*LookupResult, error) { values := make(url.Values) - values.Add("volumeId", vid.String()) + values.Add("volumeId", vid) jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values) if err != nil { return nil, err @@ -37,11 +37,11 @@ func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) { } func LookupFileId(server string, fileId string) (fullUrl string, err error) { - fid, parseErr := storage.ParseFileId(fileId) - if parseErr != nil { - return "", parseErr + a := strings.Split(fileId, ",") + if len(a) != 2 { + return "", errors.New("Invalid fileId " + fileId) } - lookup, lookupError := Lookup(server, fid.VolumeId) + lookup, lookupError := Lookup(server, a[0]) if lookupError != nil { return "", lookupError } |
