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.
- data/.watchr +11 -3
- data/Rakefile +12 -5
- data/functional/.gitignore +1 -0
- data/{bin/datagram_example → functional/bin/datagram} +2 -0
- data/{config/environments/development.rb → functional/config/.gitignore} +0 -0
- data/{config → functional/config}/boot.rb +0 -0
- data/functional/config/daemons.yml +12 -0
- data/{config → functional/config}/environment.rb +0 -0
- data/{config/environments/production.rb → functional/config/environments/development.rb} +0 -0
- data/{config/environments/test.rb → functional/config/environments/production.rb} +0 -0
- data/{lib/jobs/Rakefile → functional/config/environments/test.rb} +0 -0
- data/functional/lib/daemon/datagram.rb +23 -0
- data/functional/lib/handler/socket_to_file.rb +36 -0
- data/functional/lib/protocol/socket_to_file.rb +55 -0
- data/{libexec → functional/libexec}/daemon.rb +14 -3
- data/functional/log/.gitignore +3 -0
- data/functional/tmp/README +1 -0
- data/lib/langrove.rb +1 -0
- data/lib/langrove/_base.rb +26 -0
- data/lib/langrove/adaptor/base.rb +3 -0
- data/lib/langrove/adaptor/datagram.rb +27 -0
- data/lib/langrove/adaptor_base.rb +89 -0
- data/lib/langrove/client/base.rb +2 -0
- data/lib/langrove/client/datagram.rb +28 -0
- data/lib/langrove/client_base.rb +114 -0
- data/lib/langrove/daemon/base.rb +2 -0
- data/lib/{daemon_base.rb → langrove/daemon_base.rb} +30 -23
- data/lib/langrove/ext.rb +7 -0
- data/lib/langrove/ext/class_loader.rb +146 -0
- data/lib/{ext → langrove/ext}/config_item.rb +4 -5
- data/lib/{ext → langrove/ext}/config_loader.rb +2 -2
- data/lib/langrove/ext/fake_logger.rb +8 -0
- data/lib/{ext → langrove/ext}/persistable.rb +2 -2
- data/lib/{ext → langrove/ext}/string.rb +0 -0
- data/lib/langrove/handler/base.rb +2 -0
- data/lib/{handler_base.rb → langrove/handler_base.rb} +25 -9
- data/lib/langrove/protocol/base.rb +2 -0
- data/lib/langrove/protocol/syslog.rb +32 -0
- data/lib/langrove/protocol_base.rb +32 -0
- data/lib/langrove/version.rb +3 -0
- data/spec/functional/daemon/datagram_spec.rb +115 -0
- data/spec/langrove/adaptor/datagram_spec.rb +6 -0
- data/spec/langrove/adaptor_base_spec.rb +48 -0
- data/spec/langrove/client/datagram_spec.rb +1 -0
- data/spec/langrove/client_base_spec.rb +5 -0
- data/spec/langrove/daemon_base_spec.rb +101 -0
- data/spec/langrove/ext/class_loader_spec.rb +83 -0
- data/spec/langrove/ext/config_item_spec.rb +81 -0
- data/spec/langrove/ext/config_loader_spec.rb +5 -0
- data/{tmp/TMP → spec/langrove/ext/fake_logger_spec.rb} +0 -0
- data/spec/{ext → langrove/ext}/persistable_spec.rb +8 -9
- data/spec/{ext → langrove/ext}/string_spec.rb +1 -1
- data/spec/langrove/handler_base_spec.rb +57 -0
- data/spec/langrove/protocol/syslog_spec.rb +45 -0
- data/spec/langrove/protocol_base_spec.rb +6 -0
- data/spec/todo_spec.rb +1 -2
- data/tmp/README +2 -0
- metadata +150 -46
- data/config/daemons.yml.tmpl +0 -78
- data/lib/adaptor/base.rb +0 -1
- data/lib/adaptor/datagram.rb +0 -20
- data/lib/adaptor/socket_handler.rb +0 -27
- data/lib/adaptor_base.rb +0 -39
- data/lib/client/base.rb +0 -1
- data/lib/client/puppet_state.rb +0 -74
- data/lib/client/radio_state.rb +0 -81
- data/lib/client_base.rb +0 -24
- data/lib/daemon/base.rb +0 -1
- data/lib/daemon/datagram_example.rb +0 -12
- data/lib/handler/base.rb +0 -1
- data/lib/handler/socket_to_file.rb +0 -30
- data/lib/jobs/jobs.rb +0 -1
- data/lib/jobs/updated_puppet_state.rb +0 -17
- data/lib/protocol_base.rb +0 -5
- data/spec/adaptor/datagram_spec.rb +0 -6
- data/spec/adaptor/socket_handler_spec.rb +0 -5
- data/spec/adaptor_base_spec.rb +0 -45
- data/spec/client_base_spec.rb +0 -5
- data/spec/daemon_base_spec.rb +0 -97
- data/spec/ext/config_item_spec.rb +0 -77
- data/spec/ext/config_loader_spec.rb +0 -5
- data/spec/functional/datagram_spec.rb +0 -122
- data/spec/handler_base_spec.rb +0 -71
- data/spec/protocol_base_spec.rb +0 -6
data/lib/adaptor/base.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'adaptor_base'
|
data/lib/adaptor/datagram.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'adaptor/base'
|
2
|
-
|
3
|
-
module Adaptor
|
4
|
-
|
5
|
-
class Datagram < Base
|
6
|
-
|
7
|
-
def listen( collection )
|
8
|
-
|
9
|
-
@logger.info "starting listen at UDP #{@iface}:#{@port}"
|
10
|
-
|
11
|
-
EventMachine::open_datagram_socket( @iface, @port,
|
12
|
-
|
13
|
-
@connector ) do |connection|
|
14
|
-
|
15
|
-
connection.handler = collection
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'eventmachine'
|
2
|
-
|
3
|
-
module Adaptor
|
4
|
-
|
5
|
-
class SocketHandler < EM::Connection
|
6
|
-
|
7
|
-
#
|
8
|
-
# The handler collection specified in config
|
9
|
-
# is bound to this attribute after connect.
|
10
|
-
#
|
11
|
-
attr_accessor :handler
|
12
|
-
attr_accessor :protocol
|
13
|
-
|
14
|
-
def receive_data(data)
|
15
|
-
|
16
|
-
#@handler.message( @protocol.decode( data ) )
|
17
|
-
@handler.message( data )
|
18
|
-
|
19
|
-
#
|
20
|
-
# sort out application layer ACKs later
|
21
|
-
# currently only datagrams arriving here
|
22
|
-
# so it's not necessary
|
23
|
-
#
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/adaptor_base.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'eventmachine'
|
2
|
-
|
3
|
-
require 'adaptor/socket_handler'
|
4
|
-
|
5
|
-
module Adaptor
|
6
|
-
|
7
|
-
class Base
|
8
|
-
|
9
|
-
def initialize( config, logger )
|
10
|
-
|
11
|
-
@config = config
|
12
|
-
@logger = logger
|
13
|
-
|
14
|
-
@iface = '127.0.0.1'
|
15
|
-
@port = 12701
|
16
|
-
@connector = Adaptor::SocketHandler
|
17
|
-
|
18
|
-
@iface = @config['iface'] if @config.has_key? 'iface'
|
19
|
-
@port = @config['port'] if @config.has_key? 'port'
|
20
|
-
|
21
|
-
if @config.has_key? 'connector' then
|
22
|
-
|
23
|
-
#
|
24
|
-
# TODO: may need to override default connection handler
|
25
|
-
#
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def listen( collection ) # ---> handler
|
32
|
-
|
33
|
-
raise DaemonConfigException.new( "NotYetExtended: undefined listen()" )
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/lib/client/base.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'client_base'
|
data/lib/client/puppet_state.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'client/abstract/syslog_state_machine'
|
2
|
-
|
3
|
-
class PuppetState < SyslogStateMachine
|
4
|
-
|
5
|
-
def initialize( hostname, config, logger )
|
6
|
-
super
|
7
|
-
|
8
|
-
@state[:exit_code] = nil
|
9
|
-
@state[:last_run_at] = nil
|
10
|
-
@state[:revision] = ''
|
11
|
-
@state[:last_run_duration_seconds] = nil
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def change_state( date, tag, message )
|
16
|
-
|
17
|
-
#
|
18
|
-
# return true if state changed
|
19
|
-
#
|
20
|
-
|
21
|
-
### last_started_at
|
22
|
-
#
|
23
|
-
# run_puppet: obtained lock: beginning run
|
24
|
-
#
|
25
|
-
if /obtained lock: beginning run/.match( message ) then
|
26
|
-
|
27
|
-
@state[:last_run_at] = date
|
28
|
-
return true
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def reset
|
33
|
-
|
34
|
-
@state[:exit_code] = nil
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
### revision
|
39
|
-
#
|
40
|
-
# puppet-git-rev: 0acbf0a78ed813e31dcc3fe58f9c6e9a30219da4
|
41
|
-
#
|
42
|
-
if tag == 'puppet-git-rev' then
|
43
|
-
|
44
|
-
@state[:revision] = message
|
45
|
-
return true
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
### success
|
50
|
-
### last_run_duration_seconds
|
51
|
-
#
|
52
|
-
# run_puppet: completed, releasing lock (exit code : 2)
|
53
|
-
#
|
54
|
-
|
55
|
-
if /completed, releasing lock/.match( message ) then
|
56
|
-
|
57
|
-
@state[:exit_code] = /[\d]+/.match(message)[0]
|
58
|
-
@state[:running] = false
|
59
|
-
|
60
|
-
if @state[:last_run_at] then
|
61
|
-
@state[:last_run_duration_seconds] = date - @state[:last_run_at]
|
62
|
-
else
|
63
|
-
@state[:last_run_duration_seconds] = -1
|
64
|
-
end
|
65
|
-
|
66
|
-
return true
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
return false
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
data/lib/client/radio_state.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'client/abstract/syslog_state_machine'
|
2
|
-
|
3
|
-
class RadioState < SyslogStateMachine
|
4
|
-
|
5
|
-
def persist_change_state( data )
|
6
|
-
|
7
|
-
#
|
8
|
-
# default product will override with Nano *
|
9
|
-
#
|
10
|
-
@state[:vendor] = "BST"
|
11
|
-
@state[:product] = "Subscriber"
|
12
|
-
|
13
|
-
@state.merge!( data )
|
14
|
-
@state[:last_seen_at] = data[:timestamp].clone
|
15
|
-
@state[:last_seen] = data[:timestamp].strftime( '%Y/%m/%d %H:%M:%S')
|
16
|
-
|
17
|
-
|
18
|
-
new_min :rx, :rx_min, :rx_min_at
|
19
|
-
new_max :rx, :rx_max, :rx_max_at
|
20
|
-
|
21
|
-
new_min :tx, :tx_min, :tx_min_at
|
22
|
-
new_max :tx, :tx_max, :tx_max_at
|
23
|
-
|
24
|
-
#
|
25
|
-
# flag to store
|
26
|
-
#
|
27
|
-
@stored = false
|
28
|
-
|
29
|
-
return true
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
def new_min( val, min_val, at )
|
35
|
-
|
36
|
-
newval = @state[val].to_i
|
37
|
-
|
38
|
-
if @state.has_key? min_val then
|
39
|
-
|
40
|
-
minval = @state[min_val]
|
41
|
-
begin
|
42
|
-
|
43
|
-
@state[min_val] = newval
|
44
|
-
@state[at] = @state[:timestamp].clone
|
45
|
-
|
46
|
-
end if minval > newval
|
47
|
-
|
48
|
-
else
|
49
|
-
|
50
|
-
@state[min_val] = newval
|
51
|
-
@state[at] = @state[:timestamp].clone
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
def new_max( val, max_val, at )
|
59
|
-
|
60
|
-
newval = @state[val].to_i
|
61
|
-
|
62
|
-
if @state.has_key? max_val then
|
63
|
-
|
64
|
-
maxval = @state[max_val]
|
65
|
-
begin
|
66
|
-
|
67
|
-
@state[max_val] = newval
|
68
|
-
@state[at] = @state[:timestamp].clone
|
69
|
-
|
70
|
-
end if maxval < newval
|
71
|
-
|
72
|
-
else
|
73
|
-
|
74
|
-
@state[max_val] = newval
|
75
|
-
@state[at] = @state[:timestamp].clone
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
data/lib/client_base.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'ext/persistable'
|
2
|
-
|
3
|
-
module Client class Base < Persistable
|
4
|
-
|
5
|
-
#
|
6
|
-
# Misnomer.
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# This is not the client,
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# It is the server's perspective of the client,
|
13
|
-
#
|
14
|
-
# These are generally stored in the daemon's
|
15
|
-
# handler collection,
|
16
|
-
#
|
17
|
-
# Which contains this and all similar clients,
|
18
|
-
#
|
19
|
-
# Each bonded through the daemon's connection
|
20
|
-
# adaptor to the socket that couples them to
|
21
|
-
# their actual client..
|
22
|
-
#
|
23
|
-
|
24
|
-
end; end
|
data/lib/daemon/base.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'daemon_base'
|
data/lib/handler/base.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'handler_base'
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Mainly to facilitate functional tests
|
3
|
-
#
|
4
|
-
|
5
|
-
require 'handler/base'
|
6
|
-
|
7
|
-
module Handler
|
8
|
-
|
9
|
-
class SocketToFile < Base
|
10
|
-
|
11
|
-
def message( data )
|
12
|
-
|
13
|
-
@logger.debug( "Received: #{data}" )
|
14
|
-
|
15
|
-
filename = data.split('|')[0]
|
16
|
-
filecontents = data.split('|',2)[1]
|
17
|
-
|
18
|
-
File.open( filename, 'w' ) do |f|
|
19
|
-
|
20
|
-
f.write( filecontents )
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
@logger.debug "Wrote file: #{filename}"
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/lib/jobs/jobs.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'jobs/updated_puppet_state'
|
data/lib/protocol_base.rb
DELETED
data/spec/adaptor_base_spec.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'adaptor/base'
|
2
|
-
|
3
|
-
require 'ext/fake_logger'
|
4
|
-
|
5
|
-
describe Adaptor::Base do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
|
9
|
-
@logger = FakeLogger.new
|
10
|
-
|
11
|
-
@extendhandler = 'ExtendedHandler'
|
12
|
-
|
13
|
-
@config = {
|
14
|
-
|
15
|
-
'iface' => '111.111.111.111',
|
16
|
-
|
17
|
-
'port' => 11111,
|
18
|
-
|
19
|
-
'connector' => @extendhandler
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
pending 'may need to override default connection handler' do
|
26
|
-
|
27
|
-
Adaptor.const_set( @extendhandler, Class.new )
|
28
|
-
|
29
|
-
subject = Adaptor::Base.new( @config, @logger )
|
30
|
-
connector = subject.instance_variable_get( :@handler )
|
31
|
-
|
32
|
-
connector.should be_a( Adaptor.const_get( @extendhandler ) )
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'assigns defaults' do
|
37
|
-
|
38
|
-
subject = Adaptor::Base.new( {}, @logger )
|
39
|
-
connector = subject.instance_variable_get( :@connector )
|
40
|
-
|
41
|
-
connector.should == Adaptor::SocketHandler
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/spec/client_base_spec.rb
DELETED
data/spec/daemon_base_spec.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'daemon_base'
|
2
|
-
|
3
|
-
require 'ext/fake_logger'
|
4
|
-
|
5
|
-
describe Daemon::Base do
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
|
9
|
-
@logger = FakeLogger.new :silent
|
10
|
-
|
11
|
-
@daemon_name = 'pretend_daemon'
|
12
|
-
|
13
|
-
@adaptor_class = 'Base'
|
14
|
-
@collection_class = 'Base'
|
15
|
-
|
16
|
-
@config = {
|
17
|
-
|
18
|
-
'server' => false,
|
19
|
-
|
20
|
-
'daemons' => {
|
21
|
-
|
22
|
-
'pretend_daemon' => {
|
23
|
-
|
24
|
-
'adaptor' => {
|
25
|
-
|
26
|
-
'connection' => @adaptor_class
|
27
|
-
|
28
|
-
},
|
29
|
-
|
30
|
-
'handler' => {
|
31
|
-
|
32
|
-
'collection' => @collection_class
|
33
|
-
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
subject do
|
42
|
-
|
43
|
-
Daemon::Base.new( @config, @daemon_name, @logger )
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'requires a logger' do
|
48
|
-
|
49
|
-
expect {
|
50
|
-
|
51
|
-
Daemon::Base.new( @config, @daemon_name, nil )
|
52
|
-
|
53
|
-
}.to raise_error( DaemonConfigException, /Requires a logger/ )
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'requires a configuration' do
|
58
|
-
|
59
|
-
expect {
|
60
|
-
|
61
|
-
Daemon::Base.new( {}, @daemon_name, @logger )
|
62
|
-
|
63
|
-
}.to raise_error( DaemonConfigException, /Missing config item/ )
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'latebinds an adaptor by config' do
|
68
|
-
|
69
|
-
adaptor = subject.instance_variable_get( :@adaptor )
|
70
|
-
|
71
|
-
adaptor.should be_a( Adaptor.const_get( @adaptor_class ) )
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'latebinds a handler by config' do
|
76
|
-
|
77
|
-
handler = subject.instance_variable_get( :@handler )
|
78
|
-
|
79
|
-
handler.should be_a( Handler.const_get( @collection_class ) )
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'it schedules periodics'
|
84
|
-
|
85
|
-
it 'when run, it calls to listen if server is true' do
|
86
|
-
|
87
|
-
expect {
|
88
|
-
|
89
|
-
subject.instance_variable_set( :@server, true )
|
90
|
-
|
91
|
-
subject.run
|
92
|
-
|
93
|
-
}.to raise_error( DaemonConfigException, "NotYetExtended: undefined listen()" )
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|