@@ -15,12 +15,12 @@ class GemRegistry
15
15
LOGSTASH_METADATA_KEY = "logstash_plugin"
16
16
17
17
class << self
18
- def available_libraries
18
+ def installed_gems
19
19
::Gem ::Specification
20
20
end
21
21
22
22
def logstash_plugins
23
- available_libraries
23
+ installed_gems
24
24
. select { |spec | spec . metadata && spec . metadata [ LOGSTASH_METADATA_KEY ] }
25
25
. collect { |spec | PluginRawContext . new ( spec ) }
26
26
end
@@ -65,11 +65,7 @@ def has_hooks?
65
65
end
66
66
67
67
def execute_hooks!
68
- if has_hooks?
69
- require hooks_file
70
- else
71
- raise ArgumentError , "#execute_hooks! called but no hooks file where found for #{ name } of type #{ type } "
72
- end
68
+ require hooks_file
73
69
end
74
70
end
75
71
@@ -98,8 +94,8 @@ def register(hooks, settings)
98
94
attr_reader :hooks
99
95
100
96
def initialize
101
- @registry = { }
102
- @hooks = HooksRegistry . new
97
+ @registry = { }
98
+ @hooks = HooksRegistry . new
103
99
end
104
100
105
101
def setup!
@@ -134,38 +130,47 @@ def lookup(type, plugin_name, &block)
134
130
plugin = get ( type , plugin_name )
135
131
# Assume that we have a legacy plugin
136
132
if plugin . nil?
137
- begin
138
- path = "logstash/#{ type } s/#{ plugin_name } "
139
-
140
- begin
141
- require path
142
- rescue LoadError
143
- # Plugin might be already defined in the current scope
144
- # This scenario often happen in test when we write an adhoc class
145
- end
146
-
147
- klass = namespace_lookup ( type , plugin_name )
148
- plugin = lazy_add ( type , plugin_name , klass )
149
- rescue => e
150
- logger . warn ( "Problems loading a plugin with" ,
151
- :type => type ,
152
- :name => plugin_name ,
153
- :path => path ,
154
- :error_message => e . message ,
155
- :error_class => e . class ,
156
- :error_backtrace => e . backtrace )
157
-
158
- raise LoadError , "Problems loading the requested plugin named #{ plugin_name } of type #{ type } . Error: #{ e . class } #{ e . message } "
159
- end
133
+ plugin = legacy_lookup ( type , plugin_name )
160
134
end
161
135
162
136
if block_given? # if provided pass a block to do validation
163
- raise LoadError unless block . call ( plugin . klass , plugin_name )
137
+ raise LoadError , "Block validation fails for plugin named #{ plugin_name } of type #{ type } ," unless block . call ( plugin . klass , plugin_name )
164
138
end
165
139
166
140
return plugin . klass
167
141
end
168
142
143
+ # The legacy_lookup method uses the 1.5->5.0 file structure to find and match
144
+ # a plugin and will do a lookup on the namespace of the required class to find a matching
145
+ # plugin with the appropriate type.
146
+ def legacy_lookup ( type , plugin_name )
147
+ begin
148
+ path = "logstash/#{ type } s/#{ plugin_name } "
149
+
150
+ begin
151
+ require path
152
+ rescue LoadError
153
+ # Plugin might be already defined in the current scope
154
+ # This scenario often happen in test when we write an adhoc class
155
+ end
156
+
157
+ klass = namespace_lookup ( type , plugin_name )
158
+ plugin = lazy_add ( type , plugin_name , klass )
159
+ rescue => e
160
+ logger . error ( "Problems loading a plugin with" ,
161
+ :type => type ,
162
+ :name => plugin_name ,
163
+ :path => path ,
164
+ :error_message => e . message ,
165
+ :error_class => e . class ,
166
+ :error_backtrace => e . backtrace )
167
+
168
+ raise LoadError , "Problems loading the requested plugin named #{ plugin_name } of type #{ type } . Error: #{ e . class } #{ e . message } "
169
+ end
170
+
171
+ plugin
172
+ end
173
+
169
174
def lookup_pipeline_plugin ( type , name )
170
175
LogStash ::PluginRegistry . lookup ( type , name ) do |plugin_klass , plugin_name |
171
176
is_a_plugin? ( plugin_klass , plugin_name )
@@ -176,12 +181,12 @@ def lookup_pipeline_plugin(type, name)
176
181
end
177
182
178
183
def lazy_add ( type , name , klass )
179
- logger . error ( "On demand adding plugin to the registry" , :name => name , :type => type , :class => klass )
184
+ logger . debug ( "On demand adding plugin to the registry" , :name => name , :type => type , :class => klass )
180
185
add_plugin ( type , name , klass )
181
186
end
182
187
183
188
def add ( type , name , klass )
184
- logger . error ( "Adding plugin to the registry" , :name => name , :type => type , :class => klass )
189
+ logger . debug ( "Adding plugin to the registry" , :name => name , :type => type , :class => klass )
185
190
add_plugin ( type , name , klass )
186
191
end
187
192
@@ -230,7 +235,7 @@ def add_plugin(type, name, klass)
230
235
specification_klass = type == :universal ? UniversalPluginSpecification : PluginSpecification
231
236
@registry [ key_for ( type , name ) ] = specification_klass . new ( type , name , klass )
232
237
else
233
- logger . info ( "Ignoring, plugin already added to the registry" , :name => name , :type => type , :klass => klass )
238
+ logger . debug ( "Ignoring, plugin already added to the registry" , :name => name , :type => type , :klass => klass )
234
239
end
235
240
end
236
241
0 commit comments