Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
27f07e9d
Commit
27f07e9d
authored
Dec 16, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progress on data source admin
parent
b70a3f09
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
107 additions
and
73 deletions
+107
-73
Makefile
+1
-0
grafana
+1
-1
pkg/api/api.go
+2
-1
pkg/api/api_datasources.go
+17
-1
pkg/bus/bus.go
+17
-18
pkg/bus/bus_test.go
+6
-6
pkg/components/renderer/renderer_test.go
+33
-32
pkg/models/datasource.go
+10
-0
pkg/stores/sqlstore/sqlstore.go
+14
-13
pkg/stores/sqlstore/sqlstore_datasource.go
+6
-1
No files found.
Makefile
View file @
27f07e9d
...
...
@@ -4,6 +4,7 @@ all: build
build
:
go build
-o
bin/grafana .
go
test
./pkg/...
lint
:
@
gofmt
-w
.
&&
go tool vet pkg/
**
/
*
.go
&&
echo
"
$(GOLINT)
"
...
...
grafana
@
adb1502e
Subproject commit
b3b096e204a8ad6eb2aba6b98802589ab3d1fa28
Subproject commit
adb1502e728e5a312a6e4dc680edbd1f75219ea1
pkg/api/api.go
View file @
27f07e9d
...
...
@@ -27,7 +27,8 @@ func Register(m *macaron.Macaron) {
// datasources
m
.
Get
(
"/admin/datasources/"
,
auth
,
Index
)
m
.
Get
(
"/api/admin/datasources/"
,
auth
,
GetDataSources
)
m
.
Get
(
"/api/admin/datasource/list"
,
auth
,
GetDataSources
)
m
.
Post
(
"/api/admin/datasource/add"
,
auth
,
AddDataSource
)
// user register
m
.
Get
(
"/register/*_"
,
Index
)
...
...
pkg/api/api_datasources.go
View file @
27f07e9d
...
...
@@ -8,10 +8,26 @@ import (
func
GetDataSources
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
c
.
Account
.
Id
}
err
:=
bus
.
SendQuery
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to query datasources"
,
err
)
return
}
}
func
AddDataSource
(
c
*
middleware
.
Context
)
{
cmd
:=
m
.
AddDataSourceCommand
{}
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"bad request"
,
nil
)
return
}
err
:=
bus
.
Dispatch
(
&
cmd
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to add datasource"
,
err
)
return
}
}
pkg/bus/bus.go
View file @
27f07e9d
...
...
@@ -6,16 +6,16 @@ import (
"reflect"
)
type
QueryHandler
interface
{}
type
Query
interface
{}
type
HandlerFunc
interface
{}
type
Msg
interface
{}
type
Bus
interface
{
SendQuery
(
query
Query
)
error
Add
QueryHandler
(
handler
QueryHandler
)
Dispatch
(
msg
Msg
)
error
Add
Handler
(
handler
HandlerFunc
)
}
type
InProcBus
struct
{
handler
Index
map
[
string
]
QueryHandler
handler
s
map
[
string
]
HandlerFunc
}
// temp stuff, not sure how to handle bus instance, and init yet
...
...
@@ -23,21 +23,20 @@ var globalBus = New()
func
New
()
Bus
{
bus
:=
&
InProcBus
{}
bus
.
handler
Index
=
make
(
map
[
string
]
QueryHandler
)
bus
.
handler
s
=
make
(
map
[
string
]
HandlerFunc
)
return
bus
}
func
(
b
*
InProcBus
)
SendQuery
(
query
Query
)
error
{
var
queryName
=
reflect
.
TypeOf
(
query
)
.
Elem
()
.
Name
()
fmt
.
Printf
(
"sending query for type: %v
\n
"
,
queryName
)
func
(
b
*
InProcBus
)
Dispatch
(
msg
Msg
)
error
{
var
msgName
=
reflect
.
TypeOf
(
msg
)
.
Elem
()
.
Name
()
var
handler
=
b
.
handler
Index
[
query
Name
]
var
handler
=
b
.
handler
s
[
msg
Name
]
if
handler
==
nil
{
return
errors
.
New
(
"handler not found"
)
}
var
params
=
make
([]
reflect
.
Value
,
1
)
params
[
0
]
=
reflect
.
ValueOf
(
query
)
params
[
0
]
=
reflect
.
ValueOf
(
msg
)
ret
:=
reflect
.
ValueOf
(
handler
)
.
Call
(
params
)
err
:=
ret
[
0
]
.
Interface
()
...
...
@@ -48,18 +47,18 @@ func (b *InProcBus) SendQuery(query Query) error {
}
}
func
(
b
*
InProcBus
)
Add
QueryHandler
(
handler
QueryHandler
)
{
func
(
b
*
InProcBus
)
Add
Handler
(
handler
HandlerFunc
)
{
handlerType
:=
reflect
.
TypeOf
(
handler
)
queryTypeName
:=
handlerType
.
In
(
0
)
.
Elem
()
.
Name
()
fmt
.
Printf
(
"QueryType %v
\n
"
,
queryTypeName
)
b
.
handler
Index
[
queryTypeName
]
=
handler
b
.
handler
s
[
queryTypeName
]
=
handler
}
// Package level functions
func
Add
QueryHandler
(
implName
string
,
handler
QueryHandler
)
{
globalBus
.
Add
Query
Handler
(
handler
)
func
Add
Handler
(
implName
string
,
handler
HandlerFunc
)
{
globalBus
.
AddHandler
(
handler
)
}
func
SendQuery
(
query
Query
)
error
{
return
globalBus
.
SendQuery
(
query
)
func
Dispatch
(
msg
Msg
)
error
{
return
globalBus
.
Dispatch
(
msg
)
}
pkg/bus/bus_test.go
View file @
27f07e9d
...
...
@@ -10,14 +10,14 @@ type TestQuery struct {
Resp
string
}
func
TestHandlerReturnsError
(
t
*
testing
.
T
)
{
func
Test
Query
HandlerReturnsError
(
t
*
testing
.
T
)
{
bus
:=
New
()
bus
.
Add
Query
Handler
(
func
(
query
*
TestQuery
)
error
{
bus
.
AddHandler
(
func
(
query
*
TestQuery
)
error
{
return
errors
.
New
(
"handler error"
)
})
err
:=
bus
.
SendQuery
(
&
TestQuery
{})
err
:=
bus
.
Dispatch
(
&
TestQuery
{})
if
err
==
nil
{
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
...
...
@@ -26,16 +26,16 @@ func TestHandlerReturnsError(t *testing.T) {
}
}
func
TestHandlerReturn
(
t
*
testing
.
T
)
{
func
Test
Query
HandlerReturn
(
t
*
testing
.
T
)
{
bus
:=
New
()
bus
.
Add
Query
Handler
(
func
(
q
*
TestQuery
)
error
{
bus
.
AddHandler
(
func
(
q
*
TestQuery
)
error
{
q
.
Resp
=
"hello from handler"
return
nil
})
query
:=
&
TestQuery
{}
err
:=
bus
.
SendQuery
(
query
)
err
:=
bus
.
Dispatch
(
query
)
if
err
!=
nil
{
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
...
...
pkg/components/renderer/renderer_test.go
View file @
27f07e9d
package
renderer
import
(
"io/ioutil"
"os"
"testing"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestPhantomRender
(
t
*
testing
.
T
)
{
Convey
(
"Can render url"
,
t
,
func
()
{
tempDir
,
_
:=
ioutil
.
TempDir
(
""
,
"img"
)
png
,
err
:=
RenderToPng
(
"http://www.google.com"
)
So
(
err
,
ShouldBeNil
)
So
(
exists
(
png
),
ShouldEqual
,
true
)
//_, err = os.Stat(store.getFilePathForDashboard("hello"))
//So(err, ShouldBeNil)
})
}
func
exists
(
path
string
)
bool
{
_
,
err
:=
os
.
Stat
(
path
)
if
err
==
nil
{
return
true
}
if
os
.
IsNotExist
(
err
)
{
return
false
}
return
false
}
//
// import (
// "io/ioutil"
// "os"
// "testing"
//
// . "github.com/smartystreets/goconvey/convey"
// )
//
// func TestPhantomRender(t *testing.T) {
//
// Convey("Can render url", t, func() {
// tempDir, _ := ioutil.TempDir("", "img")
// ipng, err := RenderToPng("http://www.google.com")
// So(err, ShouldBeNil)
// So(exists(png), ShouldEqual, true)
//
// //_, err = os.Stat(store.getFilePathForDashboard("hello"))
// //So(err, ShouldBeNil)
// })
//
// }
//
// func exists(path string) bool {
// _, err := os.Stat(path)
// if err == nil {
// return true
// }
// if os.IsNotExist(err) {
// return false
// }
// return false
// }
pkg/models/datasource.go
View file @
27f07e9d
...
...
@@ -33,3 +33,13 @@ type GetDataSourcesQuery struct {
AccountId
int64
Resp
[]
*
DataSource
}
type
AddDataSourceCommand
struct
{
AccountId
int64
Name
string
Type
DsType
Access
DsAccess
Url
string
Password
string
User
string
}
pkg/stores/sqlstore/sqlstore.go
View file @
27f07e9d
...
...
@@ -6,7 +6,7 @@ import (
"path"
"strings"
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/go-xorm/xorm"
...
...
@@ -27,18 +27,19 @@ var (
)
func
Init
()
{
tables
=
append
(
tables
,
new
(
models
.
Account
),
new
(
models
.
Dashboard
),
new
(
models
.
Collaborator
))
models
.
SaveAccount
=
SaveAccount
models
.
GetAccount
=
GetAccount
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetOtherAccountsFor
=
GetOtherAccountsFor
models
.
GetDashboard
=
GetDashboard
models
.
SaveDashboard
=
SaveDashboard
models
.
SearchQuery
=
SearchQuery
models
.
DeleteDashboard
=
DeleteDashboard
models
.
GetCollaboratorsForAccount
=
GetCollaboratorsForAccount
models
.
AddCollaborator
=
AddCollaborator
tables
=
append
(
tables
,
new
(
m
.
Account
),
new
(
m
.
Dashboard
),
new
(
m
.
Collaborator
),
new
(
m
.
DataSource
))
m
.
SaveAccount
=
SaveAccount
m
.
GetAccount
=
GetAccount
m
.
GetAccountByLogin
=
GetAccountByLogin
m
.
GetOtherAccountsFor
=
GetOtherAccountsFor
m
.
GetDashboard
=
GetDashboard
m
.
SaveDashboard
=
SaveDashboard
m
.
SearchQuery
=
SearchQuery
m
.
DeleteDashboard
=
DeleteDashboard
m
.
GetCollaboratorsForAccount
=
GetCollaboratorsForAccount
m
.
AddCollaborator
=
AddCollaborator
}
func
LoadModelsConfig
()
{
...
...
pkg/stores/sqlstore/sqlstore_datasource.go
View file @
27f07e9d
...
...
@@ -7,9 +7,14 @@ import (
)
func
init
()
{
bus
.
AddQueryHandler
(
"sql"
,
GetDataSourcesQuery
)
bus
.
AddHandler
(
"sql"
,
GetDataSourcesQuery
)
bus
.
AddHandler
(
"sql"
,
AddDataSource
)
}
func
GetDataSourcesQuery
(
query
*
m
.
GetDataSourcesQuery
)
error
{
return
errors
.
New
(
"Hello from query handler"
)
}
func
AddDataSource
(
cmd
*
m
.
AddDataSourceCommand
)
error
{
return
errors
.
New
(
"Hello from command handler"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment