logstash-integration-jdbc 5.0.1 → 5.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a71840d1b072e13fc4ddcc96cee6a6f68e8c12608167a138858c147c11795509
4
- data.tar.gz: e782665b9e41de726ccf59e6110d7f2f77fc49127ce4bfe6c5bf16683ab2ffb2
3
+ metadata.gz: fd1883c21c6bbe0cdfb87cf641cc106d59cb5e4b43b9a7c7de547d9e1ff263f4
4
+ data.tar.gz: 749710ce22a5c81ce8bb3b024803a2075052cd21aff5870ade488b7ae4dddef7
5
5
  SHA512:
6
- metadata.gz: 9166b1b3b4e0d461da084d78e5f69ad12ea07d33d61331520bfe755f920df5c406e414f9c60d2209e2432237c6842b1a627b2a852a91cfc250fa4fee0b934f70
7
- data.tar.gz: 906d918fd928c2263ec6f1497d7995e7c0f6d9caa8044e23dcc2f8cb020c44c3c83372ed1cf808f3ee86aea33529d7b4378df778fa908ca2c5a97814e45df817
6
+ metadata.gz: 0c3b0320dc3dfab3381fb2a62642e37e99445178f8d569e3f63dc0d1c83a4f4959398e4ca87163328380d28d389388bf5741a8dcbffd0a7897c151d518871690
7
+ data.tar.gz: 77961a244d1fbfd0c9d5cf0049eb868fdd423869828733fc1a8e76cdede5f8d9bc9731ecf7668691aa0fbdbc805a5864a035cacb2c834c43a9eb6b594460f72c
@@ -1,3 +1,19 @@
1
+ ## 5.0.6
2
+ - DOC:Replaced plugin_header file with plugin_header-integration file. [#40](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/40)
3
+
4
+ ## 5.0.5
5
+ - Fixed user sequel_opts not being passed down properly [#37](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/37)
6
+ - Refactored jdbc_streaming to share driver loading, so the fixes from the jdbc plugin also effect jdbc_streaming
7
+
8
+ ## 5.0.4
9
+ - Fixed issue where JDBC Drivers that don't correctly register with Java's DriverManager fail to load (such as Sybase) [#34](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/34)
10
+
11
+ ## 5.0.3
12
+ - Fixed issue where a lost connection to the database can cause errors when using prepared statements with the scheduler [#25](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/25)
13
+
14
+ ## 5.0.2
15
+ - Fixed potential resource leak by ensuring scheduler is shutdown when a pipeline encounter an error during the running [#28](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/28)
16
+
1
17
  ## 5.0.1
2
18
  - Fixed tracking_column regression with Postgresql Numeric types [#17](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/17)
3
19
  - Fixed driver loading when file not accessible [#15](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/15)
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,3 +1,4 @@
1
+ :integration: jdbc
1
2
  :plugin: jdbc_static
2
3
  :type: filter
3
4
 
@@ -16,7 +17,7 @@ END - GENERATED VARIABLES, DO NOT EDIT!
16
17
 
17
18
  === Jdbc_static filter plugin
18
19
 
19
- include::{include_path}/plugin_header.asciidoc[]
20
+ include::{include_path}/plugin_header-integration.asciidoc[]
20
21
 
21
22
  ==== Description
22
23
 
@@ -1,3 +1,4 @@
1
+ :integration: jdbc
1
2
  :plugin: jdbc_streaming
2
3
  :type: filter
3
4
 
@@ -16,7 +17,7 @@ END - GENERATED VARIABLES, DO NOT EDIT!
16
17
 
17
18
  === Jdbc_streaming filter plugin
18
19
 
19
- include::{include_path}/plugin_header.asciidoc[]
20
+ include::{include_path}/plugin_header-integration.asciidoc[]
20
21
 
21
22
  ==== Description
22
23
 
@@ -1,3 +1,4 @@
1
+ :integration: jdbc
1
2
  :plugin: jdbc
2
3
  :type: input
3
4
  :default_codec: plain
@@ -17,7 +18,7 @@ END - GENERATED VARIABLES, DO NOT EDIT!
17
18
 
18
19
  === Jdbc input plugin
19
20
 
20
- include::{include_path}/plugin_header.asciidoc[]
21
+ include::{include_path}/plugin_header-integration.asciidoc[]
21
22
 
22
23
  ==== Description
23
24
 
@@ -95,7 +95,7 @@ module LogStash module Filters module Jdbc
95
95
  end
96
96
  begin
97
97
  db = nil
98
- ::Sequel::JDBC.load_driver(driver_class)
98
+ @options_hash[:driver] = ::Sequel::JDBC.load_driver(driver_class)
99
99
  @connection_string = connection_string
100
100
  if user
101
101
  @options_hash[:user] = user
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/filters/base"
3
3
  require "logstash/namespace"
4
+ require "logstash/plugin_mixins/jdbc/common"
4
5
  require "logstash/plugin_mixins/jdbc_streaming"
5
6
  require "logstash/plugin_mixins/jdbc_streaming/cache_payload"
6
7
  require "logstash/plugin_mixins/jdbc_streaming/statement_handler"
@@ -46,6 +47,7 @@ require "lru_redux"
46
47
  # }
47
48
  #
48
49
  module LogStash module Filters class JdbcStreaming < LogStash::Filters::Base
50
+ include LogStash::PluginMixins::Jdbc::Common
49
51
  include LogStash::PluginMixins::JdbcStreaming
50
52
 
51
53
  config_name "jdbc_streaming"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/inputs/base"
3
3
  require "logstash/namespace"
4
+ require "logstash/plugin_mixins/jdbc/common"
4
5
  require "logstash/plugin_mixins/jdbc/jdbc"
5
6
 
6
7
  # this require_relative returns early unless the JRuby version is between 9.2.0.0 and 9.2.8.0
@@ -126,6 +127,7 @@ require_relative "tzinfo_jruby_patch"
126
127
  # ---------------------------------------------------------------------------------------------------
127
128
  #
128
129
  module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
130
+ include LogStash::PluginMixins::Jdbc::Common
129
131
  include LogStash::PluginMixins::Jdbc::Jdbc
130
132
  config_name "jdbc"
131
133
 
@@ -283,6 +285,10 @@ module LogStash module Inputs class Jdbc < LogStash::Inputs::Base
283
285
  end
284
286
  end # def run
285
287
 
288
+ def close
289
+ @scheduler.shutdown if @scheduler
290
+ end
291
+
286
292
  def stop
287
293
  close_jdbc_connection
288
294
  @scheduler.shutdown(:wait) if @scheduler
@@ -0,0 +1,66 @@
1
+
2
+ module LogStash module PluginMixins module Jdbc
3
+ module Common
4
+
5
+ private
6
+
7
+ def complete_sequel_opts(defaults = {})
8
+ sequel_opts = @sequel_opts.
9
+ map { |key,val| [key.is_a?(String) ? key.to_sym : key, val] }.
10
+ map { |key,val| [key, val.eql?('true') ? true : (val.eql?('false') ? false : val)] }
11
+ sequel_opts = defaults.merge Hash[sequel_opts]
12
+ sequel_opts[:user] = @jdbc_user unless @jdbc_user.nil? || @jdbc_user.empty?
13
+ sequel_opts[:password] = @jdbc_password.value unless @jdbc_password.nil?
14
+ sequel_opts[:driver] = @driver_impl # Sequel uses this as a fallback, if given URI doesn't auto-load the driver correctly
15
+ sequel_opts
16
+ end
17
+
18
+ def load_driver
19
+ return @driver_impl if @driver_impl ||= nil
20
+
21
+ require "java"
22
+ require "sequel"
23
+ require "sequel/adapters/jdbc"
24
+
25
+ load_driver_jars
26
+ begin
27
+ @driver_impl = Sequel::JDBC.load_driver(@jdbc_driver_class)
28
+ rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
29
+ # fix this !!!
30
+ message = if jdbc_driver_library_set?
31
+ "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
32
+ else
33
+ ":jdbc_driver_library is not set, are you sure you included " +
34
+ "the proper driver client libraries in your classpath?"
35
+ end
36
+ raise LogStash::PluginLoadingError, "#{e}. #{message}"
37
+ end
38
+ end
39
+
40
+ def load_driver_jars
41
+ if jdbc_driver_library_set?
42
+ @jdbc_driver_library.split(",").each do |driver_jar|
43
+ @logger.debug("loading #{driver_jar}")
44
+ # load 'driver.jar' is different than load 'some.rb' as it only causes the file to be added to
45
+ # JRuby's class-loader lookup (class) path - won't raise a LoadError when file is not readable
46
+ unless FileTest.readable?(driver_jar)
47
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, " +
48
+ "file not readable (please check user and group permissions for the path)"
49
+ end
50
+ begin
51
+ require driver_jar
52
+ rescue LoadError => e
53
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
54
+ rescue StandardError => e
55
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def jdbc_driver_library_set?
62
+ !@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
63
+ end
64
+
65
+ end
66
+ end end end
@@ -106,17 +106,12 @@ module LogStash module PluginMixins module Jdbc
106
106
 
107
107
  private
108
108
  def jdbc_connect
109
- opts = {
110
- :user => @jdbc_user,
111
- :password => @jdbc_password.nil? ? nil : @jdbc_password.value,
112
- :pool_timeout => @jdbc_pool_timeout,
113
- :keep_reference => false
114
- }.merge(@sequel_opts)
109
+ sequel_opts = complete_sequel_opts(:pool_timeout => @jdbc_pool_timeout, :keep_reference => false)
115
110
  retry_attempts = @connection_retry_attempts
116
111
  loop do
117
112
  retry_attempts -= 1
118
113
  begin
119
- return Sequel.connect(@jdbc_connection_string, opts=opts)
114
+ return Sequel.connect(@jdbc_connection_string, sequel_opts)
120
115
  rescue Sequel::PoolTimeout => e
121
116
  if retry_attempts <= 0
122
117
  @logger.error("Failed to connect to database. #{@jdbc_pool_timeout} second timeout exceeded. Tried #{@connection_retry_attempts} times.")
@@ -127,7 +122,7 @@ module LogStash module PluginMixins module Jdbc
127
122
  # rescue Java::JavaSql::SQLException, ::Sequel::Error => e
128
123
  rescue ::Sequel::Error => e
129
124
  if retry_attempts <= 0
130
- @logger.error("Unable to connect to database. Tried #{@connection_retry_attempts} times", :error_message => e.message, )
125
+ @logger.error("Unable to connect to database. Tried #{@connection_retry_attempts} times", :error_message => e.message)
131
126
  raise e
132
127
  else
133
128
  @logger.error("Unable to connect to database. Trying again", :error_message => e.message)
@@ -137,56 +132,6 @@ module LogStash module PluginMixins module Jdbc
137
132
  end
138
133
  end
139
134
 
140
- private
141
-
142
- def load_driver
143
- if @drivers_loaded.false?
144
- require "java"
145
- require "sequel"
146
- require "sequel/adapters/jdbc"
147
-
148
- load_driver_jars
149
- begin
150
- Sequel::JDBC.load_driver(@jdbc_driver_class)
151
- rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
152
- # fix this !!!
153
- message = if jdbc_driver_library_set?
154
- "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
155
- else
156
- ":jdbc_driver_library is not set, are you sure you included " +
157
- "the proper driver client libraries in your classpath?"
158
- end
159
- raise LogStash::PluginLoadingError, "#{e}. #{message}"
160
- end
161
- @drivers_loaded.make_true
162
- end
163
- end
164
-
165
- def load_driver_jars
166
- if jdbc_driver_library_set?
167
- @jdbc_driver_library.split(",").each do |driver_jar|
168
- @logger.debug("loading #{driver_jar}")
169
- # load 'driver.jar' is different than load 'some.rb' as it only causes the file to be added to
170
- # JRuby's class-loader lookup (class) path - won't raise a LoadError when file is not readable
171
- unless FileTest.readable?(driver_jar)
172
- raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, " +
173
- "file not readable (please check user and group permissions for the path)"
174
- end
175
- begin
176
- require driver_jar
177
- rescue LoadError => e
178
- raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
179
- rescue StandardError => e
180
- raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e}"
181
- end
182
- end
183
- end
184
- end
185
-
186
- def jdbc_driver_library_set?
187
- !@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
188
- end
189
-
190
135
  def open_jdbc_connection
191
136
  # at this point driver is already loaded
192
137
  Sequel.application_timezone = @plugin_timezone.to_sym
@@ -229,7 +174,6 @@ module LogStash module PluginMixins module Jdbc
229
174
  public
230
175
  def prepare_jdbc_connection
231
176
  @connection_lock = ReentrantLock.new
232
- @drivers_loaded = Concurrent::AtomicBoolean.new
233
177
  end
234
178
 
235
179
  public
@@ -260,7 +204,9 @@ module LogStash module PluginMixins module Jdbc
260
204
  end
261
205
  success = true
262
206
  rescue Sequel::DatabaseConnectionError, Sequel::DatabaseError, Java::JavaSql::SQLException => e
263
- @logger.warn("Exception when executing JDBC query", :exception => e)
207
+ details = { :exception => e.message }
208
+ details[:backtrace] = e.backtrace if @logger.debug?
209
+ @logger.warn("Exception when executing JDBC query", details)
264
210
  else
265
211
  @value_tracker.set_value(sql_last_value)
266
212
  ensure
@@ -97,7 +97,14 @@ module LogStash module PluginMixins module Jdbc
97
97
  end
98
98
  bind_value_sql_last_value(sql_last_value)
99
99
  statement_logger.log_statement_parameters(statement, parameters, nil)
100
- db.call(name, parameters)
100
+ begin
101
+ db.call(name, parameters)
102
+ rescue => e
103
+ # clear the statement prepared flag - the statement may be closed by this
104
+ # time.
105
+ statement_prepared.make_false
106
+ raise e
107
+ end
101
108
  end
102
109
 
103
110
  def post_init(plugin)
@@ -55,37 +55,11 @@ module LogStash module PluginMixins module JdbcStreaming
55
55
  config :jdbc_validation_timeout, :validate => :number, :default => 3600
56
56
  end
57
57
 
58
- private
59
-
60
- def load_driver_jars
61
- unless @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
62
- @jdbc_driver_library.split(",").each do |driver_jar|
63
- begin
64
- @logger.debug("loading #{driver_jar}")
65
- # Use https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files to make classes from jar
66
- # available
67
- require driver_jar
68
- rescue LoadError => e
69
- raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
70
- end
71
- end
72
- end
73
- end
74
-
75
58
  public
76
59
  def prepare_jdbc_connection
77
- require "sequel"
78
- require "sequel/adapters/jdbc"
79
- require "java"
80
-
81
- load_driver_jars
82
-
83
- @sequel_opts_symbols = @sequel_opts.inject({}) {|hash, (k,v)| hash[k.to_sym] = v; hash}
84
- @sequel_opts_symbols[:user] = @jdbc_user unless @jdbc_user.nil? || @jdbc_user.empty?
85
- @sequel_opts_symbols[:password] = @jdbc_password.value unless @jdbc_password.nil?
60
+ load_driver
86
61
 
87
- Sequel::JDBC.load_driver(@jdbc_driver_class)
88
- @database = Sequel.connect(@jdbc_connection_string, @sequel_opts_symbols)
62
+ @database = Sequel.connect(@jdbc_connection_string, complete_sequel_opts)
89
63
  if @jdbc_validate_connection
90
64
  @database.extension(:connection_validator)
91
65
  @database.pool.connection_validation_timeout = @jdbc_validation_timeout
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.0.1'
3
+ s.version = '5.0.6'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Integration with JDBC - input and filter plugins"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -4,7 +4,6 @@ require "logstash/filters/jdbc_static"
4
4
  require "sequel"
5
5
  require "sequel/adapters/jdbc"
6
6
  require "stud/temporary"
7
- require "timecop"
8
7
 
9
8
  module LogStash module Filters
10
9
  describe JdbcStatic, :integration => true do
@@ -35,6 +34,7 @@ module LogStash module Filters
35
34
  let(:settings) do
36
35
  {
37
36
  "jdbc_user" => ENV['USER'],
37
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
38
38
  "jdbc_driver_class" => "org.postgresql.Driver",
39
39
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
40
40
  "staging_directory" => temp_import_path_plugin,
@@ -88,6 +88,7 @@ module LogStash module Filters
88
88
  let(:settings) do
89
89
  {
90
90
  "jdbc_user" => ENV['USER'],
91
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
91
92
  "jdbc_driver_class" => "org.postgresql.Driver",
92
93
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
93
94
  "staging_directory" => temp_import_path_plugin,
@@ -134,18 +135,16 @@ module LogStash module Filters
134
135
  describe "scheduled operation" do
135
136
  context "given a loader_schedule" do
136
137
  it "should properly schedule" do
137
- settings["loader_schedule"] = "*/10 * * * * * UTC"
138
- Timecop.travel(Time.now.utc - 3600)
139
- Timecop.scale(60)
138
+ settings["loader_schedule"] = "*/3 * * * * * UTC"
140
139
  static_filter = JdbcStatic.new(settings)
141
140
  runner = Thread.new(static_filter) do |filter|
142
141
  filter.register
143
142
  end
144
- sleep 3
143
+ runner.join(4)
144
+ sleep 4
145
145
  static_filter.filter(event)
146
146
  expect(static_filter.loader_runner.reload_count).to be > 1
147
147
  static_filter.close
148
- Timecop.return
149
148
  expect(event.get("server")).to eq([{"ip"=>"10.3.1.1", "name"=>"mv-server-1", "location"=>"MV-9-6-4"}])
150
149
  end
151
150
  end
@@ -16,7 +16,10 @@ module LogStash module Filters
16
16
  "jdbc:postgresql://postgresql:5432") + "/jdbc_streaming_db?user=postgres"
17
17
 
18
18
  let(:mixin_settings) do
19
- { "jdbc_driver_class" => "org.postgresql.Driver",
19
+ {
20
+ "jdbc_user" => ENV['USER'],
21
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
22
+ "jdbc_driver_class" => "org.postgresql.Driver",
20
23
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
21
24
  "jdbc_connection_string" => jdbc_connection_string
22
25
  }
@@ -10,28 +10,37 @@ module LogStash module Filters module Jdbc
10
10
  let(:driver_class) { "org.apache.derby.jdbc.EmbeddedDriver" }
11
11
  let(:driver_library) { nil }
12
12
  subject(:read_only_db) { described_class.create(connection_string, driver_class, driver_library) }
13
+ let(:stub_driver_class) { double(driver_class).as_null_object }
13
14
 
14
15
  describe "basic operations" do
15
16
  describe "initializing" do
17
+ before(:each) do
18
+ allow(Sequel::JDBC).to receive(:load_driver).and_return(stub_driver_class)
19
+ end
20
+
16
21
  it "tests the connection with defaults" do
17
22
  expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
18
- expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true})
23
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true, :driver => stub_driver_class})
19
24
  expect(read_only_db.empty_record_set).to eq([])
20
25
  end
21
26
 
22
- it "tests the connection with fully specified arguments" do
23
- connection_str = "a connection string"
24
- user = "a user"
25
- password = Util::Password.new("secret")
26
- expect(Sequel::JDBC).to receive(:load_driver).once.with("a driver class")
27
- expect(Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value, :test => true}).and_return(db)
28
- described_class.create(connection_str, "a driver class", nil, user, password)
27
+ context 'with fully-specified arguments' do
28
+ let(:connection_string) { "a connection string" }
29
+ let(:user) { "a user" }
30
+ let(:password) { Util::Password.new("secret") }
31
+ let(:driver_class) { "a driver class" }
32
+
33
+ it "tests the connection" do
34
+ expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
35
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:user => user, :password => password.value, :test => true, :driver => stub_driver_class}).and_return(db)
36
+ described_class.create(connection_string, driver_class, nil, user, password)
37
+ end
29
38
  end
30
39
 
31
40
  it "connects with defaults" do
32
41
  expect(Sequel::JDBC).to receive(:load_driver).once.with(driver_class)
33
- expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true}).and_return(db)
34
- expect(Sequel).to receive(:connect).once.with(connection_string, {}).and_return(db)
42
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:test => true, :driver => stub_driver_class}).and_return(db)
43
+ expect(Sequel).to receive(:connect).once.with(connection_string, {:driver => stub_driver_class}).and_return(db)
35
44
  expect(read_only_db.connected?).to be_falsey
