forked from Terry-Mao/bfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Terry-Mao#52 from StartFeng/master
写了个go版的ops & 添加了hbase thrift 协议开启Frame的配置
- Loading branch information
Showing
23 changed files
with
32,885 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,72 @@ | ||
package conf | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
"io/ioutil" | ||
"os" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
Snowflake *Snowflake | ||
Zookeeper *Zookeeper | ||
HBase *HBase | ||
|
||
MaxNum int | ||
ApiListen string | ||
PprofEnable bool | ||
PprofListen string | ||
} | ||
|
||
type Snowflake struct { | ||
ZkAddrs []string | ||
ZkTimeout duration | ||
ZkPath string | ||
WorkId int64 | ||
} | ||
|
||
type Zookeeper struct { | ||
Addrs []string | ||
Timeout duration | ||
PullInterval duration | ||
VolumeRoot string | ||
StoreRoot string | ||
GroupRoot string | ||
} | ||
|
||
type HBase struct { | ||
Addr string | ||
MaxActive int | ||
MaxIdle int | ||
Timeout duration | ||
LvsTimeout duration | ||
} | ||
|
||
// Code to implement the TextUnmarshaler interface for `duration`: | ||
type duration struct { | ||
time.Duration | ||
} | ||
|
||
func (d *duration) UnmarshalText(text []byte) error { | ||
var err error | ||
d.Duration, err = time.ParseDuration(string(text)) | ||
return err | ||
} | ||
|
||
// NewConfig new a config. | ||
func NewConfig(conf string) (c *Config, err error) { | ||
var ( | ||
file *os.File | ||
blob []byte | ||
) | ||
c = new(Config) | ||
if file, err = os.Open(conf); err != nil { | ||
return | ||
} | ||
if blob, err = ioutil.ReadAll(file); err != nil { | ||
return | ||
} | ||
err = toml.Unmarshal(blob, c) | ||
return | ||
} | ||
package conf | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
"io/ioutil" | ||
"os" | ||
"time" | ||
) | ||
|
||
type Config struct { | ||
Snowflake *Snowflake | ||
Zookeeper *Zookeeper | ||
HBase *HBase | ||
|
||
MaxNum int | ||
ApiListen string | ||
PprofEnable bool | ||
PprofListen string | ||
} | ||
|
||
type Snowflake struct { | ||
ZkAddrs []string | ||
ZkTimeout duration | ||
ZkPath string | ||
WorkId int64 | ||
} | ||
|
||
type Zookeeper struct { | ||
Addrs []string | ||
Timeout duration | ||
PullInterval duration | ||
VolumeRoot string | ||
StoreRoot string | ||
GroupRoot string | ||
} | ||
|
||
type HBase struct { | ||
Addr string | ||
MaxActive int | ||
MaxIdle int | ||
Timeout duration | ||
LvsTimeout duration | ||
Framed bool | ||
} | ||
|
||
// Code to implement the TextUnmarshaler interface for `duration`: | ||
type duration struct { | ||
time.Duration | ||
} | ||
|
||
func (d *duration) UnmarshalText(text []byte) error { | ||
var err error | ||
d.Duration, err = time.ParseDuration(string(text)) | ||
return err | ||
} | ||
|
||
// NewConfig new a config. | ||
func NewConfig(conf string) (c *Config, err error) { | ||
var ( | ||
file *os.File | ||
blob []byte | ||
) | ||
c = new(Config) | ||
if file, err = os.Open(conf); err != nil { | ||
return | ||
} | ||
if blob, err = ioutil.ReadAll(file); err != nil { | ||
return | ||
} | ||
err = toml.Unmarshal(blob, c) | ||
return | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ MaxIdle = 100 | |
|
||
# Note that you must specify a number here. | ||
Timeout = "1s" | ||
|
||
Framed = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
appname = gops | ||
httpport = 8080 | ||
runmode = dev | ||
|
||
TemplateLeft=<<< | ||
TemplateRight=>>> | ||
|
||
[dev] | ||
ZkServers=192.168.1.192:2181 | ||
ZkTimeout=1 | ||
StoreDomain=192.168.1.197 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/astaxie/beego" | ||
"bfs/gops/models/ops" | ||
"strings" | ||
) | ||
|
||
type ApiController struct { | ||
beego.Controller | ||
} | ||
|
||
func (c *ApiController) Initialization() { | ||
|
||
} | ||
|
||
func (c *ApiController) GetRack() { | ||
var err error | ||
if c.Data["json"], err = ops.OpsManager.GetRack(); err != nil { | ||
c.Abort("500") | ||
beego.Error(err) | ||
} | ||
|
||
c.ServeJSON() | ||
} | ||
|
||
|
||
func (c *ApiController) GetGroup() { | ||
var err error | ||
if c.Data["json"], err = ops.OpsManager.GetGroup(); err != nil { | ||
beego.Error(err) | ||
c.Abort("500") | ||
} | ||
|
||
c.ServeJSON() | ||
} | ||
|
||
|
||
|
||
func (c *ApiController) GetFreeStore() { | ||
var err error | ||
if c.Data["json"], err = ops.OpsManager.GetFreeStore(); err != nil { | ||
beego.Error(err) | ||
c.Abort("500") | ||
} | ||
|
||
c.ServeJSON() | ||
} | ||
|
||
func (c *ApiController)AddFreeVolume() { | ||
|
||
var ( | ||
err error | ||
host string | ||
bdir string | ||
idir string | ||
n int32 | ||
res map[string]interface{} | ||
) | ||
|
||
res = make(map[string]interface{}) | ||
res["success"] = true | ||
|
||
host = c.GetString("host") | ||
bdir = c.GetString("bdir") | ||
idir = c.GetString("idir") | ||
if n, err = c.GetInt32("n"); err !=nil{ | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
if err = ops.OpsManager.AddFreeVolume(host,n,bdir,idir);err != nil{ | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
c.Data["json"] = res | ||
c.ServeJSON() | ||
} | ||
|
||
func (c *ApiController)AddGroup() { | ||
var ( | ||
err error | ||
stores []string | ||
racks int | ||
copys int | ||
res map[string]interface{} = make(map[string]interface{}) | ||
) | ||
|
||
|
||
res["success"] = true | ||
|
||
stores = strings.Split(c.GetString("stores"), ",") | ||
|
||
if racks, err = c.GetInt("racks"); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
if copys, err = c.GetInt("copys"); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
if err = ops.OpsManager.AddGroup(stores, racks, copys); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
c.Data["json"] = res | ||
c.ServeJSON() | ||
} | ||
|
||
func (c *ApiController)AddVolume() { | ||
var ( | ||
err error | ||
groupId int64 | ||
n int | ||
res map[string]interface{} = make(map[string]interface{}) | ||
) | ||
|
||
|
||
res["success"] = true | ||
|
||
|
||
if groupId, err = c.GetInt64("groupId"); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
if n, err = c.GetInt("n"); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
if err = ops.OpsManager.AddVolume(uint64(groupId),n); err != nil { | ||
beego.Error(err) | ||
c.responseError(err) | ||
} | ||
|
||
c.Data["json"] = res | ||
c.ServeJSON() | ||
} | ||
|
||
|
||
|
||
|
||
func (c *ApiController)responseError(err error) { | ||
res := make(map[string]interface{}) | ||
res["success"] = false | ||
res["msg"] = err.Error() | ||
c.Data["json"] = res | ||
c.ServeJSON() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/astaxie/beego" | ||
) | ||
|
||
type MainController struct { | ||
beego.Controller | ||
} | ||
|
||
func (c *MainController) Get() { | ||
c.TplName = "index.tpl" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
_ "bfs/gops/routers" | ||
"github.com/astaxie/beego" | ||
"bfs/gops/models/ops" | ||
) | ||
|
||
func main() { | ||
ops.InitOps() | ||
beego.Run() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package global | ||
import "bfs/gops/models/types" | ||
|
||
var ( | ||
MAX_GROUP_ID uint64 = 0; | ||
MAX_VOLUME_ID uint64 = 0; | ||
STORES map[string]*types.Store | ||
IN_GROUP_STORES map[string]*types.Store | ||
GROUPS map[uint64]*types.Group | ||
) |
Oops, something went wrong.