Rename StorageInterface methods

This commit is contained in:
Wojciech Tyczynski
2015-07-27 11:59:09 +02:00
parent db5f6eae6c
commit 7ce51db40d
13 changed files with 79 additions and 92 deletions

View File

@@ -81,7 +81,7 @@ func (h *etcdHelper) Versioner() StorageVersioner {
}
// Implements StorageInterface.
func (h *etcdHelper) CreateObj(key string, obj, out runtime.Object, ttl uint64) error {
func (h *etcdHelper) Create(key string, obj, out runtime.Object, ttl uint64) error {
key = h.prefixEtcdKey(key)
data, err := h.codec.Encode(obj)
if err != nil {
@@ -109,7 +109,7 @@ func (h *etcdHelper) CreateObj(key string, obj, out runtime.Object, ttl uint64)
}
// Implements StorageInterface.
func (h *etcdHelper) SetObj(key string, obj, out runtime.Object, ttl uint64) error {
func (h *etcdHelper) Set(key string, obj, out runtime.Object, ttl uint64) error {
var response *etcd.Response
data, err := h.codec.Encode(obj)
if err != nil {
@@ -150,7 +150,7 @@ func (h *etcdHelper) SetObj(key string, obj, out runtime.Object, ttl uint64) err
}
// Implements StorageInterface.
func (h *etcdHelper) DeleteObj(key string, out runtime.Object) error {
func (h *etcdHelper) Delete(key string, out runtime.Object) error {
key = h.prefixEtcdKey(key)
if _, err := conversion.EnforcePtr(out); err != nil {
panic("unable to convert output object to pointer")
@@ -169,7 +169,7 @@ func (h *etcdHelper) DeleteObj(key string, out runtime.Object) error {
}
// Implements StorageInterface.
func (h *etcdHelper) Delete(key string, recursive bool) error {
func (h *etcdHelper) RecursiveDelete(key string, recursive bool) error {
key = h.prefixEtcdKey(key)
startTime := time.Now()
_, err := h.client.Delete(key, recursive)
@@ -194,7 +194,7 @@ func (h *etcdHelper) WatchList(key string, resourceVersion uint64, filter Filter
}
// Implements StorageInterface.
func (h *etcdHelper) ExtractObj(key string, objPtr runtime.Object, ignoreNotFound bool) error {
func (h *etcdHelper) Get(key string, objPtr runtime.Object, ignoreNotFound bool) error {
key = h.prefixEtcdKey(key)
_, _, _, err := h.bodyAndExtractObj(key, objPtr, ignoreNotFound)
return err
@@ -245,8 +245,8 @@ func (h *etcdHelper) extractObj(response *etcd.Response, inErr error, objPtr run
}
// Implements StorageInterface.
func (h *etcdHelper) ExtractObjToList(key string, listObj runtime.Object) error {
trace := util.NewTrace("ExtractObjToList " + getTypeName(listObj))
func (h *etcdHelper) GetToList(key string, listObj runtime.Object) error {
trace := util.NewTrace("GetToList " + getTypeName(listObj))
listPtr, err := runtime.GetItemsPtr(listObj)
if err != nil {
return err
@@ -319,8 +319,8 @@ func (h *etcdHelper) decodeNodeList(nodes []*etcd.Node, slicePtr interface{}) er
}
// Implements StorageInterface.
func (h *etcdHelper) ExtractToList(key string, listObj runtime.Object) error {
trace := util.NewTrace("ExtractToList " + getTypeName(listObj))
func (h *etcdHelper) List(key string, listObj runtime.Object) error {
trace := util.NewTrace("List " + getTypeName(listObj))
defer trace.LogIfLong(time.Second)
listPtr, err := runtime.GetItemsPtr(listObj)
if err != nil {

View File

@@ -89,7 +89,7 @@ func getEncodedPod(name string) string {
return string(pod)
}
func TestExtractToList(t *testing.T) {
func TestList(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key")
@@ -149,7 +149,7 @@ func TestExtractToList(t *testing.T) {
}
var got api.PodList
err := helper.ExtractToList("/some/key", &got)
err := helper.List("/some/key", &got)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
@@ -158,8 +158,8 @@ func TestExtractToList(t *testing.T) {
}
}
// TestExtractToListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
func TestExtractToListAcrossDirectories(t *testing.T) {
// TestListAcrossDirectories ensures that the client excludes directories and flattens tree-response - simulates cross-namespace query
func TestListAcrossDirectories(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key")
@@ -233,7 +233,7 @@ func TestExtractToListAcrossDirectories(t *testing.T) {
}
var got api.PodList
err := helper.ExtractToList("/some/key", &got)
err := helper.List("/some/key", &got)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
@@ -242,7 +242,7 @@ func TestExtractToListAcrossDirectories(t *testing.T) {
}
}
func TestExtractToListExcludesDirectories(t *testing.T) {
func TestListExcludesDirectories(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key")
@@ -304,7 +304,7 @@ func TestExtractToListExcludesDirectories(t *testing.T) {
}
var got api.PodList
err := helper.ExtractToList("/some/key", &got)
err := helper.List("/some/key", &got)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
@@ -313,7 +313,7 @@ func TestExtractToListExcludesDirectories(t *testing.T) {
}
}
func TestExtractObj(t *testing.T) {
func TestGet(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
key := etcdtest.AddPrefix("/some/key")
@@ -326,7 +326,7 @@ func TestExtractObj(t *testing.T) {
}
fakeClient.Set(key, runtime.EncodeOrDie(testapi.Codec(), &expect), 0)
var got api.Pod
err := helper.ExtractObj("/some/key", &got, false)
err := helper.Get("/some/key", &got, false)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
@@ -335,7 +335,7 @@ func TestExtractObj(t *testing.T) {
}
}
func TestExtractObjNotFoundErr(t *testing.T) {
func TestGetNotFoundErr(t *testing.T) {
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
key1 := etcdtest.AddPrefix("/some/key")
@@ -363,11 +363,11 @@ func TestExtractObjNotFoundErr(t *testing.T) {
}
try := func(key string) {
var got api.Pod
err := helper.ExtractObj(key, &got, false)
err := helper.Get(key, &got, false)
if err == nil {
t.Errorf("%s: wanted error but didn't get one", key)
}
err = helper.ExtractObj(key, &got, true)
err = helper.Get(key, &got, true)
if err != nil {
t.Errorf("%s: didn't want error but got %#v", key, err)
}
@@ -378,12 +378,12 @@ func TestExtractObjNotFoundErr(t *testing.T) {
try("/some/key3")
}
func TestCreateObj(t *testing.T) {
func TestCreate(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{}
err := helper.CreateObj("/some/key", obj, returnedObj, 5)
err := helper.Create("/some/key", obj, returnedObj, 5)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
@@ -404,22 +404,22 @@ func TestCreateObj(t *testing.T) {
}
}
func TestCreateObjNilOutParam(t *testing.T) {
func TestCreateNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
err := helper.CreateObj("/some/key", obj, nil, 5)
err := helper.Create("/some/key", obj, nil, 5)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
}
func TestSetObj(t *testing.T) {
func TestSet(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
returnedObj := &api.Pod{}
err := helper.SetObj("/some/key", obj, returnedObj, 5)
err := helper.Set("/some/key", obj, returnedObj, 5)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}
@@ -441,18 +441,18 @@ func TestSetObj(t *testing.T) {
}
}
func TestSetObjFailCAS(t *testing.T) {
func TestSetFailCAS(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := NewFakeEtcdClient(t)
fakeClient.CasErr = fakeClient.NewError(123)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
err := helper.SetObj("/some/key", obj, nil, 5)
err := helper.Set("/some/key", obj, nil, 5)
if err == nil {
t.Errorf("Expecting error.")
}
}
func TestSetObjWithVersion(t *testing.T) {
func TestSetWithVersion(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo", ResourceVersion: "1"}}
fakeClient := NewFakeEtcdClient(t)
fakeClient.TestIndex = true
@@ -468,7 +468,7 @@ func TestSetObjWithVersion(t *testing.T) {
}
returnedObj := &api.Pod{}
err := helper.SetObj("/some/key", obj, returnedObj, 7)
err := helper.Set("/some/key", obj, returnedObj, 7)
if err != nil {
t.Fatalf("Unexpected error %#v", err)
}
@@ -489,13 +489,13 @@ func TestSetObjWithVersion(t *testing.T) {
}
}
func TestSetObjWithoutResourceVersioner(t *testing.T) {
func TestSetWithoutResourceVersioner(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper.versioner = nil
returnedObj := &api.Pod{}
err := helper.SetObj("/some/key", obj, returnedObj, 3)
err := helper.Set("/some/key", obj, returnedObj, 3)
key := etcdtest.AddPrefix("/some/key")
if err != nil {
t.Errorf("Unexpected error %#v", err)
@@ -517,12 +517,12 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) {
}
}
func TestSetObjNilOutParam(t *testing.T) {
func TestSetNilOutParam(t *testing.T) {
obj := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
fakeClient := NewFakeEtcdClient(t)
helper := newEtcdHelper(fakeClient, testapi.Codec(), etcdtest.PathPrefix())
helper.versioner = nil
err := helper.SetObj("/some/key", obj, nil, 3)
err := helper.Set("/some/key", obj, nil, 3)
if err != nil {
t.Errorf("Unexpected error %#v", err)
}

View File

@@ -99,29 +99,22 @@ type StorageInterface interface {
// Returns StorageVersioner associated with this interface.
Versioner() StorageVersioner
// CreateObj adds a new object at a key unless it already exists. 'ttl' is time-to-live
// Create adds a new object at a key unless it already exists. 'ttl' is time-to-live
// in seconds (0 means forever). If no error is returned and out is not nil, out will be
// set to the read value from etcd.
//
// TODO(wojtekt): Rename to Create().
CreateObj(key string, obj, out runtime.Object, ttl uint64) error
Create(key string, obj, out runtime.Object, ttl uint64) error
// SetObj marshals obj via json and stores in etcd under key. Will do an atomic update
// Set marshals obj via json and stores in etcd under key. Will do an atomic update
// if obj's ResourceVersion field is set. 'ttl' is time-to-live in seconds (0 means forever).
// If no error is returned and out is not nil, out will be set to the read value from etcd.
//
// TODO(wojtekt): Rename to Set() (or Update?).
SetObj(key string, obj, out runtime.Object, ttl uint64) error
Set(key string, obj, out runtime.Object, ttl uint64) error
// DeleteObj removes the specified key and returns the value that existed at that spot.
//
// TODO(wojtekt): Rename to Delete().
DeleteObj(key string, out runtime.Object) error
// Delete removes the specified key and returns the value that existed at that spot.
Delete(key string, out runtime.Object) error
// Delete removes the specified key.
//
// TODO(wojtekt): Unify it with DeleteObj().
Delete(key string, recursive bool) error
// RecursiveDelete removes the specified key.
// TODO: Get rid of this method and use Delete() instead.
RecursiveDelete(key string, recursive bool) error
// Watch begins watching the specified key. Events are decoded into API objects,
// and any items passing 'filter' are sent down to returned watch.Interface.
@@ -135,24 +128,18 @@ type StorageInterface interface {
// (e.g. reconnecting without missing any updates).
WatchList(key string, resourceVersion uint64, filter FilterFunc) (watch.Interface, error)
// ExtractObj unmarshals json found at key into objPtr. On a not found error, will either
// Get unmarshals json found at key into objPtr. On a not found error, will either
// return a zero object of the requested type, or an error, depending on ignoreNotFound.
// Treats empty responses and nil response nodes exactly like a not found error.
//
// TODO(wojtekt): Rename to Get().
ExtractObj(key string, objPtr runtime.Object, ignoreNotFound bool) error
Get(key string, objPtr runtime.Object, ignoreNotFound bool) error
// ExtractObjToList unmarshals json found at key and opaque it into *List api object
// GetToList unmarshals json found at key and opaque it into *List api object
// (an object that satisfies the runtime.IsList definition).
//
// TODO(wojtekt): Rename to GetToList().
ExtractObjToList(key string, listObj runtime.Object) error
GetToList(key string, listObj runtime.Object) error
// ExtractToList unmarshalls jsons found at directory defined by key and opaque them
// List unmarshalls jsons found at directory defined by key and opaque them
// into *List api object (an object that satisfies runtime.IsList definition).
//
// TODO(wojtekt): Rename to List().
ExtractToList(key string, listObj runtime.Object) error
List(key string, listObj runtime.Object) error
// GuaranteedUpdate keeps calling 'tryUpdate()' to update key 'key' (of type 'ptrToType')
// retrying the update until success if there is etcd index conflict.