logstash-core 1.5.0.beta2-java → 1.5.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core.rb +2 -0
  3. data/lib/logstash/agent.rb +0 -41
  4. data/lib/logstash/config/config_ast.rb +62 -29
  5. data/lib/logstash/config/mixin.rb +3 -3
  6. data/lib/logstash/environment.rb +37 -100
  7. data/lib/logstash/event.rb +32 -20
  8. data/lib/logstash/filters/base.rb +20 -0
  9. data/lib/logstash/java_integration.rb +72 -18
  10. data/lib/logstash/namespace.rb +0 -3
  11. data/lib/logstash/outputs/base.rb +1 -1
  12. data/lib/logstash/patches/bundler.rb +20 -0
  13. data/lib/logstash/patches/rubygems.rb +37 -0
  14. data/lib/logstash/pipeline.rb +59 -39
  15. data/lib/logstash/runner.rb +4 -50
  16. data/lib/logstash/util.rb +0 -1
  17. data/lib/logstash/util/accessors.rb +6 -0
  18. data/lib/logstash/version.rb +1 -1
  19. data/locales/en.yml +5 -0
  20. data/logstash-core.gemspec +51 -0
  21. data/spec/core/conditionals_spec.rb +428 -0
  22. data/spec/core/config_mixin_spec.rb +99 -0
  23. data/spec/core/config_spec.rb +108 -0
  24. data/spec/core/environment_spec.rb +44 -0
  25. data/spec/core/event_spec.rb +473 -0
  26. data/spec/core/pipeline_spec.rb +198 -0
  27. data/spec/core/plugin_spec.rb +106 -0
  28. data/spec/core/runner_spec.rb +39 -0
  29. data/spec/core/timestamp_spec.rb +83 -0
  30. data/spec/filters/base_spec.rb +318 -0
  31. data/spec/inputs/base_spec.rb +13 -0
  32. data/spec/lib/logstash/bundler_spec.rb +120 -0
  33. data/spec/lib/logstash/java_integration_spec.rb +257 -0
  34. data/spec/logstash/agent_spec.rb +37 -0
  35. data/spec/outputs/base_spec.rb +47 -0
  36. data/spec/spec_helper.rb +1 -0
  37. data/spec/util/accessors_spec.rb +215 -0
  38. data/spec/util/charset_spec.rb +74 -0
  39. data/spec/util/fieldeval_spec.rb +96 -0
  40. data/spec/util/gemfile_spec.rb +212 -0
  41. data/spec/util/json_spec.rb +97 -0
  42. data/spec/util/plugin_version_spec.rb +48 -0
  43. data/spec/util/retryable_spec.rb +145 -0
  44. data/spec/util_spec.rb +34 -0
  45. metadata +96 -253
  46. data/lib/logstash-event.rb +0 -2
  47. data/lib/logstash.rb +0 -4
  48. data/lib/logstash/JRUBY-PR1448.rb +0 -32
  49. data/lib/logstash/bundler.rb +0 -124
  50. data/lib/logstash/gemfile.rb +0 -175
  51. data/lib/logstash/pluginmanager.rb +0 -17
  52. data/lib/logstash/pluginmanager/install.rb +0 -112
  53. data/lib/logstash/pluginmanager/list.rb +0 -38
  54. data/lib/logstash/pluginmanager/main.rb +0 -22
  55. data/lib/logstash/pluginmanager/maven_tools_patch.rb +0 -12
  56. data/lib/logstash/pluginmanager/uninstall.rb +0 -49
  57. data/lib/logstash/pluginmanager/update.rb +0 -50
  58. data/lib/logstash/pluginmanager/util.rb +0 -88
