diff options
Diffstat (limited to 'plugins/resetter')
-rw-r--r-- | plugins/resetter/plugin.go | 33 | ||||
-rw-r--r-- | plugins/resetter/rpc.go | 4 | ||||
-rw-r--r-- | plugins/resetter/tests/.rr-resetter.yaml | 5 | ||||
-rw-r--r-- | plugins/resetter/tests/resetter_test.go | 2 |
4 files changed, 37 insertions, 7 deletions
diff --git a/plugins/resetter/plugin.go b/plugins/resetter/plugin.go index 99e02aef..8dc5cc31 100644 --- a/plugins/resetter/plugin.go +++ b/plugins/resetter/plugin.go @@ -10,12 +10,39 @@ import ( const PluginName = "resetter" type Plugin struct { - registry map[string]resetter.Resetter + 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.Resetter) + p.registry = make(map[string]resetter.Resettable) p.log = log return nil } @@ -31,7 +58,7 @@ func (p *Plugin) Reset(name string) error { } // RegisterTarget resettable service. -func (p *Plugin) RegisterTarget(name endure.Named, r resetter.Resetter) error { +func (p *Plugin) RegisterTarget(name endure.Named, r resetter.Resettable) error { p.registry[name.Name()] = r return nil } diff --git a/plugins/resetter/rpc.go b/plugins/resetter/rpc.go index ecc51bb3..344c6681 100644 --- a/plugins/resetter/rpc.go +++ b/plugins/resetter/rpc.go @@ -7,7 +7,7 @@ type rpc struct { log log.Logger } -// List all resettable services. +// List all resettable plugins. func (rpc *rpc) List(_ bool, list *[]string) error { rpc.log.Debug("started List method") *list = make([]string, 0) @@ -21,7 +21,7 @@ func (rpc *rpc) List(_ bool, list *[]string) error { return nil } -// Reset named service. +// 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) diff --git a/plugins/resetter/tests/.rr-resetter.yaml b/plugins/resetter/tests/.rr-resetter.yaml index 83ecd582..266933fd 100644 --- a/plugins/resetter/tests/.rr-resetter.yaml +++ b/plugins/resetter/tests/.rr-resetter.yaml @@ -10,4 +10,7 @@ server: rpc: listen: tcp://127.0.0.1:6001 - disabled: false
\ No newline at end of file + 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 index 3bfccf47..45de67e3 100644 --- a/plugins/resetter/tests/resetter_test.go +++ b/plugins/resetter/tests/resetter_test.go @@ -20,7 +20,7 @@ import ( ) func TestResetterInit(t *testing.T) { - cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.DebugLevel)) + cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel)) if err != nil { t.Fatal(err) } |