diff options
author | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-21 19:42:23 +0300 |
commit | ee8b4075c0f836d698d1ae505c87c17147de447a (patch) | |
tree | 531d980e5bfb94ee39b03952a97e0445f7955409 /plugins/resetter | |
parent | 0ad45031047bb479e06ce0a0f496c6db9b2641c9 (diff) |
Move plugins to the roadrunner-plugins repository
Diffstat (limited to 'plugins/resetter')
-rw-r--r-- | plugins/resetter/plugin.go | 81 | ||||
-rw-r--r-- | plugins/resetter/rpc.go | 30 | ||||
-rw-r--r-- | plugins/resetter/tests/.rr-resetter.yaml | 16 | ||||
-rw-r--r-- | plugins/resetter/tests/resetter_test.go | 102 | ||||
-rw-r--r-- | plugins/resetter/tests/test_plugin.go | 66 |
5 files changed, 0 insertions, 295 deletions
diff --git a/plugins/resetter/plugin.go b/plugins/resetter/plugin.go deleted file mode 100644 index 8dc5cc31..00000000 --- a/plugins/resetter/plugin.go +++ /dev/null @@ -1,81 +0,0 @@ -package resetter - -import ( - "github.com/spiral/endure" - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/interfaces/log" - "github.com/spiral/roadrunner/v2/interfaces/resetter" -) - -const PluginName = "resetter" - -type Plugin struct { - registry map[string]resetter.Resettable - log log.Logger -} - -func (p *Plugin) ResetAll() error { - const op = errors.Op("reset all") - for name := range p.registry { - err := p.registry[name].Reset() - if err != nil { - return errors.E(op, err) - } - } - return nil -} - -func (p *Plugin) ResetByName(plugin string) error { - const op = errors.Op("reset by name") - if plugin, ok := p.registry[plugin]; ok { - return plugin.Reset() - } - return errors.E(op, errors.Errorf("can't find plugin: %s", plugin)) -} - -func (p *Plugin) GetAll() []string { - all := make([]string, 0, len(p.registry)) - for name := range p.registry { - all = append(all, name) - } - return all -} - -func (p *Plugin) Init(log log.Logger) error { - p.registry = make(map[string]resetter.Resettable) - p.log = log - return nil -} - -// Reset named service. -func (p *Plugin) Reset(name string) error { - svc, ok := p.registry[name] - if !ok { - return errors.E("no such service", errors.Str(name)) - } - - return svc.Reset() -} - -// RegisterTarget resettable service. -func (p *Plugin) RegisterTarget(name endure.Named, r resetter.Resettable) error { - p.registry[name.Name()] = r - return nil -} - -// Collects declares services to be collected. -func (p *Plugin) Collects() []interface{} { - return []interface{}{ - p.RegisterTarget, - } -} - -// Name of the service. -func (p *Plugin) Name() string { - return PluginName -} - -// RPCService returns associated rpc service. -func (p *Plugin) RPC() interface{} { - return &rpc{srv: p, log: p.log} -} diff --git a/plugins/resetter/rpc.go b/plugins/resetter/rpc.go deleted file mode 100644 index 344c6681..00000000 --- a/plugins/resetter/rpc.go +++ /dev/null @@ -1,30 +0,0 @@ -package resetter - -import "github.com/spiral/roadrunner/v2/interfaces/log" - -type rpc struct { - srv *Plugin - log log.Logger -} - -// List all resettable plugins. -func (rpc *rpc) List(_ bool, list *[]string) error { - rpc.log.Debug("started List method") - *list = make([]string, 0) - - for name := range rpc.srv.registry { - *list = append(*list, name) - } - rpc.log.Debug("services list", "services", *list) - - rpc.log.Debug("finished List method") - return nil -} - -// Reset named plugin. -func (rpc *rpc) Reset(service string, done *bool) error { - rpc.log.Debug("started Reset method for the service", "service", service) - defer rpc.log.Debug("finished Reset method for the service", "service", service) - *done = true - return rpc.srv.Reset(service) -} diff --git a/plugins/resetter/tests/.rr-resetter.yaml b/plugins/resetter/tests/.rr-resetter.yaml deleted file mode 100644 index 266933fd..00000000 --- a/plugins/resetter/tests/.rr-resetter.yaml +++ /dev/null @@ -1,16 +0,0 @@ -server: - command: "php ../../../tests/client.php echo pipes" - user: "" - group: "" - env: - "RR_CONFIG": "/some/place/on/the/C134" - "RR_CONFIG2": "C138" - relay: "pipes" - relayTimeout: "20s" - -rpc: - listen: tcp://127.0.0.1:6001 - disabled: false -logs: - mode: development - level: error
\ No newline at end of file diff --git a/plugins/resetter/tests/resetter_test.go b/plugins/resetter/tests/resetter_test.go deleted file mode 100644 index 95c3a6b4..00000000 --- a/plugins/resetter/tests/resetter_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package tests - -import ( - "net" - "net/rpc" - "os" - "os/signal" - "syscall" - "testing" - "time" - - "github.com/spiral/endure" - goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc" - "github.com/spiral/roadrunner/v2/plugins/config" - "github.com/spiral/roadrunner/v2/plugins/logger" - "github.com/spiral/roadrunner/v2/plugins/resetter" - rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc" - "github.com/spiral/roadrunner/v2/plugins/server" - "github.com/stretchr/testify/assert" -) - -func TestResetterInit(t *testing.T) { - cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) - if err != nil { - t.Fatal(err) - } - - cfg := &config.Viper{ - Path: ".rr-resetter.yaml", - Prefix: "rr", - } - - err = cont.RegisterAll( - cfg, - &server.Plugin{}, - &logger.ZapLogger{}, - &resetter.Plugin{}, - &rpcPlugin.Plugin{}, - &Plugin1{}, - ) - assert.NoError(t, err) - - err = cont.Init() - if err != nil { - t.Fatal(err) - } - - ch, err := cont.Serve() - assert.NoError(t, err) - - sig := make(chan os.Signal, 1) - signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - - tt := time.NewTimer(time.Second * 15) - - t.Run("ResetterRpcTest", resetterRPCTest) - - for { - select { - case e := <-ch: - assert.Fail(t, "error", e.Error.Error()) - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - case <-sig: - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return - case <-tt.C: - // timeout - err = cont.Stop() - if err != nil { - assert.FailNow(t, "error", err.Error()) - } - return - } - } -} - -func resetterRPCTest(t *testing.T) { - conn, err := net.Dial("tcp", "127.0.0.1:6001") - assert.NoError(t, err) - client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn)) - // WorkerList contains list of workers. - - var ret bool - err = client.Call("resetter.Reset", "resetter.plugin1", &ret) - assert.NoError(t, err) - assert.True(t, ret) - ret = false - - var services []string - err = client.Call("resetter.List", nil, &services) - assert.NotNil(t, services) - assert.NoError(t, err) - if services[0] != "resetter.plugin1" { - t.Fatal("no enough services") - } -} diff --git a/plugins/resetter/tests/test_plugin.go b/plugins/resetter/tests/test_plugin.go deleted file mode 100644 index af96508a..00000000 --- a/plugins/resetter/tests/test_plugin.go +++ /dev/null @@ -1,66 +0,0 @@ -package tests - -import ( - "context" - "time" - - "github.com/spiral/roadrunner/v2/interfaces/config" - "github.com/spiral/roadrunner/v2/interfaces/server" - poolImpl "github.com/spiral/roadrunner/v2/pkg/pool" -) - -var testPoolConfig = poolImpl.Config{ - NumWorkers: 10, - MaxJobs: 100, - AllocateTimeout: time.Second * 10, - DestroyTimeout: time.Second * 10, - Supervisor: &poolImpl.SupervisorConfig{ - WatchTick: 60, - TTL: 1000, - IdleTTL: 10, - ExecTTL: 10, - MaxWorkerMemory: 1000, - }, -} - -// Gauge ////////////// -type Plugin1 struct { - config config.Configurer - server server.Server -} - -func (p1 *Plugin1) Init(cfg config.Configurer, server server.Server) error { - p1.config = cfg - p1.server = server - return nil -} - -func (p1 *Plugin1) Serve() chan error { - errCh := make(chan error, 1) - return errCh -} - -func (p1 *Plugin1) Stop() error { - return nil -} - -func (p1 *Plugin1) Name() string { - return "resetter.plugin1" -} - -func (p1 *Plugin1) Reset() error { - pool, err := p1.server.NewWorkerPool(context.Background(), testPoolConfig, nil) - if err != nil { - panic(err) - } - pool.Destroy(context.Background()) - - pool, err = p1.server.NewWorkerPool(context.Background(), testPoolConfig, nil) - if err != nil { - panic(err) - } - - _ = pool - - return nil -} |