当前位置: 首页>>代码示例>>Golang>>正文


Golang Controller.ConfigureServer方法代码示例

本文整理汇总了Golang中confab.Controller.ConfigureServer方法的典型用法代码示例。如果您正苦于以下问题:Golang Controller.ConfigureServer方法的具体用法?Golang Controller.ConfigureServer怎么用?Golang Controller.ConfigureServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在confab.Controller的用法示例。


在下文中一共展示了Controller.ConfigureServer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)
	}
}
开发者ID:tkysk,项目名称:consul-release,代码行数:15,代码来源:main.go

示例2: 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,
//.........这里部分代码省略.........
开发者ID:Tier3,项目名称:consul-release,代码行数:101,代码来源:main.go

示例3:

			It("swallows the error", func() {
				Expect(controller.StopAgent()).To(Succeed())
				Expect(agentRunner.WaitCall.CallCount).To(Equal(1))
			})

			It("logs the error", func() {
				Expect(controller.StopAgent()).To(Succeed())
				Expect(logBuffer.String()).To(ContainSubstring("wait error"))
			})
		})
	})

	Describe("ConfigureServer", func() {
		It("does not launch the consul agent", func() {
			Expect(controller.ConfigureServer()).To(Succeed())
			Expect(agentRunner.RunCalls.CallCount).To(Equal(0))
		})

		It("does not check that the agent has joined a cluster", func() {
			Expect(controller.ConfigureServer()).To(Succeed())
			Expect(agentClient.VerifyJoinedCalls.CallCount).To(Equal(0))
		})

		Context("when it is not the last node in the cluster", func() {
			It("does not check that it is synced", func() {
				Expect(controller.ConfigureServer()).To(Succeed())
				Expect(agentClient.VerifySyncedCalls.CallCount).To(Equal(0))
			})
		})
开发者ID:Tier3,项目名称:consul-release,代码行数:29,代码来源:controller_test.go

示例4:

					{
						Action: "controller.stop-agent.cleanup.failed",
						Error:  errors.New("cleanup error"),
					},
					{
						Action: "controller.stop-agent.success",
					},
				}))
			})
		})
	})

	Describe("ConfigureServer", func() {
		Context("when it is not the last node in the cluster", func() {
			It("does not check that it is synced", func() {
				Expect(controller.ConfigureServer(confab.NewTimeout(make(chan time.Time)))).To(Succeed())
				Expect(agentClient.VerifySyncedCalls.CallCount).To(Equal(0))
				Expect(agentRunner.WritePIDCall.CallCount).To(Equal(1))
				Expect(logger.Messages).To(ContainSequence([]fakes.LoggerMessage{
					{
						Action: "controller.configure-server.is-last-node",
					},
					{
						Action: "controller.configure-server.set-keys",
						Data: []lager.Data{{
							"keys": []string{"key 1", "key 2", "key 3"},
						}},
					},
					{
						Action: "controller.configure-server.success",
					},
开发者ID:liuyuns,项目名称:consul-release,代码行数:31,代码来源:controller_test.go


注:本文中的confab.Controller.ConfigureServer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。