Skip to content
This repository was archived by the owner on Sep 17, 2019. It is now read-only.

Commit 6bae1d8

Browse files
committed
Apache phoenix-thin support
1 parent 667e066 commit 6bae1d8

File tree

7 files changed

+77
-14
lines changed

7 files changed

+77
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Change Log
22
All notable changes to this project will be documented in this file, from 0.2.0.
33

4-
## [0.3.1] = 2016-08-28
4+
## [5.1.0] - 2016-12-17
5+
- phoenix-thin fixes for issue #60
6+
7+
## [5.0.0] - 2016-11-03
8+
- logstash v5 support
9+
10+
## [0.3.1] - 2016-08-28
511
- Adds connection_test configuration option, to prevent the connection test from occuring, allowing the error to be suppressed.
612
Useful for cockroachdb deployments. https://github.com/theangryangel/logstash-output-jdbc/issues/53
713

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ For development:
4444
| driver_jar_path | String | File path to jar file containing your JDBC driver. This is optional, and all JDBC jars may be placed in $LOGSTASH_HOME/vendor/jar/jdbc instead. | No | |
4545
| connection_string | String | JDBC connection URL | Yes | |
4646
| connection_test | Boolean | Run a JDBC connection test. Some drivers do not function correctly, and you may need to disable the connection test to supress an error. Cockroach with the postgres JDBC driver is such an example. | No | Yes |
47+
| connection_test_query | String | Connection test and init query string, required for some JDBC drivers that don't support isValid(). Typically you'd set to this "SELECT 1" | No | |
4748
| username | String | JDBC username - this is optional as it may be included in the connection string, for many drivers | No | |
4849
| password | String | JDBC password - this is optional as it may be included in the connection string, for many drivers | No | |
4950
| statement | Array | An array of strings representing the SQL statement to run. Index 0 is the SQL statement that is prepared, all other array entries are passed in as parameters (in order). A parameter may either be a property of the event (i.e. "@timestamp", or "host") or a formatted string (i.e. "%{host} - %{message}" or "%{message}"). If a key is passed then it will be automatically converted as required for insertion into SQL. If it's a formatted string then it will be passed in verbatim. | Yes | |

Vagrantfile

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,35 @@
22
# vi: set ft=ruby :
33

44
Vagrant.configure(2) do |config|
5-
config.vm.box = 'debian/jessie64'
6-
config.vm.synced_folder '.', '/vagrant', type: :virtualbox
75

8-
config.vm.provision 'shell', inline: <<-EOP
9-
echo "deb http://ftp.debian.org/debian jessie-backports main" | tee --append /etc/apt/sources.list > /dev/null
10-
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
11-
apt-get update
12-
apt-get remove openjdk-7-jre-headless -y -q
13-
apt-get install git openjdk-8-jre curl -y -q
14-
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
15-
curl -sSL https://get.rvm.io | bash -s stable --ruby=jruby-1.7
16-
usermod -a -G rvm vagrant
17-
EOP
6+
config.vm.define "debian" do |deb|
7+
deb.vm.box = 'debian/jessie64'
8+
deb.vm.synced_folder '.', '/vagrant', type: :virtualbox
9+
10+
deb.vm.provision 'shell', inline: <<-EOP
11+
echo "deb http://ftp.debian.org/debian jessie-backports main" | tee --append /etc/apt/sources.list > /dev/null
12+
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
13+
apt-get update
14+
apt-get remove openjdk-7-jre-headless -y -q
15+
apt-get install git openjdk-8-jre curl -y -q
16+
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
17+
curl -sSL https://get.rvm.io | bash -s stable --ruby=jruby-1.7
18+
usermod -a -G rvm vagrant
19+
EOP
20+
end
21+
22+
config.vm.define "centos" do |centos|
23+
centos.vm.box = 'centos/7'
24+
centos.ssh.insert_key = false # https://github.com/mitchellh/vagrant/issues/7610
25+
centos.vm.synced_folder '.', '/vagrant', type: :virtualbox
26+
27+
centos.vm.provision 'shell', inline: <<-EOP
28+
yum update
29+
yum install java-1.7.0-openjdk
30+
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
31+
curl -sSL https://get.rvm.io | bash -s stable --ruby=jruby-1.7
32+
usermod -a -G rvm vagrant
33+
EOP
34+
end
35+
1836
end

examples/apache-phoenix-hbase-sql.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Example: Apache Phoenix (HBase SQL)
22
* Tested with Ubuntu 14.04.03 / Logstash 2.1 / Apache Phoenix 4.6
33
* <!> HBase and Zookeeper must be both accessible from logstash machine <!>
4+
* Please see apache-phoenix-thin-hbase-sql for phoenix-thin. The examples are different.
45
```
56
input
67
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Example: Apache Phoenix-Thin (HBase SQL)
2+
3+
**There are special instructions for phoenix-thin. Please read carefully!**
4+
5+
* Tested with Logstash 5.1.1 / Apache Phoenix 4.9
6+
* HBase and Zookeeper must be both accessible from logstash machine
7+
* At time of writing phoenix-client does not include all the required jars (see https://issues.apache.org/jira/browse/PHOENIX-3476), therefore you must *not* use the driver_jar_path configuration option and instead:
8+
- `mkdir -p vendor/jar/jdbc` in your logstash installation path
9+
- copy `phoenix-queryserver-client-4.9.0-HBase-1.2.jar` from the phoenix distribution into this folder
10+
- download the calcite jar from https://mvnrepository.com/artifact/org.apache.calcite/calcite-avatica/1.6.0 and place it into your `vendor/jar/jdbc` directory
11+
* Use the following configuration as a base. The connection_test => false and connection_test_query are very important and should not be omitted. Phoenix-thin does not appear to support isValid and these are necessary for the connection to be added to the pool and be available.
12+
13+
```
14+
input
15+
{
16+
stdin { }
17+
}
18+
output {
19+
jdbc {
20+
connection_test => false
21+
connection_test_query => "select 1"
22+
driver_class => "org.apache.phoenix.queryserver.client.Driver"
23+
connection_string => "jdbc:phoenix:thin:url=http://localhost:8765;serialization=PROTOBUF"
24+
statement => [ "UPSERT INTO log (host, timestamp, message) VALUES(?, ?, ?)", "host", "@timestamp", "message" ]
25+
}
26+
27+
}
28+
```

lib/logstash/outputs/jdbc.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
8686
# Run a connection test on start.
8787
config :connection_test, validate: :boolean, default: true
8888

89+
# Connection test and init string, required for some JDBC endpoints
90+
# notable phoenix-thin - see logstash-output-jdbc issue #60
91+
config :connection_test_query, validate: :string, required: false
92+
8993
# Maximum number of sequential failed attempts, before we stop retrying.
9094
# If set to < 1, then it will infinitely retry.
9195
# At the default values this is a little over 10 minutes
@@ -146,6 +150,11 @@ def setup_and_test_pool!
146150

147151
validate_connection_timeout = (@connection_timeout / 1000) / 2
148152

153+
if !@connection_test_query.nil? and @connection_test_query.length > 1
154+
@pool.setConnectionTestQuery(@connection_test_query)
155+
@pool.setConnectionInitSql(@connection_test_query)
156+
end
157+
149158
return unless @connection_test
150159

151160
# Test connection

logstash-output-jdbc.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-jdbc'
3-
s.version = '5.0.0'
3+
s.version = '5.1.0'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = 'This plugin allows you to output to SQL, via JDBC'
66
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 'logstash-output-jdbc'. This gem is not a stand-alone program"

0 commit comments

Comments
 (0)