Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHANGED] Listing Key Value stores and object stores to return status instead of interface #1099

Merged
merged 1 commit into from Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions kv.go
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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_")}
}
}
}()
Expand Down
15 changes: 9 additions & 6 deletions object.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion test/kv_test.go
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion test/object_test.go
Expand Up @@ -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)
}
Expand Down