func main() { n := flag.String("name", os.Getenv("NAME"), "zoidberg name") h := flag.String("host", os.Getenv("HOST"), "host") p := flag.String("port", os.Getenv("PORT"), "port") bff := flag.String("balancer-finder", os.Getenv("BALANCER_FINDER"), "balancer finder") aff := flag.String("application-finder", os.Getenv("APPLICATION_FINDER"), "application finder") z := flag.String("zk", os.Getenv("ZK"), "zk connection in host:port,host:port/path format") flag.Parse() if *bff == "" || *aff == "" || *h == "" || *p == "" || *z == "" { flag.PrintDefaults() os.Exit(1) } bf, err := balancer.FinderByName(*bff) if err != nil { log.Fatal(err) } af, err := application.FinderByName(*aff) if err != nil { log.Fatal(err) } zc, zp, err := initZK(*z) if err != nil { log.Fatal(err) } e, err := zoidberg.NewExplorer(*n, af, bf, zc, zp) if err != nil { log.Fatal(err) } go func() { addr := fmt.Sprintf("%s:%s", *h, *p) log.Fatal(http.ListenAndServe(addr, e.ServeMux())) }() err = e.Run() if err != nil { log.Fatal(err) } }
func main() { n := flag.String("name", "", "zoidberg name") m := flag.String("master", "", "mesos master url") b := flag.String("balancer", "", "balancer to provide") z := flag.String("zk", "", "zk connection in host:port,host:port/path format") flag.Parse() if *n == "" || *m == "" || *b == "" || *z == "" { flag.PrintDefaults() os.Exit(1) } if os.Getenv("HOST") == "" || os.Getenv("PORT") == "" { log.Println("HOST and PORT environment variables should be set") os.Exit(1) } host := os.Getenv("HOST") port, err := strconv.Atoi(os.Getenv("PORT")) if err != nil { log.Fatal("error parsing port from environment:", err) } if !strings.Contains(*z, "/") { log.Fatal("zk connection string is invalid") } zz := strings.SplitN(*z, "/", 2) zh, zp := zz[0], "/"+zz[1] zp = path.Clean(zp) zc, zch, err := zk.Connect(strings.Split(zh, ","), time.Minute) if err != nil { log.Fatal("error connecting to zookeeper:", err) } go func() { for e := range zch { log.Println("received zk event:", e) } }() d := zoidberg.NewMesosDiscoverer([]string{*m}, *b) e, err := zoidberg.NewExplorer(*n, d, zc, zp) if err != nil { log.Fatal(err) } go func() { addr := fmt.Sprintf("%s:%d", host, port) err := http.ListenAndServe(addr, e.ServeMux()) if err != nil { log.Fatal(err) } }() err = e.Run() if err != nil { log.Fatal(err) } }
func main() { m := flag.String("marathon", "", "marathon url") b := flag.String("balancer", "", "balancer name") z := flag.String("zk", "", "zk connection in host:port,host:port/path format") flag.Parse() if *m == "" || *b == "" || *z == "" { flag.PrintDefaults() os.Exit(1) } if os.Getenv("HOST") == "" || os.Getenv("PORT") == "" { log.Println("HOST and PORT environment variables should be set") os.Exit(1) } host := os.Getenv("HOST") port, err := strconv.Atoi(os.Getenv("PORT")) if err != nil { log.Fatal("error parsing port from environment:", err) } if !strings.Contains(*z, "/") { log.Fatal("zk connection string is invalid") } zz := strings.SplitN(*z, "/", 2) zh, zp := zz[0], "/"+zz[1] log.Println(zh, zp) zc, zch, err := zk.Connect(strings.Split(zh, ","), time.Minute) if err != nil { log.Fatal("error connecting to zookeeper:", err) } go func() { for e := range zch { log.Println("received zk event:", e) } }() mc, err := marathon.NewClient(marathon.Config{ URL: *m, RequestTimeout: 5, }) if err != nil { log.Fatal(err) } l := zoidberg.ExplorerLocation{ Host: host, Port: port, } d := zoidberg.NewMarathonDiscoverer(mc, *b) e, err := zoidberg.NewExplorer(d, zc, zp, l) if err != nil { log.Fatal(err) } go func() { addr := fmt.Sprintf("%s:%d", host, port) err := http.ListenAndServe(addr, e.ServeMux()) if err != nil { log.Fatal(err) } }() err = e.Run() if err != nil { log.Fatal(err) } }