Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

Commit 6b74b23

Browse files
andrewvcjordansissel
authored andcommitted
This cleans up the structure of protocol instance settings methods
Fixes #13
1 parent 77136fb commit 6b74b23

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

lib/logstash/outputs/elasticsearch_java.rb

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -308,50 +308,19 @@ def register
308308
raise LogStash::ConfigurationError, "network_host MUST be set if the 'node' protocol is in use! If this is set incorrectly Logstash will hang attempting to connect!"
309309
end
310310

311-
client_settings = {}
312-
client_settings["cluster.name"] = @cluster if @cluster
313-
client_settings["network.host"] = @network_host if @network_host
314-
client_settings["transport.tcp.port"] = @transport_tcp_port if @transport_tcp_port
315-
client_settings["client.transport.sniff"] = @sniffing
316-
317-
if @node_name
318-
client_settings["node.name"] = @node_name
319-
else
320-
client_settings["node.name"] = "logstash-#{Socket.gethostname}-#{$$}-#{object_id}"
321-
end
322-
323-
@@plugins.each do |plugin|
324-
name = plugin.name.split('-')[-1]
325-
client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
326-
end
327-
328311
if (@hosts.nil? || @hosts.empty?) && @protocol != "node" # node can use zen discovery
329312
@logger.info("No 'hosts' set in elasticsearch output. Defaulting to localhost")
330313
@hosts = ["localhost"]
331314
end
332315

333-
common_options = {
334-
:protocol => @protocol,
335-
:client_settings => client_settings,
336-
:hosts => @hosts,
337-
:port => @port
338-
}
339-
340-
# Update API setup
341-
update_options = {
342-
:upsert => @upsert,
343-
:doc_as_upsert => @doc_as_upsert
344-
}
345-
common_options.merge! update_options if @action == 'update'
346-
347316
client_class = case @protocol
348317
when "transport"
349318
LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::TransportClient
350319
when "node"
351320
LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient
352321
end
353322

354-
@client = client_class.new(common_options)
323+
@client = client_class.new(client_options)
355324

356325
if @manage_template
357326
begin
@@ -389,6 +358,41 @@ def register
389358
end
390359
end # def register
391360

361+
def client_options
362+
client_settings = {}
363+
client_settings["cluster.name"] = @cluster if @cluster
364+
client_settings["network.host"] = @network_host if @network_host
365+
client_settings["transport.tcp.port"] = @transport_tcp_port if @transport_tcp_port
366+
client_settings["client.transport.sniff"] = @sniffing
367+
368+
if @node_name
369+
client_settings["node.name"] = @node_name
370+
else
371+
client_settings["node.name"] = "logstash-#{Socket.gethostname}-#{$$}-#{object_id}"
372+
end
373+
374+
@@plugins.each do |plugin|
375+
name = plugin.name.split('-')[-1]
376+
client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
377+
end
378+
379+
common_options = {
380+
:protocol => @protocol,
381+
:client_settings => client_settings,
382+
:hosts => @hosts,
383+
:port => @port
384+
}
385+
386+
# Update API setup
387+
update_options = {
388+
:upsert => @upsert,
389+
:doc_as_upsert => @doc_as_upsert
390+
}
391+
common_options.merge! update_options if @action == 'update'
392+
393+
common_options
394+
end
395+
392396

393397
public
394398
def get_template

logstash-output-elasticsearch_java.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-elasticsearch_java'
3-
s.version = '2.0.0.beta7'
3+
s.version = '2.0.0.beta8'
44
s.licenses = ['apache-2.0']
55
s.summary = "Logstash Output to Elasticsearch using Java node/transport client"
66
s.description = "Output events to elasticsearch using the java client"

0 commit comments

Comments
 (0)