Пример #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
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
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
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
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
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
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
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
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
}