@@ -11,29 +11,25 @@ import (
1111
1212var errNoConfig = errors .New ("no-config" )
1313
14- // ExecRule encapsulates what's required to exec a plugin
15- type ExecRule struct {
16- // Exec is the name of the exec to use to start the plugin
17- Exec string
18- // Properties is the properties for the executor
19- Properties * types.Any
20- }
14+ // ExecName is the name of the executor to use (e.g. 'os', 'docker-run', etc.). It's found in the config.
15+ type ExecName string
2116
2217// Rule provides the instructions on starting the plugin
2318type Rule struct {
2419
2520 // Plugin is the name of the plugin
2621 Plugin plugin.Name
2722
28- // Launch is the rule for starting / launching the plugin.
29- Launch ExecRule
23+ // Launch is the rule for starting / launching the plugin. It's a dictionary with the key being
24+ // the name of the executor and the value being the properties used by that executor.
25+ Launch map [ExecName ]* types.Any
3026}
3127
3228// Monitor runs continuously receiving requests to start a plugin.
3329// Monitor uses a launcher to actually start the process of the plugin.
3430type Monitor struct {
3531 exec Exec
36- rules map [plugin.Name ]Rule
32+ rules map [plugin.Name ]* types. Any
3733 startChan <- chan StartPlugin
3834 inputChan chan <- StartPlugin
3935 stop chan interface {}
@@ -42,12 +38,13 @@ type Monitor struct {
4238
4339// NewMonitor returns a monitor that continuously watches for input
4440// requests and launches the process for the plugin, if not already running.
41+ // The configuration to use in the config is matched to the Name() of the executor (the field Exec).
4542func NewMonitor (l Exec , rules []Rule ) * Monitor {
46- m := map [plugin.Name ]Rule {}
43+ m := map [plugin.Name ]* types. Any {}
4744 // index by name of plugin
4845 for _ , r := range rules {
49- if r . Launch . Exec == l .Name () {
50- m [r .Plugin ] = r
46+ if cfg , has := r . Launch [ ExecName ( l .Name ())]; has {
47+ m [r .Plugin ] = cfg
5148 }
5249 }
5350 return & Monitor {
@@ -100,30 +97,30 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) {
10097 }
10198
10299 // match first by full name of the form lookup/type -- 'specialization'
103- r , has := m .rules [req .Plugin ]
100+ properties , has := m .rules [req .Plugin ]
104101 if ! has {
105102 // match now by lookup only -- 'base class'
106103 alternate , _ := req .Plugin .GetLookupAndType ()
107- r , has = m .rules [plugin .Name (alternate )]
104+ properties , has = m .rules [plugin .Name (alternate )]
108105 }
109106 if ! has {
110107 log .Warningln ("no plugin:" , req )
111- req .reportError (r . Launch . Properties , errNoConfig )
108+ req .reportError (nil , errNoConfig )
112109 continue loop
113110 }
114111
115112 configCopy := types .AnyBytes (nil )
116- if r . Launch . Properties != nil {
117- * configCopy = * r . Launch . Properties
113+ if properties != nil {
114+ * configCopy = * properties
118115 }
119116
120- block , err := m .exec .Exec (r .Plugin .String (), configCopy )
117+ block , err := m .exec .Exec (req .Plugin .String (), configCopy )
121118 if err != nil {
122119 req .reportError (configCopy , err )
123120 continue loop
124121 }
125122
126- log .Infoln ("Waiting for" , r .Plugin , "to start:" , configCopy .String ())
123+ log .Infoln ("Waiting for" , req .Plugin , "to start:" , configCopy .String ())
127124 err = <- block
128125 if err != nil {
129126 req .reportError (configCopy , err )
0 commit comments