bitgirder-platform 0.1.7

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.
Files changed (51) hide show
  1. data/LICENSE.txt +176 -0
  2. data/bin/ensure-test-db +117 -0
  3. data/bin/install-mysql +375 -0
  4. data/bin/tomcat7 +569 -0
  5. data/lib/bitgirder/concurrent.rb +400 -0
  6. data/lib/bitgirder/core.rb +1235 -0
  7. data/lib/bitgirder/etl.rb +58 -0
  8. data/lib/bitgirder/event/file.rb +485 -0
  9. data/lib/bitgirder/event/logger/testing.rb +140 -0
  10. data/lib/bitgirder/event/logger.rb +137 -0
  11. data/lib/bitgirder/event/testing.rb +88 -0
  12. data/lib/bitgirder/http.rb +255 -0
  13. data/lib/bitgirder/io/testing.rb +33 -0
  14. data/lib/bitgirder/io.rb +959 -0
  15. data/lib/bitgirder/irb.rb +35 -0
  16. data/lib/bitgirder/mysql.rb +60 -0
  17. data/lib/bitgirder/ops/java.rb +117 -0
  18. data/lib/bitgirder/ops/ruby.rb +235 -0
  19. data/lib/bitgirder/testing.rb +152 -0
  20. data/lib/doc-gen0.rb +0 -0
  21. data/lib/doc-gen1.rb +0 -0
  22. data/lib/doc-gen10.rb +0 -0
  23. data/lib/doc-gen11.rb +0 -0
  24. data/lib/doc-gen12.rb +0 -0
  25. data/lib/doc-gen13.rb +0 -0
  26. data/lib/doc-gen14.rb +0 -0
  27. data/lib/doc-gen15.rb +0 -0
  28. data/lib/doc-gen16.rb +0 -0
  29. data/lib/doc-gen17.rb +14 -0
  30. data/lib/doc-gen18.rb +0 -0
  31. data/lib/doc-gen19.rb +0 -0
  32. data/lib/doc-gen2.rb +0 -0
  33. data/lib/doc-gen20.rb +182 -0
  34. data/lib/doc-gen21.rb +0 -0
  35. data/lib/doc-gen3.rb +0 -0
  36. data/lib/doc-gen4.rb +0 -0
  37. data/lib/doc-gen5.rb +0 -0
  38. data/lib/doc-gen6.rb +0 -0
  39. data/lib/doc-gen7.rb +0 -0
  40. data/lib/doc-gen8.rb +0 -0
  41. data/lib/doc-gen9.rb +0 -0
  42. data/lib/mingle/bincodec.rb +512 -0
  43. data/lib/mingle/codec.rb +54 -0
  44. data/lib/mingle/http.rb +156 -0
  45. data/lib/mingle/io/stream.rb +142 -0
  46. data/lib/mingle/io.rb +160 -0
  47. data/lib/mingle/json.rb +257 -0
  48. data/lib/mingle/service.rb +110 -0
  49. data/lib/mingle-em.rb +92 -0
  50. data/lib/mingle.rb +2917 -0
  51. metadata +100 -0
@@ -0,0 +1,35 @@
1
+ require 'bitgirder/core'
2
+
3
+ require 'irb'
4
+
5
+ module BitGirder
6
+ module Irb
7
+
8
+ STATE = {}
9
+
10
+ def Irb.run( opts )
11
+
12
+ STATE[ :init_eval ] = opts[ :init_eval ]
13
+ IRB.start( __FILE__ )
14
+ end
15
+
16
+ end
17
+ end
18
+
19
+ module IRB
20
+
21
+ class Irb
22
+
23
+ BG_EVAL_INPUT_ORIG = instance_method( :eval_input )
24
+
25
+ def eval_input( *argv )
26
+
27
+ if ( script = BitGirder::Irb::STATE[ :init_eval ] )
28
+ @context.evaluate( script, 1 )
29
+ end
30
+
31
+ BG_EVAL_INPUT_ORIG.bind( self ).call( *argv )
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,60 @@
1
+ require 'bitgirder/core'
2
+
3
+ module BitGirder
4
+ module MySql
5
+
6
+ # Although the 3p Mysql module won't conflict with this module (cases differ
7
+ # on the 'S' in 'sql') we nevertheless reference the external module via
8
+ # this local instance variable to help avoid typo-related errors
9
+ require 'mysql'
10
+ @@mysql = Mysql # The 3p library we're working on top of
11
+
12
+ extend BitGirder::Core::BitGirderMethods
13
+
14
+ def self.connect_from_hash( h )
15
+
16
+ flattened = h.values_at( :host, :user, :password, :db, :port, :socket )
17
+ flattened << ( h[ :flag ] || 0 )
18
+
19
+ @@mysql.connect( *flattened )
20
+ end
21
+
22
+ def self.connect( *argv )
23
+
24
+ case argv.size
25
+
26
+ when 0 then raise "Need connect args"
27
+
28
+ when 1
29
+ case argv[ 0 ]
30
+ when Hash then connect_from_hash( argv[ 0 ] )
31
+ else @@mysql.connect( *argv ) # assume passthrough args
32
+ end
33
+
34
+ else raise ArgumentError, "Unexpected argv: #{argv}"
35
+ end
36
+ end
37
+
38
+ def self.open( *argv )
39
+
40
+ mysql = connect( *argv )
41
+
42
+ begin
43
+ yield( mysql )
44
+ ensure
45
+ mysql.close
46
+ end
47
+ end
48
+
49
+ def self.flush_privileges( db )
50
+
51
+ not_nil( db, :db )
52
+ db.query( "flush privileges" )
53
+ end
54
+
55
+ def self.quote( str )
56
+ @@mysql.quote( str )
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,117 @@
1
+ require 'bitgirder/core'
2
+ require 'bitgirder/io'
3
+
4
+ module BitGirder
5
+ module Ops
6
+ module Java
7
+
8
+ include BitGirder::Core
9
+
10
+ module JavaEnvironments
11
+
12
+ extend BitGirder::Core::BitGirderMethods
13
+
14
+ ENV_JAVA_HOME = "JAVA_HOME"
15
+
16
+ def get_java_home
17
+
18
+ if res = ENV[ ENV_JAVA_HOME ]
19
+ if File.exist?( res )
20
+ res
21
+ else
22
+ raise
23
+ "Location specified in #{ENV_JAVA_HOME} doesn't exist: " +
24
+ res
25
+ end
26
+ else
27
+ if jv = Io.which( "java" )
28
+ File.dirname( File.dirname( jv ) )
29
+ else
30
+ raise "#{ENV_JAVA_HOME} is not set and no 'java' found on path"
31
+ end
32
+ end
33
+ end
34
+
35
+ module_function :get_java_home
36
+ end
37
+
38
+ class JavaEnvironment < BitGirderClass
39
+
40
+ include BitGirder::Io
41
+
42
+ bg_attr :java_home, :validation => :file_exists
43
+
44
+ public
45
+ def jcmd( cmd )
46
+
47
+ not_nil( cmd, :cmd )
48
+ file_exists( "#@java_home/bin/#{cmd}" )
49
+ end
50
+
51
+ public
52
+ def as_classpath( val )
53
+
54
+ if val.respond_to?( :join )
55
+ val.join( ":" )
56
+ else
57
+ val.to_s
58
+ end
59
+ end
60
+
61
+ def self.get_default
62
+ self.new( :java_home => JavaEnvironments.get_java_home )
63
+ end
64
+ end
65
+
66
+ class JavaRunner < BitGirderClass
67
+
68
+ bg_attr :java_env
69
+ bg_attr :command
70
+ bg_attr :classpath, :default => proc { [] }
71
+ bg_attr :jvm_args, :default => proc { [] }
72
+ bg_attr :sys_props, :default => proc { {} }
73
+ bg_attr :argv, :validation => :not_empty
74
+ bg_attr :proc_env, :default => proc { {} }
75
+ bg_attr :proc_opts, :default => proc { {} }
76
+
77
+ private
78
+ def create_jv_argv
79
+
80
+ res = []
81
+
82
+ unless @classpath.empty?
83
+ res << "-classpath" << @java_env.as_classpath( @classpath )
84
+ end
85
+
86
+ res += @jvm_args
87
+ @sys_props.each_pair { |k, v| res << "-D#{k}=#{v}" }
88
+ res += argv
89
+
90
+ res.map { |v| v.to_s }
91
+ end
92
+
93
+ public
94
+ def process_builder
95
+
96
+ BitGirder::Io::UnixProcessBuilder.new(
97
+ :cmd => @java_env.jcmd( @command ),
98
+ :argv => create_jv_argv,
99
+ :env => @proc_env,
100
+ :opts => @proc_opts
101
+ )
102
+ end
103
+
104
+ def self.create_application_runner( opts )
105
+
106
+ not_nil( opts, :opts )
107
+
108
+ argv = [ has_key( opts, :main ) ]
109
+ argv += ( opts[ :argv ] || [] )
110
+
111
+ JavaRunner.new( opts.merge( :command => "java", :argv => argv ) )
112
+ end
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,235 @@
1
+ require 'bitgirder/core'
2
+ require 'bitgirder/io'
3
+
4
+ module BitGirder
5
+ module Ops
6
+ module Ruby
7
+
8
+ module RubyEnvVarNames
9
+ ENV_GEM_HOME = "GEM_HOME"
10
+ ENV_RUBYLIB = "RUBYLIB"
11
+ ENV_PATH = "PATH"
12
+ end
13
+
14
+ module RubyIncludes
15
+
16
+ extend BitGirder::Core::BitGirderMethods
17
+
18
+ extend BitGirder::Io
19
+
20
+ # clean up adjacent slashes and other things that can be unsightly and in
21
+ # some cases cause more serious problems
22
+ def self.clean_include_dir_names( dirs )
23
+
24
+ dirs.map { |dir| dir.gsub( %r{/+}, "/" ) }.
25
+ map { |dir| dir.sub( %r{/$}, "" ) }
26
+ end
27
+
28
+ def self.get_single_dir( dir, pat )
29
+
30
+ res =
31
+ Dir.chdir( dir ) do |dir|
32
+ Dir.glob( "*" ).
33
+ select { |f| File.directory?( f ) }.
34
+ grep( pat )
35
+ end
36
+
37
+ case res.size
38
+
39
+ when 0 then nil
40
+ when 1 then res[ 0 ]
41
+ else raise "Multiple directories in #{dir} match #{pat}"
42
+ end
43
+ end
44
+
45
+ def self.expect_single_dir( dir, pat )
46
+
47
+ self.get_single_dir( dir, pat ) or
48
+ raise "Couldn't find entry in #{dir} matching #{pat}"
49
+ end
50
+
51
+ def self.infer_version_str( lib_dir )
52
+ self.expect_single_dir( lib_dir, /^\d+(?:\.\d+)*$/ )
53
+ end
54
+
55
+ def self.get_arch_dir( dir )
56
+
57
+ self.get_single_dir(
58
+ dir, /^(?:i\d86|x86_64).*(?:darwin|linux|solaris)/ )
59
+ end
60
+
61
+ def self.get_ruby_include_dirs( opts )
62
+
63
+ ruby_home = has_key( opts, :ruby_home )
64
+ lib_dir = file_exists( "#{ruby_home}/lib/ruby" )
65
+
66
+ ver = opts[ :version ] || self.infer_version_str( lib_dir )
67
+
68
+ res = [ "", "site_ruby", "vendor_ruby" ].inject( [] ) do |res, dir|
69
+
70
+ dir = file_exists( "#{lib_dir}/#{dir}/#{ver}" )
71
+ res << dir
72
+
73
+ if arch_dir = self.get_arch_dir( dir )
74
+ res << "#{dir}/#{arch_dir}"
75
+ end
76
+
77
+ res
78
+ end
79
+
80
+ self.clean_include_dir_names( res )
81
+ end
82
+
83
+ def self.as_include_argv( incl_dirs )
84
+ incl_dirs.map { |dir| [ "-I", dir ] }.flatten
85
+ end
86
+ end
87
+
88
+ class RubyContext < BitGirderClass
89
+
90
+ require 'set'
91
+
92
+ bg_attr :id
93
+ bg_attr :gem_home, validation: :file_exists
94
+ bg_attr :ruby_home, validation: :file_exists
95
+ bg_attr :ruby_flavor, required: false
96
+ bg_attr :env, default: {}
97
+
98
+ def rcmd( cmd, alts = true )
99
+
100
+ not_nil( cmd, :cmd )
101
+
102
+ cmds = [ cmd ]
103
+ cmds << "j#{cmd}" if alts
104
+
105
+ bin_dirs = [ @gem_home, @ruby_home ].map { |dir| "#{dir}/bin" }
106
+ files = bin_dirs.map { |bd| cmds.map { |cmd| "#{bd}/#{cmd}" } }.flatten
107
+
108
+ files.find { |f| File.exist?( f ) } or
109
+ raise "No #{cmd} in #{bin_dirs.join( " or " )}"
110
+ end
111
+
112
+ def prepend_path_ruby_home
113
+ "#@gem_home/bin:#@ruby_home/bin:#{ENV[ ENV_PATH ]}"
114
+ end
115
+
116
+ def get_ruby_include_dirs
117
+
118
+ if @ruby_flavor == "jruby"
119
+ []
120
+ else
121
+ RubyIncludes.get_ruby_include_dirs( ruby_home: @ruby_home )
122
+ end
123
+ end
124
+
125
+ def get_env_var_rubylib
126
+
127
+ res = get_ruby_include_dirs.join( ":" )
128
+
129
+ if prev = ENV[ ENV_RUBYLIB ]
130
+ res << ":#{prev}"
131
+ end
132
+
133
+ res
134
+ end
135
+
136
+ def proc_builder_opts( cmd = nil )
137
+
138
+ opts = { opts: {}, argv: [] }
139
+
140
+ opts[ :env ] = @env.merge(
141
+ ENV_GEM_HOME => @gem_home,
142
+ ENV_PATH => prepend_path_ruby_home,
143
+ )
144
+
145
+ opts[ :cmd ] = rcmd( cmd ) if cmd
146
+
147
+ opts
148
+ end
149
+
150
+ def self.read_env_in( s )
151
+
152
+ ( s[ :env ] || [] ).inject( {} ) do |env, pair|
153
+
154
+ nm, val = pair[ 0 ], pair[ 1 ]
155
+
156
+ if env.key?( nm )
157
+ raise "Multiple definitions of env var #{nm}"
158
+ else
159
+ env[ nm ] = val
160
+ end
161
+
162
+ env
163
+ end
164
+ end
165
+
166
+ def self.from_mingle_struct( s )
167
+
168
+ self.new(
169
+ id: s.expect_string( :id ),
170
+ ruby_home: s.expect_string( :ruby_home ),
171
+ gem_home: s.expect_string( :gem_home ),
172
+ ruby_flavor: s.get_string( :ruby_flavor ),
173
+ env: read_env_in( s )
174
+ )
175
+ end
176
+ end
177
+
178
+ class RubyEnv < BitGirderClass
179
+
180
+ bg_attr :rubies
181
+ bg_attr :default_id, required: false # name of default ruby
182
+
183
+ def initialize( *argv )
184
+
185
+ super( *argv )
186
+
187
+ if @default_id
188
+ unless @rubies.key?( @default_id )
189
+ raise "Default id #@default_id not a defined ruby"
190
+ end
191
+ end
192
+ end
193
+
194
+ def get_context( id = nil )
195
+
196
+ if id
197
+ @rubies[ id ] or raise "No ruby context with id: #{id}"
198
+ else
199
+ if @default_id
200
+ @rubies[ @default_id ] or
201
+ raise "Default context #@default_id not set (!?)"
202
+ else
203
+ raise "No default ruby context set"
204
+ end
205
+ end
206
+ end
207
+
208
+ def self.read_rubies_in( s )
209
+
210
+ ( s[ :rubies ] || [] ).inject( {} ) do |res, mg_ctx|
211
+
212
+ ctx = RubyContext.from_mingle_struct( mg_ctx )
213
+
214
+ if res.key?( ctx.id )
215
+ raise "Env has multiple ruby contexts with id: #{ctx.id}"
216
+ else
217
+ res[ ctx.id ] = ctx
218
+ end
219
+
220
+ res
221
+ end
222
+ end
223
+
224
+ def self.from_mingle_struct( s )
225
+
226
+ self.new(
227
+ rubies: self.read_rubies_in( s ),
228
+ default_id: s.get_string( :default_ruby ),
229
+ )
230
+ end
231
+ end
232
+
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,152 @@
1
+ require 'bitgirder/core'
2
+
3
+ module BitGirder
4
+ module Testing
5
+
6
+ ENV_TEST_DATA_PATH = "TEST_DATA_PATH"
7
+
8
+ def self.find_test_data( name )
9
+
10
+ ( ENV[ ENV_TEST_DATA_PATH ] || "" ).split( ":" ).
11
+ map { |path| "#{path}/#{name}" }.
12
+ find { |f| File.exists?( f ) } or
13
+ raise "No #{name} found on path $#{ENV_TEST_DATA_PATH}"
14
+ end
15
+
16
+ class AssertionFailure < StandardError; end
17
+
18
+ module BeforePhase; end
19
+ module TestPhase; end
20
+ module AfterPhase; end
21
+
22
+ module AssertMethods
23
+
24
+ include BitGirder::Core::BitGirderMethods
25
+
26
+ def fail_test( msg = nil )
27
+
28
+ msg = msg.call if msg.is_a?( Proc )
29
+ raise AssertionFailure.new( msg )
30
+ end
31
+
32
+ def assert( passed, msg = nil )
33
+ fail_test( msg ) unless passed
34
+ end
35
+
36
+ def assert_false( val, *argv )
37
+ assert( ! val, *argv )
38
+ end
39
+
40
+ def assert_equal( expct, actual, msg = nil )
41
+
42
+ unless expct == actual
43
+ fail_test( msg || "expct != actual (#{expct} != #{actual})" )
44
+ end
45
+ end
46
+
47
+ def assert_equal_meth( expct_obj, actual_obj, meth, msg = nil )
48
+
49
+ not_nil( meth, :meth )
50
+ assert_equal( expct_obj.send( meth ), actual_obj.send( meth ), msg )
51
+ end
52
+
53
+ def assert_equal_i( expct, actual, msg = nil )
54
+ assert_equal_meth( expct, actual, :to_i, msg )
55
+ end
56
+
57
+ def assert_equal_s( expct, actual, msg = nil )
58
+ assert_equal_meth( expct, actual, :to_s, msg )
59
+ end
60
+
61
+ def assert_nil( val, msg = nil )
62
+ assert( val == nil, msg ||= "Expected nil but got #{val}" )
63
+ end
64
+
65
+ def assert_match( pat, str, msg = nil )
66
+
67
+ msg ||= lambda { "#{str.inspect} does not match #{pat}" }
68
+ assert( pat.match( str ), msg )
69
+ end
70
+
71
+ def get_expect_raised_pat( excpts )
72
+
73
+ case excpts[ 0 ]
74
+ when String then Regexp.new( /^#{Regexp.quote( excpts.shift )}$/ )
75
+ when Regexp then excpts.shift
76
+ else nil
77
+ end
78
+ end
79
+
80
+ def assert_raised( *excpts )
81
+
82
+ res = nil
83
+
84
+ pat = get_expect_raised_pat( excpts )
85
+
86
+ begin
87
+ yield
88
+ rescue *excpts => e; # got an expected exception
89
+ res = e
90
+ rescue Exception => e
91
+ raise e
92
+ end
93
+
94
+ if pat && res
95
+ pat.match( res.message ) or
96
+ raise "Message #{res.message.inspect} does not match #{pat}"
97
+ end
98
+
99
+ # res or raise "No expected exception raised"
100
+ res or fail_test( "Expected raise of one of #{excpts.inspect}" )
101
+ end
102
+ end
103
+
104
+ #def assert_raise( *argv, &blk ); assert_raised( *argv, &blk ); end
105
+
106
+ # May also have a base class TestClass for classes that want it
107
+ module TestClassMixin
108
+ include AssertMethods
109
+ end
110
+
111
+ class AbstractPhaseClass < BitGirder::Core::BitGirderClass
112
+
113
+ include AssertMethods
114
+
115
+ bg_abstract :start_impl
116
+
117
+ public
118
+ def start_invocation( ctx )
119
+
120
+ @ctx = ctx
121
+ start_impl
122
+ end
123
+
124
+ private
125
+ def inst_set( fld, val )
126
+
127
+ not_nil( fld, :fld )
128
+ @ctx.inst.instance_variable_set( :"@#{fld}", val )
129
+ end
130
+
131
+ private
132
+ def inst_get( fld )
133
+
134
+ not_nil( fld, :fld )
135
+ @ctx.inst.instance_variable_get( :"@#{fld}" )
136
+ end
137
+ end
138
+
139
+ class TestHolder < BitGirder::Core::BitGirderClass
140
+
141
+ def self.inherited( by )
142
+ by.send( :include, TestClassMixin )
143
+ end
144
+ end
145
+
146
+ class TestRunClass < AbstractPhaseClass
147
+ include TestClassMixin
148
+ include TestPhase
149
+ end
150
+
151
+ end
152
+ end
data/lib/doc-gen0.rb ADDED
File without changes
data/lib/doc-gen1.rb ADDED
File without changes
data/lib/doc-gen10.rb ADDED
File without changes
data/lib/doc-gen11.rb ADDED
File without changes
data/lib/doc-gen12.rb ADDED
File without changes
data/lib/doc-gen13.rb ADDED
File without changes
data/lib/doc-gen14.rb ADDED
File without changes
data/lib/doc-gen15.rb ADDED
File without changes
data/lib/doc-gen16.rb ADDED
File without changes
data/lib/doc-gen17.rb ADDED
@@ -0,0 +1,14 @@
1
+
2
+ # Autogenerated docs on 2012-11-21 11:47:21 -0800
3
+ #
4
+
5
+ # This code is only included for rdoc purposes and would not normally get
6
+ # required. Even so, in case of overzealous scripts which might auto-require
7
+ # this file, we enclose the entire body of this file in a guard that will
8
+ # prevent it from being interpreted in an actual run
9
+ #
10
+ if false
11
+
12
+
13
+ end # 'if false...' block
14
+
data/lib/doc-gen18.rb ADDED
File without changes
data/lib/doc-gen19.rb ADDED
File without changes
data/lib/doc-gen2.rb ADDED
File without changes