From 3bb20dbf2e63514369daf3a271b4427cbe622de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 8 Jan 2016 23:15:44 +0100 Subject: [PATCH] feat(plugins): changed plugin schema, pluginType -> type, type -> id --- pkg/api/app_plugin.go | 2 +- pkg/api/frontendsettings.go | 2 +- pkg/plugins/models.go | 21 ++++---- pkg/plugins/plugins.go | 53 +++++++------------ pkg/plugins/plugins_test.go | 2 +- .../plugins/datasource/cloudwatch/plugin.json | 4 +- .../datasource/elasticsearch/plugin.json | 4 +- .../plugins/datasource/grafana/plugin.json | 5 +- .../plugins/datasource/graphite/plugin.json | 4 +- .../plugins/datasource/influxdb/plugin.json | 4 +- .../app/plugins/datasource/mixed/plugin.json | 5 +- .../plugins/datasource/opentsdb/plugin.json | 5 +- .../plugins/datasource/prometheus/plugin.json | 4 +- .../app/plugins/datasource/sql/datasource.js | 18 ------- .../datasource/sql/partials/config.html | 53 ------------------- .../datasource/sql/partials/query.editor.html | 17 ------ .../app/plugins/datasource/sql/plugin.json_ | 16 ------ .../app/plugins/panels/dashlist/plugin.json | 5 +- public/app/plugins/panels/graph/plugin.json | 5 +- .../app/plugins/panels/singlestat/plugin.json | 5 +- public/app/plugins/panels/table/plugin.json | 5 +- public/app/plugins/panels/text/plugin.json | 5 +- tests/app-plugin-json/plugin.json | 38 +++++++------ 23 files changed, 79 insertions(+), 203 deletions(-) delete mode 100644 public/app/plugins/datasource/sql/datasource.js delete mode 100644 public/app/plugins/datasource/sql/partials/config.html delete mode 100644 public/app/plugins/datasource/sql/partials/query.editor.html delete mode 100644 public/app/plugins/datasource/sql/plugin.json_ diff --git a/pkg/api/app_plugin.go b/pkg/api/app_plugin.go index 0ad81827246..bcab5fa4788 100644 --- a/pkg/api/app_plugin.go +++ b/pkg/api/app_plugin.go @@ -22,7 +22,7 @@ func GetAppPlugins(c *middleware.Context) Response { Enabled: app.Enabled, Pinned: app.Pinned, Module: app.Module, - Info: app.Info, + Info: &app.Info, } } diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 9334b030201..486d59608ba 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -119,7 +119,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro panels := map[string]interface{}{} for _, panel := range enabledPlugins.Panels { - panels[panel.Type] = map[string]interface{}{ + panels[panel.Id] = map[string]interface{}{ "module": panel.Module, "name": panel.Name, } diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 7c0bfcafc50..078a63a884f 100644 --- a/pkg/plugins/models.go +++ b/pkg/plugins/models.go @@ -4,6 +4,13 @@ import ( "github.com/grafana/grafana/pkg/models" ) +type PluginCommon struct { + Type string `json:"type"` + Name string `json:"name"` + Id string `json:"id"` + Info PluginInfo `json:"info"` +} + type PluginInfo struct { Author PluginInfoLink `json:"author"` Description string `json:"description"` @@ -22,10 +29,9 @@ type PluginLogos struct { } type DataSourcePlugin struct { - Type string `json:"type"` - Name string `json:"name"` - ServiceName string `json:"serviceName"` + PluginCommon Module string `json:"module"` + ServiceName string `json:"serviceName"` Partials map[string]interface{} `json:"partials"` DefaultMatchFormat string `json:"defaultMatchFormat"` Annotations bool `json:"annotations"` @@ -36,8 +42,7 @@ type DataSourcePlugin struct { } type PanelPlugin struct { - Type string `json:"type"` - Name string `json:"name"` + PluginCommon Module string `json:"module"` PublicContent *PublicContent `json:"public"` App string `json:"app"` @@ -71,21 +76,19 @@ type AppPluginCss struct { } type ApiPlugin struct { - Type string `json:"type"` + PluginCommon Routes []*ApiPluginRoute `json:"routes"` App string `json:"app"` } type AppPlugin struct { - Type string `json:"type"` - Name string `json:"name"` + PluginCommon Enabled bool `json:"enabled"` Pinned bool `json:"pinned"` Module string `json:"module"` Css *AppPluginCss `json:"css"` Page *AppPluginPage `json:"page"` PublicContent *PublicContent `json:"public"` - Info *PluginInfo `json:"info"` } type EnabledPlugins struct { diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index a1ae0ff8dd6..8002e505b01 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -121,7 +121,7 @@ func addPublicContent(public *PublicContent, currentDir string) { } } -func interpolatePluginJson(reader io.Reader) (io.Reader, error) { +func interpolatePluginJson(reader io.Reader, pluginCommon *PluginCommon) (io.Reader, error) { buf := new(bytes.Buffer) buf.ReadFrom(reader) jsonStr := buf.String() // @@ -132,7 +132,7 @@ func interpolatePluginJson(reader io.Reader) (io.Reader, error) { } data := map[string]interface{}{ - "PluginPublicRoot": "HAHAHA", + "PluginPublicRoot": "public/plugins/" + pluginCommon.Id, } var resultBuffer bytes.Buffer @@ -153,76 +153,59 @@ func (scanner *PluginScanner) loadPluginJson(pluginJsonFilePath string) error { defer reader.Close() jsonParser := json.NewDecoder(reader) - pluginJson := make(map[string]interface{}) - if err := jsonParser.Decode(&pluginJson); err != nil { + pluginCommon := PluginCommon{} + if err := jsonParser.Decode(&pluginCommon); err != nil { return err } - pluginType, exists := pluginJson["pluginType"] - if !exists { - return errors.New("Did not find pluginType property in plugin.json") + if pluginCommon.Id == "" || pluginCommon.Type == "" { + return errors.New("Did not find type and id property in plugin.json") } reader.Seek(0, 0) - if newReader, err := interpolatePluginJson(reader); err != nil { + if newReader, err := interpolatePluginJson(reader, &pluginCommon); err != nil { return err } else { jsonParser = json.NewDecoder(newReader) } - if pluginType == "datasource" { + switch pluginCommon.Type { + case "datasource": p := DataSourcePlugin{} if err := jsonParser.Decode(&p); err != nil { return err } - if p.Type == "" { - return errors.New("Did not find type property in plugin.json") - } - - DataSources[p.Type] = &p + DataSources[p.Id] = &p addPublicContent(p.PublicContent, currentDir) - } - if pluginType == "panel" { + case "panel": p := PanelPlugin{} reader.Seek(0, 0) if err := jsonParser.Decode(&p); err != nil { return err } - if p.Type == "" { - return errors.New("Did not find type property in plugin.json") - } - - Panels[p.Type] = &p + Panels[p.Id] = &p addPublicContent(p.PublicContent, currentDir) - } - - if pluginType == "api" { + case "api": p := ApiPlugin{} reader.Seek(0, 0) if err := jsonParser.Decode(&p); err != nil { return err } - if p.Type == "" { - return errors.New("Did not find type property in plugin.json") - } - ApiPlugins[p.Type] = &p - } - - if pluginType == "app" { + ApiPlugins[p.Id] = &p + case "app": p := AppPlugin{} reader.Seek(0, 0) if err := jsonParser.Decode(&p); err != nil { return err } - if p.Type == "" { - return errors.New("Did not find type property in plugin.json") - } - Apps[p.Type] = &p + Apps[p.Id] = &p addPublicContent(p.PublicContent, currentDir) + default: + return errors.New("Unkown plugin type " + pluginCommon.Type) } return nil diff --git a/pkg/plugins/plugins_test.go b/pkg/plugins/plugins_test.go index 812b8ad19f2..92982d8abe4 100644 --- a/pkg/plugins/plugins_test.go +++ b/pkg/plugins/plugins_test.go @@ -29,7 +29,7 @@ func TestPluginScans(t *testing.T) { So(err, ShouldBeNil) So(len(Apps), ShouldBeGreaterThan, 0) - So(Apps["app-test"].Info.Logos.Large, ShouldEqual, "plugins/app-exampl/img/logo_large.png") + So(Apps["app-test"].Info.Logos.Large, ShouldEqual, "public/plugins/app-test/logo_large.png") }) } diff --git a/public/app/plugins/datasource/cloudwatch/plugin.json b/public/app/plugins/datasource/cloudwatch/plugin.json index f1cf0e5512c..5e54db64f52 100644 --- a/public/app/plugins/datasource/cloudwatch/plugin.json +++ b/public/app/plugins/datasource/cloudwatch/plugin.json @@ -1,8 +1,8 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "CloudWatch", + "id": "cloudwatch", - "type": "cloudwatch", "serviceName": "CloudWatchDatasource", "module": "app/plugins/datasource/cloudwatch/datasource", diff --git a/public/app/plugins/datasource/elasticsearch/plugin.json b/public/app/plugins/datasource/elasticsearch/plugin.json index a0350bd8c6c..c06f9e7ba99 100644 --- a/public/app/plugins/datasource/elasticsearch/plugin.json +++ b/public/app/plugins/datasource/elasticsearch/plugin.json @@ -1,8 +1,8 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "Elasticsearch", + "id": "elasticsearch", - "type": "elasticsearch", "serviceName": "ElasticDatasource", "module": "app/plugins/datasource/elasticsearch/datasource", diff --git a/public/app/plugins/datasource/grafana/plugin.json b/public/app/plugins/datasource/grafana/plugin.json index 8d4ba70e471..5b74f9ea613 100644 --- a/public/app/plugins/datasource/grafana/plugin.json +++ b/public/app/plugins/datasource/grafana/plugin.json @@ -1,9 +1,10 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "Grafana", + "id": "grafana", + "builtIn": true, - "type": "grafana", "serviceName": "GrafanaDatasource", "module": "app/plugins/datasource/grafana/datasource", diff --git a/public/app/plugins/datasource/graphite/plugin.json b/public/app/plugins/datasource/graphite/plugin.json index 0a94404533d..9a7360ba50a 100644 --- a/public/app/plugins/datasource/graphite/plugin.json +++ b/public/app/plugins/datasource/graphite/plugin.json @@ -1,7 +1,7 @@ { - "pluginType": "datasource", "name": "Graphite", - "type": "graphite", + "type": "datasource", + "id": "graphite", "serviceName": "GraphiteDatasource", "module": "app/plugins/datasource/graphite/datasource", diff --git a/public/app/plugins/datasource/influxdb/plugin.json b/public/app/plugins/datasource/influxdb/plugin.json index d586d679367..3a9aea175cb 100644 --- a/public/app/plugins/datasource/influxdb/plugin.json +++ b/public/app/plugins/datasource/influxdb/plugin.json @@ -1,8 +1,8 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "InfluxDB 0.9.x", + "id": "influxdb", - "type": "influxdb", "serviceName": "InfluxDatasource", "module": "app/plugins/datasource/influxdb/datasource", diff --git a/public/app/plugins/datasource/mixed/plugin.json b/public/app/plugins/datasource/mixed/plugin.json index 85be108d995..fb9bb340a04 100644 --- a/public/app/plugins/datasource/mixed/plugin.json +++ b/public/app/plugins/datasource/mixed/plugin.json @@ -1,10 +1,11 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "Mixed datasource", + "id": "mixed", + "builtIn": true, "mixed": true, - "type": "mixed", "serviceName": "MixedDatasource", "module": "app/plugins/datasource/mixed/datasource", diff --git a/public/app/plugins/datasource/opentsdb/plugin.json b/public/app/plugins/datasource/opentsdb/plugin.json index 311dcf0da9a..a72e09a1ab0 100644 --- a/public/app/plugins/datasource/opentsdb/plugin.json +++ b/public/app/plugins/datasource/opentsdb/plugin.json @@ -1,10 +1,9 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "OpenTSDB", + "id": "opentsdb", - "type": "opentsdb", "serviceName": "OpenTSDBDatasource", - "module": "app/plugins/datasource/opentsdb/datasource", "partials": { diff --git a/public/app/plugins/datasource/prometheus/plugin.json b/public/app/plugins/datasource/prometheus/plugin.json index 5c97866101d..2580db9e5c9 100644 --- a/public/app/plugins/datasource/prometheus/plugin.json +++ b/public/app/plugins/datasource/prometheus/plugin.json @@ -1,8 +1,8 @@ { - "pluginType": "datasource", + "type": "datasource", "name": "Prometheus", + "id": "prometheus", - "type": "prometheus", "serviceName": "PrometheusDatasource", "module": "app/plugins/datasource/prometheus/datasource", diff --git a/public/app/plugins/datasource/sql/datasource.js b/public/app/plugins/datasource/sql/datasource.js deleted file mode 100644 index ae6e62286ba..00000000000 --- a/public/app/plugins/datasource/sql/datasource.js +++ /dev/null @@ -1,18 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.services'); - - module.factory('SqlDatasource', function() { - - function SqlDatasource() { - } - - return SqlDatasource; - - }); - -}); diff --git a/public/app/plugins/datasource/sql/partials/config.html b/public/app/plugins/datasource/sql/partials/config.html deleted file mode 100644 index e6b7749a2f7..00000000000 --- a/public/app/plugins/datasource/sql/partials/config.html +++ /dev/null @@ -1,53 +0,0 @@ -

SQL Options

- -
- -
-
-
- -
-
-
- -
-
- diff --git a/public/app/plugins/datasource/sql/partials/query.editor.html b/public/app/plugins/datasource/sql/partials/query.editor.html deleted file mode 100644 index 0d6d21d0ad2..00000000000 --- a/public/app/plugins/datasource/sql/partials/query.editor.html +++ /dev/null @@ -1,17 +0,0 @@ - -
-
-
-
Test graph
- -

- This is just a test data source that generates random walk series. If this is your only data source - open the left side menu and navigate to the data sources admin screen and add your data sources. You can change - data source using the button to the left of the Add query button. -

-
-
- -
-
- diff --git a/public/app/plugins/datasource/sql/plugin.json_ b/public/app/plugins/datasource/sql/plugin.json_ deleted file mode 100644 index 8d3f6effae7..00000000000 --- a/public/app/plugins/datasource/sql/plugin.json_ +++ /dev/null @@ -1,16 +0,0 @@ -{ - "pluginType": "datasource", - "name": "Generic SQL (prototype)", - - "type": "generic_sql", - "serviceName": "SqlDatasource", - - "module": "app/plugins/datasource/sql/datasource", - - "partials": { - "config": "app/plugins/datasource/sql/partials/config.html", - "query": "app/plugins/datasource/sql/partials/query.editor.html" - }, - - "metrics": true -} diff --git a/public/app/plugins/panels/dashlist/plugin.json b/public/app/plugins/panels/dashlist/plugin.json index af9b9d8bbc8..e1fcb2f9221 100644 --- a/public/app/plugins/panels/dashlist/plugin.json +++ b/public/app/plugins/panels/dashlist/plugin.json @@ -1,8 +1,7 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Dashboard list", - "type": "dashlist", + "id": "dashlist", "module": "app/plugins/panels/dashlist/module" } diff --git a/public/app/plugins/panels/graph/plugin.json b/public/app/plugins/panels/graph/plugin.json index 8b683c9d750..7e4dc3093bb 100644 --- a/public/app/plugins/panels/graph/plugin.json +++ b/public/app/plugins/panels/graph/plugin.json @@ -1,8 +1,7 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Graph", - "type": "graph", + "id": "graph", "module": "app/plugins/panels/graph/module" } diff --git a/public/app/plugins/panels/singlestat/plugin.json b/public/app/plugins/panels/singlestat/plugin.json index dfb38d615c7..5bc8e536510 100644 --- a/public/app/plugins/panels/singlestat/plugin.json +++ b/public/app/plugins/panels/singlestat/plugin.json @@ -1,8 +1,7 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Singlestat", - "type": "singlestat", + "id": "singlestat", "module": "app/plugins/panels/singlestat/module" } diff --git a/public/app/plugins/panels/table/plugin.json b/public/app/plugins/panels/table/plugin.json index cdcfb7081dc..4fdb393b3db 100644 --- a/public/app/plugins/panels/table/plugin.json +++ b/public/app/plugins/panels/table/plugin.json @@ -1,8 +1,7 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Table", - "type": "table", + "id": "table", "module": "app/plugins/panels/table/module" } diff --git a/public/app/plugins/panels/text/plugin.json b/public/app/plugins/panels/text/plugin.json index 4a6c039104b..33c49b2f8a4 100644 --- a/public/app/plugins/panels/text/plugin.json +++ b/public/app/plugins/panels/text/plugin.json @@ -1,8 +1,7 @@ { - "pluginType": "panel", - + "type": "panel", "name": "Text", - "type": "text", + "id": "text", "module": "app/plugins/panels/text/module" } diff --git a/tests/app-plugin-json/plugin.json b/tests/app-plugin-json/plugin.json index 34c60f84f52..5f48132f4db 100644 --- a/tests/app-plugin-json/plugin.json +++ b/tests/app-plugin-json/plugin.json @@ -1,25 +1,7 @@ { - "pluginType": "app", "name": "App Example", - "type": "app-test", - - "plugins": [], - - "css": { - "light": "plugin.dark.css", - "dark": "plugin.light.css" - }, - - "module": "app", - - "pages": [ - {"name": "Example1", "url": "/app-example", "reqRole": "Editor"} - ], - - "public": { - "urlFragment": "app-example", - "path": "./public" - }, + "id": "app-test", + "type": "app", "info": { "description": "Example Grafana App", @@ -40,6 +22,22 @@ "updated": "2015-02-10" }, + "css": { + "light": "plugin.dark.css", + "dark": "plugin.light.css" + }, + + "module": "app", + + "pages": [ + {"name": "Example1", "url": "/app-example", "reqRole": "Editor"} + ], + + "public": { + "urlFragment": "app-example", + "path": "./public" + }, + "dependencies": { "grafanaVersion": "2.6.x", "plugins": [