@@ -1,2 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/event"
@@ -1,4 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/agent"
3
- require "logstash/event"
4
- require "logstash/namespace"
@@ -1,32 +0,0 @@
1
- # This patch fixes a problem that exists in JRuby prior to 1.7.11 where the
2
- # ruby binary path used by rubygems is malformed on Windows, causing
3
- # dependencies to not install cleanly when using `.\bin\logstash.bat deps`.
4
- # This monkeypatch can probably be removed once it's unlikely that people
5
- # are still using JRuby older than 1.7.11.
6
- class << Gem
7
- def ruby
8
- ruby_path = original_ruby
9
- ruby_path = "java -jar #{jar_path(ruby_path)}" if jarred_path?(ruby_path)
10
- ruby_path
11
- end
12
-
13
- def jarred_path?(p)
14
- p =~ /^file:/
15
- end
16
-
17
- # A jar path looks like this on non-Windows platforms:
18
- # file:/path/to/file.jar!/path/within/jar/to/file.txt
19
- # and like this on Windows:
20
- # file:/C:/path/to/file.jar!/path/within/jar/to/file.txt
21
- #
22
- # This method returns:
23
- # /path/to/file.jar
24
- # or
25
- # C:/path/to/file.jar
26
- # as appropriate.
27
- def jar_path(p)
28
- path = p.sub(/^file:/, "").sub(/!.*/, "")
29
- path = path.sub(/^\//, "") if win_platform? && path =~ /^\/[A-Za-z]:/
30
- path
31
- end
32
- end
@@ -1,124 +0,0 @@
1
- require "bundler"
2
- require "bundler/cli"
3
-
4
- module Bundler
5
- # Patch bundler to write a .lock file specific to the version of ruby.
6
- # This keeps MRI/JRuby/RBX from conflicting over the Gemfile.lock updates
7
- module SharedHelpers
8
- def default_lockfile
9
- ruby = "#{LogStash::Environment.ruby_engine}-#{LogStash::Environment.ruby_abi_version}"
10
- Pathname.new("#{default_gemfile}.#{ruby}.lock")
11
- end
12
- end
13
-
14
- # Add the Bundler.reset! method which has been added in master but is not in 1.7.9.
15
- class << self
16
- unless self.method_defined?("reset!")
17
- def reset!
18
- @definition = nil
19
- end
20
- end
21
-
22
- def reset_settings
23
- # reset!
24
- # clear_gemspec_cache
25
-
26
- # remove_instance_variable(:@setup) if defined?(@setup)
27
- # remove_instance_variable(:@locked_gems) if defined?(@locked_gems)
28
- # remove_instance_variable(:@load) if defined?(@load)
29
- remove_instance_variable(:@settings) if defined?(@settings)
30
- end
31
- end
32
- end
33
-
34
- module LogStash
35
- module Bundler
36
-
37
- # capture any $stdout from the passed block. also trap any exception in that block, in which case the trapped exception will be returned
38
- # @param [Proc] the code block to execute
39
- # @return [String, Exception] the captured $stdout string and any trapped exception or nil if none
40
- def self.capture_stdout(&block)
41
- old_stdout = $stdout
42
- $stdout = StringIO.new("", "w")
43
- begin
44
- block.call
45
- rescue => e
46
- return [$stdout.string, e]
47
- end
48
-
49
- [$stdout.string, nil]
50
- ensure
51
- $stdout = old_stdout
52
- end
53
-
54
- # execute bundle install and capture any $stdout output. any raised exception in the process will be trapped
55
- # and returned. logs errors to $stdout.
56
- # @param options [Hash] invoke options with default values, :max_tries => 10, :clean => false, :install => false, :update => false
57
- # @param options[:update] must be either false or a String or an Array of String
58
- # @return [String, Exception] the installation captured output and any raised exception or nil if none
59
- def self.invoke_bundler!(options = {})
60
- options = {:max_tries => 10, :clean => false, :install => false, :update => false, :without => [:development]}.merge(options)
61
- options[:without] = Array(options[:without])
62
- options[:update] = Array(options[:update]) if options[:update]
63
-
64
- ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home
65
- ENV["BUNDLE_PATH"] = LogStash::Environment::BUNDLE_DIR
66
- ENV["BUNDLE_GEMFILE"] = LogStash::Environment::GEMFILE_PATH
67
- ENV["BUNDLE_WITHOUT"] = options[:without].join(":")
68
-
69
- try = 0
70
-
71
- # capture_stdout also traps any raised exception and pass them back as the function return [output, exception]
72
- capture_stdout do
73
- loop do
74
- begin
75
- ::Bundler.reset!
76
- ::Bundler::CLI.start(bundler_arguments(options))
77
- break
78
- rescue ::Bundler::VersionConflict => e
79
- $stderr.puts("Plugin version conflict, aborting")
80
- raise(e)
81
- rescue ::Bundler::GemNotFound => e
82
- $stderr.puts("Plugin not found, aborting")
83
- raise(e)
84
- rescue => e
85
- if try >= options[:max_tries]
86
- $stderr.puts("Too many retries, aborting, caused by #{e.class}")
87
- $stderr.puts(e.message) if ENV["DEBUG"]
88
- raise(e)
89
- end
90
-
91
- try += 1
92
- $stderr.puts("Error #{e.class}, retrying #{try}/#{options[:max_tries]}")
93
- $stderr.puts(e.message) if ENV["DEBUG"]
94
- sleep(0.5)
95
- end
96
- end
97
- end
98
- end
99
-
100
- # build Bundler::CLI.start arguments array from the given options hash
101
- # @param option [Hash] the invoke_bundler! options hash
102
- # @return [Array<String>] Bundler::CLI.start string arguments array
103
- def self.bundler_arguments(options = {})
104
- arguments = []
105
-
106
- if options[:install]
107
- arguments << "install"
108
- arguments << "--gemfile=#{LogStash::Environment::GEMFILE_PATH}"
109
- arguments << ["--path", LogStash::Environment::BUNDLE_DIR]
110
- # note that generating "--without=" when options[:without] is empty is intended
111
- arguments << "--without=#{options[:without].join(' ')}"
112
- end
113
-
114
- if options[:update]
115
- arguments << "update"
116
- arguments << options[:update]
117
- end
118
-
119
- arguments << "--clean" if options[:clean]
120
-
121
- arguments.flatten
122
- end
123
- end
124
- end
@@ -1,175 +0,0 @@
1
- module LogStash
2
-
3
- class GemfileError < StandardError; end
4
-
5
- class Gemfile
6
- attr_accessor :gemset
7
-
8
- HEADER = \
9
- "# This is a Logstash generated Gemfile.\n" + \
10
- "# If you modify this file manually all comments and formatting will be lost.\n\n"
11
-
12
- # @params io [IO] any IO object that supports read, write, truncate, rewind
13
- def initialize(io)
14
- @io = io
15
- @gemset = nil
16
- end
17
-
18
- def load
19
- @gemset ||= DSL.parse(@io.read)
20
- self
21
- end
22
-
23
- def save
24
- raise(GemfileError, "a Gemfile must first be loaded") unless @gemset
25
- @io.truncate(0)
26
- @io.rewind
27
- @io.write(HEADER)
28
- @io.write(@gemset.to_s)
29
- @io.flush
30
- end
31
-
32
- def find(name)
33
- @gemset.find_gem(name)
34
- end
35
-
36
- # @param name [String] gem name
37
- # @param *requirements params following name use the same notation as the Gemfile gem DSL statement
38
- # @raise GemfileError if gem already exists in Gemfile
39
- def add(name, *requirements)
40
- @gemset.add_gem(Gem.parse(name, *requirements))
41
- end
42
-
43
- # update existing or add new
44
- # @param name [String] gem name
45
- # @param *requirements params following name use the same notation as the Gemfile gem DSL statement
46
- def update(name, *requirements)
47
- @gemset.update_gem(Gem.parse(name, *requirements))
48
- end
49
-
50
- # @return [Gem] removed gem or nil if not found
51
- def remove(name)
52
- @gemset.remove_gem(name)
53
- end
54
- end
55
-
56
- class Gemset
57
- attr_accessor :sources, :gems, :gemspec
58
-
59
- def initialize
60
- @sources = [] # list of urls
61
- @gems = [] # list of Gem class
62
- @gems_by_name = {} # hash of name => Gem
63
- @gemspec = {} # gemspec is a options hash
64
- end
65
-
66
- def to_s
67
- [sources_to_s, gemspec_to_s, gems_to_s].select{|s| !s.empty?}.join("\n") + "\n"
68
- end
69
-
70
- # @return [Gem] found gem or nil if not found
71
- def find_gem(name)
72
- @gems_by_name[name.downcase]
73
- end
74
-
75
- # @raise GemfileError if gem already exists
76
- def add_gem(_gem)
77
- raise(GemfileError, "duplicate gem #{_gem.name}") if find_gem(_gem.name)
78
- @gems << _gem
79
- @gems_by_name[_gem.name.downcase] = _gem
80
- end
81
-
82
- # update existing or add new
83
- def update_gem(_gem)
84
- if old = find_gem(_gem.name)
85
- @gems[@gems.index(old)] = _gem
86
- else
87
- @gems << _gem
88
- end
89
- @gems_by_name[_gem.name.downcase] = _gem
90
- end
91
-
92
- # @return [Gem] removed gem or nil if not found
93
- def remove_gem(name)
94
- if _gem = @gems_by_name.delete(name.downcase)
95
- @gems.delete_at(@gems.index(_gem))
96
- end
97
- _gem
98
- end
99
-
100
- # deep clone self
101
- def copy
102
- Marshal.load(Marshal.dump(self))
103
- end
104
-
105
- private
106
-
107
- def sources_to_s
108
- return "" if @sources.empty?
109
- @sources.map{|source| "source #{source.inspect}"}.join("\n")
110
- end
111
-
112
- def gems_to_s
113
- return "" if @gems.empty?
114
- @gems.map do |gem|
115
- requirements = gem.requirements.empty? ? nil : gem.requirements.map{|r| r.inspect}.join(", ")
116
- options = gem.options.empty? ? nil : gem.options.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
117
- "gem " + [gem.name.inspect, requirements, options].compact.join(", ")
118
- end.join("\n")
119
- end
120
-
121
- def gemspec_to_s
122
- return "" if @gemspec.empty?
123
- options = @gemspec.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
124
- "gemspec #{options}"
125
- end
126
- end
127
-
128
- # DSL is a minimal, incomplete Gemfile DSL subset parser, only what is currently required is implemented.
129
- class DSL
130
- attr_reader :gemset
131
-
132
- def initialize
133
- @gemset = Gemset.new
134
- end
135
-
136
- # @param gemfile_content [String] the Gemfile string content
137
- # @return [Gemset] parsed Gemfile content as a Gemset
138
- def self.parse(gemfile_content)
139
- dsl = self.new
140
- dsl.instance_eval(gemfile_content)
141
- dsl.gemset
142
- end
143
-
144
- # DSL methods
145
-
146
- def source(url)
147
- @gemset.sources << url
148
- end
149
-
150
- def gem(name, *requirements)
151
- parsed = Gem.parse(name, *requirements)
152
- @gemset.add_gem(parsed)
153
- end
154
-
155
- def gemspec(options = {})
156
- raise(GemfileError, "cannot declare multiple gemspec directives") unless @gemset.gemspec.empty?
157
- @gemset.gemspec = options
158
- end
159
- end
160
-
161
- class Gem
162
- attr_accessor :name, :requirements, :options
163
-
164
- def initialize(name, requirements = [], options = {})
165
- @name = name
166
- @requirements = requirements.map{|r| r.to_s.strip}.select{|r| !r.empty?}
167
- @options = options
168
- end
169
-
170
- def self.parse(name, *requirements)
171
- options = requirements.last.is_a?(Hash) ? requirements.pop : {}
172
- self.new(name, requirements, options)
173
- end
174
- end
175
- end
@@ -1,17 +0,0 @@
1
- $DEBUGLIST = (ENV["DEBUG"] || "").split(",")
2
-
3
- require "logstash/environment"
4
-
5
- ENV["GEM_HOME"] = ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home
6
- Gem.use_paths(LogStash::Environment.logstash_gem_home)
7
-
8
- require 'logstash/pluginmanager/main'
9
-
10
- if __FILE__ == $0
11
- begin
12
- LogStash::PluginManager::Main.run("bin/plugin", ARGV)
13
- rescue LogStash::PluginManager::Error => e
14
- $stderr.puts(e.message)
15
- exit(1)
16
- end
17
- end
@@ -1,112 +0,0 @@
1
- require 'clamp'
2
- require 'logstash/namespace'
3
- require 'logstash/environment'
4
- require 'logstash/pluginmanager/util'
5
- require 'jar-dependencies'
6
- require 'jar_install_post_install_hook'
7
- require 'file-dependencies/gem'
8
-
9
- require "logstash/gemfile"
10
- require "logstash/bundler"
11
-
12
- class LogStash::PluginManager::Install < Clamp::Command
13
- parameter "[PLUGIN] ...", "plugin name(s) or file"
14
- option "--version", "VERSION", "version of the plugin to install"
15
- option "--[no-]verify", :flag, "verify plugin validity before installation", :default => true
16
- option "--development", :flag, "install all development dependencies of currently installed plugins", :default => false
17
-
18
- # the install logic below support installing multiple plugins with each a version specification
19
- # but the argument parsing does not support it for now so currently if specifying --version only
20
- # one plugin name can be also specified.
21
- #
22
- # TODO: find right syntax to allow specifying list of plugins with optional version specification for each
23
-
24
- def execute
25
- if development?
26
- raise(LogStash::PluginManager::Error, "Cannot specify plugin(s) with --development, it will add the development dependencies of the currently installed plugins") unless plugin_list.empty?
27
- else
28
- raise(LogStash::PluginManager::Error, "No plugin specified") if plugin_list.empty? && verify?
29
-
30
- # temporary until we fullfil TODO ^^
31
- raise(LogStash::PluginManager::Error, "Only 1 plugin name can be specified with --version") if version && plugin_list.size > 1
32
- end
33
- raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
34
-
35
- gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
36
- # keep a copy of the gemset to revert on error
37
- original_gemset = gemfile.gemset.copy
38
-
39
- # force Rubygems sources to our Gemfile sources
40
- Gem.sources = gemfile.gemset.sources
41
-
42
- # install_list will be an array of [plugin name, version] tuples, version can be nil
43
- install_list = []
44
-
45
- if development?
46
- specs = LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile)
47
- install_list = specs.inject([]) do |result, spec|
48
- result = result + spec.dependencies.select{|dep| dep.type == :development}.map{|dep| [dep.name] + dep.requirement.as_list + [{:group => :development}]}
49
- end
50
- else
51
- # at this point we know that plugin_list is not empty and if the --version is specified there is only one plugin in plugin_list
52
-
53
- install_list = version ? [plugin_list << version] : plugin_list.map{|plugin| [plugin, nil]}
54
-
55
- install_list.each do |plugin, version|
56
- puts("Validating #{[plugin, version].compact.join("-")}")
57
- raise(LogStash::PluginManager::Error, "Installation aborted") unless LogStash::PluginManager.logstash_plugin?(plugin, version)
58
- end if verify?
59
-
60
- # at this point we know that we either have a valid gem name & version or a valid .gem file path
61
-
62
- # if LogStash::PluginManager.plugin_file?(plugin)
63
- # raise(LogStash::PluginManager::Error) unless cache_gem_file(plugin)
64
- # spec = LogStash::PluginManager.plugin_file_spec(plugin)
65
- # gemfile.update(spec.name, spec.version.to_s)
66
- # else
67
- # plugins.each{|tuple| gemfile.update(*tuple)}
68
- # end
69
- end
70
-
71
-
72
- install_list = LogStash::PluginManager.merge_duplicates(install_list)
73
- install_list.each{|plugin, version| gemfile.update(plugin, version)}
74
- gemfile.save
75
-
76
- puts("Installing" + (install_list.empty? ? "..." : " " + install_list.map{|plugin, version| plugin}.join(", ")))
77
-
78
- bundler_options = {:install => true}
79
- bundler_options[:without] = [] if development?
80
-
81
- # any errors will be logged to $stderr by invoke_bundler!
82
- output, exception = LogStash::Bundler.invoke_bundler!(bundler_options)
83
-
84
- if ENV["DEBUG"]
85
- $stderr.puts(output)
86
- $stderr.puts("Error: #{exception.class}, #{exception.message}") if exception
87
- end
88
-
89
- if exception
90
- # revert to original Gemfile content
91
- gemfile.gemset = original_gemset
92
- gemfile.save
93
- raise(LogStash::PluginManager::Error, "Installation aborted")
94
- end
95
-
96
- puts("Installation successful")
97
- end
98
-
99
- # copy .gem file into bundler cache directory, log any error to $stderr
100
- # @param path [String] the source .gem file to copy
101
- # @return [Boolean] true if successful
102
- def cache_gem_file(path)
103
- dest = ::File.join(LogStash::Environment.logstash_gem_home, "cache")
104
- begin
105
- FileUtils.cp(path, dest)
106
- rescue => e
107
- $stderr.puts("Error copying #{plugin} to #{dest}, caused by #{e.class}")
108
- return false
109
- end
110
- true
111
- end
112
- end # class Logstash::PluginManager