logstash-core 5.6.16-java → 6.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +4 -7
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/version.rb +4 -8
  5. data/lib/logstash-core_jars.rb +12 -26
  6. data/lib/logstash/agent.rb +261 -246
  7. data/lib/logstash/api/commands/default_metadata.rb +1 -1
  8. data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
  9. data/lib/logstash/api/commands/node.rb +3 -2
  10. data/lib/logstash/api/commands/stats.rb +3 -2
  11. data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
  12. data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
  13. data/lib/logstash/bootstrap_check/default_config.rb +17 -0
  14. data/lib/logstash/compiler.rb +38 -0
  15. data/lib/logstash/compiler/lscl.rb +566 -0
  16. data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
  17. data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
  18. data/lib/logstash/config/config_ast.rb +4 -82
  19. data/lib/logstash/config/mixin.rb +73 -41
  20. data/lib/logstash/config/pipeline_config.rb +48 -0
  21. data/lib/logstash/config/source/base.rb +16 -0
  22. data/lib/logstash/config/source/local.rb +215 -0
  23. data/lib/logstash/config/source_loader.rb +125 -0
  24. data/lib/logstash/converge_result.rb +103 -0
  25. data/lib/logstash/environment.rb +6 -19
  26. data/lib/logstash/errors.rb +2 -0
  27. data/lib/logstash/execution_context.rb +4 -7
  28. data/lib/logstash/filter_delegator.rb +6 -9
  29. data/lib/logstash/inputs/base.rb +0 -2
  30. data/lib/logstash/instrument/collector.rb +5 -7
  31. data/lib/logstash/instrument/metric_store.rb +12 -12
  32. data/lib/logstash/instrument/metric_type/mean.rb +0 -5
  33. data/lib/logstash/instrument/namespaced_metric.rb +0 -4
  34. data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
  35. data/lib/logstash/instrument/null_metric.rb +0 -10
  36. data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
  37. data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
  38. data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
  39. data/lib/logstash/instrument/periodic_pollers.rb +1 -3
  40. data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
  41. data/lib/logstash/logging/logger.rb +15 -47
  42. data/lib/logstash/namespace.rb +0 -1
  43. data/lib/logstash/output_delegator.rb +5 -7
  44. data/lib/logstash/outputs/base.rb +0 -2
  45. data/lib/logstash/pipeline.rb +159 -87
  46. data/lib/logstash/pipeline_action.rb +13 -0
  47. data/lib/logstash/pipeline_action/base.rb +29 -0
  48. data/lib/logstash/pipeline_action/create.rb +47 -0
  49. data/lib/logstash/pipeline_action/reload.rb +48 -0
  50. data/lib/logstash/pipeline_action/stop.rb +23 -0
  51. data/lib/logstash/plugin.rb +0 -1
  52. data/lib/logstash/plugins/hooks_registry.rb +6 -0
  53. data/lib/logstash/plugins/registry.rb +0 -1
  54. data/lib/logstash/program.rb +14 -0
  55. data/lib/logstash/queue_factory.rb +5 -1
  56. data/lib/logstash/runner.rb +58 -80
  57. data/lib/logstash/settings.rb +3 -27
  58. data/lib/logstash/state_resolver.rb +41 -0
  59. data/lib/logstash/util/java_version.rb +6 -0
  60. data/lib/logstash/util/safe_uri.rb +12 -148
  61. data/lib/logstash/util/thread_dump.rb +4 -7
  62. data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
  63. data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
  64. data/lib/logstash/version.rb +10 -8
  65. data/locales/en.yml +3 -54
  66. data/logstash-core.gemspec +8 -35
  67. data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
  68. data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
  69. data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
  70. data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
  71. data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
  72. data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
  73. data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
  74. data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
  75. data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
  76. data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
  77. data/spec/api/spec_helper.rb +106 -0
  78. data/spec/logstash/agent/converge_spec.rb +286 -0
  79. data/spec/logstash/agent/metrics_spec.rb +244 -0
  80. data/spec/logstash/agent_spec.rb +213 -225
  81. data/spec/logstash/compiler/compiler_spec.rb +584 -0
  82. data/spec/logstash/config/config_ast_spec.rb +8 -47
  83. data/spec/logstash/config/mixin_spec.rb +2 -42
  84. data/spec/logstash/config/pipeline_config_spec.rb +75 -0
  85. data/spec/logstash/config/source/local_spec.rb +395 -0
  86. data/spec/logstash/config/source_loader_spec.rb +122 -0
  87. data/spec/logstash/converge_result_spec.rb +179 -0
  88. data/spec/logstash/event_spec.rb +0 -66
  89. data/spec/logstash/execution_context_spec.rb +8 -12
  90. data/spec/logstash/filter_delegator_spec.rb +12 -24
  91. data/spec/logstash/inputs/base_spec.rb +7 -5
  92. data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
  93. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
  94. data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
  95. data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
  96. data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
  97. data/spec/logstash/output_delegator_spec.rb +11 -20
  98. data/spec/logstash/outputs/base_spec.rb +7 -5
  99. data/spec/logstash/pipeline_action/create_spec.rb +83 -0
  100. data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
  101. data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
  102. data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
  103. data/spec/logstash/pipeline_spec.rb +81 -137
  104. data/spec/logstash/plugin_spec.rb +2 -1
  105. data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
  106. data/spec/logstash/queue_factory_spec.rb +13 -1
  107. data/spec/logstash/runner_spec.rb +29 -140
  108. data/spec/logstash/settings/writable_directory_spec.rb +10 -13
  109. data/spec/logstash/settings_spec.rb +0 -91
  110. data/spec/logstash/state_resolver_spec.rb +156 -0
  111. data/spec/logstash/timestamp_spec.rb +2 -6
  112. data/spec/logstash/util/java_version_spec.rb +22 -0
  113. data/spec/logstash/util/safe_uri_spec.rb +0 -56
  114. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
  115. data/spec/support/helpers.rb +9 -11
  116. data/spec/support/matchers.rb +96 -6
  117. data/spec/support/mocks_classes.rb +80 -0
  118. data/spec/support/shared_contexts.rb +2 -27
  119. metadata +100 -149
  120. data/lib/logstash/config/loader.rb +0 -107
  121. data/lib/logstash/config/modules_common.rb +0 -103
  122. data/lib/logstash/config/source/modules.rb +0 -55
  123. data/lib/logstash/config/string_escape.rb +0 -27
  124. data/lib/logstash/dependency_report.rb +0 -131
  125. data/lib/logstash/dependency_report_runner.rb +0 -17
  126. data/lib/logstash/elasticsearch_client.rb +0 -142
  127. data/lib/logstash/instrument/global_metrics.rb +0 -13
  128. data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
  129. data/lib/logstash/modules/cli_parser.rb +0 -74
  130. data/lib/logstash/modules/elasticsearch_config.rb +0 -22
  131. data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
  132. data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
  133. data/lib/logstash/modules/file_reader.rb +0 -36
  134. data/lib/logstash/modules/kibana_base.rb +0 -24
  135. data/lib/logstash/modules/kibana_client.rb +0 -124
  136. data/lib/logstash/modules/kibana_config.rb +0 -105
  137. data/lib/logstash/modules/kibana_dashboards.rb +0 -36
  138. data/lib/logstash/modules/kibana_importer.rb +0 -17
  139. data/lib/logstash/modules/kibana_resource.rb +0 -10
  140. data/lib/logstash/modules/kibana_settings.rb +0 -40
  141. data/lib/logstash/modules/logstash_config.rb +0 -120
  142. data/lib/logstash/modules/resource_base.rb +0 -38
  143. data/lib/logstash/modules/scaffold.rb +0 -52
  144. data/lib/logstash/modules/settings_merger.rb +0 -23
  145. data/lib/logstash/modules/util.rb +0 -17
  146. data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
  147. data/lib/logstash/util/environment_variables.rb +0 -43
  148. data/spec/logstash/config/loader_spec.rb +0 -38
  149. data/spec/logstash/config/string_escape_spec.rb +0 -24
  150. data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
  151. data/spec/logstash/modules/logstash_config_spec.rb +0 -56
  152. data/spec/logstash/modules/scaffold_spec.rb +0 -234
  153. data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
  154. data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
  155. data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
  156. data/versions-gem-copy.yml +0 -12
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require "logstash/pipeline_action/base"
3
+ require "logstash/pipeline_action/create"
4
+ require "logstash/pipeline_action/stop"
5
+ require "logstash/pipeline_action/reload"
6
+
7
+ module LogStash module PipelineAction
8
+ ORDERING = {
9
+ LogStash::PipelineAction::Create => 100,
10
+ LogStash::PipelineAction::Reload => 200,
11
+ LogStash::PipelineAction::Stop => 300
12
+ }
13
+ end end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ # I've decided to take the action strategy, I think this make the code a bit easier to understand.
3
+ # maybe in the context of config management we will want to have force kill on the
4
+ # threads instead of waiting forever or sending feedback to the host
5
+ #
6
+ # Some actions could be retryable, or have a delay or timeout.
7
+ module LogStash module PipelineAction
8
+ class Base
9
+ # Only used for debugging purpose and in the logger statement.
10
+ def inspect
11
+ "#{self.class.name}/pipeline_id:#{pipeline_id}"
12
+ end
13
+ alias_method :to_s, :inspect
14
+
15
+ def execute(agent, pipelines)
16
+ raise "`#execute` Not implemented!"
17
+ end
18
+
19
+ # See the definition in `logstash/pipeline_action.rb` for the default ordering
20
+ def execution_priority
21
+ ORDERING.fetch(self.class)
22
+ end
23
+
24
+ def <=>(other)
25
+ order = self.execution_priority <=> other.execution_priority
26
+ order.nonzero? ? order : self.pipeline_id <=> other.pipeline_id
27
+ end
28
+ end
29
+ end end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require "logstash/pipeline_action/base"
3
+ require "logstash/pipeline"
4
+ require "logstash/converge_result"
5
+ require "logstash/util/loggable"
6
+
7
+ module LogStash module PipelineAction
8
+ class Create < Base
9
+ include LogStash::Util::Loggable
10
+
11
+ # We currently pass around the metric object again this
12
+ # is needed to correctly create a pipeline, in a future
13
+ # PR we could pass a factory to create the pipeline so we pass the logic
14
+ # to create the pipeline instead.
15
+ def initialize(pipeline_config, metric)
16
+ @pipeline_config = pipeline_config
17
+ @metric = metric
18
+ end
19
+
20
+ def pipeline_id
21
+ @pipeline_config.pipeline_id
22
+ end
23
+
24
+ # Make sure we execution system pipeline like the monitoring
25
+ # before any user defined pipelines, system pipeline register hooks into the system that will be
26
+ # triggered by the user defined pipeline.
27
+ def execution_priority
28
+ default_priority = super
29
+ @pipeline_config.system? ? default_priority * -1 : default_priority
30
+ end
31
+
32
+ # The execute assume that the thread safety access of the pipeline
33
+ # is managed by the caller.
34
+ def execute(agent, pipelines)
35
+ pipeline = LogStash::Pipeline.new(@pipeline_config.config_string, @pipeline_config.settings, @metric, agent)
36
+
37
+ status = pipeline.start # block until the pipeline is correctly started or crashed
38
+
39
+ if status
40
+ pipelines[pipeline_id] = pipeline # The pipeline is successfully started we can add it to the hash
41
+ end
42
+
43
+ LogStash::ConvergeResult::ActionResult.create(self, status)
44
+ end
45
+
46
+ end
47
+ end end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require "logstash/pipeline_action/base"
3
+ require "logstash/pipeline_action/create"
4
+ require "logstash/pipeline_action/stop"
5
+ require "logstash/errors"
6
+ require "logstash/util/loggable"
7
+ require "logstash/converge_result"
8
+
9
+ module LogStash module PipelineAction
10
+ class Reload < Base
11
+ include LogStash::Util::Loggable
12
+
13
+ def initialize(pipeline_config, metric)
14
+ @pipeline_config = pipeline_config
15
+ @metric = metric
16
+ end
17
+
18
+ def pipeline_id
19
+ @pipeline_config.pipeline_id
20
+ end
21
+
22
+ def execute(agent, pipelines)
23
+ old_pipeline = pipelines[pipeline_id]
24
+
25
+ if !old_pipeline.reloadable?
26
+ return LogStash::ConvergeResult::FailedAction.new("Cannot reload pipeline, because the existing pipeline is not reloadable")
27
+ end
28
+
29
+ begin
30
+ pipeline_validator = LogStash::BasePipeline.new(@pipeline_config.config_string, @pipeline_config.settings)
31
+ rescue => e
32
+ return LogStash::ConvergeResult::FailedAction.from_exception(e)
33
+ end
34
+
35
+ if !pipeline_validator.reloadable?
36
+ return LogStash::ConvergeResult::FailedAction.new("Cannot reload pipeline, because the new pipeline is not reloadable")
37
+ end
38
+
39
+ status = Stop.new(pipeline_id).execute(agent, pipelines)
40
+
41
+ if status
42
+ return Create.new(@pipeline_config, @metric).execute(agent, pipelines)
43
+ else
44
+ return status
45
+ end
46
+ end
47
+ end
48
+ end end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require "logstash/pipeline_action/base"
3
+ require "logstash/shutdown_watcher"
4
+ require "logstash/converge_result"
5
+
6
+ module LogStash module PipelineAction
7
+ class Stop < Base
8
+ attr_reader :pipeline_id
9
+
10
+ def initialize(pipeline_id)
11
+ @pipeline_id = pipeline_id
12
+ end
13
+
14
+ def execute(agent, pipelines)
15
+ pipeline = pipelines[pipeline_id]
16
+ pipeline.shutdown { LogStash::ShutdownWatcher.start(pipeline) }
17
+ pipelines.delete(pipeline_id)
18
+ # If we reach this part of the code we have succeeded because
19
+ # the shutdown call will block.
20
+ return LogStash::ConvergeResult::SuccessfulAction.new
21
+ end
22
+ end
23
+ end end
@@ -3,7 +3,6 @@ require "logstash/namespace"
3
3
  require "logstash/logging"
