Class: LogStash::Inputs::Jdbc
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Jdbc
- Includes:
- PluginMixins::Jdbc::Jdbc
- Defined in:
- lib/logstash/inputs/jdbc.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
for test mocking/stubbing.
Instance Method Summary collapse
- #register ⇒ Object
- #run(queue) ⇒ Object
-
#set_statement_logger(instance) ⇒ Object
test injection points.
- #set_value_tracker(instance) ⇒ Object
-
#stop ⇒ Object
def run.
Methods included from PluginMixins::Jdbc::Jdbc
#close_jdbc_connection, #execute_statement, #get_column_value, included, #prepare_jdbc_connection, #setup_jdbc_config
Instance Attribute Details
#database ⇒ Object (readonly)
for test mocking/stubbing
204 205 206 |
# File 'lib/logstash/inputs/jdbc.rb', line 204 def database @database end |
Instance Method Details
#register ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/logstash/inputs/jdbc.rb', line 208 def register @logger = self.logger require "rufus/scheduler" prepare_jdbc_connection if @use_column_value # Raise an error if @use_column_value is true, but no @tracking_column is set if @tracking_column.nil? raise(LogStash::ConfigurationError, "Must set :tracking_column if :use_column_value is true.") end end set_value_tracker(LogStash::PluginMixins::Jdbc::ValueTracking.build_last_value_tracker(self)) set_statement_logger(LogStash::PluginMixins::Jdbc::CheckedCountLogger.new(@logger)) @enable_encoding = !@charset.nil? || !@columns_charset.empty? unless @statement.nil? ^ @statement_filepath.nil? raise(LogStash::ConfigurationError, "Must set either :statement or :statement_filepath. Only one may be set at a time.") end @statement = ::File.read(@statement_filepath) if @statement_filepath if (@jdbc_password_filepath and @jdbc_password) raise(LogStash::ConfigurationError, "Only one of :jdbc_password, :jdbc_password_filepath may be set at a time.") end @jdbc_password = LogStash::Util::Password.new(::File.read(@jdbc_password_filepath).strip) if @jdbc_password_filepath if enable_encoding? encodings = @columns_charset.values encodings << @charset if @charset @converters = encodings.each_with_object({}) do |encoding, converters| converter = LogStash::Util::Charset.new(encoding) converter.logger = self.logger converters[encoding] = converter end end end |
#run(queue) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/logstash/inputs/jdbc.rb', line 258 def run(queue) if @schedule @scheduler = Rufus::Scheduler.new(:max_work_threads => 1) @scheduler.cron @schedule do execute_query(queue) end @scheduler.join else execute_query(queue) end end |
#set_statement_logger(instance) ⇒ Object
test injection points
250 251 252 |
# File 'lib/logstash/inputs/jdbc.rb', line 250 def set_statement_logger(instance) @statement_logger = instance end |
#set_value_tracker(instance) ⇒ Object
254 255 256 |
# File 'lib/logstash/inputs/jdbc.rb', line 254 def set_value_tracker(instance) @value_tracker = instance end |
#stop ⇒ Object
def run
271 272 273 274 |
# File 'lib/logstash/inputs/jdbc.rb', line 271 def stop close_jdbc_connection @scheduler.shutdown(:wait) if @scheduler end |