grafana/pkg/plugins/renderer_plugin.go
Arve Knudsen 07582a8e85
Chore: Fix various spelling errors in back-end code (#25241)
* Chore: Fix various spelling errors in back-end code
Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>>
2020-06-01 17:11:25 +02:00

66 lines
1.9 KiB
Go

package plugins
import (
"context"
"encoding/json"
"path"
pluginModel "github.com/grafana/grafana-plugin-model/go/renderer"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
"github.com/grafana/grafana/pkg/util/errutil"
)
type RendererPlugin struct {
FrontendPluginBase
Executable string `json:"executable,omitempty"`
GrpcPluginV1 pluginModel.RendererPlugin
GrpcPluginV2 pluginextensionv2.RendererPlugin
backendPluginManager backendplugin.Manager
}
func (r *RendererPlugin) Load(decoder *json.Decoder, pluginDir string, backendPluginManager backendplugin.Manager) error {
if err := decoder.Decode(r); err != nil {
return err
}
if err := r.registerPlugin(pluginDir); err != nil {
return err
}
r.backendPluginManager = backendPluginManager
cmd := ComposePluginStartCommand("plugin_start")
fullpath := path.Join(r.PluginDir, cmd)
descriptor := backendplugin.NewRendererPluginDescriptor(r.Id, fullpath, backendplugin.PluginStartFuncs{
OnLegacyStart: r.onLegacyPluginStart,
OnStart: r.onPluginStart,
})
if err := backendPluginManager.Register(descriptor); err != nil {
return errutil.Wrapf(err, "Failed to register backend plugin")
}
Renderer = r
return nil
}
func (r *RendererPlugin) Start(ctx context.Context) error {
if err := r.backendPluginManager.StartPlugin(ctx, r.Id); err != nil {
return errutil.Wrapf(err, "Failed to start renderer plugin")
}
return nil
}
func (r *RendererPlugin) onLegacyPluginStart(pluginID string, client *backendplugin.LegacyClient, logger log.Logger) error {
r.GrpcPluginV1 = client.RendererPlugin
return nil
}
func (r *RendererPlugin) onPluginStart(pluginID string, client *backendplugin.Client, logger log.Logger) error {
r.GrpcPluginV2 = client.RendererPlugin
return nil
}