本文整理匯總了Golang中github.com/funkygao/gafka/ctx.ZoneZkAddrs函數的典型用法代碼示例。如果您正苦於以下問題:Golang ZoneZkAddrs函數的具體用法?Golang ZoneZkAddrs怎麽用?Golang ZoneZkAddrs使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ZoneZkAddrs函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (this *Zones) Run(args []string) (exitCode int) {
// header
this.Ui.Output(fmt.Sprintf("%10s %-70s", "zone", "zookeeper ensemble"))
this.Ui.Output(fmt.Sprintf("%s %s",
strings.Repeat("-", 10),
strings.Repeat("-", 70)))
if len(args) > 0 {
// user specified the zones to print
for _, zone := range args {
if zk, present := ctx.Zones()[zone]; present {
this.Ui.Output(fmt.Sprintf("%10s %s", zone, zk))
} else {
this.Ui.Output(fmt.Sprintf("%10s not defined", zone))
}
}
return
}
// print all by default
defaultZone := ctx.ZkDefaultZone()
for _, zone := range ctx.SortedZones() {
if defaultZone == zone {
this.Ui.Output(fmt.Sprintf("%10s %s", zone+"*", ctx.ZoneZkAddrs(zone)))
continue
}
this.Ui.Output(fmt.Sprintf("%10s %s", zone, ctx.ZoneZkAddrs(zone)))
}
return
}
示例2: Main
func (this *Mirror) Main() (exitCode int) {
this.quit = make(chan struct{})
signal.RegisterHandler(func(sig os.Signal) {
log.Info("received signal: %s", strings.ToUpper(sig.String()))
log.Info("quiting...")
this.once.Do(func() {
close(this.quit)
})
}, syscall.SIGINT, syscall.SIGTERM)
limit := (1 << 20) * this.BandwidthLimit / 8
if this.BandwidthLimit > 0 {
this.bandwidthRateLimiter = ratelimiter.NewLeakyBucket(limit*10, time.Second*10)
}
log.Info("starting [email protected]%s", gafka.BuildId)
// pprof
debugAddr := ":10009"
go http.ListenAndServe(debugAddr, nil)
log.Info("pprof ready on %s", debugAddr)
z1 := zk.NewZkZone(zk.DefaultConfig(this.Z1, ctx.ZoneZkAddrs(this.Z1)))
z2 := zk.NewZkZone(zk.DefaultConfig(this.Z2, ctx.ZoneZkAddrs(this.Z2)))
c1 := z1.NewCluster(this.C1)
c2 := z2.NewCluster(this.C2)
this.runMirror(c1, c2, limit)
log.Info("bye [email protected]%s, %s", gafka.BuildId, time.Since(this.startedAt))
log.Close()
return
}
示例3: Run
func (this *Mirror) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("mirror", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone1, "z1", "", "")
cmdFlags.StringVar(&this.zone2, "z2", "", "")
cmdFlags.StringVar(&this.cluster1, "c1", "", "")
cmdFlags.StringVar(&this.cluster2, "c2", "", "")
cmdFlags.StringVar(&this.excludes, "excluded", "", "")
cmdFlags.BoolVar(&this.debug, "debug", false, "")
cmdFlags.StringVar(&this.compress, "compress", "", "")
cmdFlags.Int64Var(&this.bandwidthLimit, "net", 100, "")
cmdFlags.BoolVar(&this.autoCommit, "commit", true, "")
cmdFlags.Int64Var(&this.progressStep, "step", 5000, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
require("-z1", "-z2", "-c1", "-c2").
invalid(args) {
return 2
}
this.topicsExcluded = make(map[string]struct{})
for _, e := range strings.Split(this.excludes, ",") {
this.topicsExcluded[e] = struct{}{}
}
log.SetOutput(os.Stdout)
this.quit = make(chan struct{})
limit := (1 << 20) * this.bandwidthLimit / 8
this.bandwidthRateLimiter = ratelimiter.NewLeakyBucket(limit, time.Second)
log.Printf("[%s]%s -> [%s]%s with bandwidth %sbps",
this.zone1, this.cluster1,
this.zone2, this.cluster2,
gofmt.Comma(int64(limit*8)))
signal.RegisterSignalsHandler(func(sig os.Signal) {
log.Printf("received signal: %s", strings.ToUpper(sig.String()))
log.Println("quiting...")
this.once.Do(func() {
close(this.quit)
})
}, syscall.SIGINT, syscall.SIGTERM)
z1 := zk.NewZkZone(zk.DefaultConfig(this.zone1, ctx.ZoneZkAddrs(this.zone1)))
z2 := zk.NewZkZone(zk.DefaultConfig(this.zone2, ctx.ZoneZkAddrs(this.zone2)))
c1 := z1.NewCluster(this.cluster1)
c2 := z2.NewCluster(this.cluster2)
this.makeMirror(c1, c2)
return
}
示例4: Run
func (this *Zones) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("zones", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.BoolVar(&this.ipInNumber, "n", false, "")
cmdFlags.BoolVar(&this.plain, "plain", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 2
}
// print all by default
zones := make([][]string, 0)
defaultZone := ctx.ZkDefaultZone()
for _, zone := range ctx.SortedZones() {
if defaultZone == zone {
if this.ipInNumber {
zones = append(zones, []string{zone + "*", ctx.ZoneZkAddrs(zone)})
} else {
zones = append(zones, []string{zone + "*", ctx.NamedZoneZkAddrs(zone)})
}
continue
}
if this.ipInNumber {
zones = append(zones, []string{zone, ctx.ZoneZkAddrs(zone)})
} else {
zones = append(zones, []string{zone, ctx.NamedZoneZkAddrs(zone)})
}
}
if this.plain {
for _, z := range zones {
this.Ui.Output(fmt.Sprintf("%s:", z[0]))
this.Ui.Output(fmt.Sprintf("%s\n", z[1]))
}
return
}
table := tablewriter.NewWriter(os.Stdout)
for _, z := range zones {
table.Append(z)
}
table.SetHeader([]string{"Zone", "ZK ensemble"})
table.SetFooter([]string{"Total", fmt.Sprintf("%d", len(zones))})
table.Render() // Send output
return
}
示例5: Run
func (this *Stat) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("stat", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if this.zone == "" {
this.Ui.Error("unknown zone")
return 2
}
if len(args) == 0 {
this.Ui.Error("missing path")
return 2
}
this.path = args[len(args)-1]
zkzone := gzk.NewZkZone(gzk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
defer zkzone.Close()
conn := zkzone.Conn()
_, stat, err := conn.Get(this.path)
must(err)
this.Ui.Output(fmt.Sprintf("%# v", pretty.Formatter(*stat)))
ctime := gzk.ZkTimestamp(stat.Ctime).Time()
mtime := gzk.ZkTimestamp(stat.Mtime).Time()
this.Ui.Output(fmt.Sprintf("ctime: %s, mtime: %s",
gofmt.PrettySince(ctime), gofmt.PrettySince(mtime)))
return
}
示例6: Run
func (this *Partition) Run(args []string) (exitCode int) {
var (
zone string
topic string
cluster string
partitions int
)
cmdFlags := flag.NewFlagSet("partition", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&zone, "z", "", "")
cmdFlags.StringVar(&cluster, "c", "", "")
cmdFlags.StringVar(&topic, "t", "", "")
cmdFlags.IntVar(&partitions, "n", 1, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
require("-z", "-c", "-t", "-n").
requireAdminRights("-z").
invalid(args) {
return 2
}
zkzone := zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZoneZkAddrs(zone)))
zkcluster := zkzone.NewCluster(cluster)
this.addPartition(zkcluster.ZkConnectAddr(), topic, partitions)
return
}
示例7: Run
func (this *Topology) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("topology", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.StringVar(&this.cluster, "c", "", "")
cmdFlags.StringVar(&this.hostPattern, "host", "", "")
cmdFlags.BoolVar(&this.verbose, "l", false, "")
cmdFlags.BoolVar(&this.watchMode, "w", false, "")
cmdFlags.BoolVar(&this.maxPort, "maxport", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
// a single zone
ensureZoneValid(this.zone)
zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
for {
if this.maxPort {
this.displayZoneMaxPort(zkzone)
} else {
this.displayZoneTopology(zkzone)
}
if !this.watchMode {
return
}
time.Sleep(time.Second * 5)
refreshScreen()
}
return
}
示例8: TestOrchestatorAll
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)
}
}
示例9: Run
func (this *Kguard) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("kguard", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.BoolVar(&this.longFmt, "l", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 2
}
zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
kguards, err := zkzone.KguardInfos()
if err != nil {
this.Ui.Error(fmt.Sprintf("%s %v", zk.KguardLeaderPath, err.Error()))
return
}
leader := kguards[0]
this.Ui.Output(fmt.Sprintf("%s(out of %d candidates) up: %s",
color.Green(leader.Host), leader.Candidates,
gofmt.PrettySince(leader.Ctime)))
if this.longFmt {
this.showKguardVersion(leader.Host)
this.showStats(leader.Host)
}
return
}
示例10: Run
func (this *Create) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("create", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.StringVar(&this.path, "p", "", "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
require("-p").
requireAdminRights("-p").
invalid(args) {
return 2
}
if this.zone == "" {
this.Ui.Error("unknown zone")
return 2
}
zkzone := gzk.NewZkZone(gzk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
defer zkzone.Close()
conn := zkzone.Conn()
data := inData()
flags := int32(0)
acl := zk.WorldACL(zk.PermAll)
_, err := conn.Create(this.path, data, flags, acl)
must(err)
return
}
示例11: Run
func (this *Rebalance) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("rebalance", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", "", "")
cmdFlags.StringVar(&this.cluster, "c", "", "")
cmdFlags.StringVar(&this.topic, "t", "", "")
cmdFlags.StringVar(&this.partition, "p", "", "comma seperated ids")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
require("-z", "-c", "-t", "-p").
requireAdminRights("-t").
invalid(args) {
return 2
}
zkzone := zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
this.zkcluster = zkzone.NewCluster(this.cluster)
data := this.generateReassignFile()
this.Ui.Output(data)
yes, _ := this.Ui.Ask("Are you sure to execute? [Y/N]")
if yes == "Y" {
this.executeReassignment()
} else {
this.Ui.Output("bye")
}
return
}
示例12: Run
// TODO run 3 nodes in a zone to monitor as daemon
// register the 3 nodes as host service tag.
func (this *Ping) Run(args []string) (exitCode int) {
cmdFlags := flag.NewFlagSet("ping", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&this.zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.DurationVar(&this.interval, "interval", time.Minute*5, "")
cmdFlags.StringVar(&this.logfile, "logfile", "stdout", "")
cmdFlags.BoolVar(&this.problematicMode, "p", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
this.setupLog()
this.zkzone = zk.NewZkZone(zk.DefaultConfig(this.zone, ctx.ZoneZkAddrs(this.zone)))
for {
this.diagnose()
if this.logfile == "stdout" {
break
}
time.Sleep(this.interval)
}
return
}
示例13: Run
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
}
示例14: Run
func (this *Controllers) Run(args []string) (exitCode int) {
var (
zone string
)
cmdFlags := flag.NewFlagSet("controllers", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&zone, "z", "", "")
cmdFlags.StringVar(&this.cluster, "c", "", "") // TODO not used
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if zone == "" {
forSortedZones(func(zkzone *zk.ZkZone) {
this.printControllers(zkzone)
printSwallowedErrors(this.Ui, zkzone)
})
return
}
zkzone := zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZoneZkAddrs(zone)))
this.printControllers(zkzone)
printSwallowedErrors(this.Ui, zkzone)
return
}
示例15: Run
func (this *Consumers) Run(args []string) (exitCode int) {
var (
cluster string
zone string
)
cmdFlags := flag.NewFlagSet("consumers", flag.ContinueOnError)
cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
cmdFlags.StringVar(&zone, "z", ctx.ZkDefaultZone(), "")
cmdFlags.StringVar(&cluster, "c", "", "")
cmdFlags.StringVar(&this.groupPattern, "g", "", "")
cmdFlags.BoolVar(&this.onlineOnly, "online", false, "")
cmdFlags.BoolVar(&this.byHost, "byhost", false, "")
cmdFlags.StringVar(&this.topicPattern, "t", "", "")
cmdFlags.BoolVar(&this.warnOnly, "warn", false, "")
cmdFlags.BoolVar(&this.ownerOnly, "own", false, "")
cmdFlags.BoolVar(&this.cleanup, "cleanup", false, "")
cmdFlags.BoolVar(&this.confirmYes, "yes", false, "")
if err := cmdFlags.Parse(args); err != nil {
return 1
}
if validateArgs(this, this.Ui).
requireAdminRights("-cleanup").
invalid(args) {
return 2
}
if this.ownerOnly {
this.onlineOnly = true
}
if zone == "" {
forSortedZones(func(zkzone *zk.ZkZone) {
switch {
case this.cleanup:
this.cleanupStaleConsumerGroups(zkzone, cluster)
case this.byHost:
this.printConsumersByHost(zkzone, cluster)
default:
this.printConsumersByGroupTable(zkzone, cluster)
}
})
return
}
zkzone := zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZoneZkAddrs(zone)))
switch {
case this.cleanup:
this.cleanupStaleConsumerGroups(zkzone, cluster)
case this.byHost:
this.printConsumersByHost(zkzone, cluster)
default:
this.printConsumersByGroupTable(zkzone, cluster)
}
return
}