From 21ec6cd72f6dc666a28650cb4cd8e661c486038e Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Wed, 5 Oct 2016 23:26:39 -0500 Subject: [PATCH 1/5] Add layouts endpoint and storage --- bolt/client.go | 7 + bolt/internal/internal.go | 64 ++++++- bolt/internal/internal.pb.go | 102 ++++++++--- bolt/internal/internal.proto | 59 ++++--- bolt/layouts.go | 116 +++++++++++++ errors.go | 1 + handlers/layout.go | 158 ++++++++++++++++++ handlers/store.go | 1 + mock/handlers.go | 7 +- models/cell.go | 106 ++++++++++-- models/dashboards.go | 61 ------- models/{dashboard.go => layout.go} | 14 +- models/layouts.go | 64 +++++++ models/routes.go | 8 +- restapi/configure_mr_fusion.go | 27 +-- restapi/operations/delete_dashboards_id.go | 55 ------ .../delete_dashboards_id_responses.go | 122 -------------- restapi/operations/delete_layouts_id.go | 55 ++++++ ...ers.go => delete_layouts_id_parameters.go} | 18 +- .../operations/delete_layouts_id_responses.go | 122 ++++++++++++++ restapi/operations/get_dashboards.go | 58 ------- restapi/operations/get_dashboards_id.go | 58 ------- .../operations/get_dashboards_id_responses.go | 141 ---------------- .../operations/get_dashboards_parameters.go | 40 ----- .../operations/get_dashboards_responses.go | 104 ------------ restapi/operations/get_layouts.go | 58 +++++++ restapi/operations/get_layouts_id.go | 58 +++++++ ...meters.go => get_layouts_id_parameters.go} | 18 +- .../operations/get_layouts_id_responses.go | 141 ++++++++++++++++ restapi/operations/get_layouts_parameters.go | 92 ++++++++++ restapi/operations/get_layouts_responses.go | 104 ++++++++++++ .../operations/get_sources_id_responses.go | 2 +- restapi/operations/mr_fusion_api.go | 50 +++--- restapi/operations/post_dashboards.go | 55 ------ .../operations/post_dashboards_responses.go | 123 -------------- restapi/operations/post_layouts.go | 55 ++++++ ...rameters.go => post_layouts_parameters.go} | 24 +-- restapi/operations/post_layouts_responses.go | 123 ++++++++++++++ restapi/operations/put_dashboards_id.go | 55 ------ .../operations/put_dashboards_id_responses.go | 122 -------------- restapi/operations/put_layouts_id.go | 55 ++++++ ...meters.go => put_layouts_id_parameters.go} | 24 +-- .../operations/put_layouts_id_responses.go | 141 ++++++++++++++++ stores.go | 22 +-- swagger.yaml | 106 +++++++----- 45 files changed, 1784 insertions(+), 1212 deletions(-) create mode 100644 bolt/layouts.go create mode 100644 handlers/layout.go delete mode 100644 models/dashboards.go rename models/{dashboard.go => layout.go} (80%) create mode 100644 models/layouts.go delete mode 100644 restapi/operations/delete_dashboards_id.go delete mode 100644 restapi/operations/delete_dashboards_id_responses.go create mode 100644 restapi/operations/delete_layouts_id.go rename restapi/operations/{get_dashboards_id_parameters.go => delete_layouts_id_parameters.go} (70%) create mode 100644 restapi/operations/delete_layouts_id_responses.go delete mode 100644 restapi/operations/get_dashboards.go delete mode 100644 restapi/operations/get_dashboards_id.go delete mode 100644 restapi/operations/get_dashboards_id_responses.go delete mode 100644 restapi/operations/get_dashboards_parameters.go delete mode 100644 restapi/operations/get_dashboards_responses.go create mode 100644 restapi/operations/get_layouts.go create mode 100644 restapi/operations/get_layouts_id.go rename restapi/operations/{delete_dashboards_id_parameters.go => get_layouts_id_parameters.go} (64%) create mode 100644 restapi/operations/get_layouts_id_responses.go create mode 100644 restapi/operations/get_layouts_parameters.go create mode 100644 restapi/operations/get_layouts_responses.go delete mode 100644 restapi/operations/post_dashboards.go delete mode 100644 restapi/operations/post_dashboards_responses.go create mode 100644 restapi/operations/post_layouts.go rename restapi/operations/{post_dashboards_parameters.go => post_layouts_parameters.go} (62%) create mode 100644 restapi/operations/post_layouts_responses.go delete mode 100644 restapi/operations/put_dashboards_id.go delete mode 100644 restapi/operations/put_dashboards_id_responses.go create mode 100644 restapi/operations/put_layouts_id.go rename restapi/operations/{put_dashboards_id_parameters.go => put_layouts_id_parameters.go} (72%) create mode 100644 restapi/operations/put_layouts_id_responses.go diff --git a/bolt/client.go b/bolt/client.go index b82a504529..407ab37cc8 100644 --- a/bolt/client.go +++ b/bolt/client.go @@ -15,6 +15,7 @@ type Client struct { ExplorationStore *ExplorationStore SourcesStore *SourcesStore ServersStore *ServersStore + LayoutStore *LayoutStore } func NewClient() *Client { @@ -22,6 +23,7 @@ func NewClient() *Client { c.ExplorationStore = &ExplorationStore{client: c} c.SourcesStore = &SourcesStore{client: c} c.ServersStore = &ServersStore{client: c} + c.LayoutStore = &LayoutStore{client: c} return c } @@ -47,6 +49,10 @@ func (c *Client) Open() error { if _, err := tx.CreateBucketIfNotExists(ServersBucket); err != nil { return err } + // Always create Layouts bucket. + if _, err := tx.CreateBucketIfNotExists(LayoutBucket); err != nil { + return err + } return nil }); err != nil { @@ -56,6 +62,7 @@ func (c *Client) Open() error { c.ExplorationStore = &ExplorationStore{client: c} c.SourcesStore = &SourcesStore{client: c} c.ServersStore = &ServersStore{client: c} + c.LayoutStore = &LayoutStore{client: c} return nil } diff --git a/bolt/internal/internal.go b/bolt/internal/internal.go index 1910dd19e9..27eafde1f7 100644 --- a/bolt/internal/internal.go +++ b/bolt/internal/internal.go @@ -40,7 +40,7 @@ func UnmarshalExploration(data []byte, e *mrfusion.Exploration) error { return nil } -// MarshalSource encodes an source to binary protobuf format. +// MarshalSource encodes a source to binary protobuf format. func MarshalSource(s mrfusion.Source) ([]byte, error) { return proto.Marshal(&Source{ ID: int64(s.ID), @@ -53,7 +53,7 @@ func MarshalSource(s mrfusion.Source) ([]byte, error) { }) } -// UnmarshalSource decodes an source from binary protobuf data. +// UnmarshalSource decodes a source from binary protobuf data. func UnmarshalSource(data []byte, s *mrfusion.Source) error { var pb Source if err := proto.Unmarshal(data, &pb); err != nil { @@ -70,7 +70,7 @@ func UnmarshalSource(data []byte, s *mrfusion.Source) error { return nil } -// MarshalServer encodes an source to binary protobuf format. +// MarshalServer encodes a server to binary protobuf format. func MarshalServer(s mrfusion.Server) ([]byte, error) { return proto.Marshal(&Server{ ID: int64(s.ID), @@ -82,7 +82,7 @@ func MarshalServer(s mrfusion.Server) ([]byte, error) { }) } -// UnmarshalServer decodes an source from binary protobuf data. +// UnmarshalServer decodes a server from binary protobuf data. func UnmarshalServer(data []byte, s *mrfusion.Server) error { var pb Server if err := proto.Unmarshal(data, &pb); err != nil { @@ -97,3 +97,59 @@ func UnmarshalServer(data []byte, s *mrfusion.Server) error { s.URL = pb.URL return nil } + +// MarshalLayout encodes a layout to binary protobuf format. +func MarshalLayout(l mrfusion.Layout) ([]byte, error) { + cells := make([]*Cell, len(l.Cells)) + for i, c := range l.Cells { + queries := make([]*Query, len(c.Queries)) + for j, q := range c.Queries { + queries[j] = &Query{ + Command: q.Command, + DB: q.DB, + RP: q.RP, + } + } + cells[i] = &Cell{ + X: c.X, + Y: c.Y, + W: c.W, + H: c.H, + Queries: queries, + } + } + return proto.Marshal(&Layout{ + ID: int64(l.ID), + Cells: cells, + }) +} + +// UnmarshalLayout decodes a layout from binary protobuf data. +func UnmarshalLayout(data []byte, l *mrfusion.Layout) error { + var pb Layout + if err := proto.Unmarshal(data, &pb); err != nil { + return err + } + + l.ID = int(pb.ID) + cells := make([]mrfusion.Cell, len(pb.Cells)) + for i, c := range pb.Cells { + queries := make([]mrfusion.Query, len(c.Queries)) + for j, q := range c.Queries { + queries[j] = mrfusion.Query{ + Command: q.Command, + DB: q.DB, + RP: q.RP, + } + } + cells[i] = mrfusion.Cell{ + X: c.X, + Y: c.Y, + W: c.W, + H: c.H, + Queries: queries, + } + } + l.Cells = cells + return nil +} diff --git a/bolt/internal/internal.pb.go b/bolt/internal/internal.pb.go index 665c0a040e..ce53767abd 100644 --- a/bolt/internal/internal.pb.go +++ b/bolt/internal/internal.pb.go @@ -12,6 +12,9 @@ It has these top-level messages: Exploration Source Server + Layout + Cell + Query */ package internal @@ -74,33 +77,92 @@ func (m *Server) String() string { return proto.CompactTextString(m) func (*Server) ProtoMessage() {} func (*Server) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{2} } +type Layout struct { + ID int64 `protobuf:"varint,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` + Cells []*Cell `protobuf:"bytes,2,rep,name=Cells,json=cells" json:"Cells,omitempty"` +} + +func (m *Layout) Reset() { *m = Layout{} } +func (m *Layout) String() string { return proto.CompactTextString(m) } +func (*Layout) ProtoMessage() {} +func (*Layout) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{3} } + +func (m *Layout) GetCells() []*Cell { + if m != nil { + return m.Cells + } + return nil +} + +type Cell struct { + X int32 `protobuf:"varint,1,opt,name=x,proto3" json:"x,omitempty"` + Y int32 `protobuf:"varint,2,opt,name=y,proto3" json:"y,omitempty"` + W int32 `protobuf:"varint,3,opt,name=w,proto3" json:"w,omitempty"` + H int32 `protobuf:"varint,4,opt,name=h,proto3" json:"h,omitempty"` + Queries []*Query `protobuf:"bytes,5,rep,name=queries" json:"queries,omitempty"` +} + +func (m *Cell) Reset() { *m = Cell{} } +func (m *Cell) String() string { return proto.CompactTextString(m) } +func (*Cell) ProtoMessage() {} +func (*Cell) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{4} } + +func (m *Cell) GetQueries() []*Query { + if m != nil { + return m.Queries + } + return nil +} + +type Query struct { + Command string `protobuf:"bytes,1,opt,name=Command,json=command,proto3" json:"Command,omitempty"` + DB string `protobuf:"bytes,2,opt,name=DB,json=dB,proto3" json:"DB,omitempty"` + RP string `protobuf:"bytes,3,opt,name=RP,json=rP,proto3" json:"RP,omitempty"` +} + +func (m *Query) Reset() { *m = Query{} } +func (m *Query) String() string { return proto.CompactTextString(m) } +func (*Query) ProtoMessage() {} +func (*Query) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{5} } + func init() { proto.RegisterType((*Exploration)(nil), "internal.Exploration") proto.RegisterType((*Source)(nil), "internal.Source") proto.RegisterType((*Server)(nil), "internal.Server") + proto.RegisterType((*Layout)(nil), "internal.Layout") + proto.RegisterType((*Cell)(nil), "internal.Cell") + proto.RegisterType((*Query)(nil), "internal.Query") } func init() { proto.RegisterFile("internal.proto", fileDescriptorInternal) } var fileDescriptorInternal = []byte{ - // 299 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x4a, 0x33, 0x31, - 0x14, 0x86, 0x99, 0x4e, 0x9a, 0xce, 0x9c, 0x0f, 0xca, 0x47, 0x10, 0x09, 0xe2, 0x62, 0xe8, 0xaa, - 0x2b, 0x37, 0x5e, 0x81, 0x18, 0x17, 0x85, 0x41, 0x24, 0x75, 0x2e, 0x20, 0x76, 0x8e, 0x50, 0x68, - 0x27, 0x21, 0x3f, 0x6a, 0xef, 0xc1, 0xeb, 0xf0, 0x06, 0xbc, 0x41, 0x49, 0x9a, 0x01, 0x71, 0x51, - 0xba, 0x7c, 0xce, 0xfb, 0x72, 0x78, 0x92, 0x03, 0xf3, 0xed, 0xe0, 0xd1, 0x0e, 0x6a, 0x77, 0x63, - 0xac, 0xf6, 0x9a, 0x55, 0x23, 0x2f, 0xbe, 0x0b, 0xf8, 0xf7, 0xf0, 0x61, 0x76, 0xda, 0x2a, 0xbf, - 0xd5, 0x03, 0x9b, 0xc3, 0x64, 0x25, 0x78, 0xd1, 0x14, 0xcb, 0x52, 0x4e, 0xb6, 0x82, 0x31, 0x20, - 0x8f, 0x6a, 0x8f, 0x7c, 0xd2, 0x14, 0xcb, 0x5a, 0x92, 0x41, 0xed, 0x91, 0x5d, 0x02, 0xed, 0x1c, - 0xda, 0x95, 0xe0, 0x65, 0xea, 0xd1, 0x90, 0x28, 0x76, 0x85, 0xf2, 0x8a, 0x93, 0x63, 0xb7, 0x57, - 0x5e, 0xb1, 0x6b, 0xa8, 0xef, 0x2d, 0x2a, 0x8f, 0xfd, 0x9d, 0xe7, 0xd3, 0x54, 0xaf, 0x37, 0xe3, - 0x20, 0xa6, 0x9d, 0xe9, 0x73, 0x4a, 0x8f, 0x69, 0x18, 0x07, 0x8c, 0xc3, 0x4c, 0xe0, 0xab, 0x0a, - 0x3b, 0xcf, 0x67, 0x4d, 0xb1, 0xac, 0xe4, 0xac, 0x3f, 0xe2, 0xe2, 0xab, 0x00, 0xba, 0xd6, 0xc1, - 0x6e, 0xf0, 0x2c, 0x61, 0x06, 0xe4, 0xf9, 0x60, 0x30, 0xe9, 0xd6, 0x92, 0xf8, 0x83, 0x41, 0x76, - 0x05, 0x55, 0x7c, 0x44, 0xcc, 0xb3, 0x70, 0x15, 0x32, 0xc7, 0xec, 0x49, 0x39, 0xf7, 0xae, 0x6d, - 0x9f, 0x9c, 0x6b, 0x59, 0x99, 0xcc, 0x71, 0x57, 0x27, 0x5b, 0xc7, 0x69, 0x53, 0xc6, 0x5d, 0x41, - 0xb6, 0xee, 0x84, 0xe8, 0x67, 0x14, 0x45, 0xfb, 0x86, 0xf6, 0x2c, 0xd1, 0xdf, 0x52, 0xe5, 0x09, - 0x29, 0xf2, 0x47, 0xea, 0x3f, 0x94, 0x9d, 0x6c, 0xb3, 0x6b, 0x19, 0x64, 0xcb, 0x2e, 0x60, 0xba, - 0xb6, 0x9b, 0x95, 0xc8, 0xbf, 0x3a, 0x75, 0x11, 0x5e, 0x68, 0x3a, 0xff, 0xed, 0x4f, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xd9, 0x74, 0xaa, 0x1f, 0x10, 0x02, 0x00, 0x00, + // 423 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x8a, 0xd4, 0x4e, + 0x10, 0xc7, 0xe9, 0x24, 0x9d, 0x3f, 0xb5, 0x3f, 0xe6, 0x27, 0x8d, 0x48, 0x23, 0x1e, 0x42, 0xf0, + 0x30, 0x5e, 0xf6, 0xa0, 0x77, 0x61, 0x77, 0xe2, 0x61, 0x20, 0xc8, 0x58, 0xeb, 0x3c, 0x40, 0x9b, + 0xb4, 0x6c, 0x20, 0x93, 0xc4, 0x4e, 0xb7, 0x33, 0x79, 0x07, 0x9f, 0xc3, 0x17, 0xf0, 0x05, 0xa5, + 0x7a, 0x32, 0x2a, 0x0a, 0xcb, 0x1e, 0x3f, 0xf5, 0xad, 0xa4, 0x3e, 0x55, 0x34, 0xac, 0xda, 0xde, + 0x6a, 0xd3, 0xab, 0xee, 0x7a, 0x34, 0x83, 0x1d, 0x44, 0x7a, 0xe1, 0xe2, 0x07, 0x83, 0xab, 0x77, + 0xa7, 0xb1, 0x1b, 0x8c, 0xb2, 0xed, 0xd0, 0x8b, 0x15, 0x04, 0xdb, 0x52, 0xb2, 0x9c, 0xad, 0x43, + 0x0c, 0xda, 0x52, 0x08, 0x88, 0xde, 0xab, 0x83, 0x96, 0x41, 0xce, 0xd6, 0x19, 0x46, 0xbd, 0x3a, + 0x68, 0xf1, 0x0c, 0xe2, 0xfd, 0xa4, 0xcd, 0xb6, 0x94, 0xa1, 0xef, 0x8b, 0x9d, 0x27, 0xea, 0x2d, + 0x95, 0x55, 0x32, 0x3a, 0xf7, 0x36, 0xca, 0x2a, 0xf1, 0x02, 0xb2, 0x8d, 0xd1, 0xca, 0xea, 0xe6, + 0xc6, 0x4a, 0xee, 0xdb, 0xb3, 0xfa, 0x52, 0xa0, 0x74, 0x3f, 0x36, 0x4b, 0x1a, 0x9f, 0x53, 0x77, + 0x29, 0x08, 0x09, 0x49, 0xa9, 0x3f, 0x2b, 0xd7, 0x59, 0x99, 0xe4, 0x6c, 0x9d, 0x62, 0xd2, 0x9c, + 0xb1, 0xf8, 0xce, 0x20, 0xbe, 0x1b, 0x9c, 0xa9, 0xf5, 0xa3, 0x84, 0x05, 0x44, 0x1f, 0xe7, 0x51, + 0x7b, 0xdd, 0x0c, 0x23, 0x3b, 0x8f, 0x5a, 0x3c, 0x87, 0x94, 0x96, 0xa0, 0x7c, 0x11, 0x4e, 0xdd, + 0xc2, 0x94, 0xed, 0xd4, 0x34, 0x1d, 0x07, 0xd3, 0x78, 0xe7, 0x0c, 0xd3, 0x71, 0x61, 0xfa, 0xd7, + 0x1e, 0xab, 0x49, 0xc6, 0x79, 0x48, 0xff, 0x72, 0x58, 0x4d, 0x0f, 0x88, 0x7e, 0x23, 0x51, 0x6d, + 0xbe, 0x6a, 0xf3, 0x28, 0xd1, 0x3f, 0xa5, 0xc2, 0x07, 0xa4, 0xa2, 0xbf, 0xa4, 0x9e, 0x40, 0xb8, + 0xc7, 0x6a, 0x71, 0x0d, 0x1d, 0x56, 0xe2, 0x29, 0xf0, 0x3b, 0x53, 0x6f, 0xcb, 0xe5, 0xaa, 0x7c, + 0x22, 0x28, 0xde, 0x42, 0x5c, 0xa9, 0x79, 0x70, 0xf6, 0x1f, 0x9b, 0x97, 0xc0, 0x37, 0xba, 0xeb, + 0x26, 0x19, 0xe4, 0xe1, 0xfa, 0xea, 0xf5, 0xea, 0xfa, 0xd7, 0x8b, 0xa1, 0x32, 0xf2, 0x9a, 0xc2, + 0xa2, 0x85, 0x88, 0x50, 0xfc, 0x07, 0xec, 0xe4, 0x3f, 0xe6, 0xc8, 0x4e, 0x44, 0xb3, 0x5f, 0x83, + 0x23, 0x9b, 0x89, 0x8e, 0x5e, 0x9e, 0x23, 0x3b, 0x12, 0xdd, 0x7b, 0x5d, 0x8e, 0xec, 0x5e, 0xbc, + 0x82, 0xe4, 0x8b, 0xd3, 0xa6, 0xd5, 0x93, 0xe4, 0x7e, 0xce, 0xff, 0xbf, 0xe7, 0x7c, 0x70, 0xda, + 0xcc, 0x78, 0xc9, 0x8b, 0x1b, 0xe0, 0xbe, 0x42, 0xc7, 0xdd, 0x0c, 0x87, 0x83, 0xea, 0x1b, 0x3f, + 0x31, 0xc3, 0xa4, 0x3e, 0x23, 0xed, 0x50, 0xde, 0x2e, 0xf7, 0x0b, 0x9a, 0x5b, 0x62, 0xdc, 0x2d, + 0x77, 0x0b, 0xcc, 0xee, 0x53, 0xec, 0x1f, 0xfb, 0x9b, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbb, + 0xaf, 0x1c, 0x0c, 0xfe, 0x02, 0x00, 0x00, } diff --git a/bolt/internal/internal.proto b/bolt/internal/internal.proto index bbaa9b465f..4b3e2059cb 100644 --- a/bolt/internal/internal.proto +++ b/bolt/internal/internal.proto @@ -2,30 +2,49 @@ syntax = "proto3"; package internal; message Exploration { - int64 ID = 1; // ExplorationID is a unique ID for an Exploration. - string Name = 2; // User provided name of the Exploration. - int64 UserID = 3; // UserID is the owner of this Exploration. - string Data = 4; // Opaque blob of JSON data. - int64 CreatedAt = 5; // Time the exploration was first created. - int64 UpdatedAt = 6; // Latest time the exploration was updated. - bool Default = 7; // Flags an exploration as the default. + int64 ID = 1; // ExplorationID is a unique ID for an Exploration. + string Name = 2; // User provided name of the Exploration. + int64 UserID = 3; // UserID is the owner of this Exploration. + string Data = 4; // Opaque blob of JSON data. + int64 CreatedAt = 5; // Time the exploration was first created. + int64 UpdatedAt = 6; // Latest time the exploration was updated. + bool Default = 7; // Flags an exploration as the default. } message Source { - int64 ID = 1; // ID is the unique ID of the source - string Name = 2; // Name is the user-defined name for the source - string Type = 3; // Type specifies which kinds of source (enterprise vs oss) - string Username = 4; // Username is the username to connect to the source - string Password = 5; - repeated string URLs = 6; // URL are the connections to the source - bool Default = 7; // Flags an exploration as the default. + int64 ID = 1; // ID is the unique ID of the source + string Name = 2; // Name is the user-defined name for the source + string Type = 3; // Type specifies which kinds of source (enterprise vs oss) + string Username = 4; // Username is the username to connect to the source + string Password = 5; + repeated string URLs = 6; // URL are the connections to the source + bool Default = 7; // Flags an exploration as the default. } message Server { - int64 ID = 1; // ID is the unique ID of the server - string Name = 2; // Name is the user-defined name for the server - string Username = 3; // Username is the username to connect to the server - string Password = 4; - string URL = 5; // URL is the path to the server - int64 SrcID = 6; // SrcID is the ID of the data source + int64 ID = 1; // ID is the unique ID of the server + string Name = 2; // Name is the user-defined name for the server + string Username = 3; // Username is the username to connect to the server + string Password = 4; + string URL = 5; // URL is the path to the server + int64 SrcID = 6; // SrcID is the ID of the data source +} + +message Layout { + int64 ID = 1; // ID is the unique ID of the layout + repeated Cell Cells = 2; // Cells are the individual visualization elements. +} + +message Cell { + int32 x = 1; // X-coordinate of Cell in the Layout + int32 y = 2; // Y-coordinate of Cell in the Layout + int32 w = 3; // Width of Cell in the Layout + int32 h = 4; // Height of Cell in the Layout + repeated Query queries = 5; // Time-series data queries for Cell. +} + +message Query { + string Command = 1; // Command is the query itself + string DB = 2; // DB the database for the query (optional) + string RP = 3; // RP is a retention policy and optional; } diff --git a/bolt/layouts.go b/bolt/layouts.go new file mode 100644 index 0000000000..8be79afff2 --- /dev/null +++ b/bolt/layouts.go @@ -0,0 +1,116 @@ +package bolt + +import ( + "github.com/boltdb/bolt" + "github.com/influxdata/mrfusion" + "github.com/influxdata/mrfusion/bolt/internal" + "golang.org/x/net/context" +) + +// Ensure LayoutStore implements mrfusion.LayoutStore. +var _ mrfusion.LayoutStore = &LayoutStore{} + +var LayoutBucket = []byte("Layout") + +type LayoutStore struct { + client *Client +} + +// All returns all known layouts +func (s *LayoutStore) All(ctx context.Context) ([]mrfusion.Layout, error) { + var srcs []mrfusion.Layout + if err := s.client.db.View(func(tx *bolt.Tx) error { + if err := tx.Bucket(LayoutBucket).ForEach(func(k, v []byte) error { + var src mrfusion.Layout + if err := internal.UnmarshalLayout(v, &src); err != nil { + return err + } + srcs = append(srcs, src) + return nil + }); err != nil { + return err + } + return nil + }); err != nil { + return nil, err + } + + return srcs, nil + +} + +// Add creates a new Layout in the LayoutStore. +func (s *LayoutStore) Add(ctx context.Context, src mrfusion.Layout) (mrfusion.Layout, error) { + if err := s.client.db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket(LayoutBucket) + seq, err := b.NextSequence() + if err != nil { + return err + } + src.ID = int(seq) + + if v, err := internal.MarshalLayout(src); err != nil { + return err + } else if err := b.Put(itob(src.ID), v); err != nil { + return err + } + return nil + }); err != nil { + return mrfusion.Layout{}, err + } + + return src, nil +} + +// Delete removes the Layout from the LayoutStore +func (s *LayoutStore) Delete(ctx context.Context, src mrfusion.Layout) error { + if err := s.client.db.Update(func(tx *bolt.Tx) error { + if err := tx.Bucket(LayoutBucket).Delete(itob(src.ID)); err != nil { + return err + } + return nil + }); err != nil { + return err + } + + return nil +} + +// Get returns a Layout if the id exists. +func (s *LayoutStore) Get(ctx context.Context, id int) (mrfusion.Layout, error) { + var src mrfusion.Layout + if err := s.client.db.View(func(tx *bolt.Tx) error { + if v := tx.Bucket(LayoutBucket).Get(itob(id)); v == nil { + return mrfusion.ErrLayoutNotFound + } else if err := internal.UnmarshalLayout(v, &src); err != nil { + return err + } + return nil + }); err != nil { + return mrfusion.Layout{}, err + } + + return src, nil +} + +// Update a Layout +func (s *LayoutStore) Update(ctx context.Context, src mrfusion.Layout) error { + if err := s.client.db.Update(func(tx *bolt.Tx) error { + // Get an existing layout with the same ID. + b := tx.Bucket(LayoutBucket) + if v := b.Get(itob(src.ID)); v == nil { + return mrfusion.ErrLayoutNotFound + } + + if v, err := internal.MarshalLayout(src); err != nil { + return err + } else if err := b.Put(itob(src.ID), v); err != nil { + return err + } + return nil + }); err != nil { + return err + } + + return nil +} diff --git a/errors.go b/errors.go index 61cd6f5dc8..05de805327 100644 --- a/errors.go +++ b/errors.go @@ -6,6 +6,7 @@ const ( ErrExplorationNotFound = Error("exploration not found") ErrSourceNotFound = Error("source not found") ErrServerNotFound = Error("server not found") + ErrLayoutNotFound = Error("layout not found") ) // Error is a domain error encountered while processing mrfusion requests diff --git a/handlers/layout.go b/handlers/layout.go new file mode 100644 index 0000000000..d7cd6008f3 --- /dev/null +++ b/handlers/layout.go @@ -0,0 +1,158 @@ +package handlers + +import ( + "fmt" + "strconv" + + "github.com/go-openapi/runtime/middleware" + "github.com/influxdata/mrfusion" + "github.com/influxdata/mrfusion/models" + + op "github.com/influxdata/mrfusion/restapi/operations" + "golang.org/x/net/context" +) + +func layoutToMrF(l *models.Layout) mrfusion.Layout { + cells := make([]mrfusion.Cell, len(l.Cells)) + for i, c := range l.Cells { + queries := make([]mrfusion.Query, len(c.Queries)) + for j, q := range c.Queries { + queries[j] = mrfusion.Query{ + Command: *q.Query, + DB: q.Db, + RP: q.Rp, + } + } + cells[i] = mrfusion.Cell{ + X: *c.X, + Y: *c.Y, + W: *c.W, + H: *c.H, + Queries: queries, + } + } + return mrfusion.Layout{ + Cells: cells, + } +} + +func (h *Store) NewLayout(ctx context.Context, params op.PostLayoutsParams) middleware.Responder { + layout := layoutToMrF(params.Layout) + var err error + if layout, err = h.LayoutStore.Add(ctx, layout); err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error storing layout %v: %v", params.Layout, err)} + return op.NewPostLayoutsDefault(500).WithPayload(errMsg) + } + mlayout := layoutToModel(layout) + return op.NewPostLayoutsCreated().WithPayload(mlayout).WithLocation(*mlayout.Link.Href) +} + +func layoutToModel(l mrfusion.Layout) *models.Layout { + href := fmt.Sprintf("/chronograf/v1/layouts/%d", l.ID) + rel := "self" + + cells := make([]*models.Cell, len(l.Cells)) + for i, c := range l.Cells { + queries := make([]*models.Proxy, len(c.Queries)) + for j, q := range c.Queries { + queries[j] = &models.Proxy{ + Query: &q.Command, + Db: q.DB, + Rp: q.RP, + } + } + + x := c.X + y := c.Y + w := c.W + h := c.H + + cells[i] = &models.Cell{ + X: &x, + Y: &y, + W: &w, + H: &h, + Queries: queries, + } + } + + return &models.Layout{ + Link: &models.Link{ + Href: &href, + Rel: &rel, + }, + Cells: cells, + } +} + +func (h *Store) Layouts(ctx context.Context, params op.GetLayoutsParams) middleware.Responder { + mrLays, err := h.LayoutStore.All(ctx) + if err != nil { + errMsg := &models.Error{Code: 500, Message: "Error loading layouts"} + return op.NewGetLayoutsDefault(500).WithPayload(errMsg) + } + + lays := make([]*models.Layout, len(mrLays)) + for i, layout := range mrLays { + lays[i] = layoutToModel(layout) + } + + res := &models.Layouts{ + Layouts: lays, + } + + return op.NewGetLayoutsOK().WithPayload(res) +} + +func (h *Store) LayoutsID(ctx context.Context, params op.GetLayoutsIDParams) middleware.Responder { + id, err := strconv.Atoi(params.ID) + if err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} + return op.NewGetLayoutsIDDefault(500).WithPayload(errMsg) + } + + layout, err := h.LayoutStore.Get(ctx, id) + if err != nil { + errMsg := &models.Error{Code: 404, Message: fmt.Sprintf("Unknown ID %s", params.ID)} + return op.NewGetLayoutsIDNotFound().WithPayload(errMsg) + } + + return op.NewGetLayoutsIDOK().WithPayload(layoutToModel(layout)) +} + +func (h *Store) RemoveLayout(ctx context.Context, params op.DeleteLayoutsIDParams) middleware.Responder { + id, err := strconv.Atoi(params.ID) + if err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} + return op.NewDeleteLayoutsIDDefault(500).WithPayload(errMsg) + } + layout := mrfusion.Layout{ + ID: id, + } + if err = h.LayoutStore.Delete(ctx, layout); err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Unknown error deleting layout %s", params.ID)} + return op.NewDeleteLayoutsIDDefault(500).WithPayload(errMsg) + } + + return op.NewDeleteLayoutsIDNoContent() +} + +func (h *Store) UpdateLayout(ctx context.Context, params op.PutLayoutsIDParams) middleware.Responder { + id, err := strconv.Atoi(params.ID) + if err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} + return op.NewPutLayoutsIDDefault(500).WithPayload(errMsg) + } + layout, err := h.LayoutStore.Get(ctx, id) + if err != nil { + errMsg := &models.Error{Code: 404, Message: fmt.Sprintf("Unknown ID %s", params.ID)} + return op.NewPutLayoutsIDNotFound().WithPayload(errMsg) + } + layout = layoutToMrF(params.Config) + layout.ID = id + if err := h.LayoutStore.Update(ctx, layout); err != nil { + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error updating layout ID %s", params.ID)} + return op.NewPutLayoutsIDDefault(500).WithPayload(errMsg) + } + return op.NewPutLayoutsIDOK().WithPayload(layoutToModel(layout)) +} diff --git a/handlers/store.go b/handlers/store.go index 6514764d8a..06dccfdd48 100644 --- a/handlers/store.go +++ b/handlers/store.go @@ -7,4 +7,5 @@ type Store struct { ExplorationStore mrfusion.ExplorationStore SourcesStore mrfusion.SourcesStore ServersStore mrfusion.ServersStore + LayoutStore mrfusion.LayoutStore } diff --git a/mock/handlers.go b/mock/handlers.go index 0202cbae20..643091e840 100644 --- a/mock/handlers.go +++ b/mock/handlers.go @@ -31,10 +31,9 @@ func NewHandler() Handler { func (m *Handler) AllRoutes(ctx context.Context, params op.GetParams) middleware.Responder { routes := &models.Routes{ - Sources: "/chronograf/v1/sources", - Dashboards: "/chronograf/v1/dashboards", - Apps: "/chronograf/v1/apps", - Users: "/chronograf/v1/users", + Sources: "/chronograf/v1/sources", + Layouts: "/chronograf/v1/layouts", + Users: "/chronograf/v1/users", } return op.NewGetOK().WithPayload(routes) } diff --git a/models/cell.go b/models/cell.go index 5932989538..240733a935 100644 --- a/models/cell.go +++ b/models/cell.go @@ -8,6 +8,7 @@ import ( "github.com/go-openapi/swag" "github.com/go-openapi/errors" + "github.com/go-openapi/validate" ) /*Cell cell @@ -16,47 +17,126 @@ swagger:model Cell */ type Cell struct { - /* Height of Cell in the Dashboard - */ - H int32 `json:"h,omitempty"` + /* Height of Cell in the Layout + + Required: true + */ + H *int32 `json:"h"` /* Time-series data queries for Cell. */ - Queries []string `json:"queries,omitempty"` + Queries []*Proxy `json:"queries,omitempty"` - /* Width of Cell in the Dashboard - */ - W int32 `json:"w,omitempty"` + /* Width of Cell in the Layout - /* X-coordinate of Cell in the Dashboard - */ - X int32 `json:"x,omitempty"` + Required: true + */ + W *int32 `json:"w"` - /* Y-coordinate of Cell in the Dashboard - */ - Y int32 `json:"y,omitempty"` + /* X-coordinate of Cell in the Layout + + Required: true + */ + X *int32 `json:"x"` + + /* Y-coordinate of Cell in the Layout + + Required: true + */ + Y *int32 `json:"y"` } // Validate validates this cell func (m *Cell) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateH(formats); err != nil { + // prop + res = append(res, err) + } + if err := m.validateQueries(formats); err != nil { // prop res = append(res, err) } + if err := m.validateW(formats); err != nil { + // prop + res = append(res, err) + } + + if err := m.validateX(formats); err != nil { + // prop + res = append(res, err) + } + + if err := m.validateY(formats); err != nil { + // prop + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } +func (m *Cell) validateH(formats strfmt.Registry) error { + + if err := validate.Required("h", "body", m.H); err != nil { + return err + } + + return nil +} + func (m *Cell) validateQueries(formats strfmt.Registry) error { if swag.IsZero(m.Queries) { // not required return nil } + for i := 0; i < len(m.Queries); i++ { + + if swag.IsZero(m.Queries[i]) { // not required + continue + } + + if m.Queries[i] != nil { + + if err := m.Queries[i].Validate(formats); err != nil { + return err + } + } + + } + + return nil +} + +func (m *Cell) validateW(formats strfmt.Registry) error { + + if err := validate.Required("w", "body", m.W); err != nil { + return err + } + + return nil +} + +func (m *Cell) validateX(formats strfmt.Registry) error { + + if err := validate.Required("x", "body", m.X); err != nil { + return err + } + + return nil +} + +func (m *Cell) validateY(formats strfmt.Registry) error { + + if err := validate.Required("y", "body", m.Y); err != nil { + return err + } + return nil } diff --git a/models/dashboards.go b/models/dashboards.go deleted file mode 100644 index 286ec12554..0000000000 --- a/models/dashboards.go +++ /dev/null @@ -1,61 +0,0 @@ -package models - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - strfmt "github.com/go-openapi/strfmt" - "github.com/go-openapi/swag" - - "github.com/go-openapi/errors" -) - -/*Dashboards dashboards - -swagger:model Dashboards -*/ -type Dashboards struct { - - /* dashboards - */ - Dashboards []*Dashboard `json:"dashboards,omitempty"` -} - -// Validate validates this dashboards -func (m *Dashboards) Validate(formats strfmt.Registry) error { - var res []error - - if err := m.validateDashboards(formats); err != nil { - // prop - res = append(res, err) - } - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} - -func (m *Dashboards) validateDashboards(formats strfmt.Registry) error { - - if swag.IsZero(m.Dashboards) { // not required - return nil - } - - for i := 0; i < len(m.Dashboards); i++ { - - if swag.IsZero(m.Dashboards[i]) { // not required - continue - } - - if m.Dashboards[i] != nil { - - if err := m.Dashboards[i].Validate(formats); err != nil { - return err - } - } - - } - - return nil -} diff --git a/models/dashboard.go b/models/layout.go similarity index 80% rename from models/dashboard.go rename to models/layout.go index 3039f8a05e..d1a596324f 100644 --- a/models/dashboard.go +++ b/models/layout.go @@ -11,11 +11,11 @@ import ( "github.com/go-openapi/validate" ) -/*Dashboard dashboard +/*Layout layout -swagger:model Dashboard +swagger:model Layout */ -type Dashboard struct { +type Layout struct { /* Cells are the individual visualization elements. @@ -28,8 +28,8 @@ type Dashboard struct { Link *Link `json:"link,omitempty"` } -// Validate validates this dashboard -func (m *Dashboard) Validate(formats strfmt.Registry) error { +// Validate validates this layout +func (m *Layout) Validate(formats strfmt.Registry) error { var res []error if err := m.validateCells(formats); err != nil { @@ -48,7 +48,7 @@ func (m *Dashboard) Validate(formats strfmt.Registry) error { return nil } -func (m *Dashboard) validateCells(formats strfmt.Registry) error { +func (m *Layout) validateCells(formats strfmt.Registry) error { if err := validate.Required("cells", "body", m.Cells); err != nil { return err @@ -72,7 +72,7 @@ func (m *Dashboard) validateCells(formats strfmt.Registry) error { return nil } -func (m *Dashboard) validateLink(formats strfmt.Registry) error { +func (m *Layout) validateLink(formats strfmt.Registry) error { if swag.IsZero(m.Link) { // not required return nil diff --git a/models/layouts.go b/models/layouts.go new file mode 100644 index 0000000000..f3c1f7cd70 --- /dev/null +++ b/models/layouts.go @@ -0,0 +1,64 @@ +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + + "github.com/go-openapi/errors" + "github.com/go-openapi/validate" +) + +/*Layouts layouts + +swagger:model Layouts +*/ +type Layouts struct { + + /* layouts + + Required: true + */ + Layouts []*Layout `json:"layouts"` +} + +// Validate validates this layouts +func (m *Layouts) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateLayouts(formats); err != nil { + // prop + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Layouts) validateLayouts(formats strfmt.Registry) error { + + if err := validate.Required("layouts", "body", m.Layouts); err != nil { + return err + } + + for i := 0; i < len(m.Layouts); i++ { + + if swag.IsZero(m.Layouts[i]) { // not required + continue + } + + if m.Layouts[i] != nil { + + if err := m.Layouts[i].Validate(formats); err != nil { + return err + } + } + + } + + return nil +} diff --git a/models/routes.go b/models/routes.go index 0eca292379..041c3ba1c0 100644 --- a/models/routes.go +++ b/models/routes.go @@ -15,13 +15,9 @@ swagger:model Routes */ type Routes struct { - /* Location of the apps endpoint + /* Location of the layouts endpoint */ - Apps string `json:"apps,omitempty"` - - /* Location of the dashboards endpoint - */ - Dashboards string `json:"dashboards,omitempty"` + Layouts string `json:"layouts,omitempty"` /* Location of the sources endpoint */ diff --git a/restapi/configure_mr_fusion.go b/restapi/configure_mr_fusion.go index 90bcc43853..a8bed87f1f 100644 --- a/restapi/configure_mr_fusion.go +++ b/restapi/configure_mr_fusion.go @@ -97,7 +97,9 @@ func configureAPI(api *op.MrFusionAPI) http.Handler { ExplorationStore: c.ExplorationStore, SourcesStore: c.SourcesStore, ServersStore: c.ServersStore, + LayoutStore: c.LayoutStore, } + api.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler = op.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(h.DeleteExploration) api.GetSourcesIDUsersUserIDExplorationsExplorationIDHandler = op.GetSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(h.Exploration) api.GetSourcesIDUsersUserIDExplorationsHandler = op.GetSourcesIDUsersUserIDExplorationsHandlerFunc(h.Explorations) @@ -130,6 +132,12 @@ func configureAPI(api *op.MrFusionAPI) http.Handler { api.PatchSourcesIDKapacitorsKapaIDProxyHandler = op.PatchSourcesIDKapacitorsKapaIDProxyHandlerFunc(p.KapacitorProxyPatch) api.GetSourcesIDKapacitorsKapaIDProxyHandler = op.GetSourcesIDKapacitorsKapaIDProxyHandlerFunc(p.KapacitorProxyGet) api.DeleteSourcesIDKapacitorsKapaIDProxyHandler = op.DeleteSourcesIDKapacitorsKapaIDProxyHandlerFunc(p.KapacitorProxyDelete) + + api.DeleteLayoutsIDHandler = op.DeleteLayoutsIDHandlerFunc(h.RemoveLayout) + api.GetLayoutsHandler = op.GetLayoutsHandlerFunc(h.Layouts) + api.GetLayoutsIDHandler = op.GetLayoutsIDHandlerFunc(h.LayoutsID) + api.PostLayoutsHandler = op.PostLayoutsHandlerFunc(h.NewLayout) + api.PutLayoutsIDHandler = op.PutLayoutsIDHandlerFunc(h.UpdateLayout) } else { api.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler = op.DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.DeleteExploration) api.GetSourcesIDUsersUserIDExplorationsExplorationIDHandler = op.GetSourcesIDUsersUserIDExplorationsExplorationIDHandlerFunc(mockHandler.Exploration) @@ -154,16 +162,6 @@ func configureAPI(api *op.MrFusionAPI) http.Handler { return middleware.NotImplemented("operation .DeleteSourcesIDUsersUserID has not yet been implemented") }) - api.DeleteDashboardsIDHandler = op.DeleteDashboardsIDHandlerFunc(func(ctx context.Context, params op.DeleteDashboardsIDParams) middleware.Responder { - return middleware.NotImplemented("operation .DeleteDashboardsID has not yet been implemented") - }) - api.GetDashboardsHandler = op.GetDashboardsHandlerFunc(func(ctx context.Context, params op.GetDashboardsParams) middleware.Responder { - return middleware.NotImplemented("operation .GetDashboards has not yet been implemented") - }) - api.GetDashboardsIDHandler = op.GetDashboardsIDHandlerFunc(func(ctx context.Context, params op.GetDashboardsIDParams) middleware.Responder { - return middleware.NotImplemented("operation .GetDashboardsID has not yet been implemented") - }) - api.GetSourcesIDPermissionsHandler = op.GetSourcesIDPermissionsHandlerFunc(func(ctx context.Context, params op.GetSourcesIDPermissionsParams) middleware.Responder { return middleware.NotImplemented("operation .GetSourcesIDPermissions has not yet been implemented") }) @@ -188,21 +186,12 @@ func configureAPI(api *op.MrFusionAPI) http.Handler { api.PatchSourcesIDUsersUserIDHandler = op.PatchSourcesIDUsersUserIDHandlerFunc(func(ctx context.Context, params op.PatchSourcesIDUsersUserIDParams) middleware.Responder { return middleware.NotImplemented("operation .PatchSourcesIDUsersUserID has not yet been implemented") }) - api.PostDashboardsHandler = op.PostDashboardsHandlerFunc(func(ctx context.Context, params op.PostDashboardsParams) middleware.Responder { - return middleware.NotImplemented("operation .PostDashboards has not yet been implemented") - }) - api.PostSourcesIDRolesHandler = op.PostSourcesIDRolesHandlerFunc(func(ctx context.Context, params op.PostSourcesIDRolesParams) middleware.Responder { return middleware.NotImplemented("operation .PostSourcesIDRoles has not yet been implemented") }) api.PostSourcesIDUsersHandler = op.PostSourcesIDUsersHandlerFunc(func(ctx context.Context, params op.PostSourcesIDUsersParams) middleware.Responder { return middleware.NotImplemented("operation .PostSourcesIDUsers has not yet been implemented") }) - - api.PutDashboardsIDHandler = op.PutDashboardsIDHandlerFunc(func(ctx context.Context, params op.PutDashboardsIDParams) middleware.Responder { - return middleware.NotImplemented("operation .PutDashboardsID has not yet been implemented") - }) - api.GetSourcesIDMonitoredHandler = op.GetSourcesIDMonitoredHandlerFunc(mockHandler.MonitoredServices) api.ServerShutdown = func() {} diff --git a/restapi/operations/delete_dashboards_id.go b/restapi/operations/delete_dashboards_id.go deleted file mode 100644 index 508842a8af..0000000000 --- a/restapi/operations/delete_dashboards_id.go +++ /dev/null @@ -1,55 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - context "golang.org/x/net/context" - - middleware "github.com/go-openapi/runtime/middleware" -) - -// DeleteDashboardsIDHandlerFunc turns a function with the right signature into a delete dashboards ID handler -type DeleteDashboardsIDHandlerFunc func(context.Context, DeleteDashboardsIDParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn DeleteDashboardsIDHandlerFunc) Handle(ctx context.Context, params DeleteDashboardsIDParams) middleware.Responder { - return fn(ctx, params) -} - -// DeleteDashboardsIDHandler interface for that can handle valid delete dashboards ID params -type DeleteDashboardsIDHandler interface { - Handle(context.Context, DeleteDashboardsIDParams) middleware.Responder -} - -// NewDeleteDashboardsID creates a new http.Handler for the delete dashboards ID operation -func NewDeleteDashboardsID(ctx *middleware.Context, handler DeleteDashboardsIDHandler) *DeleteDashboardsID { - return &DeleteDashboardsID{Context: ctx, Handler: handler} -} - -/*DeleteDashboardsID swagger:route DELETE /dashboards/{id} deleteDashboardsId - -This specific dashboard will be removed from the data store - -*/ -type DeleteDashboardsID struct { - Context *middleware.Context - Handler DeleteDashboardsIDHandler -} - -func (o *DeleteDashboardsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, _ := o.Context.RouteInfo(r) - var Params = NewDeleteDashboardsIDParams() - - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(context.Background(), Params) // actually handle the request - - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/restapi/operations/delete_dashboards_id_responses.go b/restapi/operations/delete_dashboards_id_responses.go deleted file mode 100644 index 189c1aa91e..0000000000 --- a/restapi/operations/delete_dashboards_id_responses.go +++ /dev/null @@ -1,122 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/influxdata/mrfusion/models" -) - -/*DeleteDashboardsIDNoContent An array of dashboards - -swagger:response deleteDashboardsIdNoContent -*/ -type DeleteDashboardsIDNoContent struct { -} - -// NewDeleteDashboardsIDNoContent creates DeleteDashboardsIDNoContent with default headers values -func NewDeleteDashboardsIDNoContent() *DeleteDashboardsIDNoContent { - return &DeleteDashboardsIDNoContent{} -} - -// WriteResponse to the client -func (o *DeleteDashboardsIDNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(204) -} - -/*DeleteDashboardsIDNotFound Unknown dashboard id - -swagger:response deleteDashboardsIdNotFound -*/ -type DeleteDashboardsIDNotFound struct { - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteDashboardsIDNotFound creates DeleteDashboardsIDNotFound with default headers values -func NewDeleteDashboardsIDNotFound() *DeleteDashboardsIDNotFound { - return &DeleteDashboardsIDNotFound{} -} - -// WithPayload adds the payload to the delete dashboards Id not found response -func (o *DeleteDashboardsIDNotFound) WithPayload(payload *models.Error) *DeleteDashboardsIDNotFound { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete dashboards Id not found response -func (o *DeleteDashboardsIDNotFound) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteDashboardsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(404) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*DeleteDashboardsIDDefault Unexpected internal service error - -swagger:response deleteDashboardsIdDefault -*/ -type DeleteDashboardsIDDefault struct { - _statusCode int - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewDeleteDashboardsIDDefault creates DeleteDashboardsIDDefault with default headers values -func NewDeleteDashboardsIDDefault(code int) *DeleteDashboardsIDDefault { - if code <= 0 { - code = 500 - } - - return &DeleteDashboardsIDDefault{ - _statusCode: code, - } -} - -// WithStatusCode adds the status to the delete dashboards ID default response -func (o *DeleteDashboardsIDDefault) WithStatusCode(code int) *DeleteDashboardsIDDefault { - o._statusCode = code - return o -} - -// SetStatusCode sets the status to the delete dashboards ID default response -func (o *DeleteDashboardsIDDefault) SetStatusCode(code int) { - o._statusCode = code -} - -// WithPayload adds the payload to the delete dashboards ID default response -func (o *DeleteDashboardsIDDefault) WithPayload(payload *models.Error) *DeleteDashboardsIDDefault { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the delete dashboards ID default response -func (o *DeleteDashboardsIDDefault) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *DeleteDashboardsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(o._statusCode) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/restapi/operations/delete_layouts_id.go b/restapi/operations/delete_layouts_id.go new file mode 100644 index 0000000000..9ba2113eda --- /dev/null +++ b/restapi/operations/delete_layouts_id.go @@ -0,0 +1,55 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + context "golang.org/x/net/context" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// DeleteLayoutsIDHandlerFunc turns a function with the right signature into a delete layouts ID handler +type DeleteLayoutsIDHandlerFunc func(context.Context, DeleteLayoutsIDParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteLayoutsIDHandlerFunc) Handle(ctx context.Context, params DeleteLayoutsIDParams) middleware.Responder { + return fn(ctx, params) +} + +// DeleteLayoutsIDHandler interface for that can handle valid delete layouts ID params +type DeleteLayoutsIDHandler interface { + Handle(context.Context, DeleteLayoutsIDParams) middleware.Responder +} + +// NewDeleteLayoutsID creates a new http.Handler for the delete layouts ID operation +func NewDeleteLayoutsID(ctx *middleware.Context, handler DeleteLayoutsIDHandler) *DeleteLayoutsID { + return &DeleteLayoutsID{Context: ctx, Handler: handler} +} + +/*DeleteLayoutsID swagger:route DELETE /layouts/{id} deleteLayoutsId + +This specific layout will be removed from the data store + +*/ +type DeleteLayoutsID struct { + Context *middleware.Context + Handler DeleteLayoutsIDHandler +} + +func (o *DeleteLayoutsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, _ := o.Context.RouteInfo(r) + var Params = NewDeleteLayoutsIDParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(context.Background(), Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/get_dashboards_id_parameters.go b/restapi/operations/delete_layouts_id_parameters.go similarity index 70% rename from restapi/operations/get_dashboards_id_parameters.go rename to restapi/operations/delete_layouts_id_parameters.go index d5191d6935..a20b262387 100644 --- a/restapi/operations/get_dashboards_id_parameters.go +++ b/restapi/operations/delete_layouts_id_parameters.go @@ -12,23 +12,23 @@ import ( strfmt "github.com/go-openapi/strfmt" ) -// NewGetDashboardsIDParams creates a new GetDashboardsIDParams object +// NewDeleteLayoutsIDParams creates a new DeleteLayoutsIDParams object // with the default values initialized. -func NewGetDashboardsIDParams() GetDashboardsIDParams { +func NewDeleteLayoutsIDParams() DeleteLayoutsIDParams { var () - return GetDashboardsIDParams{} + return DeleteLayoutsIDParams{} } -// GetDashboardsIDParams contains all the bound params for the get dashboards ID operation +// DeleteLayoutsIDParams contains all the bound params for the delete layouts ID operation // typically these are obtained from a http.Request // -// swagger:parameters GetDashboardsID -type GetDashboardsIDParams struct { +// swagger:parameters DeleteLayoutsID +type DeleteLayoutsIDParams struct { // HTTP Request Object HTTPRequest *http.Request - /*ID of the dashboard + /*ID of the layout Required: true In: path */ @@ -37,7 +37,7 @@ type GetDashboardsIDParams struct { // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls -func (o *GetDashboardsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { +func (o *DeleteLayoutsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error o.HTTPRequest = r @@ -52,7 +52,7 @@ func (o *GetDashboardsIDParams) BindRequest(r *http.Request, route *middleware.M return nil } -func (o *GetDashboardsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { +func (o *DeleteLayoutsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string if len(rawData) > 0 { raw = rawData[len(rawData)-1] diff --git a/restapi/operations/delete_layouts_id_responses.go b/restapi/operations/delete_layouts_id_responses.go new file mode 100644 index 0000000000..1bbb9c8a59 --- /dev/null +++ b/restapi/operations/delete_layouts_id_responses.go @@ -0,0 +1,122 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/influxdata/mrfusion/models" +) + +/*DeleteLayoutsIDNoContent Layout has been removed. + +swagger:response deleteLayoutsIdNoContent +*/ +type DeleteLayoutsIDNoContent struct { +} + +// NewDeleteLayoutsIDNoContent creates DeleteLayoutsIDNoContent with default headers values +func NewDeleteLayoutsIDNoContent() *DeleteLayoutsIDNoContent { + return &DeleteLayoutsIDNoContent{} +} + +// WriteResponse to the client +func (o *DeleteLayoutsIDNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(204) +} + +/*DeleteLayoutsIDNotFound Unknown layout id + +swagger:response deleteLayoutsIdNotFound +*/ +type DeleteLayoutsIDNotFound struct { + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteLayoutsIDNotFound creates DeleteLayoutsIDNotFound with default headers values +func NewDeleteLayoutsIDNotFound() *DeleteLayoutsIDNotFound { + return &DeleteLayoutsIDNotFound{} +} + +// WithPayload adds the payload to the delete layouts Id not found response +func (o *DeleteLayoutsIDNotFound) WithPayload(payload *models.Error) *DeleteLayoutsIDNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete layouts Id not found response +func (o *DeleteLayoutsIDNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteLayoutsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*DeleteLayoutsIDDefault Unexpected internal service error + +swagger:response deleteLayoutsIdDefault +*/ +type DeleteLayoutsIDDefault struct { + _statusCode int + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteLayoutsIDDefault creates DeleteLayoutsIDDefault with default headers values +func NewDeleteLayoutsIDDefault(code int) *DeleteLayoutsIDDefault { + if code <= 0 { + code = 500 + } + + return &DeleteLayoutsIDDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the delete layouts ID default response +func (o *DeleteLayoutsIDDefault) WithStatusCode(code int) *DeleteLayoutsIDDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the delete layouts ID default response +func (o *DeleteLayoutsIDDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the delete layouts ID default response +func (o *DeleteLayoutsIDDefault) WithPayload(payload *models.Error) *DeleteLayoutsIDDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete layouts ID default response +func (o *DeleteLayoutsIDDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteLayoutsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/get_dashboards.go b/restapi/operations/get_dashboards.go deleted file mode 100644 index ab3dcd1883..0000000000 --- a/restapi/operations/get_dashboards.go +++ /dev/null @@ -1,58 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - context "golang.org/x/net/context" - - middleware "github.com/go-openapi/runtime/middleware" -) - -// GetDashboardsHandlerFunc turns a function with the right signature into a get dashboards handler -type GetDashboardsHandlerFunc func(context.Context, GetDashboardsParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn GetDashboardsHandlerFunc) Handle(ctx context.Context, params GetDashboardsParams) middleware.Responder { - return fn(ctx, params) -} - -// GetDashboardsHandler interface for that can handle valid get dashboards params -type GetDashboardsHandler interface { - Handle(context.Context, GetDashboardsParams) middleware.Responder -} - -// NewGetDashboards creates a new http.Handler for the get dashboards operation -func NewGetDashboards(ctx *middleware.Context, handler GetDashboardsHandler) *GetDashboards { - return &GetDashboards{Context: ctx, Handler: handler} -} - -/*GetDashboards swagger:route GET /dashboards getDashboards - -Pre-configured dashboards - -Dashboards are a collection of `Cells` that visualize time-series data. - - -*/ -type GetDashboards struct { - Context *middleware.Context - Handler GetDashboardsHandler -} - -func (o *GetDashboards) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, _ := o.Context.RouteInfo(r) - var Params = NewGetDashboardsParams() - - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(context.Background(), Params) // actually handle the request - - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/restapi/operations/get_dashboards_id.go b/restapi/operations/get_dashboards_id.go deleted file mode 100644 index 38e5322990..0000000000 --- a/restapi/operations/get_dashboards_id.go +++ /dev/null @@ -1,58 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - context "golang.org/x/net/context" - - middleware "github.com/go-openapi/runtime/middleware" -) - -// GetDashboardsIDHandlerFunc turns a function with the right signature into a get dashboards ID handler -type GetDashboardsIDHandlerFunc func(context.Context, GetDashboardsIDParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn GetDashboardsIDHandlerFunc) Handle(ctx context.Context, params GetDashboardsIDParams) middleware.Responder { - return fn(ctx, params) -} - -// GetDashboardsIDHandler interface for that can handle valid get dashboards ID params -type GetDashboardsIDHandler interface { - Handle(context.Context, GetDashboardsIDParams) middleware.Responder -} - -// NewGetDashboardsID creates a new http.Handler for the get dashboards ID operation -func NewGetDashboardsID(ctx *middleware.Context, handler GetDashboardsIDHandler) *GetDashboardsID { - return &GetDashboardsID{Context: ctx, Handler: handler} -} - -/*GetDashboardsID swagger:route GET /dashboards/{id} getDashboardsId - -Specific pre-configured dashboard containing cells and queries. - -dashboards will hold information about how to layout the page of graphs. - - -*/ -type GetDashboardsID struct { - Context *middleware.Context - Handler GetDashboardsIDHandler -} - -func (o *GetDashboardsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, _ := o.Context.RouteInfo(r) - var Params = NewGetDashboardsIDParams() - - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(context.Background(), Params) // actually handle the request - - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/restapi/operations/get_dashboards_id_responses.go b/restapi/operations/get_dashboards_id_responses.go deleted file mode 100644 index a980a59f1e..0000000000 --- a/restapi/operations/get_dashboards_id_responses.go +++ /dev/null @@ -1,141 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/influxdata/mrfusion/models" -) - -/*GetDashboardsIDOK Returns the specified dashboard containing `cells`. - -swagger:response getDashboardsIdOK -*/ -type GetDashboardsIDOK struct { - - // In: body - Payload *models.Dashboard `json:"body,omitempty"` -} - -// NewGetDashboardsIDOK creates GetDashboardsIDOK with default headers values -func NewGetDashboardsIDOK() *GetDashboardsIDOK { - return &GetDashboardsIDOK{} -} - -// WithPayload adds the payload to the get dashboards Id o k response -func (o *GetDashboardsIDOK) WithPayload(payload *models.Dashboard) *GetDashboardsIDOK { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the get dashboards Id o k response -func (o *GetDashboardsIDOK) SetPayload(payload *models.Dashboard) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *GetDashboardsIDOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(200) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*GetDashboardsIDNotFound Unknown dashboard id - -swagger:response getDashboardsIdNotFound -*/ -type GetDashboardsIDNotFound struct { - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewGetDashboardsIDNotFound creates GetDashboardsIDNotFound with default headers values -func NewGetDashboardsIDNotFound() *GetDashboardsIDNotFound { - return &GetDashboardsIDNotFound{} -} - -// WithPayload adds the payload to the get dashboards Id not found response -func (o *GetDashboardsIDNotFound) WithPayload(payload *models.Error) *GetDashboardsIDNotFound { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the get dashboards Id not found response -func (o *GetDashboardsIDNotFound) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *GetDashboardsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(404) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*GetDashboardsIDDefault Unexpected internal service error - -swagger:response getDashboardsIdDefault -*/ -type GetDashboardsIDDefault struct { - _statusCode int - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewGetDashboardsIDDefault creates GetDashboardsIDDefault with default headers values -func NewGetDashboardsIDDefault(code int) *GetDashboardsIDDefault { - if code <= 0 { - code = 500 - } - - return &GetDashboardsIDDefault{ - _statusCode: code, - } -} - -// WithStatusCode adds the status to the get dashboards ID default response -func (o *GetDashboardsIDDefault) WithStatusCode(code int) *GetDashboardsIDDefault { - o._statusCode = code - return o -} - -// SetStatusCode sets the status to the get dashboards ID default response -func (o *GetDashboardsIDDefault) SetStatusCode(code int) { - o._statusCode = code -} - -// WithPayload adds the payload to the get dashboards ID default response -func (o *GetDashboardsIDDefault) WithPayload(payload *models.Error) *GetDashboardsIDDefault { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the get dashboards ID default response -func (o *GetDashboardsIDDefault) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *GetDashboardsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(o._statusCode) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/restapi/operations/get_dashboards_parameters.go b/restapi/operations/get_dashboards_parameters.go deleted file mode 100644 index bbe5f1ac75..0000000000 --- a/restapi/operations/get_dashboards_parameters.go +++ /dev/null @@ -1,40 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime/middleware" -) - -// NewGetDashboardsParams creates a new GetDashboardsParams object -// with the default values initialized. -func NewGetDashboardsParams() GetDashboardsParams { - var () - return GetDashboardsParams{} -} - -// GetDashboardsParams contains all the bound params for the get dashboards operation -// typically these are obtained from a http.Request -// -// swagger:parameters GetDashboards -type GetDashboardsParams struct { - - // HTTP Request Object - HTTPRequest *http.Request -} - -// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface -// for simple values it will use straight method calls -func (o *GetDashboardsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { - var res []error - o.HTTPRequest = r - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} diff --git a/restapi/operations/get_dashboards_responses.go b/restapi/operations/get_dashboards_responses.go deleted file mode 100644 index 0d61b18d21..0000000000 --- a/restapi/operations/get_dashboards_responses.go +++ /dev/null @@ -1,104 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/influxdata/mrfusion/models" -) - -/*GetDashboardsOK An array of dashboards - -swagger:response getDashboardsOK -*/ -type GetDashboardsOK struct { - - // In: body - Payload *models.Dashboards `json:"body,omitempty"` -} - -// NewGetDashboardsOK creates GetDashboardsOK with default headers values -func NewGetDashboardsOK() *GetDashboardsOK { - return &GetDashboardsOK{} -} - -// WithPayload adds the payload to the get dashboards o k response -func (o *GetDashboardsOK) WithPayload(payload *models.Dashboards) *GetDashboardsOK { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the get dashboards o k response -func (o *GetDashboardsOK) SetPayload(payload *models.Dashboards) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *GetDashboardsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(200) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*GetDashboardsDefault Unexpected internal service error - -swagger:response getDashboardsDefault -*/ -type GetDashboardsDefault struct { - _statusCode int - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewGetDashboardsDefault creates GetDashboardsDefault with default headers values -func NewGetDashboardsDefault(code int) *GetDashboardsDefault { - if code <= 0 { - code = 500 - } - - return &GetDashboardsDefault{ - _statusCode: code, - } -} - -// WithStatusCode adds the status to the get dashboards default response -func (o *GetDashboardsDefault) WithStatusCode(code int) *GetDashboardsDefault { - o._statusCode = code - return o -} - -// SetStatusCode sets the status to the get dashboards default response -func (o *GetDashboardsDefault) SetStatusCode(code int) { - o._statusCode = code -} - -// WithPayload adds the payload to the get dashboards default response -func (o *GetDashboardsDefault) WithPayload(payload *models.Error) *GetDashboardsDefault { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the get dashboards default response -func (o *GetDashboardsDefault) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *GetDashboardsDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(o._statusCode) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/restapi/operations/get_layouts.go b/restapi/operations/get_layouts.go new file mode 100644 index 0000000000..abd2b20264 --- /dev/null +++ b/restapi/operations/get_layouts.go @@ -0,0 +1,58 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + context "golang.org/x/net/context" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetLayoutsHandlerFunc turns a function with the right signature into a get layouts handler +type GetLayoutsHandlerFunc func(context.Context, GetLayoutsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetLayoutsHandlerFunc) Handle(ctx context.Context, params GetLayoutsParams) middleware.Responder { + return fn(ctx, params) +} + +// GetLayoutsHandler interface for that can handle valid get layouts params +type GetLayoutsHandler interface { + Handle(context.Context, GetLayoutsParams) middleware.Responder +} + +// NewGetLayouts creates a new http.Handler for the get layouts operation +func NewGetLayouts(ctx *middleware.Context, handler GetLayoutsHandler) *GetLayouts { + return &GetLayouts{Context: ctx, Handler: handler} +} + +/*GetLayouts swagger:route GET /layouts getLayouts + +Pre-configured layouts + +Layouts are a collection of `Cells` that visualize time-series data. + + +*/ +type GetLayouts struct { + Context *middleware.Context + Handler GetLayoutsHandler +} + +func (o *GetLayouts) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, _ := o.Context.RouteInfo(r) + var Params = NewGetLayoutsParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(context.Background(), Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/get_layouts_id.go b/restapi/operations/get_layouts_id.go new file mode 100644 index 0000000000..09fa76e75d --- /dev/null +++ b/restapi/operations/get_layouts_id.go @@ -0,0 +1,58 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + context "golang.org/x/net/context" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// GetLayoutsIDHandlerFunc turns a function with the right signature into a get layouts ID handler +type GetLayoutsIDHandlerFunc func(context.Context, GetLayoutsIDParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetLayoutsIDHandlerFunc) Handle(ctx context.Context, params GetLayoutsIDParams) middleware.Responder { + return fn(ctx, params) +} + +// GetLayoutsIDHandler interface for that can handle valid get layouts ID params +type GetLayoutsIDHandler interface { + Handle(context.Context, GetLayoutsIDParams) middleware.Responder +} + +// NewGetLayoutsID creates a new http.Handler for the get layouts ID operation +func NewGetLayoutsID(ctx *middleware.Context, handler GetLayoutsIDHandler) *GetLayoutsID { + return &GetLayoutsID{Context: ctx, Handler: handler} +} + +/*GetLayoutsID swagger:route GET /layouts/{id} getLayoutsId + +Specific pre-configured layout containing cells and queries. + +layouts will hold information about how to layout the page of graphs. + + +*/ +type GetLayoutsID struct { + Context *middleware.Context + Handler GetLayoutsIDHandler +} + +func (o *GetLayoutsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, _ := o.Context.RouteInfo(r) + var Params = NewGetLayoutsIDParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(context.Background(), Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/delete_dashboards_id_parameters.go b/restapi/operations/get_layouts_id_parameters.go similarity index 64% rename from restapi/operations/delete_dashboards_id_parameters.go rename to restapi/operations/get_layouts_id_parameters.go index fbb092f70a..25852ad109 100644 --- a/restapi/operations/delete_dashboards_id_parameters.go +++ b/restapi/operations/get_layouts_id_parameters.go @@ -12,23 +12,23 @@ import ( strfmt "github.com/go-openapi/strfmt" ) -// NewDeleteDashboardsIDParams creates a new DeleteDashboardsIDParams object +// NewGetLayoutsIDParams creates a new GetLayoutsIDParams object // with the default values initialized. -func NewDeleteDashboardsIDParams() DeleteDashboardsIDParams { +func NewGetLayoutsIDParams() GetLayoutsIDParams { var () - return DeleteDashboardsIDParams{} + return GetLayoutsIDParams{} } -// DeleteDashboardsIDParams contains all the bound params for the delete dashboards ID operation +// GetLayoutsIDParams contains all the bound params for the get layouts ID operation // typically these are obtained from a http.Request // -// swagger:parameters DeleteDashboardsID -type DeleteDashboardsIDParams struct { +// swagger:parameters GetLayoutsID +type GetLayoutsIDParams struct { // HTTP Request Object HTTPRequest *http.Request - /*ID of the dashboard + /*ID of the layout Required: true In: path */ @@ -37,7 +37,7 @@ type DeleteDashboardsIDParams struct { // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls -func (o *DeleteDashboardsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { +func (o *GetLayoutsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error o.HTTPRequest = r @@ -52,7 +52,7 @@ func (o *DeleteDashboardsIDParams) BindRequest(r *http.Request, route *middlewar return nil } -func (o *DeleteDashboardsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { +func (o *GetLayoutsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string if len(rawData) > 0 { raw = rawData[len(rawData)-1] diff --git a/restapi/operations/get_layouts_id_responses.go b/restapi/operations/get_layouts_id_responses.go new file mode 100644 index 0000000000..fae97d4eaa --- /dev/null +++ b/restapi/operations/get_layouts_id_responses.go @@ -0,0 +1,141 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/influxdata/mrfusion/models" +) + +/*GetLayoutsIDOK Returns the specified layout containing `cells`. + +swagger:response getLayoutsIdOK +*/ +type GetLayoutsIDOK struct { + + // In: body + Payload *models.Layout `json:"body,omitempty"` +} + +// NewGetLayoutsIDOK creates GetLayoutsIDOK with default headers values +func NewGetLayoutsIDOK() *GetLayoutsIDOK { + return &GetLayoutsIDOK{} +} + +// WithPayload adds the payload to the get layouts Id o k response +func (o *GetLayoutsIDOK) WithPayload(payload *models.Layout) *GetLayoutsIDOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get layouts Id o k response +func (o *GetLayoutsIDOK) SetPayload(payload *models.Layout) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLayoutsIDOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*GetLayoutsIDNotFound Unknown layout id + +swagger:response getLayoutsIdNotFound +*/ +type GetLayoutsIDNotFound struct { + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetLayoutsIDNotFound creates GetLayoutsIDNotFound with default headers values +func NewGetLayoutsIDNotFound() *GetLayoutsIDNotFound { + return &GetLayoutsIDNotFound{} +} + +// WithPayload adds the payload to the get layouts Id not found response +func (o *GetLayoutsIDNotFound) WithPayload(payload *models.Error) *GetLayoutsIDNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get layouts Id not found response +func (o *GetLayoutsIDNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLayoutsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*GetLayoutsIDDefault Unexpected internal service error + +swagger:response getLayoutsIdDefault +*/ +type GetLayoutsIDDefault struct { + _statusCode int + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetLayoutsIDDefault creates GetLayoutsIDDefault with default headers values +func NewGetLayoutsIDDefault(code int) *GetLayoutsIDDefault { + if code <= 0 { + code = 500 + } + + return &GetLayoutsIDDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get layouts ID default response +func (o *GetLayoutsIDDefault) WithStatusCode(code int) *GetLayoutsIDDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get layouts ID default response +func (o *GetLayoutsIDDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get layouts ID default response +func (o *GetLayoutsIDDefault) WithPayload(payload *models.Error) *GetLayoutsIDDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get layouts ID default response +func (o *GetLayoutsIDDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLayoutsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/get_layouts_parameters.go b/restapi/operations/get_layouts_parameters.go new file mode 100644 index 0000000000..7a09b1df5c --- /dev/null +++ b/restapi/operations/get_layouts_parameters.go @@ -0,0 +1,92 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/swag" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetLayoutsParams creates a new GetLayoutsParams object +// with the default values initialized. +func NewGetLayoutsParams() GetLayoutsParams { + var () + return GetLayoutsParams{} +} + +// GetLayoutsParams contains all the bound params for the get layouts operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetLayouts +type GetLayoutsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request + + /*IDs for all layouts to return + In: query + Collection Format: csv + */ + Ids []string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls +func (o *GetLayoutsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qIds, qhkIds, _ := qs.GetOK("ids") + if err := o.bindIds(qIds, qhkIds, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *GetLayoutsParams) bindIds(rawData []string, hasKey bool, formats strfmt.Registry) error { + + var qvIds string + if len(rawData) > 0 { + qvIds = rawData[len(rawData)-1] + } + + raw := swag.SplitByFormat(qvIds, "csv") + size := len(raw) + + if size == 0 { + return nil + } + + ic := raw + isz := size + var ir []string + iValidateElement := func(i int, idsI string) *errors.Validation { + + return nil + } + + for i := 0; i < isz; i++ { + + if err := iValidateElement(i, ic[i]); err != nil { + return err + } + ir = append(ir, ic[i]) + } + + o.Ids = ir + + return nil +} diff --git a/restapi/operations/get_layouts_responses.go b/restapi/operations/get_layouts_responses.go new file mode 100644 index 0000000000..48f681ce05 --- /dev/null +++ b/restapi/operations/get_layouts_responses.go @@ -0,0 +1,104 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/influxdata/mrfusion/models" +) + +/*GetLayoutsOK An array of layouts + +swagger:response getLayoutsOK +*/ +type GetLayoutsOK struct { + + // In: body + Payload *models.Layouts `json:"body,omitempty"` +} + +// NewGetLayoutsOK creates GetLayoutsOK with default headers values +func NewGetLayoutsOK() *GetLayoutsOK { + return &GetLayoutsOK{} +} + +// WithPayload adds the payload to the get layouts o k response +func (o *GetLayoutsOK) WithPayload(payload *models.Layouts) *GetLayoutsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get layouts o k response +func (o *GetLayoutsOK) SetPayload(payload *models.Layouts) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLayoutsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*GetLayoutsDefault Unexpected internal service error + +swagger:response getLayoutsDefault +*/ +type GetLayoutsDefault struct { + _statusCode int + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewGetLayoutsDefault creates GetLayoutsDefault with default headers values +func NewGetLayoutsDefault(code int) *GetLayoutsDefault { + if code <= 0 { + code = 500 + } + + return &GetLayoutsDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the get layouts default response +func (o *GetLayoutsDefault) WithStatusCode(code int) *GetLayoutsDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the get layouts default response +func (o *GetLayoutsDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the get layouts default response +func (o *GetLayoutsDefault) WithPayload(payload *models.Error) *GetLayoutsDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get layouts default response +func (o *GetLayoutsDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetLayoutsDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/get_sources_id_responses.go b/restapi/operations/get_sources_id_responses.go index c2aaa609e8..827bdab841 100644 --- a/restapi/operations/get_sources_id_responses.go +++ b/restapi/operations/get_sources_id_responses.go @@ -11,7 +11,7 @@ import ( "github.com/influxdata/mrfusion/models" ) -/*GetSourcesIDOK Data source used to supply time series to dashboards. +/*GetSourcesIDOK Data source used to supply time series information. swagger:response getSourcesIdOK */ diff --git a/restapi/operations/mr_fusion_api.go b/restapi/operations/mr_fusion_api.go index 4d774fbd06..9d5c8e13c1 100644 --- a/restapi/operations/mr_fusion_api.go +++ b/restapi/operations/mr_fusion_api.go @@ -42,8 +42,8 @@ type MrFusionAPI struct { // JSONProducer registers a producer for a "application/json" mime type JSONProducer runtime.Producer - // DeleteDashboardsIDHandler sets the operation handler for the delete dashboards ID operation - DeleteDashboardsIDHandler DeleteDashboardsIDHandler + // DeleteLayoutsIDHandler sets the operation handler for the delete layouts ID operation + DeleteLayoutsIDHandler DeleteLayoutsIDHandler // DeleteSourcesIDHandler sets the operation handler for the delete sources ID operation DeleteSourcesIDHandler DeleteSourcesIDHandler // DeleteSourcesIDKapacitorsKapaIDHandler sets the operation handler for the delete sources ID kapacitors kapa ID operation @@ -58,10 +58,10 @@ type MrFusionAPI struct { DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler DeleteSourcesIDUsersUserIDExplorationsExplorationIDHandler // GetHandler sets the operation handler for the get operation GetHandler GetHandler - // GetDashboardsHandler sets the operation handler for the get dashboards operation - GetDashboardsHandler GetDashboardsHandler - // GetDashboardsIDHandler sets the operation handler for the get dashboards ID operation - GetDashboardsIDHandler GetDashboardsIDHandler + // GetLayoutsHandler sets the operation handler for the get layouts operation + GetLayoutsHandler GetLayoutsHandler + // GetLayoutsIDHandler sets the operation handler for the get layouts ID operation + GetLayoutsIDHandler GetLayoutsIDHandler // GetSourcesHandler sets the operation handler for the get sources operation GetSourcesHandler GetSourcesHandler // GetSourcesIDHandler sets the operation handler for the get sources ID operation @@ -100,8 +100,8 @@ type MrFusionAPI struct { PatchSourcesIDUsersUserIDHandler PatchSourcesIDUsersUserIDHandler // PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler sets the operation handler for the patch sources ID users user ID explorations exploration ID operation PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler - // PostDashboardsHandler sets the operation handler for the post dashboards operation - PostDashboardsHandler PostDashboardsHandler + // PostLayoutsHandler sets the operation handler for the post layouts operation + PostLayoutsHandler PostLayoutsHandler // PostSourcesHandler sets the operation handler for the post sources operation PostSourcesHandler PostSourcesHandler // PostSourcesIDKapacitorsHandler sets the operation handler for the post sources ID kapacitors operation @@ -116,8 +116,8 @@ type MrFusionAPI struct { PostSourcesIDUsersHandler PostSourcesIDUsersHandler // PostSourcesIDUsersUserIDExplorationsHandler sets the operation handler for the post sources ID users user ID explorations operation PostSourcesIDUsersUserIDExplorationsHandler PostSourcesIDUsersUserIDExplorationsHandler - // PutDashboardsIDHandler sets the operation handler for the put dashboards ID operation - PutDashboardsIDHandler PutDashboardsIDHandler + // PutLayoutsIDHandler sets the operation handler for the put layouts ID operation + PutLayoutsIDHandler PutLayoutsIDHandler // ServeError is called when an error is received, there is a default handler // but you can set your own with this @@ -181,8 +181,8 @@ func (o *MrFusionAPI) Validate() error { unregistered = append(unregistered, "JSONProducer") } - if o.DeleteDashboardsIDHandler == nil { - unregistered = append(unregistered, "DeleteDashboardsIDHandler") + if o.DeleteLayoutsIDHandler == nil { + unregistered = append(unregistered, "DeleteLayoutsIDHandler") } if o.DeleteSourcesIDHandler == nil { @@ -213,12 +213,12 @@ func (o *MrFusionAPI) Validate() error { unregistered = append(unregistered, "GetHandler") } - if o.GetDashboardsHandler == nil { - unregistered = append(unregistered, "GetDashboardsHandler") + if o.GetLayoutsHandler == nil { + unregistered = append(unregistered, "GetLayoutsHandler") } - if o.GetDashboardsIDHandler == nil { - unregistered = append(unregistered, "GetDashboardsIDHandler") + if o.GetLayoutsIDHandler == nil { + unregistered = append(unregistered, "GetLayoutsIDHandler") } if o.GetSourcesHandler == nil { @@ -297,8 +297,8 @@ func (o *MrFusionAPI) Validate() error { unregistered = append(unregistered, "PatchSourcesIDUsersUserIDExplorationsExplorationIDHandler") } - if o.PostDashboardsHandler == nil { - unregistered = append(unregistered, "PostDashboardsHandler") + if o.PostLayoutsHandler == nil { + unregistered = append(unregistered, "PostLayoutsHandler") } if o.PostSourcesHandler == nil { @@ -329,8 +329,8 @@ func (o *MrFusionAPI) Validate() error { unregistered = append(unregistered, "PostSourcesIDUsersUserIDExplorationsHandler") } - if o.PutDashboardsIDHandler == nil { - unregistered = append(unregistered, "PutDashboardsIDHandler") + if o.PutLayoutsIDHandler == nil { + unregistered = append(unregistered, "PutLayoutsIDHandler") } if len(unregistered) > 0 { @@ -417,7 +417,7 @@ func (o *MrFusionAPI) initHandlerCache() { if o.handlers["DELETE"] == nil { o.handlers[strings.ToUpper("DELETE")] = make(map[string]http.Handler) } - o.handlers["DELETE"]["/dashboards/{id}"] = NewDeleteDashboardsID(o.context, o.DeleteDashboardsIDHandler) + o.handlers["DELETE"]["/layouts/{id}"] = NewDeleteLayoutsID(o.context, o.DeleteLayoutsIDHandler) if o.handlers["DELETE"] == nil { o.handlers[strings.ToUpper("DELETE")] = make(map[string]http.Handler) @@ -457,12 +457,12 @@ func (o *MrFusionAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler) } - o.handlers["GET"]["/dashboards"] = NewGetDashboards(o.context, o.GetDashboardsHandler) + o.handlers["GET"]["/layouts"] = NewGetLayouts(o.context, o.GetLayoutsHandler) if o.handlers["GET"] == nil { o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler) } - o.handlers["GET"]["/dashboards/{id}"] = NewGetDashboardsID(o.context, o.GetDashboardsIDHandler) + o.handlers["GET"]["/layouts/{id}"] = NewGetLayoutsID(o.context, o.GetLayoutsIDHandler) if o.handlers["GET"] == nil { o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler) @@ -562,7 +562,7 @@ func (o *MrFusionAPI) initHandlerCache() { if o.handlers["POST"] == nil { o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler) } - o.handlers["POST"]["/dashboards"] = NewPostDashboards(o.context, o.PostDashboardsHandler) + o.handlers["POST"]["/layouts"] = NewPostLayouts(o.context, o.PostLayoutsHandler) if o.handlers["POST"] == nil { o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler) @@ -602,7 +602,7 @@ func (o *MrFusionAPI) initHandlerCache() { if o.handlers["PUT"] == nil { o.handlers[strings.ToUpper("PUT")] = make(map[string]http.Handler) } - o.handlers["PUT"]["/dashboards/{id}"] = NewPutDashboardsID(o.context, o.PutDashboardsIDHandler) + o.handlers["PUT"]["/layouts/{id}"] = NewPutLayoutsID(o.context, o.PutLayoutsIDHandler) } diff --git a/restapi/operations/post_dashboards.go b/restapi/operations/post_dashboards.go deleted file mode 100644 index 3eb614c1a5..0000000000 --- a/restapi/operations/post_dashboards.go +++ /dev/null @@ -1,55 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - context "golang.org/x/net/context" - - middleware "github.com/go-openapi/runtime/middleware" -) - -// PostDashboardsHandlerFunc turns a function with the right signature into a post dashboards handler -type PostDashboardsHandlerFunc func(context.Context, PostDashboardsParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn PostDashboardsHandlerFunc) Handle(ctx context.Context, params PostDashboardsParams) middleware.Responder { - return fn(ctx, params) -} - -// PostDashboardsHandler interface for that can handle valid post dashboards params -type PostDashboardsHandler interface { - Handle(context.Context, PostDashboardsParams) middleware.Responder -} - -// NewPostDashboards creates a new http.Handler for the post dashboards operation -func NewPostDashboards(ctx *middleware.Context, handler PostDashboardsHandler) *PostDashboards { - return &PostDashboards{Context: ctx, Handler: handler} -} - -/*PostDashboards swagger:route POST /dashboards postDashboards - -Create new Dashboard - -*/ -type PostDashboards struct { - Context *middleware.Context - Handler PostDashboardsHandler -} - -func (o *PostDashboards) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, _ := o.Context.RouteInfo(r) - var Params = NewPostDashboardsParams() - - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(context.Background(), Params) // actually handle the request - - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/restapi/operations/post_dashboards_responses.go b/restapi/operations/post_dashboards_responses.go deleted file mode 100644 index c8e6add2d0..0000000000 --- a/restapi/operations/post_dashboards_responses.go +++ /dev/null @@ -1,123 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "fmt" - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/influxdata/mrfusion/models" -) - -/*PostDashboardsCreated Successfully created new dashboard - -swagger:response postDashboardsCreated -*/ -type PostDashboardsCreated struct { - /*Location of the newly created dashboard - Required: true - */ - Location string `json:"Location"` - - // In: body - Payload *models.Dashboard `json:"body,omitempty"` -} - -// NewPostDashboardsCreated creates PostDashboardsCreated with default headers values -func NewPostDashboardsCreated() *PostDashboardsCreated { - return &PostDashboardsCreated{} -} - -// WithLocation adds the location to the post dashboards created response -func (o *PostDashboardsCreated) WithLocation(location string) *PostDashboardsCreated { - o.Location = location - return o -} - -// SetLocation sets the location to the post dashboards created response -func (o *PostDashboardsCreated) SetLocation(location string) { - o.Location = location -} - -// WithPayload adds the payload to the post dashboards created response -func (o *PostDashboardsCreated) WithPayload(payload *models.Dashboard) *PostDashboardsCreated { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the post dashboards created response -func (o *PostDashboardsCreated) SetPayload(payload *models.Dashboard) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *PostDashboardsCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - // response header Location - rw.Header().Add("Location", fmt.Sprintf("%v", o.Location)) - - rw.WriteHeader(201) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*PostDashboardsDefault A processing or an unexpected error. - -swagger:response postDashboardsDefault -*/ -type PostDashboardsDefault struct { - _statusCode int - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewPostDashboardsDefault creates PostDashboardsDefault with default headers values -func NewPostDashboardsDefault(code int) *PostDashboardsDefault { - if code <= 0 { - code = 500 - } - - return &PostDashboardsDefault{ - _statusCode: code, - } -} - -// WithStatusCode adds the status to the post dashboards default response -func (o *PostDashboardsDefault) WithStatusCode(code int) *PostDashboardsDefault { - o._statusCode = code - return o -} - -// SetStatusCode sets the status to the post dashboards default response -func (o *PostDashboardsDefault) SetStatusCode(code int) { - o._statusCode = code -} - -// WithPayload adds the payload to the post dashboards default response -func (o *PostDashboardsDefault) WithPayload(payload *models.Error) *PostDashboardsDefault { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the post dashboards default response -func (o *PostDashboardsDefault) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *PostDashboardsDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(o._statusCode) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/restapi/operations/post_layouts.go b/restapi/operations/post_layouts.go new file mode 100644 index 0000000000..02197b8337 --- /dev/null +++ b/restapi/operations/post_layouts.go @@ -0,0 +1,55 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + context "golang.org/x/net/context" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// PostLayoutsHandlerFunc turns a function with the right signature into a post layouts handler +type PostLayoutsHandlerFunc func(context.Context, PostLayoutsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostLayoutsHandlerFunc) Handle(ctx context.Context, params PostLayoutsParams) middleware.Responder { + return fn(ctx, params) +} + +// PostLayoutsHandler interface for that can handle valid post layouts params +type PostLayoutsHandler interface { + Handle(context.Context, PostLayoutsParams) middleware.Responder +} + +// NewPostLayouts creates a new http.Handler for the post layouts operation +func NewPostLayouts(ctx *middleware.Context, handler PostLayoutsHandler) *PostLayouts { + return &PostLayouts{Context: ctx, Handler: handler} +} + +/*PostLayouts swagger:route POST /layouts postLayouts + +Create new layout + +*/ +type PostLayouts struct { + Context *middleware.Context + Handler PostLayoutsHandler +} + +func (o *PostLayouts) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, _ := o.Context.RouteInfo(r) + var Params = NewPostLayoutsParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(context.Background(), Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/post_dashboards_parameters.go b/restapi/operations/post_layouts_parameters.go similarity index 62% rename from restapi/operations/post_dashboards_parameters.go rename to restapi/operations/post_layouts_parameters.go index 97700a7c13..c0f28548e9 100644 --- a/restapi/operations/post_dashboards_parameters.go +++ b/restapi/operations/post_layouts_parameters.go @@ -13,46 +13,46 @@ import ( "github.com/influxdata/mrfusion/models" ) -// NewPostDashboardsParams creates a new PostDashboardsParams object +// NewPostLayoutsParams creates a new PostLayoutsParams object // with the default values initialized. -func NewPostDashboardsParams() PostDashboardsParams { +func NewPostLayoutsParams() PostLayoutsParams { var () - return PostDashboardsParams{} + return PostLayoutsParams{} } -// PostDashboardsParams contains all the bound params for the post dashboards operation +// PostLayoutsParams contains all the bound params for the post layouts operation // typically these are obtained from a http.Request // -// swagger:parameters PostDashboards -type PostDashboardsParams struct { +// swagger:parameters PostLayouts +type PostLayoutsParams struct { // HTTP Request Object HTTPRequest *http.Request - /*Defines the dashboard and queries of the cells within the dashboard. + /*Defines the layout and queries of the cells within the layout. In: body */ - Dashboard *models.Dashboard + Layout *models.Layout } // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls -func (o *PostDashboardsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { +func (o *PostLayoutsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error o.HTTPRequest = r if runtime.HasBody(r) { defer r.Body.Close() - var body models.Dashboard + var body models.Layout if err := route.Consumer.Consume(r.Body, &body); err != nil { - res = append(res, errors.NewParseError("dashboard", "body", "", err)) + res = append(res, errors.NewParseError("layout", "body", "", err)) } else { if err := body.Validate(route.Formats); err != nil { res = append(res, err) } if len(res) == 0 { - o.Dashboard = &body + o.Layout = &body } } diff --git a/restapi/operations/post_layouts_responses.go b/restapi/operations/post_layouts_responses.go new file mode 100644 index 0000000000..d7d8d163e5 --- /dev/null +++ b/restapi/operations/post_layouts_responses.go @@ -0,0 +1,123 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/influxdata/mrfusion/models" +) + +/*PostLayoutsCreated Successfully created new layout + +swagger:response postLayoutsCreated +*/ +type PostLayoutsCreated struct { + /*Location of the newly created layout + Required: true + */ + Location string `json:"Location"` + + // In: body + Payload *models.Layout `json:"body,omitempty"` +} + +// NewPostLayoutsCreated creates PostLayoutsCreated with default headers values +func NewPostLayoutsCreated() *PostLayoutsCreated { + return &PostLayoutsCreated{} +} + +// WithLocation adds the location to the post layouts created response +func (o *PostLayoutsCreated) WithLocation(location string) *PostLayoutsCreated { + o.Location = location + return o +} + +// SetLocation sets the location to the post layouts created response +func (o *PostLayoutsCreated) SetLocation(location string) { + o.Location = location +} + +// WithPayload adds the payload to the post layouts created response +func (o *PostLayoutsCreated) WithPayload(payload *models.Layout) *PostLayoutsCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post layouts created response +func (o *PostLayoutsCreated) SetPayload(payload *models.Layout) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostLayoutsCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + // response header Location + rw.Header().Add("Location", fmt.Sprintf("%v", o.Location)) + + rw.WriteHeader(201) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*PostLayoutsDefault A processing or an unexpected error. + +swagger:response postLayoutsDefault +*/ +type PostLayoutsDefault struct { + _statusCode int + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostLayoutsDefault creates PostLayoutsDefault with default headers values +func NewPostLayoutsDefault(code int) *PostLayoutsDefault { + if code <= 0 { + code = 500 + } + + return &PostLayoutsDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the post layouts default response +func (o *PostLayoutsDefault) WithStatusCode(code int) *PostLayoutsDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the post layouts default response +func (o *PostLayoutsDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the post layouts default response +func (o *PostLayoutsDefault) WithPayload(payload *models.Error) *PostLayoutsDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post layouts default response +func (o *PostLayoutsDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostLayoutsDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/put_dashboards_id.go b/restapi/operations/put_dashboards_id.go deleted file mode 100644 index 69b733a4f2..0000000000 --- a/restapi/operations/put_dashboards_id.go +++ /dev/null @@ -1,55 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the generate command - -import ( - "net/http" - - context "golang.org/x/net/context" - - middleware "github.com/go-openapi/runtime/middleware" -) - -// PutDashboardsIDHandlerFunc turns a function with the right signature into a put dashboards ID handler -type PutDashboardsIDHandlerFunc func(context.Context, PutDashboardsIDParams) middleware.Responder - -// Handle executing the request and returning a response -func (fn PutDashboardsIDHandlerFunc) Handle(ctx context.Context, params PutDashboardsIDParams) middleware.Responder { - return fn(ctx, params) -} - -// PutDashboardsIDHandler interface for that can handle valid put dashboards ID params -type PutDashboardsIDHandler interface { - Handle(context.Context, PutDashboardsIDParams) middleware.Responder -} - -// NewPutDashboardsID creates a new http.Handler for the put dashboards ID operation -func NewPutDashboardsID(ctx *middleware.Context, handler PutDashboardsIDHandler) *PutDashboardsID { - return &PutDashboardsID{Context: ctx, Handler: handler} -} - -/*PutDashboardsID swagger:route PUT /dashboards/{id} putDashboardsId - -Replace dashboard configuration. - -*/ -type PutDashboardsID struct { - Context *middleware.Context - Handler PutDashboardsIDHandler -} - -func (o *PutDashboardsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - route, _ := o.Context.RouteInfo(r) - var Params = NewPutDashboardsIDParams() - - if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params - o.Context.Respond(rw, r, route.Produces, route, err) - return - } - - res := o.Handler.Handle(context.Background(), Params) // actually handle the request - - o.Context.Respond(rw, r, route.Produces, route, res) - -} diff --git a/restapi/operations/put_dashboards_id_responses.go b/restapi/operations/put_dashboards_id_responses.go deleted file mode 100644 index a1dbe78569..0000000000 --- a/restapi/operations/put_dashboards_id_responses.go +++ /dev/null @@ -1,122 +0,0 @@ -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - - "github.com/go-openapi/runtime" - - "github.com/influxdata/mrfusion/models" -) - -/*PutDashboardsIDNoContent Dashboard's configuration was changed - -swagger:response putDashboardsIdNoContent -*/ -type PutDashboardsIDNoContent struct { -} - -// NewPutDashboardsIDNoContent creates PutDashboardsIDNoContent with default headers values -func NewPutDashboardsIDNoContent() *PutDashboardsIDNoContent { - return &PutDashboardsIDNoContent{} -} - -// WriteResponse to the client -func (o *PutDashboardsIDNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(204) -} - -/*PutDashboardsIDNotFound Happens when trying to access a non-existent dashboard. - -swagger:response putDashboardsIdNotFound -*/ -type PutDashboardsIDNotFound struct { - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewPutDashboardsIDNotFound creates PutDashboardsIDNotFound with default headers values -func NewPutDashboardsIDNotFound() *PutDashboardsIDNotFound { - return &PutDashboardsIDNotFound{} -} - -// WithPayload adds the payload to the put dashboards Id not found response -func (o *PutDashboardsIDNotFound) WithPayload(payload *models.Error) *PutDashboardsIDNotFound { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the put dashboards Id not found response -func (o *PutDashboardsIDNotFound) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *PutDashboardsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(404) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} - -/*PutDashboardsIDDefault A processing or an unexpected error. - -swagger:response putDashboardsIdDefault -*/ -type PutDashboardsIDDefault struct { - _statusCode int - - // In: body - Payload *models.Error `json:"body,omitempty"` -} - -// NewPutDashboardsIDDefault creates PutDashboardsIDDefault with default headers values -func NewPutDashboardsIDDefault(code int) *PutDashboardsIDDefault { - if code <= 0 { - code = 500 - } - - return &PutDashboardsIDDefault{ - _statusCode: code, - } -} - -// WithStatusCode adds the status to the put dashboards ID default response -func (o *PutDashboardsIDDefault) WithStatusCode(code int) *PutDashboardsIDDefault { - o._statusCode = code - return o -} - -// SetStatusCode sets the status to the put dashboards ID default response -func (o *PutDashboardsIDDefault) SetStatusCode(code int) { - o._statusCode = code -} - -// WithPayload adds the payload to the put dashboards ID default response -func (o *PutDashboardsIDDefault) WithPayload(payload *models.Error) *PutDashboardsIDDefault { - o.Payload = payload - return o -} - -// SetPayload sets the payload to the put dashboards ID default response -func (o *PutDashboardsIDDefault) SetPayload(payload *models.Error) { - o.Payload = payload -} - -// WriteResponse to the client -func (o *PutDashboardsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { - - rw.WriteHeader(o._statusCode) - if o.Payload != nil { - if err := producer.Produce(rw, o.Payload); err != nil { - panic(err) // let the recovery middleware deal with this - } - } -} diff --git a/restapi/operations/put_layouts_id.go b/restapi/operations/put_layouts_id.go new file mode 100644 index 0000000000..e40ecbfe52 --- /dev/null +++ b/restapi/operations/put_layouts_id.go @@ -0,0 +1,55 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + context "golang.org/x/net/context" + + middleware "github.com/go-openapi/runtime/middleware" +) + +// PutLayoutsIDHandlerFunc turns a function with the right signature into a put layouts ID handler +type PutLayoutsIDHandlerFunc func(context.Context, PutLayoutsIDParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutLayoutsIDHandlerFunc) Handle(ctx context.Context, params PutLayoutsIDParams) middleware.Responder { + return fn(ctx, params) +} + +// PutLayoutsIDHandler interface for that can handle valid put layouts ID params +type PutLayoutsIDHandler interface { + Handle(context.Context, PutLayoutsIDParams) middleware.Responder +} + +// NewPutLayoutsID creates a new http.Handler for the put layouts ID operation +func NewPutLayoutsID(ctx *middleware.Context, handler PutLayoutsIDHandler) *PutLayoutsID { + return &PutLayoutsID{Context: ctx, Handler: handler} +} + +/*PutLayoutsID swagger:route PUT /layouts/{id} putLayoutsId + +Replace layout configuration. + +*/ +type PutLayoutsID struct { + Context *middleware.Context + Handler PutLayoutsIDHandler +} + +func (o *PutLayoutsID) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, _ := o.Context.RouteInfo(r) + var Params = NewPutLayoutsIDParams() + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(context.Background(), Params) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/put_dashboards_id_parameters.go b/restapi/operations/put_layouts_id_parameters.go similarity index 72% rename from restapi/operations/put_dashboards_id_parameters.go rename to restapi/operations/put_layouts_id_parameters.go index 402096e621..7a60384187 100644 --- a/restapi/operations/put_dashboards_id_parameters.go +++ b/restapi/operations/put_layouts_id_parameters.go @@ -16,28 +16,28 @@ import ( "github.com/influxdata/mrfusion/models" ) -// NewPutDashboardsIDParams creates a new PutDashboardsIDParams object +// NewPutLayoutsIDParams creates a new PutLayoutsIDParams object // with the default values initialized. -func NewPutDashboardsIDParams() PutDashboardsIDParams { +func NewPutLayoutsIDParams() PutLayoutsIDParams { var () - return PutDashboardsIDParams{} + return PutLayoutsIDParams{} } -// PutDashboardsIDParams contains all the bound params for the put dashboards ID operation +// PutLayoutsIDParams contains all the bound params for the put layouts ID operation // typically these are obtained from a http.Request // -// swagger:parameters PutDashboardsID -type PutDashboardsIDParams struct { +// swagger:parameters PutLayoutsID +type PutLayoutsIDParams struct { // HTTP Request Object HTTPRequest *http.Request - /*dashboard configuration update parameters + /*layout configuration update parameters Required: true In: body */ - Config *models.Dashboard - /*ID of a dashboard + Config *models.Layout + /*ID of a layout Required: true In: path */ @@ -46,13 +46,13 @@ type PutDashboardsIDParams struct { // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface // for simple values it will use straight method calls -func (o *PutDashboardsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { +func (o *PutLayoutsIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { var res []error o.HTTPRequest = r if runtime.HasBody(r) { defer r.Body.Close() - var body models.Dashboard + var body models.Layout if err := route.Consumer.Consume(r.Body, &body); err != nil { if err == io.EOF { res = append(res, errors.Required("config", "body")) @@ -85,7 +85,7 @@ func (o *PutDashboardsIDParams) BindRequest(r *http.Request, route *middleware.M return nil } -func (o *PutDashboardsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { +func (o *PutLayoutsIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { var raw string if len(rawData) > 0 { raw = rawData[len(rawData)-1] diff --git a/restapi/operations/put_layouts_id_responses.go b/restapi/operations/put_layouts_id_responses.go new file mode 100644 index 0000000000..a0d5720b1f --- /dev/null +++ b/restapi/operations/put_layouts_id_responses.go @@ -0,0 +1,141 @@ +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/influxdata/mrfusion/models" +) + +/*PutLayoutsIDOK Layout has been replaced and the new layout is returned. + +swagger:response putLayoutsIdOK +*/ +type PutLayoutsIDOK struct { + + // In: body + Payload *models.Layout `json:"body,omitempty"` +} + +// NewPutLayoutsIDOK creates PutLayoutsIDOK with default headers values +func NewPutLayoutsIDOK() *PutLayoutsIDOK { + return &PutLayoutsIDOK{} +} + +// WithPayload adds the payload to the put layouts Id o k response +func (o *PutLayoutsIDOK) WithPayload(payload *models.Layout) *PutLayoutsIDOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put layouts Id o k response +func (o *PutLayoutsIDOK) SetPayload(payload *models.Layout) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutLayoutsIDOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*PutLayoutsIDNotFound Happens when trying to access a non-existent layout. + +swagger:response putLayoutsIdNotFound +*/ +type PutLayoutsIDNotFound struct { + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewPutLayoutsIDNotFound creates PutLayoutsIDNotFound with default headers values +func NewPutLayoutsIDNotFound() *PutLayoutsIDNotFound { + return &PutLayoutsIDNotFound{} +} + +// WithPayload adds the payload to the put layouts Id not found response +func (o *PutLayoutsIDNotFound) WithPayload(payload *models.Error) *PutLayoutsIDNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put layouts Id not found response +func (o *PutLayoutsIDNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutLayoutsIDNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*PutLayoutsIDDefault A processing or an unexpected error. + +swagger:response putLayoutsIdDefault +*/ +type PutLayoutsIDDefault struct { + _statusCode int + + // In: body + Payload *models.Error `json:"body,omitempty"` +} + +// NewPutLayoutsIDDefault creates PutLayoutsIDDefault with default headers values +func NewPutLayoutsIDDefault(code int) *PutLayoutsIDDefault { + if code <= 0 { + code = 500 + } + + return &PutLayoutsIDDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the put layouts ID default response +func (o *PutLayoutsIDDefault) WithStatusCode(code int) *PutLayoutsIDDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the put layouts ID default response +func (o *PutLayoutsIDDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the put layouts ID default response +func (o *PutLayoutsIDDefault) WithPayload(payload *models.Error) *PutLayoutsIDDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put layouts ID default response +func (o *PutLayoutsIDDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutLayoutsIDDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + if err := producer.Produce(rw, o.Payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/stores.go b/stores.go index cf58757573..61338d415d 100644 --- a/stores.go +++ b/stores.go @@ -97,24 +97,24 @@ type Cell struct { Queries []Query } -// Dashboard is a collection of Cells for visualization -type Dashboard struct { +// Layout is a collection of Cells for visualization +type Layout struct { ID int Cells []Cell } -// DashboardStore stores dashboards and associated Cells -type DashboardStore interface { +// LayoutStore stores dashboards and associated Cells +type LayoutStore interface { // All returns all dashboards in the store - All(context.Context) ([]*Dashboard, error) - // Add creates a new dashboard in the DashboardStore - Add(context.Context, *Dashboard) error + All(context.Context) ([]Layout, error) + // Add creates a new dashboard in the LayoutStore + Add(context.Context, Layout) (Layout, error) // Delete the dashboard from the store - Delete(context.Context, *Dashboard) error - // Get retrieves Dashboard if `ID` exists - Get(ctx context.Context, ID int) (*Dashboard, error) + Delete(context.Context, Layout) error + // Get retrieves Layout if `ID` exists + Get(ctx context.Context, ID int) (Layout, error) // Update the dashboard in the store. - Update(context.Context, *Dashboard) error + Update(context.Context, Layout) error } type Source struct { diff --git a/swagger.yaml b/swagger.yaml index 9377a0a190..d3c3d27cc6 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -72,7 +72,7 @@ paths: description: These data sources store time series data. responses: 200: - description: Data source used to supply time series to dashboards. + description: Data source used to supply time series information. schema: $ref: '#/definitions/Source' 404: @@ -882,60 +882,69 @@ paths: description: Response directly from kapacitor schema: $ref: '#/definitions/KapacitorProxyResponse' - /dashboards: + /layouts: get: - summary: Pre-configured dashboards + summary: Pre-configured layouts + parameters: + - name: ids + in: query + description: IDs for all layouts to return + required: false + type: array + items: + type: string + collectionFormat: csv description: | - Dashboards are a collection of `Cells` that visualize time-series data. + Layouts are a collection of `Cells` that visualize time-series data. responses: 200: - description: An array of dashboards + description: An array of layouts schema: - $ref: '#/definitions/Dashboards' + $ref: '#/definitions/Layouts' default: description: Unexpected internal service error schema: $ref: '#/definitions/Error' post: - summary: Create new Dashboard + summary: Create new layout parameters: - - name: dashboard + - name: layout in: body - description: Defines the dashboard and queries of the cells within the dashboard. + description: Defines the layout and queries of the cells within the layout. schema: - $ref: '#/definitions/Dashboard' + $ref: '#/definitions/Layout' responses: 201: - description: Successfully created new dashboard + description: Successfully created new layout headers: Location: type: string format: url - description: Location of the newly created dashboard + description: Location of the newly created layout schema: - $ref: '#/definitions/Dashboard' + $ref: '#/definitions/Layout' default: description: A processing or an unexpected error. schema: $ref: '#/definitions/Error' - /dashboards/{id}: + /layouts/{id}: get: parameters: - name: id in: path type: string - description: ID of the dashboard + description: ID of the layout required: true - summary: Specific pre-configured dashboard containing cells and queries. + summary: Specific pre-configured layout containing cells and queries. description: | - dashboards will hold information about how to layout the page of graphs. + layouts will hold information about how to layout the page of graphs. responses: 200: - description: Returns the specified dashboard containing `cells`. + description: Returns the specified layout containing `cells`. schema: - $ref: '#/definitions/Dashboard' + $ref: '#/definitions/Layout' 404: - description: Unknown dashboard id + description: Unknown layout id schema: $ref: '#/definitions/Error' default: @@ -947,14 +956,14 @@ paths: - name: id in: path type: string - description: ID of the dashboard + description: ID of the layout required: true - summary: This specific dashboard will be removed from the data store + summary: This specific layout will be removed from the data store responses: 204: - description: An array of dashboards + description: Layout has been removed. 404: - description: Unknown dashboard id + description: Unknown layout id schema: $ref: '#/definitions/Error' default: @@ -962,24 +971,26 @@ paths: schema: $ref: '#/definitions/Error' put: - summary: Replace dashboard configuration. + summary: Replace layout configuration. parameters: - name: id in: path type: string - description: ID of a dashboard + description: ID of a layout required: true - name: config in: body - description: dashboard configuration update parameters + description: layout configuration update parameters schema: - $ref: '#/definitions/Dashboard' + $ref: '#/definitions/Layout' required: true responses: - 204: - description: Dashboard's configuration was changed + 200: + description: Layout has been replaced and the new layout is returned. + schema: + $ref: '#/definitions/Layout' 404: - description: Happens when trying to access a non-existent dashboard. + description: Happens when trying to access a non-existent layout. schema: $ref: '#/definitions/Error' default: @@ -1231,14 +1242,16 @@ definitions: type: array items: $ref: "#/definitions/Permission" - Dashboards: + Layouts: + required: + - layouts type: object properties: - dashboards: + layouts: type: array items: - $ref: "#/definitions/Dashboard" - Dashboard: + $ref: "#/definitions/Layout" + Layout: type: object required: - cells @@ -1252,28 +1265,33 @@ definitions: $ref: "#/definitions/Link" Cell: type: object + required: + - x + - 'y' + - w + - h properties: x: - description: X-coordinate of Cell in the Dashboard + description: X-coordinate of Cell in the Layout type: integer format: int32 'y': - description: Y-coordinate of Cell in the Dashboard + description: Y-coordinate of Cell in the Layout type: integer format: int32 w: - description: Width of Cell in the Dashboard + description: Width of Cell in the Layout type: integer format: int32 h: - description: Height of Cell in the Dashboard + description: Height of Cell in the Layout type: integer format: int32 queries: description: Time-series data queries for Cell. type: array items: - type: string + $ref: "#/definitions/Proxy" Routes: type: object properties: @@ -1281,18 +1299,14 @@ definitions: description: Location of the users endpoint type: string format: url - dashboards: - description: Location of the dashboards endpoint + layouts: + description: Location of the layouts endpoint type: string format: url sources: description: Location of the sources endpoint type: string format: url - apps: - description: Location of the apps endpoint - type: string - format: url Services: type: object properties: From 7aec0e93bf62045425a88e391f5a70cc799b3152 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Thu, 6 Oct 2016 18:31:56 -0500 Subject: [PATCH 2/5] Add ability to to filter layouts by apps or measurements. --- bolt/internal/internal.go | 8 ++- bolt/internal/internal.pb.go | 64 ++++++++++--------- bolt/internal/internal.proto | 6 +- handlers/layout.go | 36 +++++++++-- models/layout.go | 40 ++++++++++++ restapi/operations/get_layouts_parameters.go | 65 +++++++++++++++++--- stores.go | 6 +- swagger.yaml | 20 +++++- 8 files changed, 192 insertions(+), 53 deletions(-) diff --git a/bolt/internal/internal.go b/bolt/internal/internal.go index 27eafde1f7..0fd8dd33a7 100644 --- a/bolt/internal/internal.go +++ b/bolt/internal/internal.go @@ -119,8 +119,10 @@ func MarshalLayout(l mrfusion.Layout) ([]byte, error) { } } return proto.Marshal(&Layout{ - ID: int64(l.ID), - Cells: cells, + ID: int64(l.ID), + Measurement: l.Measurement, + Application: l.Application, + Cells: cells, }) } @@ -132,6 +134,8 @@ func UnmarshalLayout(data []byte, l *mrfusion.Layout) error { } l.ID = int(pb.ID) + l.Measurement = pb.Measurement + l.Application = pb.Application cells := make([]mrfusion.Cell, len(pb.Cells)) for i, c := range pb.Cells { queries := make([]mrfusion.Query, len(c.Queries)) diff --git a/bolt/internal/internal.pb.go b/bolt/internal/internal.pb.go index ce53767abd..cc91dab9ab 100644 --- a/bolt/internal/internal.pb.go +++ b/bolt/internal/internal.pb.go @@ -78,8 +78,10 @@ func (*Server) ProtoMessage() {} func (*Server) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{2} } type Layout struct { - ID int64 `protobuf:"varint,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` - Cells []*Cell `protobuf:"bytes,2,rep,name=Cells,json=cells" json:"Cells,omitempty"` + ID int64 `protobuf:"varint,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` + Application string `protobuf:"bytes,2,opt,name=Application,json=application,proto3" json:"Application,omitempty"` + Measurement string `protobuf:"bytes,3,opt,name=Measurement,json=measurement,proto3" json:"Measurement,omitempty"` + Cells []*Cell `protobuf:"bytes,4,rep,name=Cells,json=cells" json:"Cells,omitempty"` } func (m *Layout) Reset() { *m = Layout{} } @@ -137,32 +139,34 @@ func init() { func init() { proto.RegisterFile("internal.proto", fileDescriptorInternal) } var fileDescriptorInternal = []byte{ - // 423 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x8a, 0xd4, 0x4e, - 0x10, 0xc7, 0xe9, 0x24, 0x9d, 0x3f, 0xb5, 0x3f, 0xe6, 0x27, 0x8d, 0x48, 0x23, 0x1e, 0x42, 0xf0, - 0x30, 0x5e, 0xf6, 0xa0, 0x77, 0x61, 0x77, 0xe2, 0x61, 0x20, 0xc8, 0x58, 0xeb, 0x3c, 0x40, 0x9b, - 0xb4, 0x6c, 0x20, 0x93, 0xc4, 0x4e, 0xb7, 0x33, 0x79, 0x07, 0x9f, 0xc3, 0x17, 0xf0, 0x05, 0xa5, - 0x7a, 0x32, 0x2a, 0x0a, 0xcb, 0x1e, 0x3f, 0xf5, 0xad, 0xa4, 0x3e, 0x55, 0x34, 0xac, 0xda, 0xde, - 0x6a, 0xd3, 0xab, 0xee, 0x7a, 0x34, 0x83, 0x1d, 0x44, 0x7a, 0xe1, 0xe2, 0x07, 0x83, 0xab, 0x77, - 0xa7, 0xb1, 0x1b, 0x8c, 0xb2, 0xed, 0xd0, 0x8b, 0x15, 0x04, 0xdb, 0x52, 0xb2, 0x9c, 0xad, 0x43, - 0x0c, 0xda, 0x52, 0x08, 0x88, 0xde, 0xab, 0x83, 0x96, 0x41, 0xce, 0xd6, 0x19, 0x46, 0xbd, 0x3a, - 0x68, 0xf1, 0x0c, 0xe2, 0xfd, 0xa4, 0xcd, 0xb6, 0x94, 0xa1, 0xef, 0x8b, 0x9d, 0x27, 0xea, 0x2d, - 0x95, 0x55, 0x32, 0x3a, 0xf7, 0x36, 0xca, 0x2a, 0xf1, 0x02, 0xb2, 0x8d, 0xd1, 0xca, 0xea, 0xe6, - 0xc6, 0x4a, 0xee, 0xdb, 0xb3, 0xfa, 0x52, 0xa0, 0x74, 0x3f, 0x36, 0x4b, 0x1a, 0x9f, 0x53, 0x77, - 0x29, 0x08, 0x09, 0x49, 0xa9, 0x3f, 0x2b, 0xd7, 0x59, 0x99, 0xe4, 0x6c, 0x9d, 0x62, 0xd2, 0x9c, - 0xb1, 0xf8, 0xce, 0x20, 0xbe, 0x1b, 0x9c, 0xa9, 0xf5, 0xa3, 0x84, 0x05, 0x44, 0x1f, 0xe7, 0x51, - 0x7b, 0xdd, 0x0c, 0x23, 0x3b, 0x8f, 0x5a, 0x3c, 0x87, 0x94, 0x96, 0xa0, 0x7c, 0x11, 0x4e, 0xdd, - 0xc2, 0x94, 0xed, 0xd4, 0x34, 0x1d, 0x07, 0xd3, 0x78, 0xe7, 0x0c, 0xd3, 0x71, 0x61, 0xfa, 0xd7, - 0x1e, 0xab, 0x49, 0xc6, 0x79, 0x48, 0xff, 0x72, 0x58, 0x4d, 0x0f, 0x88, 0x7e, 0x23, 0x51, 0x6d, - 0xbe, 0x6a, 0xf3, 0x28, 0xd1, 0x3f, 0xa5, 0xc2, 0x07, 0xa4, 0xa2, 0xbf, 0xa4, 0x9e, 0x40, 0xb8, - 0xc7, 0x6a, 0x71, 0x0d, 0x1d, 0x56, 0xe2, 0x29, 0xf0, 0x3b, 0x53, 0x6f, 0xcb, 0xe5, 0xaa, 0x7c, - 0x22, 0x28, 0xde, 0x42, 0x5c, 0xa9, 0x79, 0x70, 0xf6, 0x1f, 0x9b, 0x97, 0xc0, 0x37, 0xba, 0xeb, - 0x26, 0x19, 0xe4, 0xe1, 0xfa, 0xea, 0xf5, 0xea, 0xfa, 0xd7, 0x8b, 0xa1, 0x32, 0xf2, 0x9a, 0xc2, - 0xa2, 0x85, 0x88, 0x50, 0xfc, 0x07, 0xec, 0xe4, 0x3f, 0xe6, 0xc8, 0x4e, 0x44, 0xb3, 0x5f, 0x83, - 0x23, 0x9b, 0x89, 0x8e, 0x5e, 0x9e, 0x23, 0x3b, 0x12, 0xdd, 0x7b, 0x5d, 0x8e, 0xec, 0x5e, 0xbc, - 0x82, 0xe4, 0x8b, 0xd3, 0xa6, 0xd5, 0x93, 0xe4, 0x7e, 0xce, 0xff, 0xbf, 0xe7, 0x7c, 0x70, 0xda, - 0xcc, 0x78, 0xc9, 0x8b, 0x1b, 0xe0, 0xbe, 0x42, 0xc7, 0xdd, 0x0c, 0x87, 0x83, 0xea, 0x1b, 0x3f, - 0x31, 0xc3, 0xa4, 0x3e, 0x23, 0xed, 0x50, 0xde, 0x2e, 0xf7, 0x0b, 0x9a, 0x5b, 0x62, 0xdc, 0x2d, - 0x77, 0x0b, 0xcc, 0xee, 0x53, 0xec, 0x1f, 0xfb, 0x9b, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xbb, - 0xaf, 0x1c, 0x0c, 0xfe, 0x02, 0x00, 0x00, + // 453 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x8e, 0xd3, 0x3e, + 0x10, 0xc7, 0xe5, 0x26, 0x4e, 0x13, 0xe7, 0xa7, 0xfe, 0x90, 0x85, 0x90, 0x85, 0x38, 0x44, 0x11, + 0x87, 0x72, 0xd9, 0x03, 0x3c, 0x41, 0xb7, 0xe1, 0x50, 0x29, 0xa0, 0xe2, 0xa5, 0x0f, 0x60, 0x92, + 0x41, 0x1b, 0x29, 0xff, 0x70, 0x6c, 0xda, 0x5c, 0x39, 0xf3, 0x1c, 0xbc, 0x00, 0x2f, 0x88, 0xc6, + 0x75, 0x29, 0x02, 0x69, 0xb5, 0xc7, 0xcf, 0x7c, 0x47, 0x9e, 0xcf, 0x38, 0x0e, 0x5b, 0x35, 0xbd, + 0x01, 0xdd, 0xab, 0xf6, 0x66, 0xd4, 0x83, 0x19, 0x78, 0x7c, 0xe1, 0xfc, 0x27, 0x61, 0xe9, 0xdb, + 0xd3, 0xd8, 0x0e, 0x5a, 0x99, 0x66, 0xe8, 0xf9, 0x8a, 0x2d, 0x76, 0x85, 0x20, 0x19, 0x59, 0x07, + 0x72, 0xd1, 0x14, 0x9c, 0xb3, 0xf0, 0xbd, 0xea, 0x40, 0x2c, 0x32, 0xb2, 0x4e, 0x64, 0xd8, 0xab, + 0x0e, 0xf8, 0x33, 0x16, 0x1d, 0x26, 0xd0, 0xbb, 0x42, 0x04, 0xae, 0x2f, 0xb2, 0x8e, 0xb0, 0xb7, + 0x50, 0x46, 0x89, 0xf0, 0xdc, 0x5b, 0x2b, 0xa3, 0xf8, 0x0b, 0x96, 0x6c, 0x35, 0x28, 0x03, 0xf5, + 0xc6, 0x08, 0xea, 0xda, 0x93, 0xea, 0x52, 0xc0, 0xf4, 0x30, 0xd6, 0x3e, 0x8d, 0xce, 0xa9, 0xbd, + 0x14, 0xb8, 0x60, 0xcb, 0x02, 0x3e, 0x2b, 0xdb, 0x1a, 0xb1, 0xcc, 0xc8, 0x3a, 0x96, 0xcb, 0xfa, + 0x8c, 0xf9, 0x0f, 0xc2, 0xa2, 0xbb, 0xc1, 0xea, 0x0a, 0x1e, 0x25, 0xcc, 0x59, 0xf8, 0x71, 0x1e, + 0xc1, 0xe9, 0x26, 0x32, 0x34, 0xf3, 0x08, 0xfc, 0x39, 0x8b, 0x71, 0x09, 0xcc, 0xbd, 0x70, 0x6c, + 0x3d, 0x63, 0xb6, 0x57, 0xd3, 0x74, 0x1c, 0x74, 0xed, 0x9c, 0x13, 0x19, 0x8f, 0x9e, 0xf1, 0xac, + 0x83, 0x2c, 0x27, 0x11, 0x65, 0x01, 0x9e, 0x65, 0x65, 0x39, 0x3d, 0x20, 0xfa, 0x1d, 0x45, 0x41, + 0x7f, 0x05, 0xfd, 0x28, 0xd1, 0x3f, 0xa5, 0x82, 0x07, 0xa4, 0xc2, 0xbf, 0xa4, 0x9e, 0xb0, 0xe0, + 0x20, 0x4b, 0xef, 0x1a, 0x58, 0x59, 0xf2, 0xa7, 0x8c, 0xde, 0xe9, 0x6a, 0x57, 0xf8, 0x5b, 0xa5, + 0x13, 0x42, 0xfe, 0x8d, 0xb0, 0xa8, 0x54, 0xf3, 0x60, 0xcd, 0x3f, 0x3a, 0x19, 0x4b, 0x37, 0xe3, + 0xd8, 0x36, 0x95, 0x7b, 0x07, 0xde, 0x2a, 0x55, 0xd7, 0x12, 0x76, 0xbc, 0x03, 0x35, 0x59, 0x0d, + 0x1d, 0xf4, 0xc6, 0xfb, 0xa5, 0xdd, 0xb5, 0xc4, 0x5f, 0x32, 0xba, 0x85, 0xb6, 0x9d, 0x44, 0x98, + 0x05, 0xeb, 0xf4, 0xf5, 0xea, 0xe6, 0xf7, 0xb3, 0xc3, 0xb2, 0xa4, 0x15, 0x86, 0x79, 0xc3, 0x42, + 0x44, 0xfe, 0x1f, 0x23, 0x27, 0x27, 0x40, 0x25, 0x39, 0x21, 0xcd, 0x6e, 0x2a, 0x95, 0x64, 0x46, + 0x3a, 0xba, 0x09, 0x54, 0x92, 0x23, 0xd2, 0xbd, 0xdb, 0x99, 0x4a, 0x72, 0xcf, 0x5f, 0xb1, 0xe5, + 0x17, 0x0b, 0xba, 0x81, 0x49, 0x50, 0x37, 0xe7, 0xff, 0xeb, 0x9c, 0x0f, 0x16, 0xf4, 0x2c, 0x2f, + 0x79, 0xbe, 0x61, 0xd4, 0x55, 0xf0, 0x0b, 0x6d, 0x87, 0xae, 0x53, 0x7d, 0xed, 0x26, 0x26, 0x72, + 0x59, 0x9d, 0x11, 0xef, 0xa1, 0xb8, 0xf5, 0xeb, 0x2e, 0xea, 0x5b, 0x64, 0xb9, 0xf7, 0xcb, 0x2d, + 0xf4, 0xfe, 0x53, 0xe4, 0xfe, 0x98, 0x37, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x3c, 0x88, 0x2a, + 0x36, 0x43, 0x03, 0x00, 0x00, } diff --git a/bolt/internal/internal.proto b/bolt/internal/internal.proto index 4b3e2059cb..bf9aad58bd 100644 --- a/bolt/internal/internal.proto +++ b/bolt/internal/internal.proto @@ -31,8 +31,10 @@ message Server { } message Layout { - int64 ID = 1; // ID is the unique ID of the layout - repeated Cell Cells = 2; // Cells are the individual visualization elements. + int64 ID = 1; // ID is the unique ID of the layout. + string Application = 2; // Application is the user facing name of this Layout. + string Measurement = 3; // Measurement is the descriptive name of the time series data. + repeated Cell Cells = 4; // Cells are the individual visualization elements. } message Cell { diff --git a/handlers/layout.go b/handlers/layout.go index d7cd6008f3..ba65a18741 100644 --- a/handlers/layout.go +++ b/handlers/layout.go @@ -32,7 +32,9 @@ func layoutToMrF(l *models.Layout) mrfusion.Layout { } } return mrfusion.Layout{ - Cells: cells, + Measurement: *l.Measurement, + Application: *l.App, + Cells: cells, } } @@ -81,20 +83,44 @@ func layoutToModel(l mrfusion.Layout) *models.Layout { Href: &href, Rel: &rel, }, - Cells: cells, + Cells: cells, + Measurement: &l.Measurement, + App: &l.Application, } } +func requestedLayout(filtered map[string]bool, layout mrfusion.Layout) bool { + // If the length of the filter is zero then all values are acceptable. + if len(filtered) == 0 { + return true + } + + // If filter contains either measurement or application + return filtered[layout.Measurement] || filtered[layout.Application] +} + func (h *Store) Layouts(ctx context.Context, params op.GetLayoutsParams) middleware.Responder { + // Construct a filter sieve for both applications and measurements + filtered := map[string]bool{} + for _, a := range params.Apps { + filtered[a] = true + } + + for _, m := range params.Measurements { + filtered[m] = true + } + mrLays, err := h.LayoutStore.All(ctx) if err != nil { errMsg := &models.Error{Code: 500, Message: "Error loading layouts"} return op.NewGetLayoutsDefault(500).WithPayload(errMsg) } - lays := make([]*models.Layout, len(mrLays)) - for i, layout := range mrLays { - lays[i] = layoutToModel(layout) + lays := []*models.Layout{} + for _, layout := range mrLays { + if requestedLayout(filtered, layout) { + lays = append(lays, layoutToModel(layout)) + } } res := &models.Layouts{ diff --git a/models/layout.go b/models/layout.go index d1a596324f..5bbd88f35f 100644 --- a/models/layout.go +++ b/models/layout.go @@ -17,6 +17,12 @@ swagger:model Layout */ type Layout struct { + /* App is the user facing name of this Layout + + Required: true + */ + App *string `json:"app"` + /* Cells are the individual visualization elements. Required: true @@ -26,12 +32,23 @@ type Layout struct { /* link */ Link *Link `json:"link,omitempty"` + + /* Measurement is the descriptive name of the time series data. + + Required: true + */ + Measurement *string `json:"measurement"` } // Validate validates this layout func (m *Layout) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateApp(formats); err != nil { + // prop + res = append(res, err) + } + if err := m.validateCells(formats); err != nil { // prop res = append(res, err) @@ -42,12 +59,26 @@ func (m *Layout) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateMeasurement(formats); err != nil { + // prop + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil } +func (m *Layout) validateApp(formats strfmt.Registry) error { + + if err := validate.Required("app", "body", m.App); err != nil { + return err + } + + return nil +} + func (m *Layout) validateCells(formats strfmt.Registry) error { if err := validate.Required("cells", "body", m.Cells); err != nil { @@ -87,3 +118,12 @@ func (m *Layout) validateLink(formats strfmt.Registry) error { return nil } + +func (m *Layout) validateMeasurement(formats strfmt.Registry) error { + + if err := validate.Required("measurement", "body", m.Measurement); err != nil { + return err + } + + return nil +} diff --git a/restapi/operations/get_layouts_parameters.go b/restapi/operations/get_layouts_parameters.go index 7a09b1df5c..03ba432e0e 100644 --- a/restapi/operations/get_layouts_parameters.go +++ b/restapi/operations/get_layouts_parameters.go @@ -30,11 +30,16 @@ type GetLayoutsParams struct { // HTTP Request Object HTTPRequest *http.Request - /*IDs for all layouts to return + /*Returns layouts with this app In: query Collection Format: csv */ - Ids []string + Apps []string + /*Returns layouts with this measurement + In: query + Collection Format: csv + */ + Measurements []string } // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface @@ -45,8 +50,13 @@ func (o *GetLayoutsParams) BindRequest(r *http.Request, route *middleware.Matche qs := runtime.Values(r.URL.Query()) - qIds, qhkIds, _ := qs.GetOK("ids") - if err := o.bindIds(qIds, qhkIds, route.Formats); err != nil { + qApps, qhkApps, _ := qs.GetOK("apps") + if err := o.bindApps(qApps, qhkApps, route.Formats); err != nil { + res = append(res, err) + } + + qMeasurements, qhkMeasurements, _ := qs.GetOK("measurements") + if err := o.bindMeasurements(qMeasurements, qhkMeasurements, route.Formats); err != nil { res = append(res, err) } @@ -56,14 +66,14 @@ func (o *GetLayoutsParams) BindRequest(r *http.Request, route *middleware.Matche return nil } -func (o *GetLayoutsParams) bindIds(rawData []string, hasKey bool, formats strfmt.Registry) error { +func (o *GetLayoutsParams) bindApps(rawData []string, hasKey bool, formats strfmt.Registry) error { - var qvIds string + var qvApps string if len(rawData) > 0 { - qvIds = rawData[len(rawData)-1] + qvApps = rawData[len(rawData)-1] } - raw := swag.SplitByFormat(qvIds, "csv") + raw := swag.SplitByFormat(qvApps, "csv") size := len(raw) if size == 0 { @@ -73,7 +83,7 @@ func (o *GetLayoutsParams) bindIds(rawData []string, hasKey bool, formats strfmt ic := raw isz := size var ir []string - iValidateElement := func(i int, idsI string) *errors.Validation { + iValidateElement := func(i int, appsI string) *errors.Validation { return nil } @@ -86,7 +96,42 @@ func (o *GetLayoutsParams) bindIds(rawData []string, hasKey bool, formats strfmt ir = append(ir, ic[i]) } - o.Ids = ir + o.Apps = ir + + return nil +} + +func (o *GetLayoutsParams) bindMeasurements(rawData []string, hasKey bool, formats strfmt.Registry) error { + + var qvMeasurements string + if len(rawData) > 0 { + qvMeasurements = rawData[len(rawData)-1] + } + + raw := swag.SplitByFormat(qvMeasurements, "csv") + size := len(raw) + + if size == 0 { + return nil + } + + ic := raw + isz := size + var ir []string + iValidateElement := func(i int, measurementsI string) *errors.Validation { + + return nil + } + + for i := 0; i < isz; i++ { + + if err := iValidateElement(i, ic[i]); err != nil { + return err + } + ir = append(ir, ic[i]) + } + + o.Measurements = ir return nil } diff --git a/stores.go b/stores.go index 61338d415d..95339cdbae 100644 --- a/stores.go +++ b/stores.go @@ -99,8 +99,10 @@ type Cell struct { // Layout is a collection of Cells for visualization type Layout struct { - ID int - Cells []Cell + ID int + Application string + Measurement string + Cells []Cell } // LayoutStore stores dashboards and associated Cells diff --git a/swagger.yaml b/swagger.yaml index d3c3d27cc6..872a1b1354 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -886,9 +886,17 @@ paths: get: summary: Pre-configured layouts parameters: - - name: ids + - name: measurements in: query - description: IDs for all layouts to return + description: Returns layouts with this measurement + required: false + type: array + items: + type: string + collectionFormat: csv + - name: apps + in: query + description: Returns layouts with this app required: false type: array items: @@ -1255,7 +1263,15 @@ definitions: type: object required: - cells + - app + - measurement properties: + app: + type: string + description: App is the user facing name of this Layout + measurement: + type: string + description: Measurement is the descriptive name of the time series data. cells: type: array description: Cells are the individual visualization elements. From f337b51beb27832bf0ca5289c8ff4a3601efa313 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Fri, 7 Oct 2016 16:49:32 -0500 Subject: [PATCH 3/5] Add mock layout store and POST /layouts test --- handlers/layout_test.go | 92 +++++++++++++++++++++++++++++++++++++++++ mock/mock.go | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 handlers/layout_test.go diff --git a/handlers/layout_test.go b/handlers/layout_test.go new file mode 100644 index 0000000000..933c12fbda --- /dev/null +++ b/handlers/layout_test.go @@ -0,0 +1,92 @@ +package handlers_test + +import ( + "context" + "errors" + "net/http" + "net/http/httptest" + "testing" + + "github.com/go-openapi/runtime" + "github.com/influxdata/mrfusion" + "github.com/influxdata/mrfusion/handlers" + "github.com/influxdata/mrfusion/mock" + "github.com/influxdata/mrfusion/models" + op "github.com/influxdata/mrfusion/restapi/operations" +) + +func TestNewLayout(t *testing.T) { + t.Parallel() + var tests = []struct { + Desc string + AddError error + ExistingLayouts map[int]mrfusion.Layout + NewLayout *models.Layout + ExpectedID int + ExpectedHref string + ExpectedStatus int + }{ + { + Desc: "Test that an error in datastore returns 500 status", + AddError: errors.New("error"), + NewLayout: &models.Layout{ + Measurement: new(string), + App: new(string), + Cells: []*models.Cell{ + &models.Cell{ + X: new(int32), + Y: new(int32), + W: new(int32), + H: new(int32), + }, + }, + }, + ExpectedStatus: http.StatusInternalServerError, + }, + { + Desc: "Test that creating a layout returns 201 status", + ExistingLayouts: map[int]mrfusion.Layout{}, + NewLayout: &models.Layout{ + Measurement: new(string), + App: new(string), + Cells: []*models.Cell{ + &models.Cell{ + X: new(int32), + Y: new(int32), + W: new(int32), + H: new(int32), + }, + }, + }, + ExpectedID: 0, + ExpectedHref: "/chronograf/v1/layouts/0", + ExpectedStatus: http.StatusCreated, + }, + } + + for _, test := range tests { + // The mocked backing store will be used to + // check stored values. + store := handlers.Store{ + LayoutStore: &mock.LayoutStore{ + AddError: test.AddError, + Layouts: test.ExistingLayouts, + }, + } + + // Send the test layout to the mocked store. + params := op.PostLayoutsParams{ + Layout: test.NewLayout, + } + resp := store.NewLayout(context.Background(), params) + w := httptest.NewRecorder() + resp.WriteResponse(w, runtime.JSONProducer()) + if w.Code != test.ExpectedStatus { + t.Fatalf("Expected status %d; actual %d", test.ExpectedStatus, w.Code) + } + loc := w.Header().Get("Location") + if loc != test.ExpectedHref { + t.Fatalf("Expected status %s; actual %s", test.ExpectedHref, loc) + } + } +} diff --git a/mock/mock.go b/mock/mock.go index 75f62f02ef..1536602d7c 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -168,3 +168,77 @@ func (t *TimeSeries) MonitoredServices(context.Context) ([]mrfusion.MonitoredSer } return hosts, nil } + +type LayoutStore struct { + Layouts map[int]mrfusion.Layout + AllError error + AddError error + DeleteError error + GetError error + UpdateError error +} + +// All will return all info in the map or whatever is AllError +func (l *LayoutStore) All(ctx context.Context) ([]mrfusion.Layout, error) { + if l.AllError != nil { + return nil, l.AllError + } + layouts := make([]mrfusion.Layout, len(l.Layouts)) + for i, l := range l.Layouts { + layouts[i] = l + } + return layouts, nil +} + +// Add create a new ID and add to map or return AddError +func (l *LayoutStore) Add(ctx context.Context, layout mrfusion.Layout) (mrfusion.Layout, error) { + if l.AddError != nil { + return mrfusion.Layout{}, l.AddError + } + id := len(l.Layouts) + layout.ID = id + l.Layouts[id] = layout + return layout, nil +} + +// Delete will remove layout from map or return DeleteError +func (l *LayoutStore) Delete(ctx context.Context, layout mrfusion.Layout) error { + if l.DeleteError != nil { + return l.DeleteError + } + + id := layout.ID + if _, ok := l.Layouts[id]; !ok { + return mrfusion.ErrLayoutNotFound + } + + delete(l.Layouts, id) + return nil +} + +// Get will return map with key ID or GetError +func (l *LayoutStore) Get(ctx context.Context, ID int) (mrfusion.Layout, error) { + if l.GetError != nil { + return mrfusion.Layout{}, l.GetError + } + + if layout, ok := l.Layouts[ID]; !ok { + return mrfusion.Layout{}, mrfusion.ErrLayoutNotFound + } else { + return layout, nil + } +} + +// Update will update layout or return UpdateError +func (l *LayoutStore) Update(ctx context.Context, layout mrfusion.Layout) error { + if l.UpdateError != nil { + return l.UpdateError + } + id := layout.ID + if _, ok := l.Layouts[id]; !ok { + return mrfusion.ErrLayoutNotFound + } else { + l.Layouts[id] = layout + } + return nil +} From 746117e8ddc14410d25476c48e304dccb7fa5632 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Fri, 7 Oct 2016 16:51:05 -0500 Subject: [PATCH 4/5] Rename measurement to telegraf_measurement --- handlers/layout.go | 2 +- restapi/operations/get_layouts_parameters.go | 20 ++++++++++---------- swagger.yaml | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/handlers/layout.go b/handlers/layout.go index ba65a18741..1de846ed6b 100644 --- a/handlers/layout.go +++ b/handlers/layout.go @@ -106,7 +106,7 @@ func (h *Store) Layouts(ctx context.Context, params op.GetLayoutsParams) middlew filtered[a] = true } - for _, m := range params.Measurements { + for _, m := range params.TelegrafMeasurements { filtered[m] = true } diff --git a/restapi/operations/get_layouts_parameters.go b/restapi/operations/get_layouts_parameters.go index 03ba432e0e..094f61b631 100644 --- a/restapi/operations/get_layouts_parameters.go +++ b/restapi/operations/get_layouts_parameters.go @@ -35,11 +35,11 @@ type GetLayoutsParams struct { Collection Format: csv */ Apps []string - /*Returns layouts with this measurement + /*Returns layouts with this telegraf measurement In: query Collection Format: csv */ - Measurements []string + TelegrafMeasurements []string } // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface @@ -55,8 +55,8 @@ func (o *GetLayoutsParams) BindRequest(r *http.Request, route *middleware.Matche res = append(res, err) } - qMeasurements, qhkMeasurements, _ := qs.GetOK("measurements") - if err := o.bindMeasurements(qMeasurements, qhkMeasurements, route.Formats); err != nil { + qTelegrafMeasurements, qhkTelegrafMeasurements, _ := qs.GetOK("telegraf_measurements") + if err := o.bindTelegrafMeasurements(qTelegrafMeasurements, qhkTelegrafMeasurements, route.Formats); err != nil { res = append(res, err) } @@ -101,14 +101,14 @@ func (o *GetLayoutsParams) bindApps(rawData []string, hasKey bool, formats strfm return nil } -func (o *GetLayoutsParams) bindMeasurements(rawData []string, hasKey bool, formats strfmt.Registry) error { +func (o *GetLayoutsParams) bindTelegrafMeasurements(rawData []string, hasKey bool, formats strfmt.Registry) error { - var qvMeasurements string + var qvTelegrafMeasurements string if len(rawData) > 0 { - qvMeasurements = rawData[len(rawData)-1] + qvTelegrafMeasurements = rawData[len(rawData)-1] } - raw := swag.SplitByFormat(qvMeasurements, "csv") + raw := swag.SplitByFormat(qvTelegrafMeasurements, "csv") size := len(raw) if size == 0 { @@ -118,7 +118,7 @@ func (o *GetLayoutsParams) bindMeasurements(rawData []string, hasKey bool, forma ic := raw isz := size var ir []string - iValidateElement := func(i int, measurementsI string) *errors.Validation { + iValidateElement := func(i int, telegrafMeasurementsI string) *errors.Validation { return nil } @@ -131,7 +131,7 @@ func (o *GetLayoutsParams) bindMeasurements(rawData []string, hasKey bool, forma ir = append(ir, ic[i]) } - o.Measurements = ir + o.TelegrafMeasurements = ir return nil } diff --git a/swagger.yaml b/swagger.yaml index 872a1b1354..0ce5e9d7e2 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -886,9 +886,9 @@ paths: get: summary: Pre-configured layouts parameters: - - name: measurements + - name: telegraf_measurements in: query - description: Returns layouts with this measurement + description: Returns layouts with this telegraf measurement required: false type: array items: From 41d6341a3679dd1bfe98e869abf4014576bc4a09 Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Mon, 10 Oct 2016 17:00:27 -0500 Subject: [PATCH 5/5] Update layout to use uuid v4 string as ID parameter. --- Godeps | 1 + bolt/client.go | 25 +++++++++++------ bolt/internal/internal.go | 4 +-- bolt/internal/internal.pb.go | 54 ++++++++++++++++++------------------ bolt/internal/internal.proto | 4 +-- bolt/layouts.go | 17 ++++++------ handlers/layout.go | 41 +++++++++------------------ handlers/layout_test.go | 12 ++++---- id.go | 7 +++++ mock/mock.go | 13 +++++---- models/layout.go | 12 +++++--- stores.go | 4 +-- swagger.yaml | 7 +++-- uuid/v4.go | 15 ++++++++++ 14 files changed, 121 insertions(+), 95 deletions(-) create mode 100644 id.go create mode 100644 uuid/v4.go diff --git a/Godeps b/Godeps index 6b9be89140..7da48c93e5 100644 --- a/Godeps +++ b/Godeps @@ -18,6 +18,7 @@ github.com/gogo/protobuf 6abcf94fd4c97dcb423fdafd42fe9f96ca7e421b github.com/gorilla/context 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 github.com/jessevdk/go-flags 4cc2832a6e6d1d3b815e2b9d544b2a4dfb3ce8fa github.com/mailru/easyjson e978125a7e335d8f4db746a9ac5b44643f27416b +github.com/satori/go.uuid b061729afc07e77a8aa4fad0a2fd840958f1942a github.com/tylerb/graceful 50a48b6e73fcc75b45e22c05b79629a67c79e938 golang.org/x/net 749a502dd1eaf3e5bfd4f8956748c502357c0bbe golang.org/x/text 1e65e9bf72c307081cea196f47ef37aed17eb316 diff --git a/bolt/client.go b/bolt/client.go index 407ab37cc8..cdb14d8b6f 100644 --- a/bolt/client.go +++ b/bolt/client.go @@ -4,13 +4,16 @@ import ( "time" "github.com/boltdb/bolt" + "github.com/influxdata/mrfusion" + "github.com/influxdata/mrfusion/uuid" ) // Client is a client for the boltDB data store. type Client struct { - Path string - db *bolt.DB - Now func() time.Time + Path string + db *bolt.DB + Now func() time.Time + LayoutIDs mrfusion.ID ExplorationStore *ExplorationStore SourcesStore *SourcesStore @@ -23,7 +26,10 @@ func NewClient() *Client { c.ExplorationStore = &ExplorationStore{client: c} c.SourcesStore = &SourcesStore{client: c} c.ServersStore = &ServersStore{client: c} - c.LayoutStore = &LayoutStore{client: c} + c.LayoutStore = &LayoutStore{ + client: c, + IDs: &uuid.V4{}, + } return c } @@ -59,10 +65,13 @@ func (c *Client) Open() error { return err } - c.ExplorationStore = &ExplorationStore{client: c} - c.SourcesStore = &SourcesStore{client: c} - c.ServersStore = &ServersStore{client: c} - c.LayoutStore = &LayoutStore{client: c} + // TODO: Ask @gunnar about these + /* + c.ExplorationStore = &ExplorationStore{client: c} + c.SourcesStore = &SourcesStore{client: c} + c.ServersStore = &ServersStore{client: c} + c.LayoutStore = &LayoutStore{client: c} + */ return nil } diff --git a/bolt/internal/internal.go b/bolt/internal/internal.go index 0fd8dd33a7..3d0a6aa3bf 100644 --- a/bolt/internal/internal.go +++ b/bolt/internal/internal.go @@ -119,7 +119,7 @@ func MarshalLayout(l mrfusion.Layout) ([]byte, error) { } } return proto.Marshal(&Layout{ - ID: int64(l.ID), + ID: l.ID, Measurement: l.Measurement, Application: l.Application, Cells: cells, @@ -133,7 +133,7 @@ func UnmarshalLayout(data []byte, l *mrfusion.Layout) error { return err } - l.ID = int(pb.ID) + l.ID = pb.ID l.Measurement = pb.Measurement l.Application = pb.Application cells := make([]mrfusion.Cell, len(pb.Cells)) diff --git a/bolt/internal/internal.pb.go b/bolt/internal/internal.pb.go index cc91dab9ab..4bc5745edb 100644 --- a/bolt/internal/internal.pb.go +++ b/bolt/internal/internal.pb.go @@ -78,7 +78,7 @@ func (*Server) ProtoMessage() {} func (*Server) Descriptor() ([]byte, []int) { return fileDescriptorInternal, []int{2} } type Layout struct { - ID int64 `protobuf:"varint,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` + ID string `protobuf:"bytes,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` Application string `protobuf:"bytes,2,opt,name=Application,json=application,proto3" json:"Application,omitempty"` Measurement string `protobuf:"bytes,3,opt,name=Measurement,json=measurement,proto3" json:"Measurement,omitempty"` Cells []*Cell `protobuf:"bytes,4,rep,name=Cells,json=cells" json:"Cells,omitempty"` @@ -139,34 +139,34 @@ func init() { func init() { proto.RegisterFile("internal.proto", fileDescriptorInternal) } var fileDescriptorInternal = []byte{ - // 453 bytes of a gzipped FileDescriptorProto + // 454 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x93, 0xcf, 0x8e, 0xd3, 0x3e, 0x10, 0xc7, 0xe5, 0x26, 0x4e, 0x13, 0xe7, 0xa7, 0xfe, 0x90, 0x85, 0x90, 0x85, 0x38, 0x44, 0x11, 0x87, 0x72, 0xd9, 0x03, 0x3c, 0x41, 0xb7, 0xe1, 0x50, 0x29, 0xa0, 0xe2, 0xa5, 0x0f, 0x60, 0x92, 0x41, 0x1b, 0x29, 0xff, 0x70, 0x6c, 0xda, 0x5c, 0x39, 0xf3, 0x1c, 0xbc, 0x00, 0x2f, 0x88, 0xc6, - 0x75, 0x29, 0x02, 0x69, 0xb5, 0xc7, 0xcf, 0x7c, 0x47, 0x9e, 0xcf, 0x38, 0x0e, 0x5b, 0x35, 0xbd, - 0x01, 0xdd, 0xab, 0xf6, 0x66, 0xd4, 0x83, 0x19, 0x78, 0x7c, 0xe1, 0xfc, 0x27, 0x61, 0xe9, 0xdb, - 0xd3, 0xd8, 0x0e, 0x5a, 0x99, 0x66, 0xe8, 0xf9, 0x8a, 0x2d, 0x76, 0x85, 0x20, 0x19, 0x59, 0x07, - 0x72, 0xd1, 0x14, 0x9c, 0xb3, 0xf0, 0xbd, 0xea, 0x40, 0x2c, 0x32, 0xb2, 0x4e, 0x64, 0xd8, 0xab, - 0x0e, 0xf8, 0x33, 0x16, 0x1d, 0x26, 0xd0, 0xbb, 0x42, 0x04, 0xae, 0x2f, 0xb2, 0x8e, 0xb0, 0xb7, - 0x50, 0x46, 0x89, 0xf0, 0xdc, 0x5b, 0x2b, 0xa3, 0xf8, 0x0b, 0x96, 0x6c, 0x35, 0x28, 0x03, 0xf5, - 0xc6, 0x08, 0xea, 0xda, 0x93, 0xea, 0x52, 0xc0, 0xf4, 0x30, 0xd6, 0x3e, 0x8d, 0xce, 0xa9, 0xbd, - 0x14, 0xb8, 0x60, 0xcb, 0x02, 0x3e, 0x2b, 0xdb, 0x1a, 0xb1, 0xcc, 0xc8, 0x3a, 0x96, 0xcb, 0xfa, - 0x8c, 0xf9, 0x0f, 0xc2, 0xa2, 0xbb, 0xc1, 0xea, 0x0a, 0x1e, 0x25, 0xcc, 0x59, 0xf8, 0x71, 0x1e, - 0xc1, 0xe9, 0x26, 0x32, 0x34, 0xf3, 0x08, 0xfc, 0x39, 0x8b, 0x71, 0x09, 0xcc, 0xbd, 0x70, 0x6c, - 0x3d, 0x63, 0xb6, 0x57, 0xd3, 0x74, 0x1c, 0x74, 0xed, 0x9c, 0x13, 0x19, 0x8f, 0x9e, 0xf1, 0xac, - 0x83, 0x2c, 0x27, 0x11, 0x65, 0x01, 0x9e, 0x65, 0x65, 0x39, 0x3d, 0x20, 0xfa, 0x1d, 0x45, 0x41, - 0x7f, 0x05, 0xfd, 0x28, 0xd1, 0x3f, 0xa5, 0x82, 0x07, 0xa4, 0xc2, 0xbf, 0xa4, 0x9e, 0xb0, 0xe0, - 0x20, 0x4b, 0xef, 0x1a, 0x58, 0x59, 0xf2, 0xa7, 0x8c, 0xde, 0xe9, 0x6a, 0x57, 0xf8, 0x5b, 0xa5, - 0x13, 0x42, 0xfe, 0x8d, 0xb0, 0xa8, 0x54, 0xf3, 0x60, 0xcd, 0x3f, 0x3a, 0x19, 0x4b, 0x37, 0xe3, - 0xd8, 0x36, 0x95, 0x7b, 0x07, 0xde, 0x2a, 0x55, 0xd7, 0x12, 0x76, 0xbc, 0x03, 0x35, 0x59, 0x0d, - 0x1d, 0xf4, 0xc6, 0xfb, 0xa5, 0xdd, 0xb5, 0xc4, 0x5f, 0x32, 0xba, 0x85, 0xb6, 0x9d, 0x44, 0x98, - 0x05, 0xeb, 0xf4, 0xf5, 0xea, 0xe6, 0xf7, 0xb3, 0xc3, 0xb2, 0xa4, 0x15, 0x86, 0x79, 0xc3, 0x42, - 0x44, 0xfe, 0x1f, 0x23, 0x27, 0x27, 0x40, 0x25, 0x39, 0x21, 0xcd, 0x6e, 0x2a, 0x95, 0x64, 0x46, - 0x3a, 0xba, 0x09, 0x54, 0x92, 0x23, 0xd2, 0xbd, 0xdb, 0x99, 0x4a, 0x72, 0xcf, 0x5f, 0xb1, 0xe5, - 0x17, 0x0b, 0xba, 0x81, 0x49, 0x50, 0x37, 0xe7, 0xff, 0xeb, 0x9c, 0x0f, 0x16, 0xf4, 0x2c, 0x2f, - 0x79, 0xbe, 0x61, 0xd4, 0x55, 0xf0, 0x0b, 0x6d, 0x87, 0xae, 0x53, 0x7d, 0xed, 0x26, 0x26, 0x72, - 0x59, 0x9d, 0x11, 0xef, 0xa1, 0xb8, 0xf5, 0xeb, 0x2e, 0xea, 0x5b, 0x64, 0xb9, 0xf7, 0xcb, 0x2d, - 0xf4, 0xfe, 0x53, 0xe4, 0xfe, 0x98, 0x37, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x3c, 0x88, 0x2a, - 0x36, 0x43, 0x03, 0x00, 0x00, + 0x75, 0xe9, 0x8a, 0xc3, 0x6a, 0x8f, 0x9f, 0xf9, 0x8e, 0x3c, 0x9f, 0x71, 0x1c, 0xb6, 0x6a, 0x7a, + 0x03, 0xba, 0x57, 0xed, 0xcd, 0xa8, 0x07, 0x33, 0xf0, 0xf8, 0xc2, 0xf9, 0x6f, 0xc2, 0xd2, 0xf7, + 0xa7, 0xb1, 0x1d, 0xb4, 0x32, 0xcd, 0xd0, 0xf3, 0x15, 0x5b, 0xec, 0x0a, 0x41, 0x32, 0xb2, 0x0e, + 0xe4, 0xa2, 0x29, 0x38, 0x67, 0xe1, 0x47, 0xd5, 0x81, 0x58, 0x64, 0x64, 0x9d, 0xc8, 0xb0, 0x57, + 0x1d, 0xf0, 0x17, 0x2c, 0x3a, 0x4c, 0xa0, 0x77, 0x85, 0x08, 0x5c, 0x5f, 0x64, 0x1d, 0x61, 0x6f, + 0xa1, 0x8c, 0x12, 0xe1, 0xb9, 0xb7, 0x56, 0x46, 0xf1, 0x57, 0x2c, 0xd9, 0x6a, 0x50, 0x06, 0xea, + 0x8d, 0x11, 0xd4, 0xb5, 0x27, 0xd5, 0xa5, 0x80, 0xe9, 0x61, 0xac, 0x7d, 0x1a, 0x9d, 0x53, 0x7b, + 0x29, 0x70, 0xc1, 0x96, 0x05, 0x7c, 0x55, 0xb6, 0x35, 0x62, 0x99, 0x91, 0x75, 0x2c, 0x97, 0xf5, + 0x19, 0xf3, 0x5f, 0x84, 0x45, 0x77, 0x83, 0xd5, 0x15, 0x3c, 0x49, 0x98, 0xb3, 0xf0, 0xf3, 0x3c, + 0x82, 0xd3, 0x4d, 0x64, 0x68, 0xe6, 0x11, 0xf8, 0x4b, 0x16, 0xe3, 0x12, 0x98, 0x7b, 0xe1, 0xd8, + 0x7a, 0xc6, 0x6c, 0xaf, 0xa6, 0xe9, 0x38, 0xe8, 0xda, 0x39, 0x27, 0x32, 0x1e, 0x3d, 0xe3, 0x59, + 0x07, 0x59, 0x4e, 0x22, 0xca, 0x02, 0x3c, 0xcb, 0xca, 0x72, 0x7a, 0x44, 0xf4, 0x27, 0x8a, 0x82, + 0xfe, 0x0e, 0xfa, 0x49, 0xa2, 0x0f, 0xa5, 0x82, 0x47, 0xa4, 0xc2, 0x7f, 0xa4, 0x9e, 0xb1, 0xe0, + 0x20, 0x4b, 0xef, 0x1a, 0x58, 0x59, 0xf2, 0xe7, 0x8c, 0xde, 0xe9, 0x6a, 0x57, 0xf8, 0x5b, 0xa5, + 0x13, 0x42, 0xfe, 0x83, 0xb0, 0xa8, 0x54, 0xf3, 0x60, 0xcd, 0x03, 0x9d, 0xc4, 0xe9, 0x64, 0x2c, + 0xdd, 0x8c, 0x63, 0xdb, 0x54, 0xee, 0x1d, 0x78, 0xab, 0x54, 0x5d, 0x4b, 0xd8, 0xf1, 0x01, 0xd4, + 0x64, 0x35, 0x74, 0xd0, 0x1b, 0xef, 0x97, 0x76, 0xd7, 0x12, 0x7f, 0xcd, 0xe8, 0x16, 0xda, 0x76, + 0x12, 0x61, 0x16, 0xac, 0xd3, 0xb7, 0xab, 0x9b, 0xbf, 0xcf, 0x0e, 0xcb, 0x92, 0x56, 0x18, 0xe6, + 0x0d, 0x0b, 0x11, 0xf9, 0x7f, 0x8c, 0x9c, 0x9c, 0x00, 0x95, 0xe4, 0x84, 0x34, 0xbb, 0xa9, 0x54, + 0x92, 0x19, 0xe9, 0xe8, 0x26, 0x50, 0x49, 0x8e, 0x48, 0xf7, 0x6e, 0x67, 0x2a, 0xc9, 0x3d, 0x7f, + 0xc3, 0x96, 0xdf, 0x2c, 0xe8, 0x06, 0x26, 0x41, 0xdd, 0x9c, 0xff, 0xaf, 0x73, 0x3e, 0x59, 0xd0, + 0xb3, 0xbc, 0xe4, 0xf9, 0x86, 0x51, 0x57, 0xc1, 0x2f, 0xb4, 0x1d, 0xba, 0x4e, 0xf5, 0xb5, 0x5f, + 0x79, 0x59, 0x9d, 0x11, 0xef, 0xa1, 0xb8, 0xf5, 0xeb, 0x2e, 0xea, 0x5b, 0x64, 0xb9, 0xf7, 0xcb, + 0x2d, 0xf4, 0xfe, 0x4b, 0xe4, 0xfe, 0x98, 0x77, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6b, 0x5c, + 0x8c, 0x14, 0x43, 0x03, 0x00, 0x00, } diff --git a/bolt/internal/internal.proto b/bolt/internal/internal.proto index bf9aad58bd..7c36ff7c43 100644 --- a/bolt/internal/internal.proto +++ b/bolt/internal/internal.proto @@ -31,7 +31,7 @@ message Server { } message Layout { - int64 ID = 1; // ID is the unique ID of the layout. + string ID = 1; // ID is the unique ID of the layout. string Application = 2; // Application is the user facing name of this Layout. string Measurement = 3; // Measurement is the descriptive name of the time series data. repeated Cell Cells = 4; // Cells are the individual visualization elements. @@ -42,7 +42,7 @@ message Cell { int32 y = 2; // Y-coordinate of Cell in the Layout int32 w = 3; // Width of Cell in the Layout int32 h = 4; // Height of Cell in the Layout - repeated Query queries = 5; // Time-series data queries for Cell. + repeated Query queries = 5; // Time-series data queries for Cell. } message Query { diff --git a/bolt/layouts.go b/bolt/layouts.go index 8be79afff2..3d920b0a5e 100644 --- a/bolt/layouts.go +++ b/bolt/layouts.go @@ -14,6 +14,7 @@ var LayoutBucket = []byte("Layout") type LayoutStore struct { client *Client + IDs mrfusion.ID } // All returns all known layouts @@ -43,15 +44,15 @@ func (s *LayoutStore) All(ctx context.Context) ([]mrfusion.Layout, error) { func (s *LayoutStore) Add(ctx context.Context, src mrfusion.Layout) (mrfusion.Layout, error) { if err := s.client.db.Update(func(tx *bolt.Tx) error { b := tx.Bucket(LayoutBucket) - seq, err := b.NextSequence() + id, err := s.IDs.Generate() if err != nil { return err } - src.ID = int(seq) + src.ID = id if v, err := internal.MarshalLayout(src); err != nil { return err - } else if err := b.Put(itob(src.ID), v); err != nil { + } else if err := b.Put([]byte(src.ID), v); err != nil { return err } return nil @@ -65,7 +66,7 @@ func (s *LayoutStore) Add(ctx context.Context, src mrfusion.Layout) (mrfusion.La // Delete removes the Layout from the LayoutStore func (s *LayoutStore) Delete(ctx context.Context, src mrfusion.Layout) error { if err := s.client.db.Update(func(tx *bolt.Tx) error { - if err := tx.Bucket(LayoutBucket).Delete(itob(src.ID)); err != nil { + if err := tx.Bucket(LayoutBucket).Delete([]byte(src.ID)); err != nil { return err } return nil @@ -77,10 +78,10 @@ func (s *LayoutStore) Delete(ctx context.Context, src mrfusion.Layout) error { } // Get returns a Layout if the id exists. -func (s *LayoutStore) Get(ctx context.Context, id int) (mrfusion.Layout, error) { +func (s *LayoutStore) Get(ctx context.Context, id string) (mrfusion.Layout, error) { var src mrfusion.Layout if err := s.client.db.View(func(tx *bolt.Tx) error { - if v := tx.Bucket(LayoutBucket).Get(itob(id)); v == nil { + if v := tx.Bucket(LayoutBucket).Get([]byte(id)); v == nil { return mrfusion.ErrLayoutNotFound } else if err := internal.UnmarshalLayout(v, &src); err != nil { return err @@ -98,13 +99,13 @@ func (s *LayoutStore) Update(ctx context.Context, src mrfusion.Layout) error { if err := s.client.db.Update(func(tx *bolt.Tx) error { // Get an existing layout with the same ID. b := tx.Bucket(LayoutBucket) - if v := b.Get(itob(src.ID)); v == nil { + if v := b.Get([]byte(src.ID)); v == nil { return mrfusion.ErrLayoutNotFound } if v, err := internal.MarshalLayout(src); err != nil { return err - } else if err := b.Put(itob(src.ID), v); err != nil { + } else if err := b.Put([]byte(src.ID), v); err != nil { return err } return nil diff --git a/handlers/layout.go b/handlers/layout.go index 1de846ed6b..222957959e 100644 --- a/handlers/layout.go +++ b/handlers/layout.go @@ -2,7 +2,6 @@ package handlers import ( "fmt" - "strconv" "github.com/go-openapi/runtime/middleware" "github.com/influxdata/mrfusion" @@ -32,7 +31,8 @@ func layoutToMrF(l *models.Layout) mrfusion.Layout { } } return mrfusion.Layout{ - Measurement: *l.Measurement, + ID: l.ID, + Measurement: *l.TelegrafMeasurement, Application: *l.App, Cells: cells, } @@ -50,7 +50,7 @@ func (h *Store) NewLayout(ctx context.Context, params op.PostLayoutsParams) midd } func layoutToModel(l mrfusion.Layout) *models.Layout { - href := fmt.Sprintf("/chronograf/v1/layouts/%d", l.ID) + href := fmt.Sprintf("/chronograf/v1/layouts/%s", l.ID) rel := "self" cells := make([]*models.Cell, len(l.Cells)) @@ -83,9 +83,10 @@ func layoutToModel(l mrfusion.Layout) *models.Layout { Href: &href, Rel: &rel, }, - Cells: cells, - Measurement: &l.Measurement, - App: &l.Application, + Cells: cells, + TelegrafMeasurement: &l.Measurement, + App: &l.Application, + ID: l.ID, } } @@ -131,13 +132,7 @@ func (h *Store) Layouts(ctx context.Context, params op.GetLayoutsParams) middlew } func (h *Store) LayoutsID(ctx context.Context, params op.GetLayoutsIDParams) middleware.Responder { - id, err := strconv.Atoi(params.ID) - if err != nil { - errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} - return op.NewGetLayoutsIDDefault(500).WithPayload(errMsg) - } - - layout, err := h.LayoutStore.Get(ctx, id) + layout, err := h.LayoutStore.Get(ctx, params.ID) if err != nil { errMsg := &models.Error{Code: 404, Message: fmt.Sprintf("Unknown ID %s", params.ID)} return op.NewGetLayoutsIDNotFound().WithPayload(errMsg) @@ -147,15 +142,10 @@ func (h *Store) LayoutsID(ctx context.Context, params op.GetLayoutsIDParams) mid } func (h *Store) RemoveLayout(ctx context.Context, params op.DeleteLayoutsIDParams) middleware.Responder { - id, err := strconv.Atoi(params.ID) - if err != nil { - errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} - return op.NewDeleteLayoutsIDDefault(500).WithPayload(errMsg) - } layout := mrfusion.Layout{ - ID: id, + ID: params.ID, } - if err = h.LayoutStore.Delete(ctx, layout); err != nil { + if err := h.LayoutStore.Delete(ctx, layout); err != nil { errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Unknown error deleting layout %s", params.ID)} return op.NewDeleteLayoutsIDDefault(500).WithPayload(errMsg) } @@ -164,20 +154,15 @@ func (h *Store) RemoveLayout(ctx context.Context, params op.DeleteLayoutsIDParam } func (h *Store) UpdateLayout(ctx context.Context, params op.PutLayoutsIDParams) middleware.Responder { - id, err := strconv.Atoi(params.ID) - if err != nil { - errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error converting ID %s", params.ID)} - return op.NewPutLayoutsIDDefault(500).WithPayload(errMsg) - } - layout, err := h.LayoutStore.Get(ctx, id) + layout, err := h.LayoutStore.Get(ctx, params.ID) if err != nil { errMsg := &models.Error{Code: 404, Message: fmt.Sprintf("Unknown ID %s", params.ID)} return op.NewPutLayoutsIDNotFound().WithPayload(errMsg) } layout = layoutToMrF(params.Config) - layout.ID = id + layout.ID = params.ID if err := h.LayoutStore.Update(ctx, layout); err != nil { - errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error updating layout ID %s", params.ID)} + errMsg := &models.Error{Code: 500, Message: fmt.Sprintf("Error updating layout ID %s: %v", params.ID, err)} return op.NewPutLayoutsIDDefault(500).WithPayload(errMsg) } return op.NewPutLayoutsIDOK().WithPayload(layoutToModel(layout)) diff --git a/handlers/layout_test.go b/handlers/layout_test.go index 933c12fbda..12946b8fb5 100644 --- a/handlers/layout_test.go +++ b/handlers/layout_test.go @@ -20,7 +20,7 @@ func TestNewLayout(t *testing.T) { var tests = []struct { Desc string AddError error - ExistingLayouts map[int]mrfusion.Layout + ExistingLayouts map[string]mrfusion.Layout NewLayout *models.Layout ExpectedID int ExpectedHref string @@ -30,8 +30,8 @@ func TestNewLayout(t *testing.T) { Desc: "Test that an error in datastore returns 500 status", AddError: errors.New("error"), NewLayout: &models.Layout{ - Measurement: new(string), - App: new(string), + TelegrafMeasurement: new(string), + App: new(string), Cells: []*models.Cell{ &models.Cell{ X: new(int32), @@ -45,10 +45,10 @@ func TestNewLayout(t *testing.T) { }, { Desc: "Test that creating a layout returns 201 status", - ExistingLayouts: map[int]mrfusion.Layout{}, + ExistingLayouts: map[string]mrfusion.Layout{}, NewLayout: &models.Layout{ - Measurement: new(string), - App: new(string), + TelegrafMeasurement: new(string), + App: new(string), Cells: []*models.Cell{ &models.Cell{ X: new(int32), diff --git a/id.go b/id.go new file mode 100644 index 0000000000..4e0c513444 --- /dev/null +++ b/id.go @@ -0,0 +1,7 @@ +package mrfusion + +// ID creates uniq ID string +type ID interface { + // Generate creates a unique ID string + Generate() (string, error) +} diff --git a/mock/mock.go b/mock/mock.go index 1536602d7c..23b2f359b5 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -2,6 +2,7 @@ package mock import ( "fmt" + "strconv" "time" "github.com/influxdata/mrfusion" @@ -170,7 +171,7 @@ func (t *TimeSeries) MonitoredServices(context.Context) ([]mrfusion.MonitoredSer } type LayoutStore struct { - Layouts map[int]mrfusion.Layout + Layouts map[string]mrfusion.Layout AllError error AddError error DeleteError error @@ -183,9 +184,9 @@ func (l *LayoutStore) All(ctx context.Context) ([]mrfusion.Layout, error) { if l.AllError != nil { return nil, l.AllError } - layouts := make([]mrfusion.Layout, len(l.Layouts)) - for i, l := range l.Layouts { - layouts[i] = l + layouts := []mrfusion.Layout{} + for _, l := range l.Layouts { + layouts = append(layouts, l) } return layouts, nil } @@ -195,7 +196,7 @@ func (l *LayoutStore) Add(ctx context.Context, layout mrfusion.Layout) (mrfusion if l.AddError != nil { return mrfusion.Layout{}, l.AddError } - id := len(l.Layouts) + id := strconv.Itoa(len(l.Layouts)) layout.ID = id l.Layouts[id] = layout return layout, nil @@ -217,7 +218,7 @@ func (l *LayoutStore) Delete(ctx context.Context, layout mrfusion.Layout) error } // Get will return map with key ID or GetError -func (l *LayoutStore) Get(ctx context.Context, ID int) (mrfusion.Layout, error) { +func (l *LayoutStore) Get(ctx context.Context, ID string) (mrfusion.Layout, error) { if l.GetError != nil { return mrfusion.Layout{}, l.GetError } diff --git a/models/layout.go b/models/layout.go index 5bbd88f35f..6536020072 100644 --- a/models/layout.go +++ b/models/layout.go @@ -29,6 +29,10 @@ type Layout struct { */ Cells []*Cell `json:"cells"` + /* ID is an opaque string that uniquely identifies this layout. + */ + ID string `json:"id,omitempty"` + /* link */ Link *Link `json:"link,omitempty"` @@ -37,7 +41,7 @@ type Layout struct { Required: true */ - Measurement *string `json:"measurement"` + TelegrafMeasurement *string `json:"telegraf_measurement"` } // Validate validates this layout @@ -59,7 +63,7 @@ func (m *Layout) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateMeasurement(formats); err != nil { + if err := m.validateTelegrafMeasurement(formats); err != nil { // prop res = append(res, err) } @@ -119,9 +123,9 @@ func (m *Layout) validateLink(formats strfmt.Registry) error { return nil } -func (m *Layout) validateMeasurement(formats strfmt.Registry) error { +func (m *Layout) validateTelegrafMeasurement(formats strfmt.Registry) error { - if err := validate.Required("measurement", "body", m.Measurement); err != nil { + if err := validate.Required("telegraf_measurement", "body", m.TelegrafMeasurement); err != nil { return err } diff --git a/stores.go b/stores.go index 95339cdbae..de0b2a7088 100644 --- a/stores.go +++ b/stores.go @@ -99,7 +99,7 @@ type Cell struct { // Layout is a collection of Cells for visualization type Layout struct { - ID int + ID string Application string Measurement string Cells []Cell @@ -114,7 +114,7 @@ type LayoutStore interface { // Delete the dashboard from the store Delete(context.Context, Layout) error // Get retrieves Layout if `ID` exists - Get(ctx context.Context, ID int) (Layout, error) + Get(ctx context.Context, ID string) (Layout, error) // Update the dashboard in the store. Update(context.Context, Layout) error } diff --git a/swagger.yaml b/swagger.yaml index 0ce5e9d7e2..4ae486a96e 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -1264,12 +1264,15 @@ definitions: required: - cells - app - - measurement + - telegraf_measurement properties: + id: + type: string + description: ID is an opaque string that uniquely identifies this layout. app: type: string description: App is the user facing name of this Layout - measurement: + telegraf_measurement: type: string description: Measurement is the descriptive name of the time series data. cells: diff --git a/uuid/v4.go b/uuid/v4.go new file mode 100644 index 0000000000..8b6141cac4 --- /dev/null +++ b/uuid/v4.go @@ -0,0 +1,15 @@ +package uuid + +import uuid "github.com/satori/go.uuid" + +type V4 struct { + u *uuid.UUID +} + +func (i *V4) Generate() (string, error) { + if i.u == nil { + u := uuid.NewV4() + i.u = &u + } + return i.u.String(), nil +}