logstash-integration-jdbc 5.1.8 → 5.1.10

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: 70e445fd000df9ba4c631d3574d67826aaafcb22bb2b4c00f9e30aa386415ed0
4
- data.tar.gz: 2fc2cef288fa7fa2f342db6096e79e49617c012e5ce9f5c4a5d94cc1f79b0838
3
+ metadata.gz: 9f3116d5abaa413fd73af725208c422a1cf98961ce7095c4d88fd7f14cb6c59d
4
+ data.tar.gz: 0ef2f5fd309236b8ec0e14bb38d275e26b3d2002cdb172a2d30d53682606ddec
5
5
  SHA512:
6
- metadata.gz: e9fd72a1ebd12db838330101716032fbe125a9dab866bd552e61eeca37d51222f1f22e29cb8cdcc1b27bba8d1e5b59e8ff22de6aba29587e3811543a23860e79
7
- data.tar.gz: ae0322899fdbc65f3be931f1e2fbc2cbb82ac7d3e9980c1aa1a404085a0d4e7218944567e4750260fd638506e6f43dceb6a477c4762fe856d3c262e152988920
6
+ metadata.gz: d701317b4edbe221b2dd9a66d6e2591a0a78e8b9502373860656a5d95f552eee06ae752904687b58b2dfda274dc7c20e5da3e5bebbefbd98c538c107f49bec7a
7
+ data.tar.gz: 22a9383f113f01025ba2f694cd61845aa4ed08474efc70cb37694993babb9ec7d6ac3d95291bbf2fe5b22835a8923ab1802061d861da2e59d5b0e3041f7b18ed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 5.1.10
2
+ - Refactor: to explicit Java (driver) class name loading [#96](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/96),
3
+ the change is expected to provide a more robust fix for the driver loading issue [#83](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/83).
4
+
5
+ - Fix: regression due returning the Java driver class [#98](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/98)
6
+
7
+ ## 5.1.9 (yanked)
8
+ - Refactor: to explicit Java (driver) class name loading [#96](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/96),
9
+ the change is expected to provide a more robust fix for the driver loading issue [#83](https://github.com/logstash-plugins/logstash-integration-jdbc/issues/83).
10
+
1
11
  ## 5.1.8
2
12
  - Fix the blocking pipeline reload and shutdown when connectivity issues happen [#85](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/85)
3
13
 
@@ -1,9 +1,12 @@
1
+ require 'jruby'
1
2
 
2
3
  module LogStash module PluginMixins module Jdbc
3
4
  module Common
4
5
 
5
6
  private
6
7
 
8
+ # NOTE: using the JRuby mechanism to load classes (through JavaSupport)
9
+ # makes the lock redundant although it does not hurt to have it around.
7
10
  DRIVERS_LOADING_LOCK = java.util.concurrent.locks.ReentrantLock.new()
8
11
 
9
12
  def complete_sequel_opts(defaults = {})
@@ -30,16 +33,16 @@ module LogStash module PluginMixins module Jdbc
30
33
  begin
31
34
  load_driver_jars
32
35
  begin
33
- @driver_impl = Sequel::JDBC.load_driver(normalized_driver_class)
34
- rescue Sequel::AdapterNotFound => e # Sequel::AdapterNotFound, "#{@jdbc_driver_class} not loaded"
35
- # fix this !!!
36
+ @driver_impl = load_jdbc_driver_class
37
+ rescue => e # catch java.lang.ClassNotFoundException, potential errors
38
+ # (e.g. ExceptionInInitializerError or LinkageError) won't get caught
36
39
  message = if jdbc_driver_library_set?
37
40
  "Are you sure you've included the correct jdbc driver in :jdbc_driver_library?"
38
41
  else
39
42
  ":jdbc_driver_library is not set, are you sure you included " +
40
43
  "the proper driver client libraries in your classpath?"
41
44
  end
42
- raise LogStash::PluginLoadingError, "#{e}. #{message} #{e.backtrace}"
45
+ raise LogStash::PluginLoadingError, "#{e.inspect}. #{message}"
43
46
  end
44
47
  ensure
45
48
  DRIVERS_LOADING_LOCK.unlock()
@@ -71,16 +74,16 @@ module LogStash module PluginMixins module Jdbc
71
74
  !@jdbc_driver_library.nil? && !@jdbc_driver_library.empty?
72
75
  end
73
76
 
74
- # normalizing the class name to always have a Java:: prefix
75
- # is helpful since JRuby is only able to directly load class names
76
- # whose top-level package is com, org, java, javax
77
- # There are many jdbc drivers that use cc, io, net, etc.
78
- def normalized_driver_class
79
- if @jdbc_driver_class.start_with?("Java::", "Java.")
80
- @jdbc_driver_class
81
- else
82
- "Java::#{@jdbc_driver_class}"
83
- end
77
+ def load_jdbc_driver_class
78
+ # sub a potential: 'Java::org::my.Driver' to 'org.my.Driver'
79
+ klass = @jdbc_driver_class.gsub('::', '.').sub(/^Java\./, '')
80
+ # NOTE: JRuby's Java::JavaClass.for_name which considers the custom class-loader(s)
81
+ # in 9.3 the API changed and thus to avoid surprises we go down to the Java API :
82
+ klass = JRuby.runtime.getJavaSupport.loadJavaClass(klass) # throws ClassNotFoundException
83
+ # unfortunately we can not simply return the wrapped java.lang.Class instance as
84
+ # Sequel assumes to be able to do a `driver_class.new` which only works on the proxy,
85
+ org.jruby.javasupport.Java.getProxyClass(JRuby.runtime, klass)
84
86
  end
87
+
85
88
  end
86
89
  end end end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-jdbc'
3
- s.version = '5.1.8'
3
+ s.version = '5.1.10'
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"
@@ -1620,16 +1620,35 @@ describe LogStash::Inputs::Jdbc do
1620
1620
  describe "jdbc_driver_class" do
1621
1621
  context "when not prefixed with Java::" do
1622
1622
  let(:jdbc_driver_class) { "org.apache.derby.jdbc.EmbeddedDriver" }
1623
- it "loads the class prefixed with Java::" do
1624
- expect(Sequel::JDBC).to receive(:load_driver).with(/^Java::/)
1625
- plugin.send(:load_driver)
1623
+ it "loads the class" do
1624
+ expect { plugin.send(:load_driver) }.not_to raise_error
1626
1625
  end
1627
1626
  end
1628
1627
  context "when prefixed with Java::" do
1629
1628
  let(:jdbc_driver_class) { "Java::org.apache.derby.jdbc.EmbeddedDriver" }
1630
- it "loads the class as-is" do
1631
- expect(Sequel::JDBC).to receive(:load_driver).with(jdbc_driver_class)
1632
- plugin.send(:load_driver)
1629
+ it "loads the class" do
1630
+ expect { plugin.send(:load_driver) }.not_to raise_error
1631
+ end
1632
+ end
1633
+ context "when prefixed with Java." do
1634
+ let(:jdbc_driver_class) { "Java.org::apache::derby::jdbc.EmbeddedDriver" }
1635
+ it "loads the class" do
1636
+ expect { plugin.send(:load_driver) }.not_to raise_error
1637
+ end
1638
+
1639
+ it "can instantiate the returned driver class" do
1640
+ # for drivers where the path through DriverManager fails, Sequel assumes
1641
+ # having a proxied Java class instance (instead of a java.lang.Class) and
1642
+ # does a driver.new.connect https://git.io/JDV6M
1643
+ driver = plugin.send(:load_driver)
1644
+ expect { driver.new }.not_to raise_error
1645
+ end
1646
+ end
1647
+ context "when class name invalid" do
1648
+ let(:jdbc_driver_class) { "org.apache.NonExistentDriver" }
1649
+ it "raises a loading error" do
1650
+ expect { plugin.send(:load_driver) }.to raise_error LogStash::PluginLoadingError,
1651
+ /java.lang.ClassNotFoundException: org.apache.NonExistentDriver/
1633
1652
  end
1634
1653
  end
1635
1654
  end
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.1.8
4
+ version: 5.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-02 00:00:00.000000000 Z
11
+ date: 2021-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement