本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/models.SetProxyStatus函数的典型用法代码示例。如果您正苦于以下问题:Golang SetProxyStatus函数的具体用法?Golang SetProxyStatus怎么用?Golang SetProxyStatus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetProxyStatus函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runSetProxyStatus
func runSetProxyStatus(proxyName, status string) error {
if err := models.SetProxyStatus(zkConn, productName, proxyName, status); err != nil {
log.Warning(err)
return err
}
return nil
}
示例2: apiSetProxyStatus
func apiSetProxyStatus(proxy models.ProxyInfo, param martini.Params) (int, string) {
conn := CreateZkConn()
defer conn.Close()
err := models.SetProxyStatus(conn, productName, proxy.Id, proxy.State)
if err != nil {
log.Warning(err)
return 500, err.Error()
}
return jsonRetSucc()
}
示例3: apiSetProxyStatus
func apiSetProxyStatus(proxy models.ProxyInfo, param martini.Params) (int, string) {
err := models.SetProxyStatus(safeZkConn, globalEnv.ProductName(), proxy.Id, proxy.State)
if err != nil {
// if this proxy is not online, just return success
if proxy.State == models.PROXY_STATE_MARK_OFFLINE && zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return jsonRetSucc()
}
log.Warning(errors.ErrorStack(err))
return 500, err.Error()
}
return jsonRetSucc()
}
示例4: TestMarkOffline
//this should be the last test
func TestMarkOffline(t *testing.T) {
suicide := int64(0)
go func() {
s.Join()
atomic.StoreInt64(&suicide, 1)
}()
err := models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_MARK_OFFLINE)
assert.MustNoError(err)
time.Sleep(3 * time.Second)
if atomic.LoadInt64(&suicide) == 0 {
t.Error("shoud be suicided")
}
}
示例5: init
func init() {
conn = zkhelper.NewConn()
conf = &Config{
proxyId: "proxy_test",
productName: "test",
zkAddr: "localhost:2181",
fact: func(string, int) (zkhelper.Conn, error) { return conn, nil },
proto: "tcp4",
}
//init action path
prefix := models.GetWatchActionPath(conf.productName)
err := models.CreateActionRootPath(conn, prefix)
assert.MustNoError(err)
//init slot
err = models.InitSlotSet(conn, conf.productName, 1024)
assert.MustNoError(err)
//init server group
g1 := models.NewServerGroup(conf.productName, 1)
g1.Create(conn)
g2 := models.NewServerGroup(conf.productName, 2)
g2.Create(conn)
redis1, _ = miniredis.Run()
redis2, _ = miniredis.Run()
s1 := models.NewServer(models.SERVER_TYPE_MASTER, redis1.Addr())
s2 := models.NewServer(models.SERVER_TYPE_MASTER, redis2.Addr())
g1.AddServer(conn, s1, "")
g2.AddServer(conn, s2, "")
//set slot range
err = models.SetSlotRange(conn, conf.productName, 0, 511, 1, models.SLOT_STATUS_ONLINE)
assert.MustNoError(err)
err = models.SetSlotRange(conn, conf.productName, 512, 1023, 2, models.SLOT_STATUS_ONLINE)
assert.MustNoError(err)
s = New(":19000", ":11000", conf)
err = models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_ONLINE)
assert.MustNoError(err)
}
示例6: initReal
func initReal() {
conn = zkhelper.NewConn()
conf = &Config{
proxyId: "proxy_test",
productName: "test",
zkAddr: "192.168.28.191:2181",
fact: nil,
proto: "tcp4",
provider: "zookeeper",
zkSessionTimeout: 30,
zkReadTimeout: 30,
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, os.Kill)
go func() {
<-c
log.Info("ctrl-c or SIGTERM found, bye bye...")
s.Close()
}()
go func() {
log.Info(http.ListenAndServe("192.168.28.192:6060", nil))
}()
go func() {
time.Sleep(10 * time.Second)
zkConn, err := zkhelper.ConnectToZk(conf.zkAddr, 20000)
if err != nil {
log.Errorf("connect to zk: %+v", errors.Trace(err))
} else {
err = models.SetProxyStatus(zkConn, conf.productName, conf.proxyId, models.PROXY_STATE_ONLINE)
if err != nil {
log.Errorf("set proxy error: %+v", errors.Trace(err))
}
}
zkConn.Close()
}()
go func() {
err := http.ListenAndServe("192.168.28.192:11001", nil)
log.PanicError(err, "http debug server quit")
}()
s = New("192.168.28.192:19001", "192.168.28.192:11001", conf)
}
示例7: TestMarkOffline
//this should be the last test
func TestMarkOffline(t *testing.T) {
InitEnv()
suicide := int64(0)
proxyMutex.Lock()
s.OnSuicide = func() error {
atomic.StoreInt64(&suicide, 1)
return nil
}
proxyMutex.Unlock()
err := models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_MARK_OFFLINE)
assert.MustNoError(err)
time.Sleep(3 * time.Second)
if atomic.LoadInt64(&suicide) == 0 {
t.Error("shoud be suicided")
}
}
示例8: InitEnv
func InitEnv() {
go once.Do(func() {
conn = zkhelper.NewConn()
conf = &Config{
proxyId: "proxy_test",
productName: "test",
zkAddr: "localhost:2181",
fact: func(string) (zkhelper.Conn, error) { return conn, nil },
proto: "tcp4",
}
//init action path
prefix := models.GetWatchActionPath(conf.productName)
err := models.CreateActionRootPath(conn, prefix)
assert.MustNoError(err)
//init slot
err = models.InitSlotSet(conn, conf.productName, 1024)
assert.MustNoError(err)
//init server group
g1 := models.NewServerGroup(conf.productName, 1)
g1.Create(conn)
g2 := models.NewServerGroup(conf.productName, 2)
g2.Create(conn)
redis1, _ = miniredis.Run()
redis2, _ = miniredis.Run()
s1 := models.NewServer(models.SERVER_TYPE_MASTER, redis1.Addr())
s2 := models.NewServer(models.SERVER_TYPE_MASTER, redis2.Addr())
g1.AddServer(conn, s1, "")
g2.AddServer(conn, s2, "")
//set slot range
err = models.SetSlotRange(conn, conf.productName, 0, 511, 1, models.SLOT_STATUS_ONLINE)
assert.MustNoError(err)
err = models.SetSlotRange(conn, conf.productName, 512, 1023, 2, models.SLOT_STATUS_ONLINE)
assert.MustNoError(err)
go func() { //set proxy online
time.Sleep(3 * time.Second)
err := models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_ONLINE)
assert.MustNoError(err)
time.Sleep(2 * time.Second)
proxyMutex.Lock()
defer proxyMutex.Unlock()
assert.Must(s.info.State == models.PROXY_STATE_ONLINE)
}()
proxyMutex.Lock()
s, err = NewServer(":19000", ":11000", conf)
assert.MustNoError(err)
proxyMutex.Unlock()
s.Serve()
})
waitonce.Do(func() {
time.Sleep(10 * time.Second)
})
}
示例9: SetProxyStatus
func (top *Topology) SetProxyStatus(proxyName string, status string) error {
return models.SetProxyStatus(top.zkConn, top.ProductName, proxyName, status)
}
示例10: InitEnv
func InitEnv() {
go once.Do(func() {
conn = zkhelper.NewConn()
conf = &Conf{
proxyId: "proxy_test",
productName: "test",
zkAddr: "localhost:2181",
netTimeout: 5,
f: func(string) (zkhelper.Conn, error) { return conn, nil },
proto: "tcp4",
}
//init action path
prefix := models.GetWatchActionPath(conf.productName)
err := models.CreateActionRootPath(conn, prefix)
if err != nil {
log.Fatal(err)
}
//init slot
err = models.InitSlotSet(conn, conf.productName, 1024)
if err != nil {
log.Fatal(err)
}
//init server group
g1 := models.NewServerGroup(conf.productName, 1)
g1.Create(conn)
g2 := models.NewServerGroup(conf.productName, 2)
g2.Create(conn)
redis1, _ = miniredis.Run()
redis2, _ = miniredis.Run()
s1 := models.NewServer(models.SERVER_TYPE_MASTER, redis1.Addr())
s2 := models.NewServer(models.SERVER_TYPE_MASTER, redis2.Addr())
g1.AddServer(conn, s1)
g2.AddServer(conn, s2)
//set slot range
err = models.SetSlotRange(conn, conf.productName, 0, 511, 1, models.SLOT_STATUS_ONLINE)
if err != nil {
log.Fatal(err)
}
err = models.SetSlotRange(conn, conf.productName, 512, 1023, 2, models.SLOT_STATUS_ONLINE)
if err != nil {
log.Fatal(err)
}
go func() { //set proxy online
time.Sleep(3 * time.Second)
err := models.SetProxyStatus(conn, conf.productName, conf.proxyId, models.PROXY_STATE_ONLINE)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
time.Sleep(2 * time.Second)
proxyMutex.Lock()
defer proxyMutex.Unlock()
pi := s.getProxyInfo()
if pi.State != models.PROXY_STATE_ONLINE {
log.Fatalf("should be online, we got %s", pi.State)
}
}()
proxyMutex.Lock()
s = NewServer(":19000", ":11000",
conf,
)
proxyMutex.Unlock()
s.Run()
})
waitonce.Do(func() {
time.Sleep(10 * time.Second)
})
}