4
4
  require "logstash/config/mixin"
5
5
  require "logstash/instrument/null_metric"
6
- require "logstash/util/dead_letter_queue_manager"
7
6
  require "concurrent"
8
7
  require "securerandom"
9
8
 
@@ -41,6 +41,12 @@ module LogStash module Plugins
41
41
  end
42
42
  end
43
43
 
44
+ def registered_hook?(emitter_scope, klass)
45
+ callbacks = @registered_hooks[emitter_scope]
46
+ return false if callbacks.nil?
47
+ callbacks.collect(&:class).include?(klass)
48
+ end
49
+
44
50
  private
45
51
  def sync_hooks
46
52
  @registered_emitters.each do |emitter, dispatcher|
@@ -3,7 +3,6 @@ require "rubygems/package"
3
3
  require "logstash/util/loggable"
4
4
  require "logstash/plugin"
5
5
  require "logstash/plugins/hooks_registry"
6
- require "logstash/modules/scaffold"
7
6
 
8
7
  module LogStash module Plugins
9
8
  class Registry
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+
4
+ module LogStash::Program
5
+ public
6
+ def exit(value)
7
+ if RUBY_ENGINE == "jruby"
8
+ # Kernel::exit() in jruby just tosses an exception? Let's actually exit.
9
+ Java::java.lang.System.exit(value)
10
+ else
11
+ Kernel::exit(value)
12
+ end
13
+ end # def exit
14
+ end # module LogStash::Program
@@ -19,6 +19,10 @@ module LogStash
19
19
  queue_path = ::File.join(settings.get("path.queue"), settings.get("pipeline.id"))
