• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang kvdb.Instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/portworx/kvdb.Instance函数的典型用法代码示例。如果您正苦于以下问题:Golang Instance函数的具体用法?Golang Instance怎么用?Golang Instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Init

func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	inst := &driver{
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}
	inst.buseDevices = make(map[string]*buseDev)
	if err := os.MkdirAll(BuseMountPath, 0744); err != nil {
		return nil, err
	}
	volumeInfo, err := inst.DefaultEnumerator.Enumerate(
		&api.VolumeLocator{},
		nil,
	)
	if err == nil {
		for _, info := range volumeInfo {
			if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE {
				info.Status = api.VolumeStatus_VOLUME_STATUS_UP
				inst.UpdateVol(info)
			}
		}
	} else {
		dlog.Println("Could not enumerate Volumes, ", err)
	}

	c, err := cluster.Inst()
	if err != nil {
		dlog.Println("BUSE initializing in single node mode")
	} else {
		dlog.Println("BUSE initializing in clustered mode")
		c.AddEventListener(inst)
	}

	dlog.Println("BUSE initialized and driver mounted at: ", BuseMountPath)
	return inst, nil
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:35,代码来源:buse.go


示例2: watchTree

func watchTree(t *testing.T) {
	fmt.Println("watchTree")

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")

	tree := "tree"

	watchData := watchData{
		t:          t,
		key:        tree + "/key",
		stop:       "stop",
		iterations: 2,
	}
	kv.Delete(watchData.key)
	time.Sleep(time.Second)
	err := kv.WatchTree(tree, 0, &watchData, watchFn)
	if err != nil {
		fmt.Printf("Cannot test watchKey: %v\n", err)
		return
	}
	go watchUpdate(&watchData)

	for watchData.watchStopped == false {
		time.Sleep(time.Millisecond * 100)
	}
}
开发者ID:pombredanne,项目名称:kvdb,代码行数:27,代码来源:kv.go


示例3: deleteTree

func deleteTree(t *testing.T) {
	fmt.Println("deleteTree")

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")

	prefix := "tree"
	keys := map[string]string{
		prefix + "/1cbc9a98-072a-4793-8608-01ab43db96c8": "bar",
		prefix + "/foo":                                  "baz",
	}

	for key, val := range keys {
		_, err := kv.Put(key, []byte(val), 10)
		assert.NoError(t, err, "Unexpected error on Put")
	}

	for key, _ := range keys {
		_, err := kv.Get(key)
		assert.NoError(t, err, "Unexpected error on Get")
	}
	err := kv.DeleteTree(prefix)
	assert.NoError(t, err, "Unexpected error on DeleteTree")

	for key, _ := range keys {
		_, err := kv.Get(key)
		assert.Error(t, err, "Get should fail on all keys after DeleteTree")
	}
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:29,代码来源:kv.go


示例4: TestRaiseWithGenerateIdAndErase

func TestRaiseWithGenerateIdAndErase(t *testing.T) {
	// RaiseWithGenerateId api.Alerts Id : 1

	raiseAlerts, err := kva.RaiseWithGenerateId(api.Alerts{Resource: api.ResourceType_VOLUMES, Severity: api.SeverityType_NOTIFY}, mockGenerateId)
	require.NoError(t, err, "Failed in raising an alert")

	kv := kvdb.Instance()
	var alert api.Alerts

	_, err = kv.GetVal(getResourceKey(api.ResourceType_VOLUMES)+strconv.FormatInt(raiseAlerts.Id, 10), &alert)
	require.NoError(t, err, "Failed to retrieve alert from kvdb")
	require.NotNil(t, alert, "api.Alerts object null in kvdb")
	require.Equal(t, raiseAlerts.Id, alert.Id, "api.Alerts Id mismatch")
	require.Equal(t, api.ResourceType_VOLUMES, alert.Resource, "api.Alerts Resource mismatch")
	require.Equal(t, api.SeverityType_NOTIFY, alert.Severity, "api.Alerts Severity mismatch")

	// RaiseWithGenerateId api.Alerts with no Resource
	_, err = kva.RaiseWithGenerateId(api.Alerts{Severity: api.SeverityType_NOTIFY}, mockGenerateId)
	require.Error(t, err, "An error was expected")
	require.Equal(t, ErrResourceNotFound, err, "Error mismatch")

	// Erase api.Alerts Id : 1
	err = kva.Erase(api.ResourceType_VOLUMES, raiseAlerts.Id)
	require.NoError(t, err, "Failed to erase an alert")

	_, err = kv.GetVal(getResourceKey(api.ResourceType_VOLUMES)+"1", &alert)
	require.Error(t, err, "api.Alerts not erased from kvdb")

}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:29,代码来源:alerts_kvdb_test.go


示例5: update

func update(t *testing.T) {
	fmt.Println("update")

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")

	key := "update/foo"
	kv.Delete(key)

	kvp, err := kv.Update(key, []byte("bar"), 0)
	assert.Error(t, err, "Update should error on non-existent key")

	defer func() {
		kv.Delete(key)
	}()

	kvp, err = kv.Create(key, []byte("bar"), 0)
	assert.NoError(t, err, "Unexpected error on create")

	kvp, err = kv.Update(key, []byte("bar"), 0)
	assert.NoError(t, err, "Unexpected error on update")

	assert.Equal(t, kvp.Action, kvdb.KVSet,
		"Expected action KVSet, actual %v", kvp.Action)
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:25,代码来源:kv.go


示例6: cas

func cas(t *testing.T) {
	fmt.Println("cas")

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")
	key := "foo/docker"
	val := "great"
	defer func() {
		kv.Delete(key)
	}()

	kvPair, err := kv.Put(key, []byte(val), 10)
	assert.NoError(t, err, "Unxpected error in Put")

	kvPair, err = kv.Get(key)
	assert.NoError(t, err, "Failed in Get")

	_, err = kv.CompareAndSet(kvPair, kvdb.KVFlags(0), []byte("badval"))
	assert.Error(t, err, "CompareAndSet should fail on an incorrect previous value")

	kvPair.ModifiedIndex++
	_, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, nil)
	assert.Error(t, err, "CompareAndSet should fail on an incorrect modified index")

	kvPair.ModifiedIndex--
	kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, nil)
	assert.NoError(t, err, "CompareAndSet should succeed on an correct modified index")

	kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVFlags(0), []byte(val))
	assert.NoError(t, err, "CompareAndSet should succeed on an correct value")

	kvPair, err = kv.CompareAndSet(kvPair, kvdb.KVModifiedIndex, []byte(val))
	assert.NoError(t, err, "CompareAndSet should succeed on an correct value and modified index")
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:34,代码来源:kv.go


