LanGrove 0.0.1 → 0.0.2

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 (84) hide show
  1. data/.watchr +11 -3
  2. data/Rakefile +12 -5
  3. data/functional/.gitignore +1 -0
  4. data/{bin/datagram_example → functional/bin/datagram} +2 -0
  5. data/{config/environments/development.rb → functional/config/.gitignore} +0 -0
  6. data/{config → functional/config}/boot.rb +0 -0
  7. data/functional/config/daemons.yml +12 -0
  8. data/{config → functional/config}/environment.rb +0 -0
  9. data/{config/environments/production.rb → functional/config/environments/development.rb} +0 -0
  10. data/{config/environments/test.rb → functional/config/environments/production.rb} +0 -0
  11. data/{lib/jobs/Rakefile → functional/config/environments/test.rb} +0 -0
  12. data/functional/lib/daemon/datagram.rb +23 -0
  13. data/functional/lib/handler/socket_to_file.rb +36 -0
  14. data/functional/lib/protocol/socket_to_file.rb +55 -0
  15. data/{libexec → functional/libexec}/daemon.rb +14 -3
  16. data/functional/log/.gitignore +3 -0
  17. data/functional/tmp/README +1 -0
  18. data/lib/langrove.rb +1 -0
  19. data/lib/langrove/_base.rb +26 -0
  20. data/lib/langrove/adaptor/base.rb +3 -0
  21. data/lib/langrove/adaptor/datagram.rb +27 -0
  22. data/lib/langrove/adaptor_base.rb +89 -0
  23. data/lib/langrove/client/base.rb +2 -0
  24. data/lib/langrove/client/datagram.rb +28 -0
  25. data/lib/langrove/client_base.rb +114 -0
  26. data/lib/langrove/daemon/base.rb +2 -0
  27. data/lib/{daemon_base.rb → langrove/daemon_base.rb} +30 -23
  28. data/lib/langrove/ext.rb +7 -0
  29. data/lib/langrove/ext/class_loader.rb +146 -0
  30. data/lib/{ext → langrove/ext}/config_item.rb +4 -5
  31. data/lib/{ext → langrove/ext}/config_loader.rb +2 -2
  32. data/lib/langrove/ext/fake_logger.rb +8 -0
  33. data/lib/{ext → langrove/ext}/persistable.rb +2 -2
  34. data/lib/{ext → langrove/ext}/string.rb +0 -0
  35. data/lib/langrove/handler/base.rb +2 -0
  36. data/lib/{handler_base.rb → langrove/handler_base.rb} +25 -9
  37. data/lib/langrove/protocol/base.rb +2 -0
  38. data/lib/langrove/protocol/syslog.rb +32 -0
  39. data/lib/langrove/protocol_base.rb +32 -0
  40. data/lib/langrove/version.rb +3 -0
  41. data/spec/functional/daemon/datagram_spec.rb +115 -0
  42. data/spec/langrove/adaptor/datagram_spec.rb +6 -0
  43. data/spec/langrove/adaptor_base_spec.rb +48 -0
  44. data/spec/langrove/client/datagram_spec.rb +1 -0
  45. data/spec/langrove/client_base_spec.rb +5 -0
  46. data/spec/langrove/daemon_base_spec.rb +101 -0
  47. data/spec/langrove/ext/class_loader_spec.rb +83 -0
  48. data/spec/langrove/ext/config_item_spec.rb +81 -0
  49. data/spec/langrove/ext/config_loader_spec.rb +5 -0
  50. data/{tmp/TMP → spec/langrove/ext/fake_logger_spec.rb} +0 -0
  51. data/spec/{ext → langrove/ext}/persistable_spec.rb +8 -9
  52. data/spec/{ext → langrove/ext}/string_spec.rb +1 -1
  53. data/spec/langrove/handler_base_spec.rb +57 -0
  54. data/spec/langrove/protocol/syslog_spec.rb +45 -0
  55. data/spec/langrove/protocol_base_spec.rb +6 -0
  56. data/spec/todo_spec.rb +1 -2
  57. data/tmp/README +2 -0
  58. metadata +150 -46
  59. data/config/daemons.yml.tmpl +0 -78
  60. data/lib/adaptor/base.rb +0 -1
  61. data/lib/adaptor/datagram.rb +0 -20
  62. data/lib/adaptor/socket_handler.rb +0 -27
  63. data/lib/adaptor_base.rb +0 -39
  64. data/lib/client/base.rb +0 -1
  65. data/lib/client/puppet_state.rb +0 -74
  66. data/lib/client/radio_state.rb +0 -81
  67. data/lib/client_base.rb +0 -24
  68. data/lib/daemon/base.rb +0 -1
  69. data/lib/daemon/datagram_example.rb +0 -12
  70. data/lib/handler/base.rb +0 -1
  71. data/lib/handler/socket_to_file.rb +0 -30
  72. data/lib/jobs/jobs.rb +0 -1
  73. data/lib/jobs/updated_puppet_state.rb +0 -17
  74. data/lib/protocol_base.rb +0 -5
  75. data/spec/adaptor/datagram_spec.rb +0 -6
  76. data/spec/adaptor/socket_handler_spec.rb +0 -5
  77. data/spec/adaptor_base_spec.rb +0 -45
  78. data/spec/client_base_spec.rb +0 -5
  79. data/spec/daemon_base_spec.rb +0 -97
  80. data/spec/ext/config_item_spec.rb +0 -77
  81. data/spec/ext/config_loader_spec.rb +0 -5
  82. data/spec/functional/datagram_spec.rb +0 -122
  83. data/spec/handler_base_spec.rb +0 -71
  84. data/spec/protocol_base_spec.rb +0 -6
