本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.NewClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClient函數的具體用法?Golang NewClient怎麽用?Golang NewClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
grohl.AddContext("app", "controller-scheduler")
grohl.Log(grohl.Data{"at": "start"})
cc, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Fatal(err)
}
cl, err := cluster.NewClient()
if err != nil {
log.Fatal(err)
}
c := newContext(cc, cl)
grohl.Log(grohl.Data{"at": "leaderwait"})
leaderWait, err := discoverd.RegisterAndStandby("flynn-controller-scheduler", ":"+os.Getenv("PORT"), nil)
if err != nil {
log.Fatal(err)
}
<-leaderWait
grohl.Log(grohl.Data{"at": "leader"})
// TODO: periodic full cluster sync for anti-entropy
c.watchFormations(nil, nil)
}
示例2: main
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
db, err := postgres.Open("", "")
if err != nil {
log.Fatal(err)
}
if err := migrateDB(db.DB); err != nil {
log.Fatal(err)
}
cc, err := cluster.NewClient()
if err != nil {
log.Fatal(err)
}
sc, err := strowgerc.New()
if err != nil {
log.Fatal(err)
}
if err := discoverd.Register("flynn-controller", addr); err != nil {
log.Fatal(err)
}
handler, _ := appHandler(handlerConfig{db: db, cc: cc, sc: sc, dc: discoverd.DefaultClient, key: os.Getenv("AUTH_KEY")})
log.Fatal(http.ListenAndServe(addr, handler))
}
示例3: Run
func Run(name string, args []string) error {
argv := make([]string, 1, 1+len(args))
argv[0] = name
argv = append(argv, args...)
cmd, ok := commands[name]
if !ok {
return ErrInvalidCommand
}
parsedArgs, err := docopt.Parse(cmd.usage, argv, true, "", strings.Contains(cmd.usage, "[--]"))
if err != nil {
return err
}
switch f := cmd.f.(type) {
case func(*docopt.Args, *cluster.Client) error:
return f(parsedArgs, cluster.NewClient())
case func(*docopt.Args):
f(parsedArgs)
return nil
case func(*docopt.Args) error:
return f(parsedArgs)
case func() error:
return f()
case func():
f()
return nil
}
return fmt.Errorf("unexpected command type %T", cmd.f)
}
示例4: main
func main() {
grohl.AddContext("app", "controller-scheduler")
grohl.Log(grohl.Data{"at": "start"})
if period := os.Getenv("BACKOFF_PERIOD"); period != "" {
var err error
backoffPeriod, err = time.ParseDuration(period)
if err != nil {
log.Fatal(err)
}
grohl.Log(grohl.Data{"at": "backoff_period", "period": backoffPeriod.String()})
}
cc, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
log.Fatal(err)
}
cl, err := cluster.NewClient()
if err != nil {
log.Fatal(err)
}
c := newContext(cc, cl)
grohl.Log(grohl.Data{"at": "leaderwait"})
leaderWait, err := discoverd.RegisterAndStandby("flynn-controller-scheduler", ":"+os.Getenv("PORT"), nil)
if err != nil {
log.Fatal(err)
}
<-leaderWait
grohl.Log(grohl.Data{"at": "leader"})
// TODO: periodic full cluster sync for anti-entropy
c.watchFormations()
}
示例5: runListHosts
func runListHosts(args *docopt.Args) error {
clusterClient := cluster.NewClient()
hosts, err := clusterClient.Hosts()
if err != nil {
return err
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
peers, _ := discoverd.DefaultClient.RaftPeers()
leader, _ := discoverd.DefaultClient.RaftLeader()
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
listRec(w, "ID", "ADDR", "RAFT STATUS")
for _, h := range hosts {
// If we have the list of raft peers augument the output
// with each hosts raft proxy/peer status.
raftStatus := ""
if len(peers) > 0 {
raftStatus = hostRaftStatus(h, peers, leader.Host)
}
listRec(w, h.ID(), h.Addr(), raftStatus)
}
return nil
}
示例6: captureJobs
func captureJobs(gist *Gist, env bool) error {
client := cluster.NewClient()
jobs, err := jobList(client, true)
if err != nil {
return err
}
var buf bytes.Buffer
printJobs(jobs, &buf)
gist.AddFile("1-jobs.log", buf.String())
for _, job := range jobs {
var name string
if app, ok := job.Job.Metadata["flynn-controller.app_name"]; ok {
name += app + "-"
}
if typ, ok := job.Job.Metadata["flynn-controller.type"]; ok {
name += typ + "-"
}
name += job.Job.ID + ".log"
var content bytes.Buffer
printJobDesc(&job, &content, env)
fmt.Fprint(&content, "\n\n***** ***** ***** ***** ***** ***** ***** ***** ***** *****\n\n")
getLog(job.HostID, job.Job.ID, client, false, true, &content, &content)
gist.AddFile(name, content.String())
}
return nil
}
示例7: init
func init() {
log.SetFlags(0)
var err error
clusterc, err = cluster.NewClient()
if err != nil {
log.Fatalln("Error connecting to cluster leader:", err)
}
}
示例8: ClusterClient
func (s *State) ClusterClient() (*cluster.Client, error) {
if s.clusterc == nil {
cc, err := cluster.NewClient()
if err != nil {
return nil, err
}
s.clusterc = cc
}
return s.clusterc, nil
}
示例9: main
func main() {
defer shutdown.Exit()
grohl.AddContext("app", "controller-scheduler")
grohl.Log(grohl.Data{"at": "start"})
go startHTTPServer()
if period := os.Getenv("BACKOFF_PERIOD"); period != "" {
var err error
backoffPeriod, err = time.ParseDuration(period)
if err != nil {
shutdown.Fatal(err)
}
grohl.Log(grohl.Data{"at": "backoff_period", "period": backoffPeriod.String()})
}
cc, err := controller.NewClient("", os.Getenv("AUTH_KEY"))
if err != nil {
shutdown.Fatal(err)
}
c := newContext(cc, cluster.NewClient())
c.watchHosts()
grohl.Log(grohl.Data{"at": "leaderwait"})
hb, err := discoverd.AddServiceAndRegister("controller-scheduler", ":"+os.Getenv("PORT"))
if err != nil {
shutdown.Fatal(err)
}
shutdown.BeforeExit(func() { hb.Close() })
leaders := make(chan *discoverd.Instance)
stream, err := discoverd.NewService("controller-scheduler").Leaders(leaders)
if err != nil {
shutdown.Fatal(err)
}
for leader := range leaders {
if leader.Addr == hb.Addr() {
break
}
}
if err := stream.Err(); err != nil {
// TODO: handle discoverd errors
shutdown.Fatal(err)
}
stream.Close()
// TODO: handle demotion
grohl.Log(grohl.Data{"at": "leader"})
// TODO: periodic full cluster sync for anti-entropy
c.watchFormations()
}
示例10: ServeHTTP
func (h *Host) ServeHTTP() {
r := httprouter.New()
r.POST("/attach", (&attachHandler{state: h.state, backend: h.backend}).ServeHTTP)
jobAPI := &jobAPI{host: h}
jobAPI.RegisterRoutes(r)
volAPI := volumeapi.NewHTTPAPI(cluster.NewClient(), h.vman)
volAPI.RegisterRoutes(r)
go http.Serve(h.listener, httphelper.ContextInjector("host", httphelper.NewRequestLogger(r)))
}
示例11: ServeHTTP
func (h *Host) ServeHTTP() {
r := httprouter.New()
r.POST("/attach", newAttachHandler(h.state, h.backend, h.log).ServeHTTP)
jobAPI := &jobAPI{
host: h,
addJobRateLimitBucket: NewRateLimitBucket(h.maxJobConcurrency),
}
jobAPI.RegisterRoutes(r)
volAPI := volumeapi.NewHTTPAPI(cluster.NewClient(), h.vman)
volAPI.RegisterRoutes(r)
go http.Serve(h.listener, httphelper.ContextInjector("host", httphelper.NewRequestLogger(r)))
}
示例12: main
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
addr := ":" + port
if seed := os.Getenv("NAME_SEED"); seed != "" {
s, err := hex.DecodeString(seed)
if err != nil {
log.Fatalln("error decoding NAME_SEED:", err)
}
name.SetSeed(s)
}
db, err := postgres.Open("", "")
if err != nil {
log.Fatal(err)
}
if err := migrateDB(db.DB); err != nil {
log.Fatal(err)
}
cc, err := cluster.NewClient()
if err != nil {
log.Fatal(err)
}
sc, err := routerc.New()
if err != nil {
log.Fatal(err)
}
if err := discoverd.Register("flynn-controller", addr); err != nil {
log.Fatal(err)
}
shutdown.BeforeExit(func() {
discoverd.Unregister("flynn-controller", addr)
})
handler, _ := appHandler(handlerConfig{db: db, cc: cc, sc: sc, dc: discoverd.DefaultClient, key: os.Getenv("AUTH_KEY")})
log.Fatal(http.ListenAndServe(addr, handler))
}
示例13: Run
func (m *Monitor) Run() {
log := monitorLogger.New("fn", "Run")
log.Info("waiting for discoverd")
m.waitDiscoverd()
log.Info("waiting for raft leader")
m.waitRaftLeader()
// we can connect the leader election wrapper now
m.discoverd = newDiscoverdWrapper(m.addr+":1113", m.logger)
// connect cluster client now that discoverd is up.
m.c = cluster.NewClient()
m.monitorSvc = discoverd.NewService("cluster-monitor")
log.Info("waiting for monitor service to be enabled for this cluster")
m.waitEnabled()
log.Info("registering cluster-monitor")
m.waitRegister()
leaderCh := m.discoverd.LeaderCh()
ticker := time.NewTicker(checkInterval)
log.Info("starting monitor loop")
for {
var isLeader bool
select {
case <-m.shutdownCh:
log.Info("shutting down monitor")
return
case isLeader = <-leaderCh:
m.isLeader = isLeader
continue
default:
}
select {
case <-ticker.C:
if m.isLeader {
m.checkCluster()
}
}
}
}
示例14: runListHosts
func runListHosts(args *docopt.Args) error {
clusterClient := cluster.NewClient()
hosts, err := clusterClient.Hosts()
if err != nil {
return err
}
if len(hosts) == 0 {
return errors.New("no hosts found")
}
w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
defer w.Flush()
listRec(w, "ID", "ADDR")
for _, h := range hosts {
listRec(w, h.ID(), h.Addr())
}
return nil
}
示例15: Run
func Run(name string, args []string) error {
argv := make([]string, 1, 1+len(args))
argv[0] = name
argv = append(argv, args...)
cmd, ok := commands[name]
if !ok {
return fmt.Errorf("%s is not a valid command", name)
}
parsedArgs, err := docopt.Parse(cmd.usage, argv, true, "", false)
if err != nil {
return err
}
switch f := cmd.f.(type) {
case func(*docopt.Args, *cluster.Client) error:
client, err := cluster.NewClient()
if err != nil {
return err
}
defer client.Close()
return f(parsedArgs, client)
case func(*docopt.Args):
f(parsedArgs)
return nil
case func(*docopt.Args) error:
return f(parsedArgs)
case func() error:
return f()
case func():
f()
return nil
}
return fmt.Errorf("unexpected command type %T", cmd.f)
}