Пример #1
0
func TestUpdateRegion(t *testing.T) {
	c := controller.NewController()

	s0 := topo.NewNode("127.0.0.1", 7000)
	s1 := topo.NewNode("127.0.0.1", 7002)

	sp := inspector.NewInspector([]*topo.Node{s0, s1})

	go func() {
		time.Sleep(10 * time.Second)
		cmd := &command.MigrateCommand{
			"1c11d8d88e7d2ac9e0bb9bb1a1208e06468cd9e0",
			"5f674075196119c0d94037583b8a4a9a0e902dd5",
			[]topo.Range{topo.Range{6010, 6020}},
		}
		fmt.Println("=====", "migrate command", "=====")
		c.ProcessCommand(cmd, 2*time.Second)
	}()

	for {
		time.Sleep(1 * time.Second)
		clusterTopo, err := sp.BuildClusterTopo()
		if err != nil {
			fmt.Println(err)
			continue
		}
		ss := clusterTopo.LocalRegionNodes()
		fmt.Println("=================", clusterTopo.Region())
		cmd := command.UpdateRegionCommand{clusterTopo.Region(), ss}
		c.ProcessCommand(cmd, 5*time.Second)
	}
}
Пример #2
0
func main() {
	flag.Parse()

	seedNodes := []*topo.Node{}
	for _, addr := range strings.Split(seeds, ",") {
		glog.Info(addr)
		n := topo.NewNodeFromString(addr)
		if n == nil {
			glog.Fatal("invalid seeds %s", addr)
		}
		seedNodes = append(seedNodes, n)
	}
	if httpPort == 0 {
		glog.Fatal("invalid http port")
		flag.PrintDefaults()
	}
	if wsPort == 0 {
		glog.Fatal("invalid websocket port")
		flag.PrintDefaults()
	}

	initCh := make(chan error)
	go meta.Run(appName, localRegion, httpPort, wsPort, zkHosts, seedNodes, initCh)
	err := <-initCh
	if err != nil {
		glog.Warning(err)
	}

	streams.StartAllStreams()
	streams.LogStream.Sub(log.WriteFileHandler)
	streams.LogStream.Sub(log.WriteRingBufferHandler)

	sp := inspector.NewInspector()
	go sp.Run()

	c := controller.NewController()
	fe := frontend.NewFrontEnd(c, httpPort, wsPort)
	fe.Run()
}