summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-30 11:44:07 +0300
committerValery Piashchynski <[email protected]>2021-04-30 11:44:07 +0300
commit50aa751dcefc0ab0e96594a5f111ead316a34a70 (patch)
tree5cf1fd278e01e1bd23a3f39d408ceb49741c448c
parent65015a3d3f4b387675b5ca005b8831a6be9e15aa (diff)
- Update Lister implementation
Signed-off-by: Valery Piashchynski <[email protected]>
-rwxr-xr-xplugins/config/plugin.go7
-rw-r--r--plugins/gzip/plugin.go7
-rw-r--r--plugins/headers/plugin.go11
-rw-r--r--plugins/http/plugin.go5
-rw-r--r--plugins/informer/interface.go13
-rw-r--r--plugins/informer/plugin.go20
-rw-r--r--plugins/informer/rpc.go11
-rw-r--r--plugins/kv/config.go1
-rw-r--r--plugins/kv/drivers/boltdb/plugin.go5
-rw-r--r--plugins/kv/drivers/memcached/plugin.go5
-rw-r--r--plugins/kv/drivers/memory/plugin.go5
-rw-r--r--plugins/kv/storage.go5
12 files changed, 66 insertions, 29 deletions
diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go
index 58647eb8..eb7146b2 100755
--- a/plugins/config/plugin.go
+++ b/plugins/config/plugin.go
@@ -113,11 +113,16 @@ 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
}
+// 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 cd8ab232..08eda00b 100644
--- a/plugins/informer/interface.go
+++ b/plugins/informer/interface.go
@@ -4,13 +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
}
-// Lister interface used to filter available plugins
-type Lister interface {
- // List gets no args, but returns list of the active plugins
- List() []string
+// 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 3d219cda..73e49575 100644
--- a/plugins/informer/plugin.go
+++ b/plugins/informer/plugin.go
@@ -4,20 +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
- plugins map[string]Lister
- 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
}
@@ -36,18 +34,18 @@ func (p *Plugin) Workers(name string) ([]process.State, error) {
func (p *Plugin) Collects() []interface{} {
return []interface{}{
p.CollectWorkers,
+ p.CollectPlugins,
}
}
// CollectPlugins collects all RR plugins
-func (p *Plugin) CollectPlugins(name endure.Named, l Lister) {
- p.plugins[name.Name()] = l
+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) error {
+func (p *Plugin) CollectWorkers(name endure.Named, r Informer) {
p.registry[name.Name()] = r
- return nil
}
// Name of the service.
@@ -57,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
+}