當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.DialHost方法代碼示例

本文整理匯總了Golang中github.com/flynn/flynn/pkg/cluster.Client.DialHost方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.DialHost方法的具體用法?Golang Client.DialHost怎麽用?Golang Client.DialHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/flynn/flynn/pkg/cluster.Client的用法示例。


在下文中一共展示了Client.DialHost方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runStop

func runStop(args *docopt.Args, client *cluster.Client) error {
	success := true
	clients := make(map[string]cluster.Host)
	for _, id := range args.All["ID"].([]string) {
		hostID, jobID, err := cluster.ParseJobID(id)
		if err != nil {
			fmt.Printf("could not parse %s: %s", id, err)
			success = false
			continue
		}
		hostClient, ok := clients[hostID]
		if !ok {
			var err error
			hostClient, err = client.DialHost(hostID)
			if err != nil {
				fmt.Printf("could not connect to host %s: %s\n", hostID, err)
				success = false
				continue
			}
			clients[hostID] = hostClient
		}
		if err := hostClient.StopJob(jobID); err != nil {
			fmt.Printf("could not stop job %s: %s\n", jobID, err)
			success = false
			continue
		}
		fmt.Println(jobID, "stopped")
	}
	if !success {
		return errors.New("could not stop all jobs")
	}
	return nil
}
開發者ID:josephwinston,項目名稱:flynn,代碼行數:33,代碼來源:stop.go

示例2: jobList

func jobList(client *cluster.Client, all bool) (sortJobs, error) {
	hosts, err := client.ListHosts()
	if err != nil {
		return nil, fmt.Errorf("could not list hosts: %s", err)
	}

	var jobs []host.ActiveJob
	for id := range hosts {
		h, err := client.DialHost(id)
		if err != nil {
			return nil, fmt.Errorf("could not dial host %s: %s", id, err)
		}
		hostJobs, err := h.ListJobs()
		if err != nil {
			return nil, fmt.Errorf("could not get jobs for host %s: %s", id, err)
		}
		for _, job := range hostJobs {
			jobs = append(jobs, job)
		}
	}

	sorted := make(sortJobs, 0, len(jobs))
	for _, job := range jobs {
		if !all && job.Status != host.StatusStarting && job.Status != host.StatusRunning {
			continue
		}
		sorted = append(sorted, job)
	}
	sort.Sort(sort.Reverse(sorted))
	return sorted, nil
}
開發者ID:ericcapricorn,項目名稱:flynn,代碼行數:31,代碼來源:ps.go

示例3: runInspect

func runInspect(args *docopt.Args, client *cluster.Client) error {
	hostID, jobID, err := cluster.ParseJobID(args.String["ID"])
	if err != nil {
		return err
	}
	hostClient, err := client.DialHost(hostID)
	if err != nil {
		return fmt.Errorf("could not connect to host %s: %s", hostID, err)
	}
	job, err := hostClient.GetJob(jobID)
	if err != nil {
		return fmt.Errorf("no such job")
	}

	printJobDesc(job, os.Stdout, !args.Bool["--omit-env"])
	return nil
}
開發者ID:josephwinston,項目名稱:flynn,代碼行數:17,代碼來源:inspect.go

示例4: getLog

func getLog(hostID, jobID string, client *cluster.Client, follow bool, stdout, stderr io.Writer) error {
	hostClient, err := client.DialHost(hostID)
	if err != nil {
		return fmt.Errorf("could not connect to host %s: %s", hostID, err)
	}
	defer hostClient.Close()
	attachReq := &host.AttachReq{
		JobID: jobID,
		Flags: host.AttachFlagStdout | host.AttachFlagStderr | host.AttachFlagLogs,
	}
	if follow {
		attachReq.Flags |= host.AttachFlagStream
	}
	attachClient, err := hostClient.Attach(attachReq, false)
	if err != nil {
		if err == cluster.ErrWouldWait {
			return errors.New("no such job")
		}
		return err
	}
	defer attachClient.Close()
	attachClient.Receive(stdout, stderr)
	return nil
}
開發者ID:ericcapricorn,項目名稱:flynn,代碼行數:24,代碼來源:log.go


注:本文中的github.com/flynn/flynn/pkg/cluster.Client.DialHost方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。