diff --git a/object.go b/object.go index 13dd7b280..4ac9bdda3 100644 --- a/object.go +++ b/object.go @@ -89,6 +89,8 @@ type ObjectStore interface { // List will list all the objects in this store. List(opts ...WatchOpt) ([]*ObjectInfo, error) + + Status() (*ObjectStoreStatus, error) } type ObjectOpt interface { @@ -132,6 +134,13 @@ type ObjectStoreConfig struct { Replicas int } +// ObjectStoreStatus is the status of the object store +type ObjectStoreStatus struct { + ObjectStoreConfig + Sealed bool + Size uint64 +} + // ObjectMetaOptions type ObjectMetaOptions struct { Link *ObjectLink `json:"link,omitempty"` @@ -857,6 +866,28 @@ func (obs *obs) List(opts ...WatchOpt) ([]*ObjectInfo, error) { return objs, nil } +// Status retrieves run-time status about a bucket +func (obs *obs) Status() (*ObjectStoreStatus, error) { + nfo, err := obs.js.StreamInfo(obs.stream) + if err != nil { + return nil, err + } + + status := &ObjectStoreStatus{ + Sealed: nfo.Config.Sealed, + Size: nfo.State.Bytes, + ObjectStoreConfig: ObjectStoreConfig{ + Bucket: obs.name, + Description: nfo.Config.Description, + TTL: nfo.Config.MaxAge, + Storage: nfo.Config.Storage, + Replicas: nfo.Config.Replicas, + }, + } + + return status, nil +} + // Read impl. func (o *objResult) Read(p []byte) (n int, err error) { o.Lock() diff --git a/test/object_test.go b/test/object_test.go index c1c70684e..7a3984c0d 100644 --- a/test/object_test.go +++ b/test/object_test.go @@ -34,7 +34,7 @@ func TestObjectBasics(t *testing.T) { nc, js := jsClient(t, s) defer nc.Close() - obs, err := js.CreateObjectStore(&nats.ObjectStoreConfig{Bucket: "OBJS"}) + obs, err := js.CreateObjectStore(&nats.ObjectStoreConfig{Bucket: "OBJS", Description: "testing"}) expectOk(t, err) // Create ~16MB object. @@ -67,6 +67,21 @@ func TestObjectBasics(t *testing.T) { t.Fatalf("Expected the object stream to be sealed, got %+v", si) } + status, err := obs.Status() + expectOk(t, err) + if !status.Sealed { + t.Fatalf("exected sealed status") + } + if status.Size == 0 { + t.Fatalf("size is 0") + } + if status.Storage != nats.FileStorage { + t.Fatalf("stauts reports %d storage", status.Storage) + } + if status.Description != "testing" { + t.Fatalf("invalid description: '%s'", status.Description) + } + // Check simple errors. _, err = obs.Get("FOO") expectErr(t, err)