diff options
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/config/plugin.go | 22 | ||||
-rw-r--r-- | plugins/gzip/plugin.go | 7 | ||||
-rw-r--r-- | plugins/headers/plugin.go | 11 | ||||
-rw-r--r-- | plugins/http/plugin.go | 5 | ||||
-rw-r--r-- | plugins/informer/interface.go | 11 | ||||
-rw-r--r-- | plugins/informer/plugin.go | 30 | ||||
-rw-r--r-- | plugins/informer/rpc.go | 11 | ||||
-rw-r--r-- | plugins/kv/config.go | 1 | ||||
-rw-r--r-- | plugins/kv/drivers/boltdb/plugin.go | 5 | ||||
-rw-r--r-- | plugins/kv/drivers/memcached/plugin.go | 5 | ||||
-rw-r--r-- | plugins/kv/drivers/memory/plugin.go | 5 | ||||
-rw-r--r-- | plugins/kv/storage.go | 5 | ||||
-rw-r--r-- | plugins/logger/plugin.go | 10 | ||||
-rw-r--r-- | plugins/metrics/plugin.go | 5 | ||||
-rw-r--r-- | plugins/redis/plugin.go | 5 | ||||
-rw-r--r-- | plugins/reload/plugin.go | 5 | ||||
-rw-r--r-- | plugins/resetter/plugin.go | 5 | ||||
-rw-r--r-- | plugins/rpc/plugin.go | 5 | ||||
-rw-r--r-- | plugins/server/plugin.go | 5 | ||||
-rw-r--r-- | plugins/service/plugin.go | 5 | ||||
-rw-r--r-- | plugins/status/plugin.go | 7 |
21 files changed, 142 insertions, 28 deletions
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go index 58647eb8..a5215226 100755 --- a/plugins/config/plugin.go +++ b/plugins/config/plugin.go @@ -10,6 +10,8 @@ import ( "github.com/spiral/errors" ) +const PluginName string = "config" + type Viper struct { viper *viper.Viper Path string @@ -113,11 +115,29 @@ func (v *Viper) Has(name string) bool { return v.viper.IsSet(name) } -// Returns common config parameters +// GetCommonConfig Returns common config parameters func (v *Viper) GetCommonConfig() *General { return v.CommonConfig } +func (v *Viper) Serve() chan error { + return make(chan error, 1) +} + +func (v *Viper) Stop() error { + return nil +} + +// Name returns user-friendly plugin name +func (v *Viper) Name() string { + return PluginName +} + +// Available interface implementation +func (v *Viper) Available() bool { + return true +} + func parseFlag(flag string) (string, string, error) { const op = errors.Op("parse_flag") if !strings.Contains(flag, "=") { diff --git a/plugins/gzip/plugin.go b/plugins/gzip/plugin.go index 18ee7b88..d25894ff 100644 --- a/plugins/gzip/plugin.go +++ b/plugins/gzip/plugin.go @@ -10,7 +10,7 @@ const PluginName = "gzip" type Plugin struct{} -// needed for the Endure +// Init needed for the Endure func (g *Plugin) Init() error { return nil } @@ -21,6 +21,11 @@ func (g *Plugin) Middleware(next http.Handler) http.Handler { }) } +// Available interface implementation +func (g *Plugin) Available() bool { + return true +} + func (g *Plugin) Name() string { return PluginName } diff --git a/plugins/headers/plugin.go b/plugins/headers/plugin.go index dea0d127..caba6aeb 100644 --- a/plugins/headers/plugin.go +++ b/plugins/headers/plugin.go @@ -8,11 +8,11 @@ import ( "github.com/spiral/roadrunner/v2/plugins/config" ) -// ID contains default service name. +// PluginName contains default service name. const PluginName = "headers" const RootPluginName = "http" -// Service serves headers files. Potentially convert into middleware? +// Plugin serves headers files. Potentially convert into middleware? type Plugin struct { // server configuration (location, forbidden files and etc) cfg *Config @@ -37,7 +37,7 @@ func (s *Plugin) Init(cfg config.Configurer) error { return nil } -// middleware must return true if request/response pair is handled within the middleware. +// Middleware is HTTP plugin middleware to serve headers func (s *Plugin) Middleware(next http.Handler) http.Handler { // Define the http.HandlerFunc return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -69,6 +69,11 @@ func (s *Plugin) Name() string { return PluginName } +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} + // configure OPTIONS response func (s *Plugin) preflightRequest(w http.ResponseWriter) { headers := w.Header() diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index 2b1dec89..cf6d75fd 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -440,3 +440,8 @@ func (s *Plugin) Ready() status.Status { Code: http.StatusServiceUnavailable, } } + +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} diff --git a/plugins/informer/interface.go b/plugins/informer/interface.go index 45f44691..08eda00b 100644 --- a/plugins/informer/interface.go +++ b/plugins/informer/interface.go @@ -4,7 +4,18 @@ import ( "github.com/spiral/roadrunner/v2/pkg/process" ) +/* +Informer plugin should not receive any other plugin in the Init or via Collects +Because Availabler implementation should present in every plugin +*/ + // Informer used to get workers from particular plugin or set of plugins type Informer interface { Workers() []process.State } + +// Availabler interface should be implemented by every plugin which wish to report to the PHP worker that it available in the RR runtime +type Availabler interface { + // Available returns true if the particular plugin available in the RR2 runtime + Available() bool +} diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go index 98081d34..2d76123b 100644 --- a/plugins/informer/plugin.go +++ b/plugins/informer/plugin.go @@ -4,19 +4,18 @@ import ( endure "github.com/spiral/endure/pkg/container" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/pkg/process" - "github.com/spiral/roadrunner/v2/plugins/logger" ) const PluginName = "informer" type Plugin struct { - registry map[string]Informer - log logger.Logger + registry map[string]Informer + available map[string]Availabler } -func (p *Plugin) Init(log logger.Logger) error { +func (p *Plugin) Init() error { + p.available = make(map[string]Availabler) p.registry = make(map[string]Informer) - p.log = log return nil } @@ -31,19 +30,24 @@ func (p *Plugin) Workers(name string) ([]process.State, error) { return svc.Workers(), nil } -// CollectTarget resettable service. -func (p *Plugin) CollectTarget(name endure.Named, r Informer) error { - p.registry[name.Name()] = r - return nil -} - // Collects declares services to be collected. func (p *Plugin) Collects() []interface{} { return []interface{}{ - p.CollectTarget, + p.CollectPlugins, + p.CollectWorkers, } } +// CollectPlugins collects all RR plugins +func (p *Plugin) CollectPlugins(name endure.Named, l Availabler) { + p.available[name.Name()] = l +} + +// CollectWorkers obtains plugins with workers inside. +func (p *Plugin) CollectWorkers(name endure.Named, r Informer) { + p.registry[name.Name()] = r +} + // Name of the service. func (p *Plugin) Name() string { return PluginName @@ -51,5 +55,5 @@ func (p *Plugin) Name() string { // RPC returns associated rpc service. func (p *Plugin) RPC() interface{} { - return &rpc{srv: p, log: p.log} + return &rpc{srv: p} } diff --git a/plugins/informer/rpc.go b/plugins/informer/rpc.go index b0b5b1af..8955af92 100644 --- a/plugins/informer/rpc.go +++ b/plugins/informer/rpc.go @@ -2,12 +2,10 @@ package informer import ( "github.com/spiral/roadrunner/v2/pkg/process" - "github.com/spiral/roadrunner/v2/plugins/logger" ) type rpc struct { srv *Plugin - log logger.Logger } // WorkerList contains list of workers. @@ -18,20 +16,17 @@ type WorkerList struct { // List all resettable services. func (rpc *rpc) List(_ bool, list *[]string) error { - rpc.log.Debug("Started List method") *list = make([]string, 0, len(rpc.srv.registry)) - for name := range rpc.srv.registry { + // append all plugin names to the output result + for name := range rpc.srv.available { *list = append(*list, name) } - rpc.log.Debug("list of services", "list", *list) - rpc.log.Debug("successfully finished List method") return nil } // Workers state of a given service. func (rpc *rpc) Workers(service string, list *WorkerList) error { - rpc.log.Debug("started Workers method", "service", service) workers, err := rpc.srv.Workers(service) if err != nil { return err @@ -40,7 +35,5 @@ func (rpc *rpc) Workers(service string, list *WorkerList) error { // write actual processes list.Workers = workers - rpc.log.Debug("list of workers", "workers", list.Workers) - rpc.log.Debug("successfully finished Workers method") return nil } diff --git a/plugins/kv/config.go b/plugins/kv/config.go index 9ecae644..66095817 100644 --- a/plugins/kv/config.go +++ b/plugins/kv/config.go @@ -1,5 +1,6 @@ package kv +// Config represents general storage configuration with keys as the user defined kv-names and values as the drivers type Config struct { Data map[string]interface{} `mapstructure:"kv"` } diff --git a/plugins/kv/drivers/boltdb/plugin.go b/plugins/kv/drivers/boltdb/plugin.go index 9d1e0dba..eba388c2 100644 --- a/plugins/kv/drivers/boltdb/plugin.go +++ b/plugins/kv/drivers/boltdb/plugin.go @@ -63,3 +63,8 @@ func (s *Plugin) Provide(key string) (kv.Storage, error) { func (s *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} diff --git a/plugins/kv/drivers/memcached/plugin.go b/plugins/kv/drivers/memcached/plugin.go index af59e91b..c95a7f73 100644 --- a/plugins/kv/drivers/memcached/plugin.go +++ b/plugins/kv/drivers/memcached/plugin.go @@ -33,6 +33,11 @@ func (s *Plugin) Name() string { return PluginName } +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} + func (s *Plugin) Provide(key string) (kv.Storage, error) { const op = errors.Op("boltdb_plugin_provide") st, err := NewMemcachedDriver(s.log, key, s.cfgPlugin) diff --git a/plugins/kv/drivers/memory/plugin.go b/plugins/kv/drivers/memory/plugin.go index acc6023d..fd4ed15f 100644 --- a/plugins/kv/drivers/memory/plugin.go +++ b/plugins/kv/drivers/memory/plugin.go @@ -62,3 +62,8 @@ func (s *Plugin) Provide(key string) (kv.Storage, error) { func (s *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} diff --git a/plugins/kv/storage.go b/plugins/kv/storage.go index e8468b77..2f1e0716 100644 --- a/plugins/kv/storage.go +++ b/plugins/kv/storage.go @@ -184,3 +184,8 @@ func (p *Plugin) RPC() interface{} { func (p *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (p *Plugin) Available() bool { + return true +} diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go index 9965b29c..1084cc5e 100644 --- a/plugins/logger/plugin.go +++ b/plugins/logger/plugin.go @@ -75,3 +75,13 @@ func (z *ZapLogger) Provides() []interface{} { z.ServiceLogger, } } + +// Name returns user-friendly plugin name +func (z *ZapLogger) Name() string { + return PluginName +} + +// Available interface implementation +func (z *ZapLogger) Available() bool { + return true +} diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index d0443177..df6ea122 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -222,3 +222,8 @@ func (m *Plugin) RPC() interface{} { log: m.log, } } + +// Available interface implementation +func (m *Plugin) Available() bool { + return true +} diff --git a/plugins/redis/plugin.go b/plugins/redis/plugin.go index 204abd17..b69af9d6 100644 --- a/plugins/redis/plugin.go +++ b/plugins/redis/plugin.go @@ -76,3 +76,8 @@ func (s Plugin) Stop() error { func (s *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} diff --git a/plugins/reload/plugin.go b/plugins/reload/plugin.go index bf88462e..d2c22fe8 100644 --- a/plugins/reload/plugin.go +++ b/plugins/reload/plugin.go @@ -161,3 +161,8 @@ func (s *Plugin) Stop() error { func (s *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} diff --git a/plugins/resetter/plugin.go b/plugins/resetter/plugin.go index 43382e56..a80c2c0f 100644 --- a/plugins/resetter/plugin.go +++ b/plugins/resetter/plugin.go @@ -74,6 +74,11 @@ func (p *Plugin) Name() string { return PluginName } +// Available interface implementation +func (p *Plugin) Available() bool { + return true +} + // RPC returns associated rpc service. func (p *Plugin) RPC() interface{} { return &rpc{srv: p, log: p.log} diff --git a/plugins/rpc/plugin.go b/plugins/rpc/plugin.go index b80994d3..f88aa6de 100644 --- a/plugins/rpc/plugin.go +++ b/plugins/rpc/plugin.go @@ -122,6 +122,11 @@ func (s *Plugin) Name() string { return PluginName } +// Available interface implementation +func (s *Plugin) Available() bool { + return true +} + // Collects all plugins which implement Name + RPCer interfaces func (s *Plugin) Collects() []interface{} { return []interface{}{ diff --git a/plugins/server/plugin.go b/plugins/server/plugin.go index c3496ae7..64793034 100644 --- a/plugins/server/plugin.go +++ b/plugins/server/plugin.go @@ -58,6 +58,11 @@ func (server *Plugin) Name() string { return PluginName } +// Available interface implementation +func (server *Plugin) Available() bool { + return true +} + // Serve (Start) server plugin (just a mock here to satisfy interface) func (server *Plugin) Serve() chan error { const op = errors.Op("server_plugin_serve") diff --git a/plugins/service/plugin.go b/plugins/service/plugin.go index b5608ff2..522fe192 100644 --- a/plugins/service/plugin.go +++ b/plugins/service/plugin.go @@ -104,3 +104,8 @@ func (service *Plugin) Stop() error { func (service *Plugin) Name() string { return PluginName } + +// Available interface implementation +func (service *Plugin) Available() bool { + return true +} diff --git a/plugins/status/plugin.go b/plugins/status/plugin.go index dc4e506d..3553bb01 100644 --- a/plugins/status/plugin.go +++ b/plugins/status/plugin.go @@ -127,7 +127,12 @@ func (c *Plugin) Name() string { return PluginName } -// RPCService returns associated rpc service. +// Available interface implementation +func (c *Plugin) Available() bool { + return true +} + +// RPC returns associated rpc service. func (c *Plugin) RPC() interface{} { return &rpc{srv: c, log: c.log} } |