20
20
 
21
21
  case queue_type
22
+ when "memory_acked"
23
+ # memory_acked is used in tests/specs
24
+ FileUtils.mkdir_p(queue_path)
25
+ LogStash::Util::WrappedAckedQueue.create_memory_based(queue_path, queue_page_capacity, queue_max_events, queue_max_bytes)
22
26
  when "persisted"
23
27
  # persisted is the disk based acked queue
24
28
  FileUtils.mkdir_p(queue_path)
@@ -27,7 +31,7 @@ module LogStash
27
31
  # memory is the legacy and default setting
28
32
  LogStash::Util::WrappedSynchronousQueue.new
29
33
  else
30
- raise ConfigurationError, "Invalid setting `#{queue_type}` for `queue.type`, supported types are 'memory' and 'persisted'"
34
+ raise ConfigurationError, "Invalid setting `#{queue_type}` for `queue.type`, supported types are: 'memory_acked', 'memory', 'persisted'"
31
35
  end
32
36
  end
33
37
  end
@@ -9,19 +9,20 @@ require "net/http"
9
9
  require "logstash/namespace"
10
10
  require "logstash-core/logstash-core"
11
11
  require "logstash/environment"
12
- require "logstash/modules/cli_parser"
13
12
 
14
13
  LogStash::Environment.load_locale!