36
45
  read_only_db.connect("a caller specific error message")
37
46
  expect(read_only_db.connected?).to be_truthy
@@ -16,10 +16,11 @@ module LogStash module Filters module Jdbc
16
16
  describe "basic operations" do
17
17
  context "connecting to a db" do
18
18
  it "connects with defaults" do
19
- expect(::Sequel::JDBC).to receive(:load_driver).once.with("org.apache.derby.jdbc.EmbeddedDriver")
19
+ stub_driver_class = double('org.apache.derby.jdbc.EmbeddedDriver').as_null_object
20
+ expect(::Sequel::JDBC).to receive(:load_driver).once.with("org.apache.derby.jdbc.EmbeddedDriver").and_return(stub_driver_class)
20
21
  # two calls to connect because ReadWriteDatabase does verify_connection and connect
21
- expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:test => true}).and_return(db)
22
- expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {}).and_return(db)
22
+ expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:driver => stub_driver_class, :test => true}).and_return(db)
23
+ expect(::Sequel).to receive(:connect).once.with(connection_string_regex, {:driver => stub_driver_class}).and_return(db)
23
24
  expect(read_write_db.empty_record_set).to eq([])
24
25
  end
25
26
 
@@ -27,9 +28,10 @@ module LogStash module Filters module Jdbc
27
28
  connection_str = "a connection string"
