Skip to content

Commit

Permalink
function accessors for object status
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <rip@devco.net>
  • Loading branch information
ripienaar committed Oct 12, 2021
1 parent 92b850d commit 06dea7f
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions object.go
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/nats-io/nuid"
)

// ObjectStoreManager creates, loads and deletes Object Stores
//
// Notice: Experimental Preview
//
// This functionality is EXPERIMENTAL and may be changed in later releases.
Expand All @@ -43,6 +45,9 @@ type ObjectStoreManager interface {
DeleteObjectStore(bucket string) error
}

// ObjectStore is a blob store capable of storing large objects efficiently in
// JetStream streams
//
// Notice: Experimental Preview
//
// This functionality is EXPERIMENTAL and may be changed in later releases.
Expand Down Expand Up @@ -91,7 +96,7 @@ type ObjectStore interface {
List(opts ...WatchOpt) ([]*ObjectInfo, error)

// Status retrieves run-time status about the backing store of the bucket.
Status() (*ObjectStoreStatus, error)
Status() (ObjectStoreStatus, error)
}

type ObjectOpt interface {
Expand Down Expand Up @@ -141,16 +146,23 @@ type BackingStore interface {
Info() map[string]string
}

// ObjectStoreStatus is the status of the object store
type ObjectStoreStatus struct {
Bucket string
Description string
TTL time.Duration
Storage StorageType
Replicas int
Sealed bool
Size uint64
BackingStore BackingStore
type ObjectStoreStatus interface {
// Bucket is the name of the bucket
Bucket() string
// Description is the description supplied when creating the bucket
Description() string
// TTL indicates how long objects are kept in the bucket
TTL() time.Duration
// Storage indicates the underlying JetStream storage technology used to store data
Storage() StorageType
// Replicas indicates how many storage replicas are kept for the data in the bucket
Replicas() int
// Sealed indicates the stream is sealed and cannot be modified in any way
Sealed() bool
// Size is the combined size of all data in the bucket including metadata, in bytes
Size() uint64
// BackingStore provides details about the underlying storage
BackingStore() BackingStore
}

// ObjectMetaOptions
Expand Down Expand Up @@ -885,8 +897,23 @@ type objBackingStore struct {
func (b *objBackingStore) Kind() string { return "JetStream" }
func (b *objBackingStore) Info() map[string]string { return b.info }

type objStatus struct {
nfo *StreamInfo
bucket string
bs BackingStore
}

func (s *objStatus) Bucket() string { return s.bucket }
func (s *objStatus) Description() string { return s.nfo.Config.Description }
func (s *objStatus) TTL() time.Duration { return s.nfo.Config.MaxAge }
func (s *objStatus) Storage() StorageType { return s.nfo.Config.Storage }
func (s *objStatus) Replicas() int { return s.nfo.Config.Replicas }
func (s *objStatus) Sealed() bool { return s.nfo.Config.Sealed }
func (s *objStatus) Size() uint64 { return s.nfo.State.Bytes }
func (s *objStatus) BackingStore() BackingStore { return s.bs }

// Status retrieves run-time status about a bucket
func (obs *obs) Status() (*ObjectStoreStatus, error) {
func (obs *obs) Status() (ObjectStoreStatus, error) {
nfo, err := obs.js.StreamInfo(obs.stream)
if err != nil {
return nil, err
Expand All @@ -903,15 +930,10 @@ func (obs *obs) Status() (*ObjectStoreStatus, error) {
bs.info["placement_cluster"] = nfo.Cluster.Name
}

status := &ObjectStoreStatus{
Sealed: nfo.Config.Sealed,
Size: nfo.State.Bytes,
Bucket: obs.name,
Description: nfo.Config.Description,
TTL: nfo.Config.MaxAge,
Storage: nfo.Config.Storage,
Replicas: nfo.Config.Replicas,
BackingStore: bs,
status := &objStatus{
nfo: nfo,
bucket: obs.name,
bs: bs,
}

return status, nil
Expand Down

0 comments on commit 06dea7f

Please sign in to comment.