@@ -0,0 +1,5 @@
1
+ require 'langrove/ext'
2
+
3
+ describe LanGrove::ConfigLoader do
4
+
5
+ end
File without changes
@@ -1,11 +1,10 @@
1
- require 'ext/persistable'
2
- require 'ext/fake_logger'
1
+ require 'langrove/ext'
3
2
 
4
3
  #
5
4
  # This will likely change.
6
5
  #
7
6
 
8
- describe Persistable do
7
+ describe LanGrove::Persistable do
9
8
 
10
9
  before :each do
11
10
 
@@ -17,7 +16,7 @@ describe Persistable do
17
16
  @class_instance.data = 'VALUE'
18
17
 
19
18
  @now = Time.now
20
- @state_file = File.dirname( __FILE__ ) + "/../../tmp/persistable.yml"
19
+ @state_file = File.dirname( __FILE__ ) + "/../../../tmp/persistable.yml"
21
20
 
22
21
  #
23
22
  # delete the file
@@ -27,7 +26,7 @@ describe Persistable do
27
26
  @hash = {
28
27
  'tree' => {
29
28
  'type' => {
30
- 'thing1' => 1
29
+ :thing1 => 1
31
30
  }
32
31
  },
33
32
  :now => @now,
@@ -38,8 +37,8 @@ describe Persistable do
38
37
 
39
38
  subject do
40
39
 
41
- test = Persistable.new
42
- test.instance_variable_set :@logger, (FakeLogger.new :silent)
40
+ test = LanGrove::Persistable.new
41
+ test.instance_variable_set :@logger, (LanGrove::FakeLogger.new :silent)
43
42
  test
44
43
 
45
44
  end
@@ -81,7 +80,7 @@ describe Persistable do
81
80
  subject.load_hash( '@hash', @state_file )
82
81
 
83
82
  hash = subject.instance_variable_get( :@hash )
84
- hash['tree']['type']['thing1'].should == 1
83
+ hash['tree']['type'][:thing1].should == 1
85
84
 
86
85
  end
87
86
 
@@ -110,7 +109,7 @@ describe Persistable do
110
109
  subject.load_hash( '@hash', @state_file )
111
110
  hash = subject.instance_variable_get( :@hash )
112
111
 
113
- hash['tree']['type']['thing1'].should == 1
112
+ hash['tree']['type'][:thing1].should == 1
114
113
  hash['thing2'].should == 2
115
114
 
116
115
  end
@@ -1,4 +1,4 @@
1
- require 'ext/string'
1
+ require 'langrove/ext'
2
2
  describe String do
3
3
 
4
4
  it 'has been extended to camelize' do
@@ -0,0 +1,57 @@
1
+ require 'langrove'
2
+
3
+ describe LanGrove::Handler::Base do
4
+
5
+ before :each do
6
+
7
+ @logger = LanGrove::FakeLogger.new :silent
8
+
9
+ @daemon_name = 'test_daemon'
10
+
11
+ @config = {
12
+
13
+ :daemons => {
14
+
15
+ @daemon_name => {
16
+
17
+ :handler => {
18
+
19
+ :collection => 'Base'
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ end
26
+
27
+ context 'uses a protocol' do
28
+
29
+ it 'that defaults to an instance of Protocol::Base' do
30
+
31
+ test = LanGrove::Handler::Base.new( @config, @daemon_name, @logger )
32
+
33
+ protocol = test.instance_variable_get( :@protocol )
34
+
35
+ protocol.should == LanGrove::Protocol::Base
36
+
37
+ end
38
+
39
+ it 'as defined by the config_hash' do
40
+
41
+ @config[:daemons][@daemon_name][:handler][:protocol] = 'MedievalLanternMorse'
42
+
43
+ expect {
44
+
45
+ test = LanGrove::Handler::Base.new( @config, @daemon_name, @logger )
46
+
47
+ }.to raise_error( LanGrove::ClassLoaderException,
48
+
49
+ "no such file to load -- protocol/medieval_lantern_morse.rb"
50
+
51
+ )
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,45 @@
1
+ require 'langrove/protocol/syslog'
2
+ require 'date'
3
+
4
+ describe LanGrove::Protocol::Syslog.new do
5
+
6
+ before :each do
7
+
8
+ @message1 = "<00>Apr 4 11:00:06 host program[321]: Message with: 1"
9
+ @message2 = "<00>Jun 25 16:15:15 host.name.co.za tag[3241]: Message with: 2"
10
+
11
+ end
12
+
13
+ pending 'it decodes the loglevel'
14
+
15
+ pending 'it supports tagless and pidless'
16
+
17
+ it 'decodes a timestamp' do
18
+
19
+ subject.decode( @message1 )[:timestamp].should == DateTime.parse( 'Apr 4 11:00:06' )
20
+ subject.decode( @message2 )[:timestamp].should == DateTime.parse( 'Jun 25 16:15:15' )
21
+
22
+ end
23
+
24
+ it 'decodes a hostname corrected for prepended vlanN' do
25
+
26
+ subject.decode( @message1 )[:hostname].should == 'host'
27
+ subject.decode( @message2 )[:hostname].should == 'host.name.co.za'
28
+
29
+ end
30
+
31
+ it 'decodes the log tag' do
32
+
33
+ subject.decode( @message1 )[:tag].should == 'program[321]'
34
+ subject.decode( @message2 )[:tag].should == 'tag[3241]'
35
+
36
+ end
37
+
38
+ it 'decodes the log event' do
39
+
40
+ subject.decode( @message1 )[:event].should == 'Message with: 1'
41
+ subject.decode( @message2 )[:event].should == 'Message with: 2'
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,6 @@
1
+ require 'langrove'
2
+
3
+ describe LanGrove::Protocol::Base do
4
+
5
+
6
+ end
data/spec/todo_spec.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  describe 'Outstanding:' do
2
2
 
3
- pending 'Push the module name \'LanGrove\' into all classes'
4
3
  pending 'Symbolize the config keys'
5
- pending 'make a langrove --create for developers to autogenerate their project base dir'
4
+ pending 'make a langrove --create for developers to recursively copy ./functional from the gem install dir as a base for getting the framework up and running'
6
5
  pending 'cut and publish'
7
6
 
8
7
 
data/tmp/README ADDED
@@ -0,0 +1,2 @@
1
+ Certain test write files into here
2
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: LanGrove
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,8 +12,100 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-04-21 00:00:00.000000000Z
16
- dependencies: []
15
+ date: 2012-04-22 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: watchr
19
+ requirement: &2156312200 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: *2156312200
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: &2156311700 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '2.9'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: *2156311700
39
+ - !ruby/object:Gem::Dependency
40
+ name: rake
41
+ requirement: &2156311180 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.8.7
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: *2156311180
53
+ - !ruby/object:Gem::Dependency
54
+ name: eventmachine
55
+ requirement: &2156310440 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '0.12'
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.12.10
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: *2156310440
67
+ - !ruby/object:Gem::Dependency
68
+ name: em-http-request
69
+ requirement: &2156309700 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '0.3'
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.3.0
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: *2156309700
81
+ - !ruby/object:Gem::Dependency
82
+ name: daemon-kit
83
+ requirement: &2156308960 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '0.1'
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 0.1.8.2
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *2156308960
95
+ - !ruby/object:Gem::Dependency
96
+ name: resque
97
+ requirement: &2156308220 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '1.20'
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.20.0
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: *2156308220
17
109
  description: ''
18
110
  email: richard@clue.co.za
19
111
  executables: []
@@ -26,50 +118,62 @@ files:
26
118
  - .rvmrc
27
119
  - .watchr
28
120
  - Rakefile
29
- - config/boot.rb
30
- - config/daemons.yml.tmpl
31
- - config/environment.rb
32
- - config/environments/development.rb
33
- - config/environments/production.rb
34
- - config/environments/test.rb
35
- - bin/datagram_example
36
- - lib/adaptor/base.rb
37
- - lib/adaptor/datagram.rb
38
- - lib/adaptor/socket_handler.rb
39
- - lib/adaptor_base.rb
40
- - lib/client/base.rb
41
- - lib/client/puppet_state.rb
42
- - lib/client/radio_state.rb
43
- - lib/client_base.rb
44
- - lib/daemon/base.rb
45
- - lib/daemon/datagram_example.rb
46
- - lib/daemon_base.rb
47
- - lib/ext/config_item.rb
48
- - lib/ext/config_loader.rb
49
- - lib/ext/persistable.rb
50
- - lib/ext/string.rb
51
- - lib/handler/base.rb
52
- - lib/handler/socket_to_file.rb
53
- - lib/handler_base.rb
54
- - lib/jobs/jobs.rb
55
- - lib/jobs/Rakefile
56
- - lib/jobs/updated_puppet_state.rb
57
- - lib/protocol_base.rb
58
- - libexec/daemon.rb
59
- - spec/functional/datagram_spec.rb
60
- - spec/ext/config_item_spec.rb
61
- - spec/ext/config_loader_spec.rb
62
- - spec/ext/persistable_spec.rb
63
- - spec/ext/string_spec.rb
64
- - spec/adaptor/datagram_spec.rb
65
- - spec/adaptor/socket_handler_spec.rb
66
- - spec/adaptor_base_spec.rb
67
- - spec/client_base_spec.rb
68
- - spec/daemon_base_spec.rb
69
- - spec/handler_base_spec.rb
70
- - spec/protocol_base_spec.rb
121
+ - functional/.gitignore
122
+ - functional/bin/datagram
123
+ - functional/config/.gitignore
124
+ - functional/config/boot.rb
125
+ - functional/config/daemons.yml
126
+ - functional/config/environment.rb
127
+ - functional/config/environments/development.rb
128
+ - functional/config/environments/production.rb
129
+ - functional/config/environments/test.rb
130
+ - functional/lib/daemon/datagram.rb
131
+ - functional/lib/handler/socket_to_file.rb
132
+ - functional/lib/protocol/socket_to_file.rb
133
+ - functional/libexec/daemon.rb
134
+ - functional/log/.gitignore
135
+ - functional/tmp/datagram.txt
136
+ - functional/tmp/README
137
+ - lib/langrove/_base.rb
138
+ - lib/langrove/adaptor/base.rb
139
+ - lib/langrove/adaptor/datagram.rb
140
+ - lib/langrove/adaptor_base.rb
141
+ - lib/langrove/client/base.rb
142
+ - lib/langrove/client/datagram.rb
143
+ - lib/langrove/client_base.rb
144
+ - lib/langrove/daemon/base.rb
145
+ - lib/langrove/daemon_base.rb
146
+ - lib/langrove/ext/class_loader.rb
147
+ - lib/langrove/ext/config_item.rb
148
+ - lib/langrove/ext/config_loader.rb
149
+ - lib/langrove/ext/fake_logger.rb
150
+ - lib/langrove/ext/persistable.rb
151
+ - lib/langrove/ext/string.rb
152
+ - lib/langrove/ext.rb
153
+ - lib/langrove/handler/base.rb
154
+ - lib/langrove/handler_base.rb
155
+ - lib/langrove/protocol/base.rb
156
+ - lib/langrove/protocol/syslog.rb
157
+ - lib/langrove/protocol_base.rb
158
+ - lib/langrove/version.rb
159
+ - lib/langrove.rb
160
+ - spec/functional/daemon/datagram_spec.rb
161
+ - spec/langrove/adaptor/datagram_spec.rb
162
+ - spec/langrove/adaptor_base_spec.rb
163
+ - spec/langrove/client/datagram_spec.rb
164
+ - spec/langrove/client_base_spec.rb
165
+ - spec/langrove/daemon_base_spec.rb
166
+ - spec/langrove/ext/class_loader_spec.rb
167
+ - spec/langrove/ext/config_item_spec.rb
168
+ - spec/langrove/ext/config_loader_spec.rb
169
+ - spec/langrove/ext/fake_logger_spec.rb
170
+ - spec/langrove/ext/persistable_spec.rb
171
+ - spec/langrove/ext/string_spec.rb
172
+ - spec/langrove/handler_base_spec.rb
173
+ - spec/langrove/protocol/syslog_spec.rb
174
+ - spec/langrove/protocol_base_spec.rb
71
175
  - spec/todo_spec.rb
72
- - tmp/TMP
176
+ - tmp/README
73
177
  homepage: ''
74
178
  licenses: []
75
179
  post_install_message:
@@ -1,78 +0,0 @@
1
- #
2
- # Using the daemon stubs in bin/ to spawn daemons from this
3
- # config file with the following guidelines.
4
- #
5
- # 1. Each daemon stub name should correspond to a sub-branch in
6
- # the daemons branch of the config.
7
- #
8
- # 2. The daemons are spawned through a generic DaemonKit based
9
- # spawner.
10
- #
11
- # 3. Daemons log to the log/<daemon_name>.log where daemon_name
12
- # exactly corresponds to the stub name.
13
- #
14
- # 4. Daemons keep a pidfile at log/<daemon_name>.pid, these are
15
- # used by DaemonKit for init.d style stop|start|restart etc.
16
- #
17
- # 5. Daemons are spawned through a generic executer which late
18
- # binds the daemon runner class. Therefore, each daemon with
19
- # a stub at
20
- #
21
- # bin/<daemon_name>
22
- #
23
- # should also have a runner class defined at
24
- #
25
- # lib/<daemon_name>.rb
26
- #
27
- # which defines the class <DaemonName> with the following:
28
- #
29
- # Mandatory
30
- # =========
31
- #
32
- # - initialize( entire_config_hash, daemon_name, logger )
33
- #
34
- # To load up and initialize as required.
35
- #
36
- # It will be provided with
37
- #
38
- # <entire_config_hash> - This entire file as a Hash
39
- # <daemon_name> - From the stub name in bin/
40
- # <logger> - An initialized logger
41
- #
42
- # - run()
43
- #
44
- # The daemons 'main' loop
45
- #
46
- # Optional
47
- # ========
48
- #
49
- # - stop_daemon()
50
- #
51
- # To properly handle daemon shutdown when the server gets
52
- # rebooted or daemon gets restarted
53
- #
54
- # PENDING
55
- # PENDING - reload_daemon()
56
- # PENDING
57
- # PENDING To reload the daemon after a config change without taking
58
- # PENDING down any currently connected sockets and such.
59
- # PENDING
60
- #
61
- # 6. Each daemon config should contain reference to a Handler class.
62
- #
63
- # PENDING explain that later.
64
- #
65
- #
66
-
67
- daemons:
68
- datagram_example:
69
- periodic: 5
70
- adaptor:
71
- connection: Datagram
72
- iface: 127.0.0.1
73
- port: 12701
74
- handler:
75
- collection: Base
76
- protocol: Base
77
-
78
-