28
29
  user = "a user"
29
30
  password = Util::Password.new("secret")
30
- expect(::Sequel::JDBC).to receive(:load_driver).once.with("a driver class")
31
- expect(::Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value, :test => true}).and_return(db)
32
- expect(::Sequel).to receive(:connect).once.with(connection_str, {:user => user, :password => password.value}).and_return(db)
31
+ stub_driver_class = double('com.example.Driver')
32
+ expect(::Sequel::JDBC).to receive(:load_driver).once.with("a driver class").and_return(stub_driver_class)
33
+ expect(::Sequel).to receive(:connect).once.with(connection_str, {:driver => stub_driver_class, :user => user, :password => password.value, :test => true}).and_return(db)
34
+ expect(::Sequel).to receive(:connect).once.with(connection_str, {:driver => stub_driver_class, :user => user, :password => password.value}).and_return(db)
33
35
  described_class.create(connection_str, "a driver class", nil, user, password)
34
36
  end
35
37
  end
@@ -1,4 +1,5 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/devutils/rspec/shared_examples"
2
3
  require "logstash/filters/jdbc_streaming"
3
4
  require 'jdbc/derby'
4
5
  require "sequel"
@@ -3,7 +3,6 @@ require "logstash/inputs/jdbc"
3
3
  require "sequel"