15
14
 
16
15
  require "logstash/agent"
17
16
  require "logstash/config/defaults"
18
- require "logstash/config/modules_common"
19
17
  require "logstash/shutdown_watcher"
20
18
  require "logstash/patches/clamp"
21
19
  require "logstash/settings"
22
20
  require "logstash/version"
23
21
  require "logstash/plugins/registry"
24
- require "logstash/modules/util"
22
+ require "logstash/bootstrap_check/default_config"
23
+ require "logstash/bootstrap_check/bad_java"
24
+ require "logstash/bootstrap_check/bad_ruby"
25
+ require "set"
25
26
 
26
27
  java_import 'org.logstash.FileLockFactory'
27
28
 
@@ -34,6 +35,14 @@ class LogStash::Runner < Clamp::StrictCommand
34
35
  LogStash::SETTINGS.register(LogStash::Setting::String.new("path.settings", ::File.join(LogStash::Environment::LOGSTASH_HOME, "config")))
35
36
  LogStash::SETTINGS.register(LogStash::Setting::String.new("path.logs", ::File.join(LogStash::Environment::LOGSTASH_HOME, "logs")))
36
37
 
38
+ # Ordered list of check to run before starting logstash
39
+ # theses checks can be changed by a plugin loaded into memory.
40
+ DEFAULT_BOOTSTRAP_CHECKS = [
41
+ LogStash::BootstrapCheck::BadRuby,
42
+ LogStash::BootstrapCheck::BadJava,
43
+ LogStash::BootstrapCheck::DefaultConfig
44
+ ]
45
+
37
46
  # Node Settings
