summaryrefslogtreecommitdiff
path: root/plugins/informer
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-09-16 17:12:37 +0300
committerValery Piashchynski <[email protected]>2021-09-16 17:12:37 +0300
commitf3491c089b4da77fd8d2bc942a88b6b8d117a8a5 (patch)
tree32bfffb1f24eeee7b909747cc00a6a6b9fd3ee83 /plugins/informer
parent5d2cd55ab522d4f1e65a833f91146444465a32ac (diff)
Move plugins to a separate repository
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/informer')
-rw-r--r--plugins/informer/interface.go34
-rw-r--r--plugins/informer/plugin.go89
-rw-r--r--plugins/informer/rpc.go59
3 files changed, 0 insertions, 182 deletions
diff --git a/plugins/informer/interface.go b/plugins/informer/interface.go
deleted file mode 100644
index 9277b85b..00000000
--- a/plugins/informer/interface.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package informer
-
-import (
- "context"
-
- "github.com/spiral/roadrunner/v2/pkg/state/job"
- "github.com/spiral/roadrunner/v2/pkg/state/process"
-)
-
-/*
-Informer plugin should not receive any other plugin in the Init or via Collects
-Because Availabler implementation should present in every plugin
-*/
-
-// Statistic interfaces ==============
-
-// Informer used to get workers from particular plugin or set of plugins
-type Informer interface {
- Workers() []*process.State
-}
-
-// JobsStat interface provide statistic for the jobs plugin
-type JobsStat interface {
- // JobsState returns slice with the attached drivers information
- JobsState(ctx context.Context) ([]*job.State, error)
-}
-
-// Statistic interfaces end ============
-
-// 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 method needed to collect all plugins which are available in the runtime.
- Available()
-}
diff --git a/plugins/informer/plugin.go b/plugins/informer/plugin.go
deleted file mode 100644
index 87180be5..00000000
--- a/plugins/informer/plugin.go
+++ /dev/null
@@ -1,89 +0,0 @@
-package informer
-
-import (
- "context"
-
- endure "github.com/spiral/endure/pkg/container"
- "github.com/spiral/roadrunner/v2/pkg/state/job"
- "github.com/spiral/roadrunner/v2/pkg/state/process"
- "github.com/spiral/roadrunner/v2/plugins/logger"
-)
-
-const PluginName = "informer"
-
-type Plugin struct {
- log logger.Logger
-
- withJobs map[string]JobsStat
- withWorkers map[string]Informer
- available map[string]Availabler
-}
-
-func (p *Plugin) Init(log logger.Logger) error {
- p.available = make(map[string]Availabler)
- p.withWorkers = make(map[string]Informer)
- p.withJobs = make(map[string]JobsStat)
-
- p.log = log
- return nil
-}
-
-// Workers provides BaseProcess slice with workers for the requested plugin
-func (p *Plugin) Workers(name string) []*process.State {
- svc, ok := p.withWorkers[name]
- if !ok {
- return nil
- }
-
- return svc.Workers()
-}
-
-// Jobs provides information about jobs for the registered plugin using jobs
-func (p *Plugin) Jobs(name string) []*job.State {
- svc, ok := p.withJobs[name]
- if !ok {
- return nil
- }
-
- st, err := svc.JobsState(context.Background())
- if err != nil {
- p.log.Info("jobs stat", "error", err)
- // skip errors here
- return nil
- }
-
- return st
-}
-
-// Collects declares services to be collected.
-func (p *Plugin) Collects() []interface{} {
- return []interface{}{
- p.CollectPlugins,
- p.CollectWorkers,
- p.CollectJobs,
- }
-}
-
-// 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.withWorkers[name.Name()] = r
-}
-
-func (p *Plugin) CollectJobs(name endure.Named, j JobsStat) {
- p.withJobs[name.Name()] = j
-}
-
-// Name of the service.
-func (p *Plugin) Name() string {
- return PluginName
-}
-
-// RPC returns associated rpc service.
-func (p *Plugin) RPC() interface{} {
- return &rpc{srv: p}
-}
diff --git a/plugins/informer/rpc.go b/plugins/informer/rpc.go
deleted file mode 100644
index 478d3227..00000000
--- a/plugins/informer/rpc.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package informer
-
-import (
- "github.com/spiral/roadrunner/v2/pkg/state/job"
- "github.com/spiral/roadrunner/v2/pkg/state/process"
-)
-
-type rpc struct {
- srv *Plugin
-}
-
-// WorkerList contains list of workers.
-type WorkerList struct {
- // Workers are list of workers.
- Workers []*process.State `json:"workers"`
-}
-
-// List all resettable services.
-func (rpc *rpc) List(_ bool, list *[]string) error {
- *list = make([]string, 0, len(rpc.srv.withWorkers))
-
- // append all plugin names to the output result
- for name := range rpc.srv.available {
- *list = append(*list, name)
- }
- return nil
-}
-
-// Workers state of a given service.
-func (rpc *rpc) Workers(service string, list *WorkerList) error {
- workers := rpc.srv.Workers(service)
- if workers == nil {
- return nil
- }
-
- // write actual processes
- list.Workers = workers
-
- return nil
-}
-
-func (rpc *rpc) Jobs(service string, out *[]*job.State) error {
- *out = rpc.srv.Jobs(service)
- return nil
-}
-
-// sort.Sort
-
-func (w *WorkerList) Len() int {
- return len(w.Workers)
-}
-
-func (w *WorkerList) Less(i, j int) bool {
- return w.Workers[i].Pid < w.Workers[j].Pid
-}
-
-func (w *WorkerList) Swap(i, j int) {
- w.Workers[i], w.Workers[j] = w.Workers[j], w.Workers[i]
-}