本文整理汇总了Golang中github.com/cloudfoundry/storeadapter.StoreAdapter类的典型用法代码示例。如果您正苦于以下问题:Golang StoreAdapter类的具体用法?Golang StoreAdapter怎么用?Golang StoreAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StoreAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StartHeartbeats
func StartHeartbeats(localIp string, ttl time.Duration, config *config.Config, storeAdapter storeadapter.StoreAdapter, logger *gosteno.Logger) (stopChan chan (chan bool)) {
if len(config.EtcdUrls) == 0 {
return
}
if storeAdapter == nil {
panic("store adapter is nil")
}
logger.Debugf("Starting Health Status Updates to Store: /healthstatus/doppler/%s/%s/%d", config.Zone, config.JobName, config.Index)
status, stopChan, err := storeAdapter.MaintainNode(storeadapter.StoreNode{
Key: fmt.Sprintf("/healthstatus/doppler/%s/%s/%d", config.Zone, config.JobName, config.Index),
Value: []byte(localIp),
TTL: uint64(ttl.Seconds()),
})
if err != nil {
panic(err)
}
go func() {
for stat := range status {
logger.Debugf("Health updates channel pushed %v at time %v", stat, time.Now())
}
}()
return stopChan
}
示例2: Announce
func Announce(localIP string, ttl time.Duration, config *config.Config, storeAdapter storeadapter.StoreAdapter, logger *gosteno.Logger) chan (chan bool) {
dopplerMetaBytes, err := buildDopplerMeta(localIP, config)
if err != nil {
panic(err)
}
key := fmt.Sprintf("%s/%s/%s/%d", META_ROOT, config.Zone, config.JobName, config.Index)
logger.Debugf("Starting Health Status Updates to Store: %s", key)
node := storeadapter.StoreNode{
Key: key,
Value: dopplerMetaBytes,
TTL: uint64(ttl.Seconds()),
}
// Call to create to make sure node is created before we return
storeAdapter.Create(node)
status, stopChan, err := storeAdapter.MaintainNode(node)
if err != nil {
panic(err)
}
// The status channel needs to be drained to maintain the node within the etcd cluster
go func() {
for stat := range status {
logger.Debugf("Health updates channel pushed %v at time %v", stat, time.Now())
}
}()
return stopChan
}
示例3: connectToStoreAdapter
func connectToStoreAdapter(l logger.Logger, conf *config.Config) storeadapter.StoreAdapter {
var adapter storeadapter.StoreAdapter
workPool, err := workpool.NewWorkPool(conf.StoreMaxConcurrentRequests)
if err != nil {
l.Error("Failed to create workpool", err)
os.Exit(1)
}
options := &etcdstoreadapter.ETCDOptions{
ClusterUrls: conf.StoreURLs,
}
adapter, err = etcdstoreadapter.New(options, workPool)
if err != nil {
l.Error("Failed to create the store adapter", err)
os.Exit(1)
}
err = adapter.Connect()
if err != nil {
l.Error("Failed to connect to the store", err)
os.Exit(1)
}
return adapter
}
示例4: Daemonize
func Daemonize(
component string,
callback func() error,
period time.Duration,
timeout time.Duration,
logger logger.Logger,
adapter storeadapter.StoreAdapter,
) error {
logger.Info("Acquiring lock for " + component)
lostLockChannel, releaseLockChannel, err := adapter.GetAndMaintainLock(component, 10)
if err != nil {
logger.Info(fmt.Sprintf("Failed to acquire lock: %s", err))
return err
}
go func() {
<-lostLockChannel
logger.Error("Lost the lock", errors.New("Lock the lock"))
os.Exit(197)
}()
logger.Info("Acquired lock for " + component)
logger.Info(fmt.Sprintf("Running Daemon every %d seconds with a timeout of %d", int(period.Seconds()), int(timeout.Seconds())))
for {
afterChan := time.After(period)
timeoutChan := time.After(timeout)
errorChan := make(chan error, 1)
t := time.Now()
go func() {
errorChan <- callback()
}()
select {
case err := <-errorChan:
logger.Info("Daemonize Time", map[string]string{
"Component": component,
"Duration": fmt.Sprintf("%.4f", time.Since(t).Seconds()),
})
if err != nil {
logger.Error("Daemon returned an error. Continuining...", err)
}
case <-timeoutChan:
releaseLockChannel <- true
return errors.New("Daemon timed out. Aborting!")
}
<-afterChan
}
return nil
}
示例5: AddETCDNode
func AddETCDNode(etcdAdapter storeadapter.StoreAdapter, key string, value string) {
node := storeadapter.StoreNode{
Key: key,
Value: []byte(value),
TTL: uint64(20),
}
etcdAdapter.Create(node)
recvNode, err := etcdAdapter.Get(key)
Expect(err).NotTo(HaveOccurred())
Expect(string(recvNode.Value)).To(Equal(value))
}
示例6: connectToStoreAdapter
func connectToStoreAdapter(l logger.Logger, conf *config.Config) (storeadapter.StoreAdapter, metricsaccountant.UsageTracker) {
var adapter storeadapter.StoreAdapter
workerPool := workerpool.NewWorkerPool(conf.StoreMaxConcurrentRequests)
adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workerPool)
err := adapter.Connect()
if err != nil {
l.Error("Failed to connect to the store", err)
os.Exit(1)
}
return adapter, workerPool
}
示例7: connectToStoreAdapter
func connectToStoreAdapter(l logger.Logger, conf *config.Config, usage *usageTracker) storeadapter.StoreAdapter {
var adapter storeadapter.StoreAdapter
var around workpool.AroundWork = workpool.DefaultAround
if usage != nil {
around = usage
}
workPool := workpool.New(conf.StoreMaxConcurrentRequests, 0, around)
adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workPool)
err := adapter.Connect()
if err != nil {
l.Error("Failed to connect to the store", err)
os.Exit(1)
}
return adapter
}
示例8: NewElector
func NewElector(instanceName string, adapter storeadapter.StoreAdapter, updateInterval time.Duration, logger *gosteno.Logger) *Elector {
for {
err := adapter.Connect()
if err == nil {
break
}
logger.Errorf("Elector: Unable to connect to store: '%s'", err.Error())
time.Sleep(updateInterval)
}
return &Elector{
instanceName: []byte(instanceName),
adapter: adapter,
updateInterval: updateInterval,
logger: logger,
}
}
示例9: connectToStoreAdapter
func connectToStoreAdapter(l logger.Logger, conf *config.Config) (storeadapter.StoreAdapter, metricsaccountant.UsageTracker) {
var adapter storeadapter.StoreAdapter
workerPool := workerpool.NewWorkerPool(conf.StoreMaxConcurrentRequests)
if conf.StoreType == "etcd" {
adapter = etcdstoreadapter.NewETCDStoreAdapter(conf.StoreURLs, workerPool)
} else if conf.StoreType == "ZooKeeper" {
adapter = zookeeperstoreadapter.NewZookeeperStoreAdapter(conf.StoreURLs, workerPool, buildTimeProvider(l), time.Second)
} else {
l.Error(fmt.Sprintf("Unknown store type %s. Choose one of 'etcd' or 'ZooKeeper'", conf.StoreType), fmt.Errorf("Unkown store type"))
os.Exit(1)
}
err := adapter.Connect()
if err != nil {
l.Error("Failed to connect to the store", err)
os.Exit(1)
}
return adapter, workerPool
}
示例10: AnnounceLegacy
func AnnounceLegacy(localIP string, ttl time.Duration, config *config.Config, storeAdapter storeadapter.StoreAdapter, logger *gosteno.Logger) chan (chan bool) {
key := fmt.Sprintf("%s/%s/%s/%d", LEGACY_ROOT, config.Zone, config.JobName, config.Index)
status, stopChan, err := storeAdapter.MaintainNode(storeadapter.StoreNode{
Key: key,
Value: []byte(localIP),
TTL: uint64(ttl.Seconds()),
})
if err != nil {
panic(err)
}
// The status channel needs to be drained to maintain the node within the etcd cluster
go func() {
for stat := range status {
logger.Debugf("Health updates channel pushed %v at time %v", stat, time.Now())
}
}()
return stopChan
}
示例11: getAllTasks
func getAllTasks(store storeadapter.StoreAdapter, state models.TaskState) ([]*models.Task, error) {
node, err := store.ListRecursively(TaskSchemaRoot)
if err == storeadapter.ErrorKeyNotFound {
return []*models.Task{}, nil
}
if err != nil {
return []*models.Task{}, err
}
tasks := []*models.Task{}
for _, node := range node.ChildNodes {
task, err := models.NewTaskFromJSON(node.Value)
if err != nil {
steno.NewLogger("bbs").Errorf("cannot parse task JSON for key %s: %s", node.Key, err.Error())
} else if task.State == state {
tasks = append(tasks, &task)
}
}
return tasks, nil
}
示例12:
. "github.com/cloudfoundry/hm9000/testhelpers/custommatchers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cloudfoundry/hm9000/config"
"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
"github.com/cloudfoundry/storeadapter"
"github.com/cloudfoundry/storeadapter/etcdstoreadapter"
)
var _ = Describe("Desired State", func() {
var (
store Store
storeAdapter storeadapter.StoreAdapter
conf *config.Config
app1 appfixture.AppFixture
app2 appfixture.AppFixture
app3 appfixture.AppFixture
)
BeforeEach(func() {
var err error
conf, err = config.DefaultConfig()
Expect(err).NotTo(HaveOccurred())
wpool, err := workpool.NewWorkPool(conf.StoreMaxConcurrentRequests)
Expect(err).NotTo(HaveOccurred())
storeAdapter, err = etcdstoreadapter.New(
&etcdstoreadapter.ETCDOptions{ClusterUrls: etcdRunner.NodeURLS()},
wpool,
)
Expect(err).NotTo(HaveOccurred())
示例13: TestIntegrationTest
)
func TestIntegrationTest(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "End-to-end Integration Test Suite")
}
var (
LocalIPAddress string
etcdRunner *etcdstorerunner.ETCDClusterRunner
etcdAdapter storeadapter.StoreAdapter
metronExecutablePath string
dopplerExecutablePath string
trafficControllerExecutablePath string
metronSession *gexec.Session
dopplerSession *gexec.Session
tcSession *gexec.Session
dopplerConfig string
metronConfig string
)
var _ = BeforeSuite(func() {
runtime.GOMAXPROCS(runtime.NumCPU())
etcdRunner = etcdstorerunner.NewETCDClusterRunner(49623, 1, nil)
etcdRunner.Start()
etcdAdapter = etcdRunner.Adapter(nil)
metronExecutablePath = buildComponent("metron")
示例14:
import (
"github.com/cloudfoundry/gunk/workpool"
. "github.com/cloudfoundry/hm9000/store"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/cloudfoundry/hm9000/config"
"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
"github.com/cloudfoundry/storeadapter"
"github.com/cloudfoundry/storeadapter/etcdstoreadapter"
)
var _ = Describe("Compact", func() {
var (
store Store
storeAdapter storeadapter.StoreAdapter
conf *config.Config
)
BeforeEach(func() {
var err error
conf, err = config.DefaultConfig()
conf.StoreSchemaVersion = 17
Ω(err).ShouldNot(HaveOccurred())
storeAdapter = etcdstoreadapter.NewETCDStoreAdapter(etcdRunner.NodeURLS(),
workpool.NewWorkPool(conf.StoreMaxConcurrentRequests))
err = storeAdapter.Connect()
Ω(err).ShouldNot(HaveOccurred())
store = NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
})
示例15: TestIntegrationTest
"runtime"
"time"
)
func TestIntegrationTest(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "End-to-end Integration Test Suite")
}
var (
LocalIPAddress string
etcdRunner *etcdstorerunner.ETCDClusterRunner
etcdAdapter storeadapter.StoreAdapter
metronExecutablePath string
dopplerExecutablePath string
trafficControllerExecutablePath string
metronSession *gexec.Session
dopplerSession *gexec.Session
tcSession *gexec.Session
)
var _ = BeforeSuite(func() {
runtime.GOMAXPROCS(runtime.NumCPU())
etcdRunner = etcdstorerunner.NewETCDClusterRunner(49623, 1, nil)
etcdRunner.Start()
etcdAdapter = etcdRunner.Adapter(nil)
metronExecutablePath = buildComponent("metron")
dopplerExecutablePath = buildComponent("doppler")
trafficControllerExecutablePath = buildComponent("trafficcontroller")