本文整理汇总了Golang中github.com/wandoulabs/zkhelper.CreateRecursive函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateRecursive函数的具体用法?Golang CreateRecursive怎么用?Golang CreateRecursive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateRecursive函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateDir
// 创建指定的Path
func (top *Topology) CreateDir(path string) (string, error) {
dir := top.FullPath(path)
if ok, _ := top.Exist(dir); ok {
log.Println("Path Exists")
return dir, nil
} else {
return zkhelper.CreateRecursive(top.zkConn, dir, "", 0, zkhelper.DefaultDirACLs())
}
}
示例2: CreateProxyInfo
func CreateProxyInfo(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error) {
data, err := json.Marshal(pi)
if err != nil {
return "", errors.Trace(err)
}
dir := GetProxyPath(productName)
zkhelper.CreateRecursive(zkConn, dir, "", 0, zkhelper.DefaultDirACLs())
return zkConn.Create(path.Join(dir, pi.Id), data, zk.FlagEphemeral, zkhelper.DefaultFileACLs())
}
示例3: NewMigrateManager
func NewMigrateManager(zkConn zkhelper.Conn, pn string) *MigrateManager {
m := &MigrateManager{
zkConn: zkConn,
productName: pn,
}
zkhelper.CreateRecursive(m.zkConn, getMigrateTasksPath(m.productName), "", 0, zkhelper.DefaultDirACLs())
m.mayRecover()
go m.loop()
return m
}
示例4: TestWaitForReceiver
func TestWaitForReceiver(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
proxies := []ProxyInfo{}
for i := 0; i < 5; i++ {
proxies = append(proxies, ProxyInfo{
Id: fmt.Sprintf("proxy_%d", i),
Addr: fmt.Sprintf("localhost:%d", i+1234),
State: PROXY_STATE_ONLINE,
})
CreateProxyInfo(fakeZkConn, productName, &proxies[i])
}
zkhelper.CreateRecursive(fakeZkConn, GetActionResponsePath(productName)+"/1", "", 0, zkhelper.DefaultDirACLs())
go func() {
time.Sleep(time.Second * 2)
doResponseForTest(fakeZkConn, "1", &proxies[0])
doResponseForTest(fakeZkConn, "1", &proxies[1])
doResponseForTest(fakeZkConn, "1", &proxies[2])
doResponseForTest(fakeZkConn, "1", &proxies[3])
doResponseForTest(fakeZkConn, "1", &proxies[4])
for {
for i := 0; i < 5; i++ {
pname := fmt.Sprintf("proxy_%d", i)
p, _ := GetProxyInfo(fakeZkConn, productName, pname)
if p != nil && p.State == PROXY_STATE_MARK_OFFLINE {
zkhelper.DeleteRecursive(fakeZkConn, path.Join(GetProxyPath(productName), pname), -1)
}
}
}
}()
err := WaitForReceiverWithTimeout(fakeZkConn, productName, GetActionResponsePath(productName)+"/1", proxies, 1000*10)
if err != nil {
t.Error("there is error not as expected")
}
p, _ := GetProxyInfo(fakeZkConn, productName, "proxy_0")
if p == nil || p.State != PROXY_STATE_ONLINE {
t.Error("proxy_0 status is not as expected")
}
p, _ = GetProxyInfo(fakeZkConn, productName, "proxy_1")
if p == nil || p.State != PROXY_STATE_ONLINE {
t.Error("proxy_1 status is not as expected")
}
p, _ = GetProxyInfo(fakeZkConn, productName, "proxy_2")
if p == nil || p.State != PROXY_STATE_ONLINE {
t.Error("proxy_2 status is not as expected")
}
p, _ = GetProxyInfo(fakeZkConn, productName, "proxy_3")
if p == nil || p.State != PROXY_STATE_ONLINE {
t.Error("proxy_3 status is not as expected")
}
p, _ = GetProxyInfo(fakeZkConn, productName, "proxy_4")
if p == nil || p.State != PROXY_STATE_ONLINE {
t.Error("proxy_4 status is not as expected")
}
}
示例5: createDashboardNode
func createDashboardNode() error {
// make sure root dir is exists
rootDir := fmt.Sprintf("/zk/codis/db_%s", globalEnv.ProductName())
zkhelper.CreateRecursive(safeZkConn, rootDir, "", 0, zkhelper.DefaultDirACLs())
zkPath := fmt.Sprintf("%s/dashboard", rootDir)
// make sure we're the only one dashboard
if exists, _, _ := safeZkConn.Exists(zkPath); exists {
data, _, _ := safeZkConn.Get(zkPath)
return errors.New("dashboard already exists: " + string(data))
}
content := fmt.Sprintf(`{"addr": "%v", "pid": %v}`, globalEnv.DashboardAddr(), os.Getpid())
pathCreated, err := safeZkConn.Create(zkPath, []byte(content), 0, zkhelper.DefaultFileACLs())
createdDashboardNode = true
log.Info("dashboard node created:", pathCreated, string(content))
return errors.Trace(err)
}
示例6: createDashboardNode
func createDashboardNode() error {
// make sure root dir is exists
rootDir := fmt.Sprintf("/zk/codis/db_%s", globalEnv.ProductName())
zkhelper.CreateRecursive(safeZkConn, rootDir, "", 0, zkhelper.DefaultDirACLs())
zkPath := fmt.Sprintf("%s/dashboard", rootDir)
// make sure we're the only one dashboard
if exists, _, _ := safeZkConn.Exists(zkPath); exists {
data, _, _ := safeZkConn.Get(zkPath)
return errors.New("dashboard already exists: " + string(data))
}
content := fmt.Sprintf(`{"addr": "%v", "pid": %v}`, globalEnv.DashboardAddr(), os.Getpid())
pathCreated, err := safeZkConn.Create(zkPath, []byte(content), 0, zkhelper.DefaultFileACLs())
createdDashboardNode = true
log.Infof("dashboard node created: %v, %s", pathCreated, string(content))
log.Warn("********** Attention **********")
log.Warn("You should use `kill {pid}` rather than `kill -9 {pid}` to stop me,")
log.Warn("or the node resisted on zk will not be cleaned when I'm quiting and you must remove it manually")
log.Warn("*******************************")
return errors.Trace(err)
}
示例7: CreateProxyFenceNode
func CreateProxyFenceNode(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error) {
return zkhelper.CreateRecursive(zkConn, path.Join(GetProxyFencePath(productName), pi.Addr), "",
0, zkhelper.DefaultFileACLs())
}