Rename Org field on stores to Organization

Signed-off-by: Michael de Sa <mjdesa@gmail.com>
pull/5028/head
Jared Scheib 2017-10-23 12:08:11 -07:00 committed by Michael de Sa
parent d220fc3e5e
commit ff575f3ca8
6 changed files with 50 additions and 50 deletions

View File

@ -17,9 +17,9 @@ var DashboardBucket = []byte("Dashoard")
// DashboardsStore is the bolt implementation of storing dashboards
type DashboardsStore struct {
client *Client
IDs chronograf.ID
Org string
client *Client
IDs chronograf.ID
Organization string
}
// AddIDs is a migration function that adds ID information to existing dashboards
@ -62,7 +62,7 @@ func (d *DashboardsStore) Migrate(ctx context.Context) error {
func (d *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, error) {
var srcs []chronograf.Dashboard
if err := d.client.db.View(func(tx *bolt.Tx) error {
if err := tx.Bucket(bucket(DashboardBucket, d.Org)).ForEach(func(k, v []byte) error {
if err := tx.Bucket(bucket(DashboardBucket, d.Organization)).ForEach(func(k, v []byte) error {
var src chronograf.Dashboard
if err := internal.UnmarshalDashboard(v, &src); err != nil {
return err
@ -83,7 +83,7 @@ func (d *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, erro
// Add creates a new Dashboard in the DashboardsStore
func (d *DashboardsStore) Add(ctx context.Context, src chronograf.Dashboard) (chronograf.Dashboard, error) {
if err := d.client.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(bucket(DashboardBucket, d.Org))
b := tx.Bucket(bucket(DashboardBucket, d.Organization))
id, _ := b.NextSequence()
src.ID = chronograf.DashboardID(id)
@ -114,7 +114,7 @@ func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (c
var src chronograf.Dashboard
if err := d.client.db.View(func(tx *bolt.Tx) error {
strID := strconv.Itoa(int(id))
if v := tx.Bucket(bucket(DashboardBucket, d.Org)).Get([]byte(strID)); v == nil {
if v := tx.Bucket(bucket(DashboardBucket, d.Organization)).Get([]byte(strID)); v == nil {
return chronograf.ErrDashboardNotFound
} else if err := internal.UnmarshalDashboard(v, &src); err != nil {
return err
@ -131,7 +131,7 @@ func (d *DashboardsStore) Get(ctx context.Context, id chronograf.DashboardID) (c
func (d *DashboardsStore) Delete(ctx context.Context, dash chronograf.Dashboard) error {
if err := d.client.db.Update(func(tx *bolt.Tx) error {
strID := strconv.Itoa(int(dash.ID))
if err := tx.Bucket(bucket(DashboardBucket, d.Org)).Delete([]byte(strID)); err != nil {
if err := tx.Bucket(bucket(DashboardBucket, d.Organization)).Delete([]byte(strID)); err != nil {
return err
}
return nil
@ -146,7 +146,7 @@ func (d *DashboardsStore) Delete(ctx context.Context, dash chronograf.Dashboard)
func (d *DashboardsStore) Update(ctx context.Context, dash chronograf.Dashboard) error {
if err := d.client.db.Update(func(tx *bolt.Tx) error {
// Get an existing dashboard with the same ID.
b := tx.Bucket(bucket(DashboardBucket, d.Org))
b := tx.Bucket(bucket(DashboardBucket, d.Organization))
strID := strconv.Itoa(int(dash.ID))
if v := b.Get([]byte(strID)); v == nil {
return chronograf.ErrDashboardNotFound

View File

@ -16,16 +16,16 @@ var LayoutBucket = []byte("Layout")
// LayoutStore is the bolt implementation to store layouts
type LayoutStore struct {
client *Client
IDs chronograf.ID
Org string
client *Client
IDs chronograf.ID
Organization string
}
// All returns all known layouts
func (s *LayoutStore) All(ctx context.Context) ([]chronograf.Layout, error) {
var srcs []chronograf.Layout
if err := s.client.db.View(func(tx *bolt.Tx) error {
if err := tx.Bucket(bucket(LayoutBucket, s.Org)).ForEach(func(k, v []byte) error {
if err := tx.Bucket(bucket(LayoutBucket, s.Organization)).ForEach(func(k, v []byte) error {
var src chronograf.Layout
if err := internal.UnmarshalLayout(v, &src); err != nil {
return err
@ -47,7 +47,7 @@ func (s *LayoutStore) All(ctx context.Context) ([]chronograf.Layout, error) {
// Add creates a new Layout in the LayoutStore.
func (s *LayoutStore) Add(ctx context.Context, src chronograf.Layout) (chronograf.Layout, error) {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(bucket(LayoutBucket, s.Org))
b := tx.Bucket(bucket(LayoutBucket, s.Organization))
id, err := s.IDs.Generate()
if err != nil {
return err
@ -74,7 +74,7 @@ func (s *LayoutStore) Delete(ctx context.Context, src chronograf.Layout) error {
return err
}
if err := s.client.db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(bucket(LayoutBucket, s.Org)).Delete([]byte(src.ID)); err != nil {
if err := tx.Bucket(bucket(LayoutBucket, s.Organization)).Delete([]byte(src.ID)); err != nil {
return err
}
return nil
@ -89,7 +89,7 @@ func (s *LayoutStore) Delete(ctx context.Context, src chronograf.Layout) error {
func (s *LayoutStore) Get(ctx context.Context, id string) (chronograf.Layout, error) {
var src chronograf.Layout
if err := s.client.db.View(func(tx *bolt.Tx) error {
if v := tx.Bucket(bucket(LayoutBucket, s.Org)).Get([]byte(id)); v == nil {
if v := tx.Bucket(bucket(LayoutBucket, s.Organization)).Get([]byte(id)); v == nil {
return chronograf.ErrLayoutNotFound
} else if err := internal.UnmarshalLayout(v, &src); err != nil {
return err
@ -106,7 +106,7 @@ func (s *LayoutStore) Get(ctx context.Context, id string) (chronograf.Layout, er
func (s *LayoutStore) Update(ctx context.Context, src chronograf.Layout) error {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
// Get an existing layout with the same ID.
b := tx.Bucket(bucket(LayoutBucket, s.Org))
b := tx.Bucket(bucket(LayoutBucket, s.Organization))
if v := b.Get([]byte(src.ID)); v == nil {
return chronograf.ErrLayoutNotFound
}

View File

@ -167,22 +167,22 @@ func (s *OrganizationsStore) get(ctx context.Context, id uint64) (*chronograf.Or
func (s *OrganizationsStore) appendStores(o *chronograf.Organization) {
idStr := strconv.FormatUint(o.ID, 10)
o.SourcesStore = &SourcesStore{
client: s.client,
Org: idStr,
client: s.client,
Organization: idStr,
}
o.ServersStore = &ServersStore{
client: s.client,
Org: idStr,
client: s.client,
Organization: idStr,
}
o.LayoutStore = &LayoutStore{
client: s.client,
Org: idStr,
IDs: &uuid.V4{},
client: s.client,
Organization: idStr,
IDs: &uuid.V4{},
}
o.DashboardsStore = &DashboardsStore{
client: s.client,
Org: idStr,
IDs: &uuid.V4{},
client: s.client,
Organization: idStr,
IDs: &uuid.V4{},
}
}

View File

@ -93,7 +93,7 @@ func TestOrganizationsStore_GetWithName(t *testing.T) {
return
}
if gotOrg, wantOrg := boltSourcesStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltSourcesStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() SourcesStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -103,7 +103,7 @@ func TestOrganizationsStore_GetWithName(t *testing.T) {
return
}
if gotOrg, wantOrg := boltServersStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltServersStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() ServerssStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -113,7 +113,7 @@ func TestOrganizationsStore_GetWithName(t *testing.T) {
return
}
if gotOrg, wantOrg := boltLayoutStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltLayoutStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() LayoutStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -123,7 +123,7 @@ func TestOrganizationsStore_GetWithName(t *testing.T) {
return
}
if gotOrg, wantOrg := boltDashboardsStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltDashboardsStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() DashboardsStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -204,7 +204,7 @@ func TestOrganizationsStore_GetWithID(t *testing.T) {
return
}
if gotOrg, wantOrg := boltSourcesStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltSourcesStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() SourcesStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -214,7 +214,7 @@ func TestOrganizationsStore_GetWithID(t *testing.T) {
return
}
if gotOrg, wantOrg := boltServersStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltServersStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() ServerssStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -224,7 +224,7 @@ func TestOrganizationsStore_GetWithID(t *testing.T) {
return
}
if gotOrg, wantOrg := boltLayoutStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltLayoutStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() LayoutStore.org = %s, want %s", gotOrg, wantOrg)
}
@ -234,7 +234,7 @@ func TestOrganizationsStore_GetWithID(t *testing.T) {
return
}
if gotOrg, wantOrg := boltDashboardsStore.Org, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
if gotOrg, wantOrg := boltDashboardsStore.Organization, strconv.FormatUint(got.ID, 10); gotOrg != wantOrg {
t.Errorf("%q. OrganizationsStore.Get() DashboardsStore.org = %s, want %s", gotOrg, wantOrg)
}
})

View File

@ -17,8 +17,8 @@ var ServersBucket = []byte("Servers")
// ServersStore is the bolt implementation to store servers in a store.
// Used store servers that are associated in some way with a source
type ServersStore struct {
client *Client
Org string
client *Client
Organization string
}
// All returns all known servers
@ -42,7 +42,7 @@ func (s *ServersStore) All(ctx context.Context) ([]chronograf.Server, error) {
// Add creates a new Server in the ServerStore.
func (s *ServersStore) Add(ctx context.Context, src chronograf.Server) (chronograf.Server, error) {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(bucket(ServersBucket, s.Org))
b := tx.Bucket(bucket(ServersBucket, s.Organization))
seq, err := b.NextSequence()
if err != nil {
return err
@ -69,7 +69,7 @@ func (s *ServersStore) Add(ctx context.Context, src chronograf.Server) (chronogr
// Delete removes the Server from the ServersStore
func (s *ServersStore) Delete(ctx context.Context, src chronograf.Server) error {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
if err := tx.Bucket(bucket(ServersBucket, s.Org)).Delete(itob(src.ID)); err != nil {
if err := tx.Bucket(bucket(ServersBucket, s.Organization)).Delete(itob(src.ID)); err != nil {
return err
}
return nil
@ -84,7 +84,7 @@ func (s *ServersStore) Delete(ctx context.Context, src chronograf.Server) error
func (s *ServersStore) Get(ctx context.Context, id int) (chronograf.Server, error) {
var src chronograf.Server
if err := s.client.db.View(func(tx *bolt.Tx) error {
if v := tx.Bucket(bucket(ServersBucket, s.Org)).Get(itob(id)); v == nil {
if v := tx.Bucket(bucket(ServersBucket, s.Organization)).Get(itob(id)); v == nil {
return chronograf.ErrServerNotFound
} else if err := internal.UnmarshalServer(v, &src); err != nil {
return err
@ -101,7 +101,7 @@ func (s *ServersStore) Get(ctx context.Context, id int) (chronograf.Server, erro
func (s *ServersStore) Update(ctx context.Context, src chronograf.Server) error {
if err := s.client.db.Update(func(tx *bolt.Tx) error {
// Get an existing server with the same ID.
b := tx.Bucket(bucket(ServersBucket, s.Org))
b := tx.Bucket(bucket(ServersBucket, s.Organization))
if v := b.Get(itob(src.ID)); v == nil {
return chronograf.ErrServerNotFound
}
@ -126,7 +126,7 @@ func (s *ServersStore) Update(ctx context.Context, src chronograf.Server) error
func (s *ServersStore) all(ctx context.Context, tx *bolt.Tx) ([]chronograf.Server, error) {
var srcs []chronograf.Server
if err := tx.Bucket(bucket(ServersBucket, s.Org)).ForEach(func(k, v []byte) error {
if err := tx.Bucket(bucket(ServersBucket, s.Organization)).ForEach(func(k, v []byte) error {
var src chronograf.Server
if err := internal.UnmarshalServer(v, &src); err != nil {
return err
@ -141,7 +141,7 @@ func (s *ServersStore) all(ctx context.Context, tx *bolt.Tx) ([]chronograf.Serve
// resetActiveServer unsets the Active flag on all sources
func (s *ServersStore) resetActiveServer(ctx context.Context, tx *bolt.Tx) error {
b := tx.Bucket(bucket(ServersBucket, s.Org))
b := tx.Bucket(bucket(ServersBucket, s.Organization))
srcs, err := s.all(ctx, tx)
if err != nil {
return err

View File

@ -16,8 +16,8 @@ var SourcesBucket = []byte("Sources")
// SourcesStore is a bolt implementation to store time-series source information.
type SourcesStore struct {
client *Client
Org string
client *Client
Organization string
}
// All returns all known sources
@ -101,7 +101,7 @@ func (s *SourcesStore) Update(ctx context.Context, src chronograf.Source) error
func (s *SourcesStore) all(ctx context.Context, tx *bolt.Tx) ([]chronograf.Source, error) {
var srcs []chronograf.Source
if err := tx.Bucket(bucket(SourcesBucket, s.Org)).ForEach(func(k, v []byte) error {
if err := tx.Bucket(bucket(SourcesBucket, s.Organization)).ForEach(func(k, v []byte) error {
var src chronograf.Source
if err := internal.UnmarshalSource(v, &src); err != nil {
return err
@ -115,7 +115,7 @@ func (s *SourcesStore) all(ctx context.Context, tx *bolt.Tx) ([]chronograf.Sourc
}
func (s *SourcesStore) add(ctx context.Context, src *chronograf.Source, tx *bolt.Tx) error {
b := tx.Bucket(bucket(SourcesBucket, s.Org))
b := tx.Bucket(bucket(SourcesBucket, s.Organization))
seq, err := b.NextSequence()
if err != nil {
return err
@ -137,7 +137,7 @@ func (s *SourcesStore) add(ctx context.Context, src *chronograf.Source, tx *bolt
}
func (s *SourcesStore) delete(ctx context.Context, src chronograf.Source, tx *bolt.Tx) error {
if err := tx.Bucket(bucket(SourcesBucket, s.Org)).Delete(itob(src.ID)); err != nil {
if err := tx.Bucket(bucket(SourcesBucket, s.Organization)).Delete(itob(src.ID)); err != nil {
return err
}
return nil
@ -145,7 +145,7 @@ func (s *SourcesStore) delete(ctx context.Context, src chronograf.Source, tx *bo
func (s *SourcesStore) get(ctx context.Context, id int, tx *bolt.Tx) (chronograf.Source, error) {
var src chronograf.Source
if v := tx.Bucket(bucket(SourcesBucket, s.Org)).Get(itob(id)); v == nil {
if v := tx.Bucket(bucket(SourcesBucket, s.Organization)).Get(itob(id)); v == nil {
return src, chronograf.ErrSourceNotFound
} else if err := internal.UnmarshalSource(v, &src); err != nil {
return src, err
@ -155,7 +155,7 @@ func (s *SourcesStore) get(ctx context.Context, id int, tx *bolt.Tx) (chronograf
func (s *SourcesStore) update(ctx context.Context, src chronograf.Source, tx *bolt.Tx) error {
// Get an existing soource with the same ID.
b := tx.Bucket(bucket(SourcesBucket, s.Org))
b := tx.Bucket(bucket(SourcesBucket, s.Organization))
if v := b.Get(itob(src.ID)); v == nil {
return chronograf.ErrSourceNotFound
}
@ -176,7 +176,7 @@ func (s *SourcesStore) update(ctx context.Context, src chronograf.Source, tx *bo
// resetDefaultSource unsets the Default flag on all sources
func (s *SourcesStore) resetDefaultSource(ctx context.Context, tx *bolt.Tx) error {
b := tx.Bucket(bucket(SourcesBucket, s.Org))
b := tx.Bucket(bucket(SourcesBucket, s.Organization))
srcs, err := s.all(ctx, tx)
if err != nil {
return err