示例#1
0
func TestOrchestatorAll(t *testing.T) {
	zkzone := NewZkZone(DefaultConfig(ctx.DefaultZone(), ctx.ZoneZkAddrs(ctx.DefaultZone())))
	defer zkzone.Close()

	actorId := "actor1"
	o := zkzone.NewOrchestrator()
	err := o.RegisterActor(actorId, []byte{})
	assert.Equal(t, nil, err)
	ok, err := o.ActorRegistered(actorId)
	assert.Equal(t, true, ok)
	assert.Equal(t, nil, err)
	ok, err = o.ActorRegistered(actorId + "non-exist")
	assert.Equal(t, false, ok)
	assert.Equal(t, nil, err)

	w, c, err := o.WatchActors()
	assert.Equal(t, true, c != nil)
	assert.Equal(t, nil, err)
	assert.Equal(t, 1, len(w))
	assert.Equal(t, actorId, w[0])

	err = zkzone.CreateJobQueue("topic", "cluster")
	if err != nil {
		assert.Equal(t, zk.ErrNodeExists, err)
	} else {
		j, c, err := o.WatchResources(PubsubJobQueues)
		assert.Equal(t, nil, err)

		assert.Equal(t, true, c != nil)
		assert.Equal(t, true, len(j) >= 1)
	}
}
示例#2
0
文件: zk_test.go 项目: funkygao/gafka
func TestAll(t *testing.T) {
	zkzone := zk.NewZkZone(zk.DefaultConfig(ctx.DefaultZone(), ctx.ZoneZkAddrs(ctx.DefaultZone())))
	defer zkzone.Close()
	z := New(DefaultConfig(), zkzone)
	z.Start()

	assert.Equal(t, "/kafka_pubsub", z.ZkChroot("me"))
	assert.Equal(t, []string{"localhost:2181"}, z.ZkAddrs())

	t.Logf("%+v", z.BrokerList("me"))
	t.Logf("%+v", z.TopicPartitions("me", "app1.foobar.v1"))
	t.Logf("%+v", z.ZkCluster("me"))
	n, err := z.OnlineConsumersCount("me", "app1.foobar.v1", "group")
	t.Logf("%d %+v", n, err)
}
示例#3
0
文件: job.go 项目: funkygao/gafka
func (this *Job) Run(args []string) (exitCode int) {
	var (
		zone    string
		appid   string
		initJob string
	)
	cmdFlags := flag.NewFlagSet("job", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&appid, "app", "", "")
	cmdFlags.IntVar(&this.due, "d", 0, "")
	cmdFlags.StringVar(&initJob, "init", "", "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	this.zkzone = zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZoneZkAddrs(zone)))
	if initJob != "" {
		this.initializeJob(initJob)
		return
	}

	if appid != "" {
		this.displayAppJobs(appid)
		return
	}

	this.printResourcesAndActors()

	return
}
示例#4
0
文件: trace.go 项目: funkygao/gafka
func (this *Trace) Run(args []string) (exitCode int) {
	var (
		zone string
	)
	cmdFlags := flag.NewFlagSet("trace", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&this.cluster, "c", "", "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if this.cluster == "" {
		this.Ui.Error("-c required")
		return 2
	}

	this.manager = getConnectedManager(zone, this.cluster, helix.InstanceTypeSpectator)
	defer this.manager.Disconnect()

	this.startTracing()

	select {}

	return
}
示例#5
0
func (this *Resource) Run(args []string) (exitCode int) {
	var (
		zone    string
		add     string
		drop    string
		scale   string
		verbose bool
	)
	cmdFlags := flag.NewFlagSet("resource", flag.ContinueOnError)
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&this.cluster, "c", "", "")
	cmdFlags.StringVar(&add, "add", "", "")
	cmdFlags.StringVar(&drop, "drop", "", "")
	cmdFlags.StringVar(&scale, "scale", "", "")
	cmdFlags.BoolVar(&verbose, "v", false, "")
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if this.cluster == "" {
		this.Ui.Error("-c required")
		return 2
	}

	this.admin = getConnectedAdmin(zone)
	defer this.admin.Disconnect()

	switch {
	case add != "":
		tuple := strings.SplitN(add, ":", 3)
		stateModel := tuple[2]
		partitions, _ := strconv.Atoi(tuple[1])
		must(this.admin.AddResource(this.cluster, tuple[0], helix.DefaultAddResourceOption(partitions, stateModel)))

	case drop != "":
		must(this.admin.DropResource(this.cluster, drop))

	case scale != "":
		// TODO

	default:
		resources, err := this.admin.Resources(this.cluster)
		must(err)

		for _, resource := range resources {
			is, err := this.admin.ResourceIdealState(this.cluster, resource)
			must(err)

			this.Ui.Info(fmt.Sprintf("%s[%s]", resource, is.StateModelDefRef()))

			if verbose {
				this.Ui.Output(fmt.Sprintf("%+v", is))
			}

		}
	}

	return
}
示例#6
0
文件: zk_test.go 项目: funkygao/gafka
func TestZkPath(t *testing.T) {
	zkzone := zk.NewZkZone(zk.DefaultConfig(ctx.DefaultZone(), ctx.ZoneZkAddrs(ctx.DefaultZone())))
	defer zkzone.Close()
	zk := New(zkzone)
	id := "1"
	assert.Equal(t, "/_kateway/ids/local/1", zk.mypath(id))

	data := []byte("foo, bar")
	err := zk.Register(id, data)
	assert.Equal(t, nil, err)
	defer zk.Deregister(id, data)

	ok, err := zk.Registered(id)
	assert.Equal(t, true, ok)
	assert.Equal(t, nil, err)
}
示例#7
0
func (this *Controller) Run(args []string) (exitCode int) {
	var zone string
	cmdFlags := flag.NewFlagSet("controller", flag.ContinueOnError)
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&this.cluster, "c", "", "")
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if this.cluster == "" {
		this.Ui.Error("-c required")
		return 2
	}

	this.admin = getConnectedAdmin(zone)
	defer this.admin.Disconnect()

	this.Ui.Info(fmt.Sprintf("leader: %s", this.admin.ControllerLeader(this.cluster)))
	history, err := this.admin.ControllerHistory(this.cluster)
	must(err)
	this.Ui.Output("history:")
	for _, hostPort := range history {
		this.Ui.Output(hostPort)
	}

	return
}
示例#8
0
func TestCreateOrUpdateWebhook(t *testing.T) {
	zkzone := NewZkZone(DefaultConfig(ctx.DefaultZone(), ctx.ZoneZkAddrs(ctx.DefaultZone())))
	defer zkzone.Close()

	o := zkzone.NewOrchestrator()
	var hook WebhookMeta
	hook.Cluster = "me"
	hook.Endpoints = []string{"http://localhost"}
	err := o.CreateOrUpdateWebhook("topic_webhook", hook)
	assert.Equal(t, nil, err)

	err = o.CreateOrUpdateWebhook("topic_webhook", hook)
	assert.Equal(t, nil, err)

	h, err := o.WebhookInfo("topic_webhook")
	assert.Equal(t, nil, err)
	assert.Equal(t, "me", h.Cluster)
	assert.Equal(t, 1, len(h.Endpoints))
}
示例#9
0
文件: jmx.go 项目: funkygao/gafka
func (this *Jmx) Run(args []string) (exitCode int) {
	cmdFlags := flag.NewFlagSet("jmx", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&this.zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&this.cluster, "c", "", "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	return
}
示例#10
0
文件: node.go 项目: funkygao/gafka
func (this *Node) Run(args []string) (exitCode int) {
	var (
		zone    string
		cluster string
		add     string
		drop    string
	)
	cmdFlags := flag.NewFlagSet("node", flag.ContinueOnError)
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&cluster, "c", "", "")
	cmdFlags.StringVar(&add, "add", "", "")
	cmdFlags.StringVar(&drop, "drop", "", "")
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if cluster == "" {
		this.Ui.Error("-c required")
		return 2
	}

	this.admin = getConnectedAdmin(zone)
	defer this.admin.Disconnect()

	switch {
	case add != "":
		host, port, err := net.SplitHostPort(add)
		must(err)
		node := fmt.Sprintf("%s_%s", host, port)
		must(this.admin.AddNode(cluster, node))

	case drop != "":
		host, port, err := net.SplitHostPort(drop)
		must(err)
		node := fmt.Sprintf("%s_%s", host, port)
		must(this.admin.DropNode(cluster, node))

	default:
		instances, err := this.admin.Instances(cluster)
		must(err)
		for _, instance := range instances {
			this.Ui.Output(instance)

			// TODO display each instance info
		}
	}

	return
}
示例#11
0
文件: cluster.go 项目: funkygao/gafka
func (this *Cluster) Run(args []string) (exitCode int) {
	var (
		zone string
		add  string
		drop string
	)
	cmdFlags := flag.NewFlagSet("cluster", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&zone, "z", ctx.DefaultZone(), "")
	cmdFlags.StringVar(&add, "add", "", "")
	cmdFlags.StringVar(&drop, "drop", "", "")

	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	this.admin = getConnectedAdmin(zone)
	defer this.admin.Disconnect()

	switch {
	case add != "":
		must(this.admin.AddCluster(add))
		this.Ui.Info(fmt.Sprintf("%s added", add))

	case drop != "":
		must(this.admin.DropCluster(drop))
		this.Ui.Info(fmt.Sprintf("%s dropped", drop))

	default:
		clusters, err := this.admin.Clusters()
		must(err)
		for _, c := range clusters {
			this.Ui.Output(c)

			// TODO get cluster config
		}
	}

	return
}
示例#12
0
文件: haproxy.go 项目: funkygao/gafka
func (this *Haproxy) Run(args []string) (exitCode int) {
	var topMode bool
	cmdFlags := flag.NewFlagSet("haproxy", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&this.zone, "z", ctx.DefaultZone(), "")
	cmdFlags.BoolVar(&topMode, "top", true, "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	zone := ctx.Zone(this.zone)
	if topMode {
		header, _ := this.getStats(zone.HaProxyStatsUri[0])
		t := top.New(header, "%8s %4s %15s %15s %8s %6s %8s %10s %8s %8s %5s %7s %9s %6s")
		go func() {
			for {
				rows := make([]string, 0)
				for _, uri := range zone.HaProxyStatsUri {
					_, r := this.getStats(uri)
					rows = append(rows, r...)
				}
				t.Refresh(rows)

				time.Sleep(time.Second * 5)
			}
		}()
		if err := t.Start(); err != nil {
			panic(err)
		}
	} else {
		for _, uri := range zone.HaProxyStatsUri {
			this.fetchStats(uri)
		}
	}

	return
}