1. volume server auto detect clustered master nodes

2. remove operation package dependency on storage
This commit is contained in:
Chris Lu
2014-02-14 17:10:49 -08:00
parent ef4c2c0d1e
commit edae676913
10 changed files with 127 additions and 23 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}