38
47
  option ["-n", "--node.name"], "NAME",
39
48
  I18n.t("logstash.runner.flag.name"),
@@ -52,22 +61,6 @@ class LogStash::Runner < Clamp::StrictCommand
52
61
  :default => LogStash::SETTINGS.get_default("config.string"),
53
62
  :attribute_name => "config.string"
54
63
 
55
- # Module settings
56
- option ["--modules"], "MODULES",
57
- I18n.t("logstash.runner.flag.modules"),
58
- :multivalued => true,
59
- :attribute_name => "modules_list"
60
-
61
- option ["-M", "--modules.variable"], "MODULES_VARIABLE",
62
- I18n.t("logstash.runner.flag.modules_variable"),
63
- :multivalued => true,
64
- :attribute_name => "modules_variable_list"
65
-
66
- option ["--setup"], :flag,
67
- I18n.t("logstash.runner.flag.modules_setup"),
68
- :default => LogStash::SETTINGS.get_default("modules_setup"),
69
- :attribute_name => "modules_setup"
70
-
71
64
  # Pipeline settings
72
65
  option ["-w", "--pipeline.workers"], "COUNT",
73
66
  I18n.t("logstash.runner.flag.pipeline-workers"),
@@ -172,10 +165,16 @@ class LogStash::Runner < Clamp::StrictCommand
172
165
  I18n.t("logstash.runner.flag.quiet"),
173
166
  :new_flag => "log.level", :new_value => "error"
174
167
 
175
- attr_reader :agent
168
+ attr_reader :agent, :settings
169
+ attr_accessor :bootstrap_checks
176
170
 
177
171
  def initialize(*args)
178
172
  @settings = LogStash::SETTINGS
173
+ @bootstrap_checks = DEFAULT_BOOTSTRAP_CHECKS.dup
174
+
175
+ # Default we check local sources: `-e`, `-f` and the logstash.yml options.
176
+ LogStash::Config::SOURCE_LOADER.add_source(LogStash::Config::Source::Local.new(@settings))
177
+
179
178
  super(*args)
180
179
  end
181
180
 
