Esempio n. 1
0
func (top *Topology) InitZkConn() {
	var err error
	// 连接到zk
	top.zkConn, err = zkhelper.ConnectToZk(top.zkAddr, 30) // 参考: Codis的默认配置
	if err != nil {
		log.PanicErrorf(err, "init failed")
	}
}
Esempio n. 2
0
func (e *CodisEnv) NewZkConn() (zkhelper.Conn, error) {
	switch e.provider {
	case "zookeeper":
		return zkhelper.ConnectToZk(e.zkAddr, 30)
	case "etcd":
		addr := strings.TrimSpace(e.zkAddr)
		if !strings.HasPrefix(addr, "http://") {
			addr = "http://" + addr
		}
		return zkhelper.NewEtcdConn(addr, 30)
	}
	return nil, errors.Errorf("need coordinator in config file, %s", e)
}
Esempio n. 3
0
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)
}