예제 #1
0
파일: zkconf.go 프로젝트: henryanand/vitess
/*
  Create a config for this instance.

  <server_id>@<hostname>:<leader_port>:<election_port>:<client_port>

  If server_id > 1000, then we assume this is a global quorum.
  server_id's must be 1-255, global id's are 1001-1255 mod 1000.
*/
func MakeZkConfigFromString(cmdLine string, myId uint32) *ZkConfig {
	zkConfig := NewZkConfig()
	for _, zki := range strings.Split(cmdLine, ",") {
		zkiParts := strings.SplitN(zki, "@", 2)
		if len(zkiParts) != 2 {
			panic("bad command line format for zk config")
		}
		zkId := zkiParts[0]
		zkAddrParts := strings.Split(zkiParts[1], ":")
		serverId, _ := strconv.ParseUint(zkId, 10, 0)
		if serverId > 1000 {
			serverId = serverId % 1000
			zkConfig.Global = true
		}
		myId = myId % 1000

		zkServer := zkServerAddr{ServerId: uint32(serverId), ClientPort: 2181,
			LeaderPort: 2888, ElectionPort: 3888}
		switch len(zkAddrParts) {
		case 4:
			zkServer.ClientPort, _ = strconv.Atoi(zkAddrParts[3])
			fallthrough
		case 3:
			zkServer.ElectionPort, _ = strconv.Atoi(zkAddrParts[2])
			fallthrough
		case 2:
			zkServer.LeaderPort, _ = strconv.Atoi(zkAddrParts[1])
			fallthrough
		case 1:
			zkServer.Hostname = zkAddrParts[0]
			// if !strings.Contains(zkServer.Hostname, ".") {
			// 	panic(fmt.Errorf("expected fully qualified hostname: %v", zkServer.Hostname))
			// }
		default:
			panic(fmt.Errorf("bad command line format for zk config"))
		}
		zkConfig.Servers = append(zkConfig.Servers, zkServer)
	}
	hostname := netutil.FullyQualifiedHostnameOrPanic()
	for _, zkServer := range zkConfig.Servers {
		if (myId > 0 && myId == zkServer.ServerId) || (myId == 0 && zkServer.Hostname == hostname) {
			zkConfig.ServerId = zkServer.ServerId
			zkConfig.ClientPort = zkServer.ClientPort
			break
		}
	}
	if zkConfig.ServerId == 0 {
		panic(fmt.Errorf("no zk server found for host %v in config %v", hostname, cmdLine))
	}
	return zkConfig
}
예제 #2
0
파일: pdns.go 프로젝트: henryanand/vitess
func main() {
	defer logutil.Flush()

	zknsDomain := flag.String("zkns-domain", "", "The naming hierarchy portion to serve")
	zknsRoot := flag.String("zkns-root", "", "The root path from which to resolve")
	bindAddr := flag.String("bind-addr", ":31981", "Bind the debug http server")
	flag.Parse()

	if *bindAddr != "" {
		go func() {
			err := http.ListenAndServe(*bindAddr, nil)
			if err != nil {
				log.Fatalf("ListenAndServe: %s", err)
			}
		}()
	}

	zconn := zk.NewMetaConn(false)
	fqdn := netutil.FullyQualifiedHostnameOrPanic()
	zr1 := newZknsResolver(zconn, fqdn, *zknsDomain, *zknsRoot)
	pd := &pdns{zr1}
	pd.Serve(os.Stdin, os.Stdout)
	os.Stdout.Close()
}
예제 #3
0
파일: mysqld.go 프로젝트: henryanand/vitess
// Addr returns the fully qualified host name + port for this instance.
func (mysqld *Mysqld) Addr() string {
	hostname := netutil.FullyQualifiedHostnameOrPanic()
	return fmt.Sprintf("%v:%v", hostname, mysqld.config.MysqlPort)
}
예제 #4
0
	fakeCNAME = `{
"Entries": [
  {
    "host": "test1"
  }
]}`

	fakeA = `{
"Entries": [
  {
    "ipv4": "0.0.0.1"
  }
]}`
)

var fqdn = netutil.FullyQualifiedHostnameOrPanic()

var zconn = &TestZkConn{map[string]string{
	"/zk/test/zkns/srv":   fakeSRV,
	"/zk/test/zkns/cname": fakeCNAME,
	"/zk/test/zkns/a":     fakeA,
}}

var queries = []string{
	"Q\t_http.srv.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\ta.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\tcname.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\tempty.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	// Sadly this test case generates a log error that cannot be squelched easily.
	"Q\tbad.domain.test.ignore.console.log.errors\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
}