mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
removed assess_jruby! & renamed spec/environment.rb
This commit is contained in:
parent
20f20b2e62
commit
adf942c342
3 changed files with 4 additions and 41 deletions
|
@ -10,7 +10,7 @@ module LogStash
|
||||||
# loads currenly embedded elasticsearch jars
|
# loads currenly embedded elasticsearch jars
|
||||||
# @raise LogStash::EnvironmentError if not runnig under JRuby or if no jar files found
|
# @raise LogStash::EnvironmentError if not runnig under JRuby or if no jar files found
|
||||||
def load_elasticsearch_jars!
|
def load_elasticsearch_jars!
|
||||||
assess_jruby!
|
raise(LogStash::EnvironmentError, "JRuby is required") unless jruby?
|
||||||
|
|
||||||
require "java"
|
require "java"
|
||||||
jars_path = ::File.join(JAR_DIR, "/elasticsearch*/lib/*.jar")
|
jars_path = ::File.join(JAR_DIR, "/elasticsearch*/lib/*.jar")
|
||||||
|
@ -24,19 +24,6 @@ module LogStash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @yield execute optional block if not currently running under JRuby
|
|
||||||
# @yieldreturn [Exception] exception to raise if Exception class returned otherwise raise default exception
|
|
||||||
# @raise [Exception] yielded exception or default if not runnig under JRuby
|
|
||||||
def assess_jruby!
|
|
||||||
unless jruby?
|
|
||||||
# grab return value from block if present, use default exception if not an exception class
|
|
||||||
exception = block_given? ? yield : nil
|
|
||||||
exception = LogStash::EnvironmentError.new("JRuby is required") unless exception.is_a?(Exception)
|
|
||||||
|
|
||||||
raise(exception)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def jruby?
|
def jruby?
|
||||||
RUBY_PLATFORM == "java"
|
RUBY_PLATFORM == "java"
|
||||||
end
|
end
|
||||||
|
|
|
@ -192,12 +192,12 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
if @protocol.nil?
|
if @protocol.nil?
|
||||||
@protocol = (RUBY_PLATFORM == "java") ? "node" : "http"
|
@protocol = LogStash::Environment.jruby? ? "node" : "http"
|
||||||
end
|
end
|
||||||
|
|
||||||
if ["node", "transport"].include?(@protocol)
|
if ["node", "transport"].include?(@protocol)
|
||||||
# Node or TransportClient; requires JRuby
|
# Node or TransportClient; requires JRuby
|
||||||
LogStash::Environment.assess_jruby!{LogStash::PluginLoadingError.new("This configuration requires JRuby. If you are not using JRuby, you must set 'protocol' to 'http'. For example: output { elasticsearch { protocol => \"http\" } }")}
|
raise(LogStash::PluginLoadingError, "This configuration requires JRuby. If you are not using JRuby, you must set 'protocol' to 'http'. For example: output { elasticsearch { protocol => \"http\" } }") unless LogStash::Environment.jruby?
|
||||||
LogStash::Environment.load_elasticsearch_jars!
|
LogStash::Environment.load_elasticsearch_jars!
|
||||||
|
|
||||||
# setup log4j properties for Elasticsearch
|
# setup log4j properties for Elasticsearch
|
||||||
|
@ -241,7 +241,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
||||||
:protocol => @protocol)
|
:protocol => @protocol)
|
||||||
|
|
||||||
if @embedded
|
if @embedded
|
||||||
LogStash::Environment.assess_jruby!{LogStash::ConfigurationError.new("The 'embedded => true' setting is only valid for the elasticsearch output under JRuby. You are running #{RUBY_DESCRIPTION}")}
|
raise(LogStash::ConfigurationError, "The 'embedded => true' setting is only valid for the elasticsearch output under JRuby. You are running #{RUBY_DESCRIPTION}") unless LogStash::Environment.jruby?
|
||||||
LogStash::Environment.load_elasticsearch_jars!
|
LogStash::Environment.load_elasticsearch_jars!
|
||||||
|
|
||||||
# Default @host with embedded to localhost. This should help avoid
|
# Default @host with embedded to localhost. This should help avoid
|
||||||
|
|
|
@ -13,28 +13,4 @@ describe LogStash::Environment do
|
||||||
expect{LogStash::Environment.load_elasticsearch_jars!}.to raise_error(LogStash::EnvironmentError)
|
expect{LogStash::Environment.load_elasticsearch_jars!}.to raise_error(LogStash::EnvironmentError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "assess_jruby!" do
|
|
||||||
|
|
||||||
it "should not raise when jruby" do
|
|
||||||
expect(LogStash::Environment).to receive(:jruby?).twice.and_return(true)
|
|
||||||
expect{LogStash::Environment.assess_jruby!}.to_not raise_error
|
|
||||||
expect{LogStash::Environment.assess_jruby!{StandardError.new}}.to_not raise_error
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should raise default exception" do
|
|
||||||
expect(LogStash::Environment).to receive(:jruby?).once.and_return(false)
|
|
||||||
expect{LogStash::Environment.assess_jruby!}.to raise_error(LogStash::EnvironmentError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should yield to block and raise returned exception" do
|
|
||||||
expect(LogStash::Environment).to receive(:jruby?).once.and_return(false)
|
|
||||||
expect{LogStash::Environment.assess_jruby!{StandardError.new}}.to raise_error(StandardError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should yield to block and raise default exception if exception not returned" do
|
|
||||||
expect(LogStash::Environment).to receive(:jruby?).once.and_return(false)
|
|
||||||
expect{LogStash::Environment.assess_jruby!{nil}}.to raise_error(LogStash::EnvironmentError)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue