Skip to content

Commit

Permalink
gops first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gogs committed May 12, 2016
1 parent ae81770 commit 33eea70
Show file tree
Hide file tree
Showing 23 changed files with 32,882 additions and 72 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ _testmain.go
*.test
*.prof
*.gitattributes

*.iml
*.ipr
*.iws
.idea/
143 changes: 72 additions & 71 deletions directory/conf/config.go
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 added directory/directory
Binary file not shown.
2 changes: 2 additions & 0 deletions directory/directory.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ MaxIdle = 100

# Note that you must specify a number here.
Timeout = "1s"

Framed = false
6 changes: 5 additions & 1 deletion directory/hbase/hpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func Init(config *conf.Config) error {
log.Error("thrift.NewTSocketTimeout error(%v)", err)
return
}
trans = thrift.NewTFramedTransport(trans)

if config.HBase.Framed {
trans = thrift.NewTFramedTransport(trans)
}

c = hbasethrift.NewTHBaseServiceClientFactory(trans, thrift.NewTBinaryProtocolFactoryDefault())
if err = trans.Open(); err != nil {
log.Error("trans.Open error(%v)", err)
Expand Down
12 changes: 12 additions & 0 deletions gops/conf/app.conf
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

154 changes: 154 additions & 0 deletions gops/controllers/api.go
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()
}
13 changes: 13 additions & 0 deletions gops/controllers/default.go
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"
}
Binary file added gops/gops
Binary file not shown.
13 changes: 13 additions & 0 deletions gops/main.go
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()
}

10 changes: 10 additions & 0 deletions gops/models/global/global.go
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
)
Loading

0 comments on commit 33eea70

Please sign in to comment.