本文整理匯總了Golang中github.com/coreos/go-etcd/etcd.Client.SetConsistency方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.SetConsistency方法的具體用法?Golang Client.SetConsistency怎麽用?Golang Client.SetConsistency使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/go-etcd/etcd.Client
的用法示例。
在下文中一共展示了Client.SetConsistency方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewEtcd
func NewEtcd(prefixKey string, config *EtcdConfig) (*Etcd, error) {
var (
client *etcd.Client
err error
)
if config.CertFile != "" && config.KeyFile != "" {
if client, err = etcd.NewTLSClient(config.Machines, config.CertFile, config.KeyFile, config.CaFile); err != nil {
Logger.Error("Failed to connect to Etcd. Error: %+v.", err)
return nil, err
}
} else {
client = etcd.NewClient(config.Machines)
}
// Set the default value if not provided.
if config.EtcdConsistency == "" {
config.EtcdConsistency = etcd.STRONG_CONSISTENCY
}
if err = client.SetConsistency(config.EtcdConsistency); err != nil {
Logger.Error("Failed to set Etcd consitency. Error: %+v.", err)
return nil, err
}
return &Etcd{client: client, prefixKey: prefixKey}, nil
}
示例2: newAdapter
func newAdapter(client *etcd.Client, workPool *workpool.WorkPool) *ETCDStoreAdapter {
client.SetConsistency(etcd.STRONG_CONSISTENCY)
return &ETCDStoreAdapter{
client: client,
workPool: workPool,
inflightWatches: map[chan bool]bool{},
inflightWatchLock: &sync.Mutex{},
}
}
示例3: reconnect
func (n *ng) reconnect() error {
n.Close()
var client *etcd.Client
if n.options.EtcdCertFile == "" && n.options.EtcdKeyFile == "" {
client = etcd.NewClient(n.nodes)
} else {
var err error
if client, err = etcd.NewTLSClient(n.nodes, n.options.EtcdCertFile, n.options.EtcdKeyFile, n.options.EtcdCaFile); err != nil {
return err
}
}
if err := client.SetConsistency(n.options.EtcdConsistency); err != nil {
return err
}
n.client = client
return nil
}
示例4: getCommandFunc
// getCommandFunc executes the "get" command.
func getCommandFunc(cmd *cobra.Command, args []string, client *etcd.Client) (*etcd.Response, error) {
if len(args) == 0 {
return nil, errors.New("Key required")
}
key := args[0]
consistent := getConsistentFlag
sorted := getSortFlag
// Setup consistency on the client.
if consistent {
client.SetConsistency(etcd.STRONG_CONSISTENCY)
} else {
client.SetConsistency(etcd.WEAK_CONSISTENCY)
}
// Retrieve the value from the server.
return client.Get(key, sorted, false)
}
示例5: initializeEtcdStoreClient
func initializeEtcdStoreClient(logger lager.Logger, etcdOptions *etcddb.ETCDOptions) etcddb.StoreClient {
var etcdClient *etcdclient.Client
var tr *http.Transport
if etcdOptions.IsSSL {
if etcdOptions.CertFile == "" || etcdOptions.KeyFile == "" {
logger.Fatal("failed-to-construct-etcd-tls-client", errors.New("Require both cert and key path"))
}
var err error
etcdClient, err = etcdclient.NewTLSClient(etcdOptions.ClusterUrls, etcdOptions.CertFile, etcdOptions.KeyFile, etcdOptions.CAFile)
if err != nil {
logger.Fatal("failed-to-construct-etcd-tls-client", err)
}
tlsCert, err := tls.LoadX509KeyPair(etcdOptions.CertFile, etcdOptions.KeyFile)
if err != nil {
logger.Fatal("failed-to-construct-etcd-tls-client", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{tlsCert},
InsecureSkipVerify: true,
ClientSessionCache: tls.NewLRUClientSessionCache(etcdOptions.ClientSessionCacheSize),
}
tr = &http.Transport{
TLSClientConfig: tlsConfig,
Dial: etcdClient.DefaultDial,
MaxIdleConnsPerHost: etcdOptions.MaxIdleConnsPerHost,
}
etcdClient.SetTransport(tr)
etcdClient.AddRootCA(etcdOptions.CAFile)
} else {
etcdClient = etcdclient.NewClient(etcdOptions.ClusterUrls)
}
etcdClient.SetConsistency(etcdclient.STRONG_CONSISTENCY)
return etcddb.NewStoreClient(etcdClient)
}
示例6: initializeEtcdClient
func initializeEtcdClient(etcdOptions *ETCDOptions) *etcd.Client {
var etcdClient *etcd.Client
var tr *http.Transport
if etcdOptions.IsSSL {
if etcdOptions.CertFile == "" || etcdOptions.KeyFile == "" {
panic(errors.New("Require both cert and key path"))
}
var err error
etcdClient, err = etcd.NewTLSClient(etcdOptions.ClusterUrls, etcdOptions.CertFile, etcdOptions.KeyFile, etcdOptions.CAFile)
if err != nil {
panic(err)
}
tlsCert, err := tls.LoadX509KeyPair(etcdOptions.CertFile, etcdOptions.KeyFile)
if err != nil {
panic(err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{tlsCert},
InsecureSkipVerify: true,
ClientSessionCache: tls.NewLRUClientSessionCache(etcdOptions.ClientSessionCacheSize),
}
tr = &http.Transport{
TLSClientConfig: tlsConfig,
Dial: etcdClient.DefaultDial,
MaxIdleConnsPerHost: etcdOptions.MaxIdleConnsPerHost,
}
etcdClient.SetTransport(tr)
} else {
etcdClient = etcd.NewClient(etcdOptions.ClusterUrls)
}
etcdClient.SetConsistency(etcd.STRONG_CONSISTENCY)
return etcdClient
}
示例7:
Expect(rawSQLDB.Ping()).NotTo(HaveOccurred())
flavor = sqlRunner.DriverName()
encryptionKey, err := encryption.NewKey("label", "passphrase")
Expect(err).NotTo(HaveOccurred())
keyManager, err := encryption.NewKeyManager(encryptionKey, nil)
Expect(err).NotTo(HaveOccurred())
cryptor = encryption.NewCryptor(keyManager, rand.Reader)
fakeClock = fakeclock.NewFakeClock(time.Now())
})
var _ = AfterSuite(func() {
etcdRunner.Stop()
Expect(rawSQLDB.Close()).NotTo(HaveOccurred())
ginkgomon.Kill(sqlProcess, 5*time.Second)
})
var _ = BeforeEach(func() {
etcdRunner.Reset()
etcdClient = etcdRunner.Client()
etcdClient.SetConsistency(etcdclient.STRONG_CONSISTENCY)
storeClient = etcd.NewStoreClient(etcdClient)
sqlRunner.Reset()
})
示例8: main
func main() {
var (
nodes string
taskList string
tasks []string
confPath string
confData *lib.RunConfig
cliVars string
cliData map[string]interface{}
verbose bool
taskDir string
tmplDir string
etcdClient *etcd.Client
base *cobra.Command
err error
)
base = &cobra.Command{
Use: "atom",
Short: "atom",
Long: "atom",
Run: func(cmd *cobra.Command, args []string) {
confData, err = lib.ParseAtomConfig(confPath)
if err != nil {
log.Printf("Config read error: %s", err)
if (taskDir == "") || (tmplDir == "") {
return
} else {
confData = &lib.RunConfig{
TaskDir: taskDir,
TmplDir: tmplDir,
Verbose: verbose,
}
}
}
if err := yaml.Unmarshal([]byte(cliVars), &cliData); err != nil {
log.Printf("Error: %s", err)
}
if nodes == "" {
etcdClient = nil
} else {
etcdClient = etcd.NewClient([]string{nodes})
etcdClient.SetDialTimeout(time.Duration(3) * time.Second)
if !etcdClient.SyncCluster() {
log.Fatal("Couldn't sync with etcd cluster.")
}
etcdClient.SetConsistency(etcd.STRONG_CONSISTENCY)
}
for _, name := range strings.Split(taskList, ",") {
if name == "" {
continue
}
tasks = append(tasks, name)
}
if len(tasks) <= 0 {
tasks = nil
}
atom := lib.NewAtom(confData, &cliData, etcdClient)
atom.Run(tasks...)
},
}
base.Flags().StringVarP(&taskList, "run", "r", "", "tasks to run")
base.PersistentFlags().StringVarP(&cliVars, "data", "d", "", "cli data (string, yaml)")
base.PersistentFlags().StringVarP(&confPath, "conf", "c", "/etc/atom/atom.yml", "atom.yml")
base.PersistentFlags().StringVarP(&nodes, "nodes", "n", "", "etcd nodes")
base.PersistentFlags().StringVarP(&taskDir, "task", "t", "", "task directory")
base.PersistentFlags().StringVarP(&tmplDir, "template", "m", "", "template directory")
base.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose")
base.Execute()
}
示例9: execWatchCommandFunc
// execWatchCommandFunc executes the "exec-watch" command.
func execWatchCommandFunc(cmd *cobra.Command, args []string, client *etcd.Client) (*etcd.Response, error) {
// _ = io.Copy
// _ = exec.Command
// args := c.Args()
argsLen := len(args)
if argsLen < 2 {
return nil, errors.New("Key and command to exec required")
}
// key := args[argsLen-1]
key := args[0]
cmdArgs := args[1:]
index := 0
if execAfterIndexFlag != 0 {
index = execAfterIndexFlag + 1
}
recursive := execRecursiveFlag
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
stop := make(chan bool)
go func() {
<-sigch
stop <- true
os.Exit(0)
}()
receiver := make(chan *etcd.Response)
client.SetConsistency(etcd.WEAK_CONSISTENCY)
go client.Watch(key, uint64(index), recursive, receiver, stop)
for {
resp := <-receiver
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Env = environResponse(resp, os.Environ())
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
stderr, err := cmd.StderrPipe()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
err = cmd.Start()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
go io.Copy(os.Stdout, stdout)
go io.Copy(os.Stderr, stderr)
cmd.Wait()
}
return nil, nil
}
示例10: main
func main() {
cf_debug_server.AddFlags(flag.CommandLine)
cf_lager.AddFlags(flag.CommandLine)
etcdFlags := AddETCDFlags(flag.CommandLine)
flag.Parse()
cf_http.Initialize(*communicationTimeout)
logger, reconfigurableSink := cf_lager.New("bbs")
logger.Info("starting")
initializeDropsonde(logger)
etcdOptions, err := etcdFlags.Validate()
if err != nil {
logger.Fatal("etcd-validation-failed", err)
}
var etcdClient *etcdclient.Client
if etcdOptions.IsSSL {
etcdClient, err = etcdclient.NewTLSClient(etcdOptions.ClusterUrls, etcdOptions.CertFile, etcdOptions.KeyFile, etcdOptions.CAFile)
if err != nil {
logger.Fatal("failed-to-construct-etcd-tls-client", err)
}
} else {
etcdClient = etcdclient.NewClient(etcdOptions.ClusterUrls)
}
etcdClient.SetConsistency(etcdclient.STRONG_CONSISTENCY)
err = validateAuctioneerFlag()
if err != nil {
logger.Fatal("auctioneer-address-validation-failed", err)
}
auctioneerClient := auctionhandlers.NewClient(*auctioneerAddress)
consulSession := initializeConsul(logger)
consulDB := consuldb.NewConsul(consulSession)
cellClient := cellhandlers.NewClient()
db := etcddb.NewETCD(etcdClient, auctioneerClient, cellClient, consulDB, clock.NewClock())
hub := events.NewHub()
watcher := watcher.NewWatcher(
logger,
db,
hub,
clock.NewClock(),
bbsWatchRetryWaitDuration,
)
handler := handlers.New(logger, db, hub)
members := grouper.Members{
{"watcher", watcher},
{"server", http_server.New(*serverAddress, handler)},
{"hub-closer", closeHub(logger.Session("hub-closer"), hub)},
}
if dbgAddr := cf_debug_server.DebugAddress(flag.CommandLine); dbgAddr != "" {
members = append(grouper.Members{
{"debug-server", cf_debug_server.Runner(dbgAddr, reconfigurableSink)},
}, members...)
}
group := grouper.NewOrdered(os.Interrupt, members)
monitor := ifrit.Invoke(sigmon.New(group))
logger.Info("started")
err = <-monitor.Wait()
if err != nil {
logger.Error("exited-with-failure", err)
os.Exit(1)
}
logger.Info("exited")
}