4
4
  require "sequel/adapters/jdbc"
5
5
 
6
- # This test requires: Firebird installed to Mac OSX, it uses the built-in example database `employee`
7
6
 
8
7
  describe LogStash::Inputs::Jdbc, :integration => true do
9
8
  # This is a necessary change test-wide to guarantee that no local timezone
@@ -19,6 +18,7 @@ describe LogStash::Inputs::Jdbc, :integration => true do
19
18
  "jdbc_connection_string" => jdbc_connection_string,
20
19
  "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
21
20
  "jdbc_user" => "postgres",
21
+ "jdbc_password" => ENV["POSTGRES_PASSWORD"],
22
22
  "statement" => 'SELECT FIRST_NAME, LAST_NAME FROM "employee" WHERE EMP_NO = 2'
23
23
  }
24
24
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/devutils/rspec/shared_examples"
3
4
  require "logstash/inputs/jdbc"
4
5
  require "jdbc/derby"
5
6
  require "sequel"
@@ -12,9 +13,13 @@ require "date"
12
13
  # We do not need to set TZ env var anymore because we can have 'Sequel.application_timezone' set to utc by default now.
13
14
 
14
15
  describe LogStash::Inputs::Jdbc do
16
+ let(:connection_string) { "jdbc:derby:memory:testdb;create=true" }
15
17
  let(:mixin_settings) do
