Skip to content

Commit

Permalink
Change listing KVs and object stores to return status (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpio committed Oct 12, 2022
1 parent 543e628 commit 7d22790
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
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

0 comments on commit 7d22790

Please sign in to comment.