logstash-input-jdbc 4.3.17 → 4.3.18

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: fa9af10e83d8b696b96da4524bc03bcce28f6b2286f1f18f38e674c562cb2994
4
- data.tar.gz: b824a04d01e52bd569cf34f14b2a77d8fb850bb05e3ae91f02a0823cc9e2be56
3
+ metadata.gz: 70e0a214e348c26f1431b84ae27846402335b2c4ea7494e4dc39a75020773a7b
4
+ data.tar.gz: 60fb0bdabb7f72560d5bd466a2290ad607ad6ab9d16bee81f4351868769d5748
5
5
  SHA512:
6
- metadata.gz: 23bb34de4f7c363bac00b01899bf3cf40560e80c4b2456115bc3d27682a5e89a573b274be44daf9664a9b9c9558bc33a4ea23125d505d24cf275f60a241a4e60
7
- data.tar.gz: 905bdf60952acfcae39f639b5d1183aa25359af3ffe4869a80dcacff6510301a316764d30eca8317f4face5e02d1e96ee3638040d2583defd40d7be6b3322c0d
6
+ metadata.gz: 189329d3d59485bbf3ced93560f02f56d1e760d9ce3745ec8955f5cd8ae0e6ec81dc5784c976a185d0ec0136cc0188a99693ce68b4dde6c50ba8357133f196b5
7
+ data.tar.gz: 284d2472358969d0efacb7633d1a22e2f8df48762bbc63d06f2aac6df1c98f2cbadaeb452f04433237263a79a9ec273aee591e38ff139dffd084dc4f915c596e
@@ -1,3 +1,6 @@
1
+ ## 4.3.18
2
+ - Fix issue with driver loading [#356](https://github.com/logstash-plugins/logstash-input-jdbc/pull/356)
3
+
1
4
  ## 4.3.17
2
5
  - Added documentation to provide more info about jdbc driver loading [#352](https://github.com/logstash-plugins/logstash-input-jdbc/pull/352)
3
6
 
@@ -140,28 +140,18 @@ module LogStash module PluginMixins module Jdbc
140
140
 
141
141
  private
142
142
 
143
- def load_drivers
144
- return if @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
145
-
146
- driver_jars = @jdbc_driver_library.split(",")
147
-
148
- # Needed for JDK 11 as the DriverManager has a different ClassLoader than Logstash
149
- urls = java.net.URL[driver_jars.length].new
150
-
151
- driver_jars.each_with_index do |driver, idx|
152
- urls[idx] = java.io.File.new(driver).toURI().toURL()
153
- end
154
- ucl = java.net.URLClassLoader.new_instance(urls)
155
- begin
156
- klass = java.lang.Class.forName(@jdbc_driver_class.to_java(:string), true, ucl);
157
- rescue Java::JavaLang::ClassNotFoundException => e
158
- raise LogStash::Error, "Unable to find driver class via URLClassLoader in given driver jars: #{@jdbc_driver_class}"
159
- end
160
- begin
161
- driver = klass.getConstructor().newInstance();
162
- java.sql.DriverManager.register_driver(WrappedDriver.new(driver.to_java(java.sql.Driver)).to_java(java.sql.Driver))
163
- rescue Java::JavaSql::SQLException => e
164
- raise LogStash::Error, "Unable to register driver with java.sql.DriverManager using WrappedDriver: #{@jdbc_driver_class}"
143
+ def load_driver_jars
144
+ unless @jdbc_driver_library.nil? || @jdbc_driver_library.empty?
145
+ @jdbc_driver_library.split(",").each do |driver_jar|
146
+ begin
147
+ @logger.debug("loading #{driver_jar}")
148
+ # Use https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby#from-jar-files to make classes from jar
149
+ # available
150
+ require driver_jar
151
+ rescue LoadError => e
152
+ raise LogStash::PluginLoadingError, "unable to load #{driver_jar} from :jdbc_driver_library, #{e.message}"
153
+ end
154
+ end
165
155
  end
166
156
  end
167
157
 
@@ -174,7 +164,7 @@ module LogStash module PluginMixins module Jdbc
174
164
  Sequel.application_timezone = @plugin_timezone.to_sym
175
165
  if @drivers_loaded.false?
176
166
  begin
177
- load_drivers
167
+ load_driver_jars
178
168
  Sequel::JDBC.load_driver(@jdbc_driver_class)
179
169
  rescue LogStash::Error => e
180
170
  # raised in load_drivers, e.cause should be the caught Java exceptions
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-jdbc'
3
- s.version = '4.3.17'
3
+ s.version = '4.3.18'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Creates events from JDBC data"
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"
@@ -28,5 +28,4 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency 'logstash-devutils'
29
29
  s.add_development_dependency 'timecop'
30
30
  s.add_development_dependency 'jdbc-derby'
31
- s.add_development_dependency 'jdbc-postgres'
32
31
  end
@@ -1,5 +1,7 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
2
  require "logstash/inputs/jdbc"
3
+ require "sequel"
4
+ require "sequel/adapters/jdbc"
3
5
 
4
6
  # This test requires: Firebird installed to Mac OSX, it uses the built-in example database `employee`
5
7
 
@@ -8,15 +10,23 @@ describe LogStash::Inputs::Jdbc, :integration => true do
8
10
  # is picked up. It could be arbitrarily set to any timezone, but then the test
9
11
  # would have to compensate differently. That's why UTC is chosen.
10
12
  ENV["TZ"] = "Etc/UTC"
11
- let(:mixin_settings) do
12
- { "jdbc_user" => "SYSDBA", "jdbc_driver_class" => "org.firebirdsql.jdbc.FBDriver", "jdbc_driver_library" => "/elastic/tmp/jaybird-full-3.0.4.jar",
13
- "jdbc_connection_string" => "jdbc:firebirdsql://localhost:3050//Library/Frameworks/Firebird.framework/Versions/A/Resources/examples/empbuild/employee.fdb", "jdbc_password" => "masterkey"}
13
+ # For Travis and CI based on docker, we source from ENV
14
+ jdbc_connection_string = ENV.fetch("PG_CONNECTION_STRING",
15
+ "jdbc:postgresql://postgresql:5432") + "/jdbc_input_db?user=postgres"
16
+
17
+ let(:settings) do
18
+ { "jdbc_driver_class" => "org.postgresql.Driver",
19
+ "jdbc_connection_string" => jdbc_connection_string,
20
+ "jdbc_driver_library" => "/usr/share/logstash/postgresql.jar",
21
+ "jdbc_user" => "postgres",
22
+ "statement" => 'SELECT FIRST_NAME, LAST_NAME FROM "employee" WHERE EMP_NO = 2'
23
+ }
14
24
  end
15
- let(:settings) { {"statement" => "SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEE WHERE EMP_NO > 144"} }
16
- let(:plugin) { LogStash::Inputs::Jdbc.new(mixin_settings.merge(settings)) }
25
+
26
+ let(:plugin) { LogStash::Inputs::Jdbc.new(settings) }
17
27
  let(:queue) { Queue.new }
18
28
 
19
- context "when passing no parameters" do
29
+ context "when connecting to a postgres instance" do
20
30
  before do
21
31
  plugin.register
22
32
  end
@@ -25,12 +35,44 @@ describe LogStash::Inputs::Jdbc, :integration => true do
25
35
  plugin.stop
26
36
  end
27
37
 
28
- it "should retrieve params correctly from Event" do
38
+ it "should populate the event with database entries" do
29
39
  plugin.run(queue)
30
40
  event = queue.pop
31
41
  expect(event.get('first_name')).to eq("Mark")
32
42
  expect(event.get('last_name')).to eq("Guckenheimer")
33
43
  end
34
44
  end
45
+
46
+ context "when supplying a non-existent library" do
47
+ let(:settings) do
48
+ super.merge(
49
+ "jdbc_driver_library" => "/no/path/to/postgresql.jar"
50
+ )
51
+ end
52
+
53
+ it "should not register correctly" do
54
+ plugin.register
55
+ q = Queue.new
56
+ expect do
57
+ plugin.run(q)
58
+ end.to raise_error(::LogStash::PluginLoadingError)
59
+ end
60
+ end
61
+
62
+ context "when connecting to a non-existent server" do
63
+ let(:settings) do
64
+ super.merge(
65
+ "jdbc_connection_string" => "jdbc:postgresql://localhost:65000/somedb"
66
+ )
67
+ end
68
+
69
+ it "should not register correctly" do
70
+ plugin.register
71
+ q = Queue.new
72
+ expect do
73
+ plugin.run(q)
74
+ end.to raise_error(::Sequel::DatabaseConnectionError)
75
+ end
76
+ end
35
77
  end
36
78
 
@@ -2,8 +2,6 @@
2
2
  require "logstash/devutils/rspec/spec_helper"
3
3
  require "logstash/inputs/jdbc"
4
4
  require "jdbc/derby"
5
- require 'jdbc/postgres'
6
- Jdbc::Postgres.load_driver
7
5
  require "sequel"
8
6
  require "sequel/adapters/jdbc"
9
7
  require "timecop"
@@ -78,24 +76,6 @@ describe LogStash::Inputs::Jdbc do
78
76
  end
79
77
  end
80
78
 
81
- context "when connecting to a non-existent server", :no_connection => true do
82
- let(:mixin_settings) do
83
- super.merge(
84
- "jdbc_driver_class" => "org.postgresql.Driver",
85
- "jdbc_connection_string" => "jdbc:postgresql://localhost:65000/somedb"
86
- )
87
- end
88
- let(:settings) { super.merge("statement" => "SELECT 1 as col1 FROM test_table", "jdbc_user" => "foo", "jdbc_password" => "bar") }
89
-
90
- it "should not register correctly" do
91
- plugin.register
92
- q = Queue.new
93
- expect do
94
- plugin.run(q)
95
- end.to raise_error(::Sequel::DatabaseConnectionError)
96
- end
97
- end
98
-
99
79
  context "when both jdbc_password and jdbc_password_filepath arguments are passed" do
100
80
  let(:statement) { "SELECT * from test_table" }
101
81
  let(:jdbc_password) { "secret" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-jdbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.17
4
+ version: 4.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -142,20 +142,6 @@ dependencies:
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
- - !ruby/object:Gem::Dependency
146
- requirement: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: '0'
151
- name: jdbc-postgres
152
- prerelease: false
153
- type: :development
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- version: '0'
159
145
  description: This gem is a Logstash plugin required to be installed on top of the
160
146
  Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
161
147
  gem is not a stand-alone program