16
- { "jdbc_user" => ENV['USER'], "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
17
- "jdbc_connection_string" => "jdbc:derby:memory:testdb;create=true"}
18
+ {
19
+ "jdbc_user" => ENV['USER'],
20
+ "jdbc_driver_class" => "org.apache.derby.jdbc.EmbeddedDriver",
21
+ "jdbc_connection_string" => connection_string
22
+ }
18
23
  end
19
24
  let(:settings) { {} }
20
25
  let(:plugin) { LogStash::Inputs::Jdbc.new(mixin_settings.merge(settings)) }
@@ -111,6 +116,57 @@ describe LogStash::Inputs::Jdbc do
111
116
  end
112
117
  end
113
118
 
119
+ context "when sequel opts has user option" do
120
+ let(:settings) do
121
+ {
122
+ "jdbc_user" => 'system',
123
+ "statement" => "SELECT * from test_table",
124
+ "sequel_opts" => { "user" => 'from-opts' }
125
+ }
126
+ end
127
+
128
+ before do
129
+ plugin.register
130
+ end
131
+
132
+ after do
133
+ plugin.stop
134
+ end
135
+
136
+ it "should honor set jdbc-user when connecting" do
137
+ expect( Sequel ).to receive(:connect).with connection_string, hash_including(:user=>"system")
138
+ plugin.send(:jdbc_connect)
139
+ end
140
+ end
141
+
142
+ context "with sequel opts" do
143
+ let(:settings) do
144
+ {
145
+ "jdbc_user" => 'system',
146
+ "statement" => "SELECT * from test_table",
147
+ "sequel_opts" => {
148
+ "truthy" => 'true',
149
+ "falsey" => 'false',
150
+ "foo" => 'bar',
151
+ "jdbc_properties" => { "some" => 'true' }
152
+ }
153
+ }
154
+ end
155
+
156
+ before do
157
+ plugin.register
158
+ end
159
+
160
+ after do
161
+ plugin.stop
162
+ end
163
+
164
+ it "should symbolize keys" do
165
+ expect( Sequel ).to receive(:connect).with connection_string,
166
+ hash_including(:truthy => true, :falsey => false, :foo => 'bar', :jdbc_properties => { 'some' => 'true' })
167
+ plugin.send(:jdbc_connect)
168
+ end
169
+ end
114
170
 
