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) } }
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) }
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 }
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 }
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 }
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) }
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 }
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)) }
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 }
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 }
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 }
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 }