From e6fe8b505d63cf636d77ee8d8d30fe7b16ed0941 Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Wed, 5 Oct 2022 14:45:55 +0200 Subject: [PATCH] Change listing KVs and object stores to return status --- kv.go | 12 ++++++------ object.go | 15 +++++++++------ test/kv_test.go | 2 +- test/object_test.go | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/kv.go b/kv.go index 735b323e6..4993df98a 100644 --- a/kv.go +++ b/kv.go @@ -37,8 +37,8 @@ type KeyValueManager interface { DeleteKeyValue(bucket string) error // KeyValueStoreNames is used to retrieve a list of key value store names KeyValueStoreNames() <-chan string - // KeyValueStores is used to retrieve a list of key value stores - KeyValueStores() <-chan KeyValue + // KeyValueStores is used to retrieve a list of key value store statuses + KeyValueStores() <-chan KeyValueStatus } // Notice: Experimental Preview @@ -992,9 +992,9 @@ func (js *js) KeyValueStoreNames() <-chan string { return ch } -// KeyValueStores is used to retrieve a list of key value stores -func (js *js) KeyValueStores() <-chan KeyValue { - ch := make(chan KeyValue) +// KeyValueStores is used to retrieve a list of key value store statuses +func (js *js) KeyValueStores() <-chan KeyValueStatus { + ch := make(chan KeyValueStatus) l := &streamLister{js: js} l.js.opts.streamListSubject = fmt.Sprintf(kvSubjectsTmpl, "*") go func() { @@ -1004,7 +1004,7 @@ func (js *js) KeyValueStores() <-chan KeyValue { if !strings.HasPrefix(info.Config.Name, "KV_") { continue } - ch <- mapStreamToKVS(js, info) + ch <- &KeyValueBucketStatus{nfo: info, bucket: strings.TrimPrefix(info.Config.Name, "KV_")} } } }() diff --git a/object.go b/object.go index 0cbb0bcd0..133001fe1 100644 --- a/object.go +++ b/object.go @@ -46,8 +46,8 @@ type ObjectStoreManager interface { DeleteObjectStore(bucket string) error // ObjectStoreNames is used to retrieve a list of bucket names ObjectStoreNames(opts ...ObjectOpt) <-chan string - // ObjectStores is used to retrieve a list of buckets - ObjectStores(opts ...ObjectOpt) <-chan ObjectStore + // ObjectStores is used to retrieve a list of bucket statuses + ObjectStores(opts ...ObjectOpt) <-chan ObjectStoreStatus } // ObjectStore is a blob store capable of storing large objects efficiently in @@ -1314,8 +1314,8 @@ func (js *js) ObjectStoreNames(opts ...ObjectOpt) <-chan string { return ch } -// ObjectStores is used to retrieve a list of buckets -func (js *js) ObjectStores(opts ...ObjectOpt) <-chan ObjectStore { +// ObjectStores is used to retrieve a list of bucket statuses +func (js *js) ObjectStores(opts ...ObjectOpt) <-chan ObjectStoreStatus { var o objOpts for _, opt := range opts { if opt != nil { @@ -1324,7 +1324,7 @@ func (js *js) ObjectStores(opts ...ObjectOpt) <-chan ObjectStore { } } } - ch := make(chan ObjectStore) + ch := make(chan ObjectStoreStatus) var cancel context.CancelFunc if o.ctx == nil { o.ctx, cancel = context.WithTimeout(context.Background(), defaultRequestWait) @@ -1343,7 +1343,10 @@ func (js *js) ObjectStores(opts ...ObjectOpt) <-chan ObjectStore { continue } select { - case ch <- &obs{name: strings.TrimPrefix(info.Config.Name, "OBJ_"), stream: info.Config.Name, js: js}: + case ch <- &ObjectBucketStatus{ + nfo: info, + bucket: strings.TrimPrefix(info.Config.Name, "OBJ_"), + }: case <-o.ctx.Done(): return } diff --git a/test/kv_test.go b/test/kv_test.go index 8531584f6..b7b7e9a5a 100644 --- a/test/kv_test.go +++ b/test/kv_test.go @@ -853,7 +853,7 @@ func TestListKeyValueStores(t *testing.T) { if len(names) != test.bucketsNum { t.Fatalf("Invalid number of stream names; want: %d; got: %d", test.bucketsNum, len(names)) } - infos := make([]nats.KeyValue, 0) + infos := make([]nats.KeyValueStatus, 0) for info := range js.KeyValueStores() { infos = append(infos, info) } diff --git a/test/object_test.go b/test/object_test.go index 20b0f7850..b9a1b30cf 100644 --- a/test/object_test.go +++ b/test/object_test.go @@ -893,7 +893,7 @@ func TestListObjectStores(t *testing.T) { if len(names) != test.bucketsNum { t.Fatalf("Invalid number of stream names; want: %d; got: %d", test.bucketsNum, len(names)) } - infos := make([]nats.ObjectStore, 0) + infos := make([]nats.ObjectStoreStatus, 0) for info := range js.ObjectStores() { infos = append(infos, info) }