115
171
  context "when neither statement and statement_filepath arguments are passed" do
116
172
  it "should fail to register" do
@@ -190,6 +246,18 @@ describe LogStash::Inputs::Jdbc do
190
246
  Timecop.return
191
247
  end
192
248
 
249
+ it "cleans up scheduler resources on close" do
250
+ runner = Thread.new do
251
+ plugin.run(queue)
252
+ end
253
+ sleep 1
254
+ plugin.do_close
255
+
256
+ scheduler = plugin.instance_variable_get(:@scheduler)
257
+ expect(scheduler).to_not be_nil
258
+ expect(scheduler.down?).to be_truthy
259
+ end
260
+
193
261
  end
194
262
 
195
263
  context "when scheduling and previous runs are to be preserved" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-integration-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +210,6 @@ files:
210
210
  - CONTRIBUTORS
211
211
  - Gemfile
212
212
  - LICENSE
213
- - NOTICE.TXT
214
213
  - README.md
215
214
  - docs/filter-jdbc_static.asciidoc
216
215
  - docs/filter-jdbc_streaming.asciidoc
@@ -235,6 +234,7 @@ files:
235
234
  - lib/logstash/inputs/jdbc.rb
236
235
  - lib/logstash/inputs/tzinfo_jruby_patch.rb