示例7: lock

func lock(t *testing.T) {

	fmt.Println("lock")

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")

	key := "locktest"
	kvPair, err := kv.Lock(key, 100)
	assert.NoError(t, err, "Unexpected error in lock")

	stash := *kvPair
	stash.Value = []byte("hoohah")
	err = kv.Unlock(&stash)
	assert.Error(t, err, "Unlock should fail for bad KVPair")

	err = kv.Unlock(kvPair)
	assert.NoError(t, err, "Unexpected error from Unlock")

	kvPair, err = kv.Lock(key, 20)
	assert.NoError(t, err, "Failed to lock after unlock")

	err = kv.Unlock(kvPair)
	assert.NoError(t, err, "Unexpected error from Unlock")
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:25,代码来源:kv.go


示例8: readDatabase

func readDatabase() (Database, error) {
	kvdb := kv.Instance()

	db := Database{Status: api.StatusInit,
		NodeEntries: make(map[string]NodeEntry)}

	kv, err := kvdb.Get("cluster/database")
	if err != nil && !strings.Contains(err.Error(), "Key not found") {
		log.Warn("Warning, could not read cluster database")
		goto done
	}

	if kv == nil || bytes.Compare(kv.Value, []byte("{}")) == 0 {
		log.Info("Cluster is uninitialized...")
		err = nil
		goto done
	} else {
		err = json.Unmarshal(kv.Value, &db)
		if err != nil {
			log.Warn("Fatal, Could not parse cluster database ", kv)
			goto done
		}
	}

done:
	return db, err
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:27,代码来源:database.go


示例9: Watch

// Watch on all alerts
func (kva *KvAlerts) Watch(alertsWatcherFunc AlertsWatcherFunc) error {

	prefix := alertsKey
	alertsWatcher = watcher{status: watchBootstrap, cb: alertsWatcherFunc, kvcb: kvdbWatch}

	if err := subscribeWatch(); err != nil {
		return err
	}

	// Subscribe for a watch is in a goroutine. Bootsrap by writing to the key and waiting for an update
	retries := 0
	kv := kvdb.Instance()
	for alertsWatcher.status == watchBootstrap {
		_, err := kv.Put(prefix+bootstrap, time.Now(), 1)
		if err != nil {
			return err
		}
		if alertsWatcher.status == watchBootstrap {
			retries++
			time.Sleep(time.Millisecond * 100)
		}
	}
	if alertsWatcher.status != watchReady {
		return fmt.Errorf("Failed to watch on %v", prefix)
	}

	return nil
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:29,代码来源:alerts_kvdb.go


示例10: getInterface

func getInterface(t *testing.T) {

	fmt.Println("getInterface")
	expected := struct {
		N int
		S string
	}{
		N: 10,
		S: "Ten",
	}

	actual := expected
	actual.N = 0
	actual.S = "zero"

	kv := kvdb.Instance()
	assert.NotNil(t, kv, "Default KVDB is not set")

	key := "DEADBEEF"
	_, err := kv.Delete(key)
	_, err = kv.Put(key, &expected, 0)
	assert.NoError(t, err, "Failed in Put")

	_, err = kv.GetVal(key, &actual)
	assert.NoError(t, err, "Failed in Get")

	assert.Equal(t, expected, actual, "Expected %#v but got %#v",
		expected, actual)
}
开发者ID:kunalkushwaha,项目名称:openstorage,代码行数:29,代码来源:kv.go


示例11: readDatabase

func readDatabase() (Database, error) {
	kvdb := kvdb.Instance()

	db := Database{
		Status:      api.Status_STATUS_INIT,
		NodeEntries: make(map[string]NodeEntry),
	}

	kv, err := kvdb.Get(ClusterDBKey)
	if err != nil && !strings.Contains(err.Error(), "Key not found") {
		dlog.Warnln("Warning, could not read cluster database")
		return db, err
	}

	if kv == nil || bytes.Compare(kv.Value, []byte("{}")) == 0 {
		dlog.Infoln("Cluster is uninitialized...")
		return db, nil
	}
	if err := json.Unmarshal(kv.Value, &db); err != nil {
		dlog.Warnln("Fatal, Could not parse cluster database ", kv)
		return db, err
	}

	return db, nil
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:25,代码来源:database.go


示例12: Erase

// Erase erases an alert
func (kva *KvAlerts) Erase(resourceType api.ResourceType, alertId int64) error {
	kv := kvdb.Instance()

	if resourceType == api.ResourceType_UNKNOWN_RESOURCE {
		return ErrResourceNotFound
	}
	var err error

	_, err = kv.Delete(getResourceKey(resourceType) + strconv.FormatInt(alertId, 10))
	return err
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:12,代码来源:alerts_kvdb.go


示例13: subscribeWatch

func subscribeWatch() error {
	watchIndex := alertsWatchIndex
	if watchIndex != 0 {
		watchIndex = alertsWatchIndex + 1
	}

	kv := kvdb.Instance()
	if err := kv.WatchTree(alertsKey, watchIndex, nil, alertsWatcher.kvcb); err != nil {
		return err
	}
	return nil
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:12,代码来源:alerts_kvdb.go


示例14: Init

func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	restUrl, ok := params["restUrl"]
	if !ok {
		return nil, fmt.Errorf("rest api 'url' configuration parameter must be set")
	}

	user, ok := params["user"]
	if !ok {
		return nil, fmt.Errorf("rest auth 'user' must be set")
	}

	pass, ok := params["password"]
	if !ok {
		return nil, fmt.Errorf("rest auth 'password' must be set")
	}

	consistency_group, ok := params["consistency_group"]
	if !ok {
		return nil, fmt.Errorf("'consistency_group' configuration parameter must be set")
	}

	project, ok := params["project"]
	if !ok {
		return nil, fmt.Errorf("'project' configuration parameter must be set")
	}

	varray, ok := params["varray"]
	if !ok {
		return nil, fmt.Errorf("'varray' configuration parameter must be set")
	}

	vpool, ok := params["vpool"]
	if !ok {
		return nil, fmt.Errorf("'vpool' configuration parameter must be set")
	}

	d := &driver{
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
		consistency_group: consistency_group,
		project:           project,
		varray:            varray,
		vpool:             vpool,
		url:               restUrl,
		creds:             url.UserPassword(user, pass),
		httpClient: &http.Client{
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
			},
		},
	}

	return d, nil
}
开发者ID:alwang1234,项目名称:openstorage,代码行数:53,代码来源:coprhd.go


示例15: Init

func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	root, ok := params[RootParam]
	if !ok {
		return nil, fmt.Errorf("Root directory should be specified with key %q", RootParam)
	}
	home := path.Join(root, Volumes)
	d, err := btrfs.Init(home, nil)
	if err != nil {
		return nil, err
	}
	s := volume.NewDefaultEnumerator(Name, kvdb.Instance())
	return &driver{btrfs: d, root: root, DefaultEnumerator: s}, nil
}
开发者ID:phoenix-io,项目名称:openstorage,代码行数:13,代码来源:btrfs.go


示例16: Init

// Init aws volume driver metadata.
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	zone, err := metadata("placement/availability-zone")
	if err != nil {
		return nil, err
	}
	instance, err := metadata("instance-id")
	if err != nil {
		return nil, err
	}
	logrus.Infof("AWS instance %v zone %v", instance, zone)
	accessKey, ok := params["AWS_ACCESS_KEY_ID"]
	if !ok {
		if accessKey = os.Getenv("AWS_ACCESS_KEY_ID"); accessKey == "" {
			return nil, fmt.Errorf("AWS_ACCESS_KEY_ID environment variable must be set")
		}
	}
	secretKey, ok := params["AWS_SECRET_ACCESS_KEY"]
	if !ok {
		if secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
			return nil, fmt.Errorf("AWS_SECRET_ACCESS_KEY environment variable must be set")
		}
	}
	creds := credentials.NewStaticCredentials(accessKey, secretKey, "")
	region := zone[:len(zone)-1]
	d := &Driver{
		ec2: ec2.New(
			session.New(
				&aws.Config{
					Region:      &region,
					Credentials: creds,
				},
			),
		),
		md: &Metadata{
			zone:     zone,
			instance: instance,
		},
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}
	devPrefix, letters, err := d.freeDevices()
	if err != nil {
		return nil, err
	}
	d.SingleLetter, err = device.NewSingleLetter(devPrefix, letters)
	if err != nil {
		return nil, err
	}
	return d, nil
}
开发者ID:pombredanne,项目名称:openstorage,代码行数:51,代码来源:aws.go


示例17: TestClear

func TestClear(t *testing.T) {
	// RaiseWithGenerateId an alert
	var alert api.Alerts
	kv := kvdb.Instance()
	raiseAlerts, err := kva.RaiseWithGenerateId(api.Alerts{Resource: api.ResourceType_NODE, Severity: api.SeverityType_ALARM}, mockGenerateId)

	err = kva.Clear(api.ResourceType_NODE, raiseAlerts.Id)
	require.NoError(t, err, "Failed to clear alert")

	_, err = kv.GetVal(getResourceKey(api.ResourceType_NODE)+strconv.FormatInt(raiseAlerts.Id, 10), &alert)
	require.Equal(t, true, alert.Cleared, "Failed to clear alert")

	err = kva.Erase(api.ResourceType_NODE, raiseAlerts.Id)
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:14,代码来源:alerts_kvdb_test.go


示例18: Retrieve

// Retrieve retrieves a specific alert
func (kva *KvAlerts) Retrieve(resourceType api.ResourceType, alertId int64) (api.Alerts, error) {
	var (
		alert api.Alerts
		err   error
	)
	if resourceType == api.ResourceType_UNKNOWN_RESOURCE {
		return api.Alerts{}, ErrResourceNotFound
	}
	kv := kvdb.Instance()

	_, err = kv.GetVal(getResourceKey(resourceType)+strconv.FormatInt(alertId, 10), &alert)

	return alert, err
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:15,代码来源:alerts_kvdb.go


示例19: writeDatabase

func writeDatabase(db *Database) error {
	kvdb := kvdb.Instance()
	b, err := json.Marshal(db)
	if err != nil {
		dlog.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
		return err
	}

	if _, err := kvdb.Put(ClusterDBKey, b, 0); err != nil {
		dlog.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
		return err
	}

	dlog.Infoln("Cluster database updated.")
	return nil
}
开发者ID:ModelRocket,项目名称:openstorage,代码行数:16,代码来源:database.go


示例20: writeDatabase

func writeDatabase(db *Database) error {
	kvdb := kvdb.Instance()
	b, err := json.Marshal(db)
	if err != nil {
		logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
		return err
	}

	if _, err := kvdb.Put("cluster/database", b, 0); err != nil {
		logrus.Warnf("Fatal, Could not marshal cluster database to JSON: %v", err)
		return err
	}

	logrus.Info("Cluster database updated.")
	return nil
}
开发者ID:pombredanne,项目名称:openstorage,代码行数:16,代码来源:database.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang kvdb.Kvdb类代码示例发布时间:2022-05-28
下一篇:
Golang webmachine.Request类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap