Update layouts package to multistore
parent
0c820ea65b
commit
56d9d4721b
|
@ -1,4 +1,4 @@
|
||||||
package layouts
|
package multistore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,15 +6,15 @@ import (
|
||||||
"github.com/influxdata/chronograf"
|
"github.com/influxdata/chronograf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MultiLayoutsStore is a LayoutsStore that contains multiple LayoutsStores
|
// Layouts is a LayoutsStore that contains multiple LayoutsStores
|
||||||
// The All method will return the set of all Layouts.
|
// The All method will return the set of all Layouts.
|
||||||
// Each method will be tried against the Stores slice serially.
|
// Each method will be tried against the Stores slice serially.
|
||||||
type MultiLayoutsStore struct {
|
type Layouts struct {
|
||||||
Stores []chronograf.LayoutsStore
|
Stores []chronograf.LayoutsStore
|
||||||
}
|
}
|
||||||
|
|
||||||
// All returns the set of all layouts
|
// All returns the set of all layouts
|
||||||
func (s *MultiLayoutsStore) All(ctx context.Context) ([]chronograf.Layout, error) {
|
func (s *Layouts) All(ctx context.Context) ([]chronograf.Layout, error) {
|
||||||
all := []chronograf.Layout{}
|
all := []chronograf.Layout{}
|
||||||
layoutSet := map[string]chronograf.Layout{}
|
layoutSet := map[string]chronograf.Layout{}
|
||||||
ok := false
|
ok := false
|
||||||
|
@ -43,7 +43,7 @@ func (s *MultiLayoutsStore) All(ctx context.Context) ([]chronograf.Layout, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add creates a new dashboard in the LayoutsStore. Tries each store sequentially until success.
|
// Add creates a new dashboard in the LayoutsStore. Tries each store sequentially until success.
|
||||||
func (s *MultiLayoutsStore) Add(ctx context.Context, layout chronograf.Layout) (chronograf.Layout, error) {
|
func (s *Layouts) Add(ctx context.Context, layout chronograf.Layout) (chronograf.Layout, error) {
|
||||||
var err error
|
var err error
|
||||||
for _, store := range s.Stores {
|
for _, store := range s.Stores {
|
||||||
var l chronograf.Layout
|
var l chronograf.Layout
|
||||||
|
@ -57,7 +57,7 @@ func (s *MultiLayoutsStore) Add(ctx context.Context, layout chronograf.Layout) (
|
||||||
|
|
||||||
// Delete the dashboard from the store. Searches through all stores to find Layout and
|
// Delete the dashboard from the store. Searches through all stores to find Layout and
|
||||||
// then deletes from that store.
|
// then deletes from that store.
|
||||||
func (s *MultiLayoutsStore) Delete(ctx context.Context, layout chronograf.Layout) error {
|
func (s *Layouts) Delete(ctx context.Context, layout chronograf.Layout) error {
|
||||||
var err error
|
var err error
|
||||||
for _, store := range s.Stores {
|
for _, store := range s.Stores {
|
||||||
err = store.Delete(ctx, layout)
|
err = store.Delete(ctx, layout)
|
||||||
|
@ -69,7 +69,7 @@ func (s *MultiLayoutsStore) Delete(ctx context.Context, layout chronograf.Layout
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get retrieves Layout if `ID` exists. Searches through each store sequentially until success.
|
// Get retrieves Layout if `ID` exists. Searches through each store sequentially until success.
|
||||||
func (s *MultiLayoutsStore) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
|
func (s *Layouts) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
|
||||||
var err error
|
var err error
|
||||||
for _, store := range s.Stores {
|
for _, store := range s.Stores {
|
||||||
var l chronograf.Layout
|
var l chronograf.Layout
|
||||||
|
@ -82,7 +82,7 @@ func (s *MultiLayoutsStore) Get(ctx context.Context, ID string) (chronograf.Layo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the dashboard in the store. Searches through each store sequentially until success.
|
// Update the dashboard in the store. Searches through each store sequentially until success.
|
||||||
func (s *MultiLayoutsStore) Update(ctx context.Context, layout chronograf.Layout) error {
|
func (s *Layouts) Update(ctx context.Context, layout chronograf.Layout) error {
|
||||||
var err error
|
var err error
|
||||||
for _, store := range s.Stores {
|
for _, store := range s.Stores {
|
||||||
err = store.Update(ctx, layout)
|
err = store.Update(ctx, layout)
|
||||||
|
|
|
@ -3,25 +3,25 @@ package server
|
||||||
import (
|
import (
|
||||||
"github.com/influxdata/chronograf"
|
"github.com/influxdata/chronograf"
|
||||||
"github.com/influxdata/chronograf/canned"
|
"github.com/influxdata/chronograf/canned"
|
||||||
"github.com/influxdata/chronograf/layouts"
|
|
||||||
"github.com/influxdata/chronograf/memdb"
|
"github.com/influxdata/chronograf/memdb"
|
||||||
|
"github.com/influxdata/chronograf/multistore"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LayoutBuilder is responsible for building Layouts
|
// LayoutBuilder is responsible for building Layouts
|
||||||
type LayoutBuilder interface {
|
type LayoutBuilder interface {
|
||||||
Build(chronograf.LayoutsStore) (*layouts.MultiLayoutsStore, error)
|
Build(chronograf.LayoutsStore) (*multistore.Layouts, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MultiLayoutBuilder implements LayoutBuilder and will return a MultiLayoutsStore
|
// MultiLayoutBuilder implements LayoutBuilder and will return a Layouts
|
||||||
type MultiLayoutBuilder struct {
|
type MultiLayoutBuilder struct {
|
||||||
Logger chronograf.Logger
|
Logger chronograf.Logger
|
||||||
UUID chronograf.ID
|
UUID chronograf.ID
|
||||||
CannedPath string
|
CannedPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build will construct a MultiLayoutsStore of canned and db-backed personalized
|
// Build will construct a Layouts of canned and db-backed personalized
|
||||||
// layouts
|
// layouts
|
||||||
func (builder *MultiLayoutBuilder) Build(db chronograf.LayoutsStore) (*layouts.MultiLayoutsStore, error) {
|
func (builder *MultiLayoutBuilder) Build(db chronograf.LayoutsStore) (*multistore.Layouts, error) {
|
||||||
// These apps are those handled from a directory
|
// These apps are those handled from a directory
|
||||||
apps := canned.NewApps(builder.CannedPath, builder.UUID, builder.Logger)
|
apps := canned.NewApps(builder.CannedPath, builder.UUID, builder.Logger)
|
||||||
// These apps are statically compiled into chronograf
|
// These apps are statically compiled into chronograf
|
||||||
|
@ -31,7 +31,7 @@ func (builder *MultiLayoutBuilder) Build(db chronograf.LayoutsStore) (*layouts.M
|
||||||
// Acts as a front-end to both the bolt layouts, filesystem layouts and binary statically compiled layouts.
|
// Acts as a front-end to both the bolt layouts, filesystem layouts and binary statically compiled layouts.
|
||||||
// The idea here is that these stores form a hierarchy in which each is tried sequentially until
|
// The idea here is that these stores form a hierarchy in which each is tried sequentially until
|
||||||
// the operation has success. So, the database is preferred over filesystem over binary data.
|
// the operation has success. So, the database is preferred over filesystem over binary data.
|
||||||
layouts := &layouts.MultiLayoutsStore{
|
layouts := &multistore.Layouts{
|
||||||
Stores: []chronograf.LayoutsStore{
|
Stores: []chronograf.LayoutsStore{
|
||||||
db,
|
db,
|
||||||
apps,
|
apps,
|
||||||
|
|
Loading…
Reference in New Issue