237
236
  - lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb
237
+ - lib/logstash/plugin_mixins/jdbc/common.rb
238
238
  - lib/logstash/plugin_mixins/jdbc/jdbc.rb
239
239
  - lib/logstash/plugin_mixins/jdbc/statement_handler.rb
240
240
  - lib/logstash/plugin_mixins/jdbc/value_tracking.rb
@@ -242,7 +242,6 @@ files:
242
242
  - lib/logstash/plugin_mixins/jdbc_streaming/cache_payload.rb
243
243
  - lib/logstash/plugin_mixins/jdbc_streaming/parameter_handler.rb
244
244
  - lib/logstash/plugin_mixins/jdbc_streaming/statement_handler.rb
245
- - lib/logstash/plugin_mixins/statement_handler.rb
246
245
  - logstash-integration-jdbc.gemspec
247
246
  - spec/filters/env_helper.rb
248
247
  - spec/filters/integration/jdbc_static_spec.rb
@@ -291,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
290
  version: '0'
292
291
  requirements: []
293
292
  rubyforge_project:
294
- rubygems_version: 2.7.9
293
+ rubygems_version: 2.6.13
295
294
  signing_key:
296
295
  specification_version: 4
297
296
  summary: Integration with JDBC - input and filter plugins
data/NOTICE.TXT DELETED
@@ -1,5 +0,0 @@
1
- Elasticsearch
2
- Copyright 2012-2018 Elasticsearch
3
-
4
- This product includes software developed by The Apache Software
5
- Foundation (http://www.apache.org/).