@@ -221,11 +220,7 @@ class LogStash::Runner < Clamp::StrictCommand
221
220
  java.lang.System.setProperty("ls.log.level", setting("log.level"))
222
221
  unless java.lang.System.getProperty("log4j.configurationFile")
223
222
  log4j_config_location = ::File.join(setting("path.settings"), "log4j2.properties")
224
-
225
- # Windows safe way to produce a file: URI.
226
- file_schema = "file://" + (LogStash::Environment.windows? ? "/" : "")
227
- LogStash::Logging::Logger::reconfigure(URI.join(file_schema + File.absolute_path(log4j_config_location)).to_s)
228
-
223
+ LogStash::Logging::Logger::initialize("file:///" + log4j_config_location)
229
224
  end
230
225
  # override log level that may have been introduced from a custom log4j config file
231
226
  LogStash::Logging::Logger::configure_logging(setting("log.level"))
@@ -234,70 +229,55 @@ class LogStash::Runner < Clamp::StrictCommand
234
229
  logger.warn("--config.debug was specified, but log.level was not set to \'debug\'! No config info will be logged.")
235
230
  end
236
231
 
237
- # Add local modules to the registry before everything else
238
- LogStash::Modules::Util.register_local_modules(LogStash::Environment::LOGSTASH_HOME)
232
+ # Skip any validation and just return the version
233
+ if version?
234
+ show_version
235
+ return 0
236
+ end
239
237
 
240
238
  # We configure the registry and load any plugin that can register hooks
241
239
  # with logstash, this need to be done before any operation.
242
240
  LogStash::PLUGIN_REGISTRY.setup!
243
- @settings.validate_all
244
241
 
245
- LogStash::Util::set_thread_name(self.class.name)
242
+ @dispatcher = LogStash::EventDispatcher.new(self)
243
+ LogStash::PLUGIN_REGISTRY.hooks.register_emitter(self.class, @dispatcher)
246
244
 
247
- if RUBY_VERSION < "1.9.2"
248
- logger.fatal "Ruby 1.9.2 or later is required. (You are running: " + RUBY_VERSION + ")"
249
- return 1
250
- end
245
+ @settings.validate_all
246
+ @dispatcher.fire(:before_bootstrap_checks)
247
+
248
+ return start_shell(setting("interactive"), binding) if setting("interactive")
251
249
 
252
- # Exit on bad java versions
253
- java_version = LogStash::Util::JavaVersion.version
254
- if LogStash::Util::JavaVersion.bad_java_version?(java_version)
255
- logger.fatal "Java version 1.8.0 or later is required. (You are running: #{java_version})"
250
+ begin
251
+ @bootstrap_checks.each { |bootstrap| bootstrap.check(@settings) }
252
+ rescue LogStash::BootstrapCheckError => e
253
+ signal_usage_error(e.message)
256
254
  return 1
257
255
  end
256
+ @dispatcher.fire(:after_bootstrap_checks)
258
257
 
259
- module_parser = LogStash::Modules::CLIParser.new(@modules_list, @modules_variable_list)
260
- # Now populate Setting for modules.list with our parsed array.
261
- @settings.set("modules.cli", module_parser.output)
258
+ LogStash::Util::set_thread_name(self.class.name)
262
259
 
263
260
  LogStash::ShutdownWatcher.unsafe_shutdown = setting("pipeline.unsafe_shutdown")
264
261
 
265
262
  configure_plugin_paths(setting("path.plugins"))
266
263
 
267
- if version?
268
- show_version
269
- return 0
270
- end
271
-
272
- return start_shell(setting("interactive"), binding) if setting("interactive")
273
264
 
274
265
  @settings.format_settings.each {|line| logger.debug(line) }
275
266
 
276
- module_configs = LogStash::Config::ModulesCommon.pipeline_configs(@settings)
277
- module_config_hash = module_configs.first
278
- if !module_config_hash.nil?
279
- @settings.set_value("config.string", module_config_hash["config_string"])
280
- end
281
- if module_configs.size > 1
282
- logger.warn "Multiple modules defined in logstash.yml - using the first one: #{module_config_hash["pipeline_id"]}"
283
- end
284
-
285
- if setting("config.string").nil? && setting("path.config").nil?
286
- fail(I18n.t("logstash.runner.missing-configuration"))
287
- end
288
-
289
- if setting("config.reload.automatic") && setting("path.config").nil?
290
- # there's nothing to reload
291
- signal_usage_error(I18n.t("logstash.runner.reload-without-config-path"))
292
- end
293
-
294
267
  if setting("config.test_and_exit")
