@@ -11,29 +11,25 @@ import (
11
11
12
12
var errNoConfig = errors .New ("no-config" )
13
13
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
21
16
22
17
// Rule provides the instructions on starting the plugin
23
18
type Rule struct {
24
19
25
20
// Plugin is the name of the plugin
26
21
Plugin plugin.Name
27
22
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
30
26
}
31
27
32
28
// Monitor runs continuously receiving requests to start a plugin.
33
29
// Monitor uses a launcher to actually start the process of the plugin.
34
30
type Monitor struct {
35
31
exec Exec
36
- rules map [plugin.Name ]Rule
32
+ rules map [plugin.Name ]* types. Any
37
33
startChan <- chan StartPlugin
38
34
inputChan chan <- StartPlugin
39
35
stop chan interface {}
@@ -42,12 +38,13 @@ type Monitor struct {
42
38
43
39
// NewMonitor returns a monitor that continuously watches for input
44
40
// 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).
45
42
func NewMonitor (l Exec , rules []Rule ) * Monitor {
46
- m := map [plugin.Name ]Rule {}
43
+ m := map [plugin.Name ]* types. Any {}
47
44
// index by name of plugin
48
45
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
51
48
}
52
49
}
53
50
return & Monitor {
@@ -100,30 +97,30 @@ func (m *Monitor) Start() (chan<- StartPlugin, error) {
100
97
}
101
98
102
99
// 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 ]
104
101
if ! has {
105
102
// match now by lookup only -- 'base class'
106
103
alternate , _ := req .Plugin .GetLookupAndType ()
107
- r , has = m .rules [plugin .Name (alternate )]
104
+ properties , has = m .rules [plugin .Name (alternate )]
108
105
}
109
106
if ! has {
110
107
log .Warningln ("no plugin:" , req )
111
- req .reportError (r . Launch . Properties , errNoConfig )
108
+ req .reportError (nil , errNoConfig )
112
109
continue loop
113
110
}
114
111
115
112
configCopy := types .AnyBytes (nil )
116
- if r . Launch . Properties != nil {
117
- * configCopy = * r . Launch . Properties
113
+ if properties != nil {
114
+ * configCopy = * properties
118
115
}
119
116
120
- block , err := m .exec .Exec (r .Plugin .String (), configCopy )
117
+ block , err := m .exec .Exec (req .Plugin .String (), configCopy )
121
118
if err != nil {
122
119
req .reportError (configCopy , err )
123
120
continue loop
124
121
}
125
122
126
- log .Infoln ("Waiting for" , r .Plugin , "to start:" , configCopy .String ())
123
+ log .Infoln ("Waiting for" , req .Plugin , "to start:" , configCopy .String ())
127
124
err = <- block
128
125
if err != nil {
129
126
req .reportError (configCopy , err )
0 commit comments