本文整理匯總了Golang中confab.Controller類的典型用法代碼示例。如果您正苦於以下問題:Golang Controller類的具體用法?Golang Controller怎麽用?Golang Controller使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Controller類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: start
func start(flagSet *flag.FlagSet, path string, controller confab.Controller, agentClient *confab.AgentClient) {
timeout := confab.NewTimeout(time.After(time.Duration(controller.Config.Confab.TimeoutInSeconds) * time.Second))
_, err := os.Stat(controller.Config.Path.ConsulConfigDir)
if err != nil {
printUsageAndExit(fmt.Sprintf("\"consul_config_dir\" %q could not be found",
controller.Config.Path.ConsulConfigDir), flagSet)
}
if len(agentClient.ExpectedMembers) == 0 {
printUsageAndExit("at least one \"expected-member\" must be provided", flagSet)
}
err = controller.WriteServiceDefinitions()
if err != nil {
stderr.Printf("error writing service definitions: %s", err)
os.Exit(1)
}
err = controller.BootAgent(timeout)
if err != nil {
stderr.Printf("error booting consul agent: %s", err)
// DO NOT call StopAgent:
// - the agent may aleady be running
// - the pidfile may contain the PID of another running process
os.Exit(1)
}
if controller.Config.Consul.Agent.Server {
configureServer(controller, agentClient, timeout)
} else {
configureClient(controller)
}
}
示例2: stop
func stop(path string, controller confab.Controller, agentClient *agent.Client) {
rpcClient, err := consulagent.NewRPCClient("localhost:8400")
if err != nil {
stderr.Printf("error connecting to RPC server: %s", err)
exit(controller, 1)
}
agentClient.ConsulRPCClient = &agent.RPCClient{*rpcClient}
stderr.Printf("stopping agent")
controller.StopAgent()
stderr.Printf("stopped agent")
}
示例3: configureServer
func configureServer(controller confab.Controller, agentClient *agent.Client, timeout confab.Timeout) {
rpcClient, err := consulagent.NewRPCClient("localhost:8400")
if err != nil {
stderr.Printf("error connecting to RPC server: %s", err)
exit(controller, 1)
}
agentClient.ConsulRPCClient = &agent.RPCClient{*rpcClient}
err = controller.ConfigureServer(timeout)
if err != nil {
stderr.Printf("error configuring server: %s", err)
exit(controller, 1)
}
}
示例4: start
func start(flagSet *flag.FlagSet, path string, controller confab.Controller, agentClient *agent.Client) {
timeout := confab.NewTimeout(time.After(time.Duration(controller.Config.Confab.TimeoutInSeconds) * time.Second))
_, err := os.Stat(controller.Config.Path.ConsulConfigDir)
if err != nil {
printUsageAndExit(fmt.Sprintf("\"consul_config_dir\" %q could not be found",
controller.Config.Path.ConsulConfigDir), flagSet)
}
if len(agentClient.ExpectedMembers) == 0 {
printUsageAndExit("at least one \"expected-member\" must be provided", flagSet)
}
err = controller.WriteConsulConfig()
if err != nil {
stderr.Printf("error writing consul config file: %s", err)
os.Exit(1)
}
err = controller.WriteServiceDefinitions()
if err != nil {
stderr.Printf("error writing service definitions: %s", err)
os.Exit(1)
}
err = controller.BootAgent(timeout)
if err != nil {
stderr.Printf("error booting consul agent: %s", err)
exit(controller, 1)
}
if controller.Config.Consul.Agent.Mode == "server" {
configureServer(controller, agentClient, timeout)
} else {
configureClient(controller)
}
}
示例5: main
func main() {
flagSet := flag.NewFlagSet("flags", flag.ContinueOnError)
flagSet.BoolVar(&isServer, "server", false, "whether to start the agent in server mode")
flagSet.StringVar(&agentPath, "agent-path", "", "path to the on-filesystem consul `executable`")
flagSet.StringVar(&consulConfigDir, "consul-config-dir", "", "path to consul configuration `directory`")
flagSet.StringVar(&pidFile, "pid-file", "", "path to consul PID `file`")
flagSet.Var(&expectedMembers, "expected-member", "address `list` of the expected members")
flagSet.Var(&encryptionKeys, "encryption-key", "`key` used to encrypt consul traffic")
if len(os.Args) < 2 {
printUsageAndExit("invalid number of arguments", flagSet)
}
command := os.Args[1]
if !validCommand(command) {
printUsageAndExit(fmt.Sprintf("invalid COMMAND %q", command), flagSet)
}
flagSet.Parse(os.Args[2:])
path, err := exec.LookPath(agentPath)
if err != nil {
printUsageAndExit(fmt.Sprintf("\"agent-path\" %q cannot be found", agentPath), flagSet)
}
if len(pidFile) == 0 {
printUsageAndExit("\"pid-file\" cannot be empty", flagSet)
}
if command == "start" {
_, err = os.Stat(consulConfigDir)
if err != nil {
printUsageAndExit(fmt.Sprintf("\"consul-config-dir\" %q could not be found", consulConfigDir), flagSet)
}
if len(expectedMembers) == 0 {
printUsageAndExit("at least one \"expected-member\" must be provided", flagSet)
}
agentRunner := confab.AgentRunner{
Path: path,
PIDFile: pidFile,
ConfigDir: consulConfigDir,
Stdout: os.Stdout,
Stderr: os.Stderr,
}
consulAPIClient, err := api.NewClient(api.DefaultConfig())
if err != nil {
panic(err) // not tested, NewClient never errors
}
agentClient := confab.AgentClient{
ExpectedMembers: expectedMembers,
ConsulAPIAgent: consulAPIClient.Agent(),
ConsulRPCClient: nil,
}
controller := confab.Controller{
AgentRunner: &agentRunner,
AgentClient: &agentClient,
MaxRetries: 10,
SyncRetryDelay: 1 * time.Second,
SyncRetryClock: clock.NewClock(),
EncryptKeys: encryptionKeys,
SSLDisabled: false,
Logger: stdout,
}
err = controller.BootAgent()
if err != nil {
stderr.Printf("error booting consul agent: %s", err)
os.Exit(1)
}
if !isServer {
return
}
rpcClient, err := agent.NewRPCClient("localhost:8400")
if err != nil {
stderr.Printf("error connecting to RPC server: %s", err)
os.Exit(1)
}
agentClient.ConsulRPCClient = &confab.RPCClient{
*rpcClient,
}
err = controller.ConfigureServer()
if err != nil {
stderr.Printf("error connecting to RPC server: %s", err)
os.Exit(1) // not tested; it is challenging with the current fake agent.
}
}
if command == "stop" {
agentRunner := confab.AgentRunner{
Path: path,
PIDFile: pidFile,
ConfigDir: "",
Stdout: os.Stdout,
Stderr: os.Stderr,
//.........這裏部分代碼省略.........
示例6:
"bytes"
"confab"
"confab/fakes"
"errors"
"log"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("controller", func() {
var (
clock *fakes.Clock
agentRunner *fakes.AgentRunner
agentClient *fakes.AgentClient
controller confab.Controller
logBuffer *bytes.Buffer
)
BeforeEach(func() {
clock = &fakes.Clock{}
agentClient = &fakes.AgentClient{}
agentClient.VerifyJoinedCalls.Returns.Errors = []error{nil}
agentClient.VerifySyncedCalls.Returns.Errors = []error{nil}
agentRunner = &fakes.AgentRunner{}
agentRunner.RunCalls.Returns.Errors = []error{nil}
logBuffer = &bytes.Buffer{}
示例7:
"confab"
"confab/fakes"
"errors"
"time"
"github.com/pivotal-golang/lager"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Controller", func() {
var (
clock *fakes.Clock
agentRunner *fakes.AgentRunner
agentClient *fakes.AgentClient
controller confab.Controller
logger *fakes.Logger
serviceDefiner *fakes.ServiceDefiner
)
BeforeEach(func() {
clock = &fakes.Clock{}
logger = &fakes.Logger{}
agentClient = &fakes.AgentClient{}
agentClient.VerifyJoinedCalls.Returns.Errors = []error{nil}
agentClient.VerifySyncedCalls.Returns.Errors = []error{nil}
agentRunner = &fakes.AgentRunner{}
agentRunner.RunCalls.Returns.Errors = []error{nil}
示例8: exit
func exit(controller confab.Controller, code int) {
controller.StopAgent()
os.Exit(code)
}
示例9: configureClient
func configureClient(controller confab.Controller) {
if err := controller.ConfigureClient(); err != nil {
stderr.Printf("error configuring client: %s", err)
exit(controller, 1)
}
}