295
- config_loader = LogStash::Config::Loader.new(logger)
296
- config_str = config_loader.format_config(setting("path.config"), setting("config.string"))
297
268
  begin
298
- LogStash::BasePipeline.new(config_str)
299
- puts "Configuration OK"
300
- logger.info "Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash"
269
+ results = LogStash::Config::SOURCE_LOADER.fetch
270
+
271
+ # TODO(ph): make it better for multiple pipeline
272
+ if results.success?
273
+ results.response.each do |pipeline_config|
274
+ LogStash::BasePipeline.new(pipeline_config.config_string)
275
+ end
276
+ puts "Configuration OK"
277
+ logger.info "Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash"
278
+ else
279
+ raise "Could not load the configuration file"
280
+ end
301
281
  return 0
302
282
  rescue => e
303
283
  logger.fatal I18n.t("logstash.runner.invalid-configuration", :error => e.message)
@@ -306,11 +286,11 @@ class LogStash::Runner < Clamp::StrictCommand
306
286
  end
307
287
 
308
288
  # lock path.data before starting the agent
309
- @data_path_lock = FileLockFactory.obtainLock(java.nio.file.Paths.get(setting("path.data")).to_absolute_path, ".lock")
289
+ @data_path_lock = FileLockFactory.getDefault().obtainLock(setting("path.data"), ".lock");
310
290
 
311
- @agent = create_agent(@settings)
312
-
313
- @agent.register_pipeline(@settings)
291
+ @dispatcher.fire(:before_agent)
292
+ @agent = create_agent(@settings, LogStash::Config::SOURCE_LOADER)
293
+ @dispatcher.fire(:after_agent)
314
294
 
315
295
  # enable sigint/sigterm before starting the agent
316
296
  # to properly handle a stalled agent
@@ -351,7 +331,7 @@ class LogStash::Runner < Clamp::StrictCommand
351
331
  Stud::untrap("INT", sigint_id) unless sigint_id.nil?
352
332
  Stud::untrap("TERM", sigterm_id) unless sigterm_id.nil?
353
333
  Stud::untrap("HUP", sighup_id) unless sighup_id.nil?
354
- FileLockFactory.releaseLock(@data_path_lock) if @data_path_lock
334
+ FileLockFactory.getDefault().releaseLock(@data_path_lock) if @data_path_lock
355
335
  @log_fd.close if @log_fd
356
336
  end # def self.main
357
337
 
@@ -427,7 +407,7 @@ class LogStash::Runner < Clamp::StrictCommand
427
407
  def trap_sighup
428
408
  Stud::trap("HUP") do
429
409
  logger.warn(I18n.t("logstash.agent.sighup"))
430
- @agent.reload_state!(true)
410
+ @agent.converge_state_and_update
431
411
  end
432
412
  end
433
413
 
@@ -442,10 +422,8 @@ class LogStash::Runner < Clamp::StrictCommand
442
422
  Stud::trap("INT") do
443
423
  if @interrupted_once
444
424
  logger.fatal(I18n.t("logstash.agent.forced_sigint"))
445
- # calling just Kernel.exit only raises SystemExit exception
446
- # and doesn't guarantee the process will terminate
447
- # We must call Kernel.exit! so java.lang.System.exit is called
448
- exit!
425
+ @agent.force_shutdown!
426
+ exit
449
427
  else
450
428
  logger.warn(I18n.t("logstash.agent.sigint"))
451
429
  Thread.new(logger) {|lg| sleep 5; lg.warn(I18n.t("logstash.agent.slow_shutdown")) }
@@ -476,7 +454,7 @@ class LogStash::Runner < Clamp::StrictCommand
476
454
  nil
477
455
  end
478
456
  end
479
-
457
+
480
458
  # is the user asking for CLI help subcommand?
481
459
  def cli_help?(args)
482
460
  # I know, double negative