rhcp 0.2.14 → 0.2.15
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/lib/rhcp.rb +3 -3
- data/lib/rhcp/command.rb +8 -25
- data/lib/rhcp/command_param.rb +4 -0
- data/lib/rhcp/request.rb +12 -0
- data/test/rhcp/command_test.rb +0 -40
- data/test/rhcp/rhcp.log +20 -0
- metadata +26 -25
data/lib/rhcp.rb
CHANGED
@@ -23,7 +23,7 @@ module RHCP #:nodoc:
|
|
23
23
|
|
24
24
|
MAJOR = 0
|
25
25
|
MINOR = 2
|
26
|
-
TINY =
|
26
|
+
TINY = 15
|
27
27
|
|
28
28
|
def Version.to_s
|
29
29
|
[ MAJOR, MINOR, TINY ].join(".")
|
@@ -40,7 +40,7 @@ module RHCP #:nodoc:
|
|
40
40
|
def initialize()
|
41
41
|
# TODO do we really want to log to STDOUT per default?
|
42
42
|
# TODO check the whole package for correct usage of loggers
|
43
|
-
@logger = Logger.new(
|
43
|
+
@logger = Logger.new("rhcp.log")
|
44
44
|
end
|
45
45
|
|
46
46
|
|
@@ -48,4 +48,4 @@ module RHCP #:nodoc:
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
#$logger = Logger.new(STDOUT)
|
data/lib/rhcp/command.rb
CHANGED
@@ -11,6 +11,9 @@ module RHCP
|
|
11
11
|
|
12
12
|
# TODO add metadata about the command's result (display type ("table"), column order etc.)
|
13
13
|
|
14
|
+
# a qualified name that identifies this command in a dot-separated namespace
|
15
|
+
attr_reader :full_name
|
16
|
+
|
14
17
|
# a unique name for this command
|
15
18
|
attr_reader :name
|
16
19
|
|
@@ -42,7 +45,10 @@ module RHCP
|
|
42
45
|
def initialize(name, description, block = nil)
|
43
46
|
@logger = RHCP::ModuleHelper.instance().logger
|
44
47
|
|
45
|
-
|
48
|
+
#@logger.info("full name : #{name}")
|
49
|
+
@full_name = name
|
50
|
+
@name = name.split(".").last
|
51
|
+
|
46
52
|
@description = description
|
47
53
|
@block = block unless block == nil
|
48
54
|
@params = Array.new()
|
@@ -132,6 +138,7 @@ module RHCP
|
|
132
138
|
@logger.debug "gonna execute request >>#{request}<<"
|
133
139
|
|
134
140
|
response = RHCP::Response.new()
|
141
|
+
|
135
142
|
# check all param values for plausibility
|
136
143
|
request.param_values.each do |key,value|
|
137
144
|
get_param(key).check_param_is_valid(request, value)
|
@@ -155,8 +162,6 @@ module RHCP
|
|
155
162
|
# the command has been executed, so we should clear the store of collected param values
|
156
163
|
#request.context.collected_values = {}
|
157
164
|
|
158
|
-
fire_post_exec_event(request, response)
|
159
|
-
|
160
165
|
response
|
161
166
|
end
|
162
167
|
|
@@ -177,7 +182,6 @@ module RHCP
|
|
177
182
|
# args is an array - but we need the (optional) hash on index 0
|
178
183
|
param_values = {}
|
179
184
|
if args.length > 0
|
180
|
-
$logger.debug("args: #{args}")
|
181
185
|
param_values = args.first
|
182
186
|
end
|
183
187
|
|
@@ -222,27 +226,6 @@ module RHCP
|
|
222
226
|
}.to_json(*args)
|
223
227
|
end
|
224
228
|
|
225
|
-
# TODO think about moving this and the whole command thing to the broker
|
226
|
-
def Command.register_post_exec_listener(block)
|
227
|
-
@@listener = [] unless defined?(@@listener)
|
228
|
-
@@listener << block
|
229
|
-
end
|
230
|
-
|
231
|
-
def Command.clear_post_exec_listeners()
|
232
|
-
@@listener = []
|
233
|
-
end
|
234
|
-
|
235
|
-
def fire_post_exec_event(request, response)
|
236
|
-
return unless defined? @@listener
|
237
|
-
@@listener.each do |listener|
|
238
|
-
begin
|
239
|
-
listener.call(request, response)
|
240
|
-
rescue => ex
|
241
|
-
@logger.warn "a post-exec listener failed with the following message : #{ex}"
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
229
|
end
|
247
230
|
|
248
231
|
end
|
data/lib/rhcp/command_param.rb
CHANGED
@@ -25,6 +25,8 @@ module RHCP
|
|
25
25
|
attr_reader :is_default_param
|
26
26
|
# the key to a context value that is used for filling this parameter
|
27
27
|
attr_reader :autofill_context_key
|
28
|
+
|
29
|
+
attr_accessor :default_value
|
28
30
|
|
29
31
|
# creates a new command parameter
|
30
32
|
# options is a hash, possibly holding the following values (all optional)
|
@@ -32,6 +34,7 @@ module RHCP
|
|
32
34
|
# :allows_multiple_values true if this parameter might be specified multiple times
|
33
35
|
# :lookup_method a block that returns an array of lookup values valid for this param
|
34
36
|
# :is_default_param true if this parameter is the default param for the enclosing command
|
37
|
+
# :default_value a value to use as default (who would have thought?)
|
35
38
|
def initialize(name, description, options = Hash.new)
|
36
39
|
@name = name
|
37
40
|
@description = description
|
@@ -44,6 +47,7 @@ module RHCP
|
|
44
47
|
@allows_multiple_values = options[:allows_multiple_values] || false
|
45
48
|
@is_default_param = options[:is_default_param] || false
|
46
49
|
@autofill_context_key = options[:autofill_context_key] || nil
|
50
|
+
@default_value = options[:default_value] || nil
|
47
51
|
end
|
48
52
|
|
49
53
|
# searches the context for a values that can be auto-filled
|
data/lib/rhcp/request.rb
CHANGED
@@ -25,15 +25,27 @@ module RHCP
|
|
25
25
|
@context = context
|
26
26
|
|
27
27
|
command.params.each do |param|
|
28
|
+
|
28
29
|
value_from_context = param.find_value_in_context(context)
|
29
30
|
if value_from_context != nil
|
30
31
|
# if the parameter has been specified in the param values, do not override
|
31
32
|
if ! param_values.has_key?(param.name)
|
32
33
|
@logger.debug "pre-filling param #{param.name} with value '#{value_from_context}' (context key '#{param.autofill_context_key}')"
|
33
34
|
param_values[param.name] = value_from_context
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# fill params with default values
|
39
|
+
if ! param_values.has_key?(param.name) and param.default_value != nil
|
40
|
+
if param.default_value.class == Proc
|
41
|
+
param_values[param.name] = param.default_value.call(param_values)
|
42
|
+
else
|
43
|
+
param_values[param.name] = param.default_value
|
34
44
|
end
|
35
45
|
end
|
46
|
+
|
36
47
|
end
|
48
|
+
|
37
49
|
|
38
50
|
# autobox the parameters if necessary
|
39
51
|
param_values.each do |k,v|
|
data/test/rhcp/command_test.rb
CHANGED
@@ -93,46 +93,6 @@ class CommandTest < Test::Unit::TestCase
|
|
93
93
|
assert_equal the_param, command.default_param
|
94
94
|
end
|
95
95
|
|
96
|
-
def test_listener
|
97
|
-
command = RHCP::Command.new("test_listener", "just some dumb command for the listener", lambda {
|
98
|
-
|req,res|
|
99
|
-
puts "While I think there could be something important to say right now, I just cannot remember what it might have been..."
|
100
|
-
res.result_text = "the test is working."
|
101
|
-
})
|
102
|
-
|
103
|
-
@listener1_fired = false
|
104
|
-
@listener2_fired = false
|
105
|
-
|
106
|
-
RHCP::Command.clear_post_exec_listeners()
|
107
|
-
RHCP::Command.register_post_exec_listener(lambda { |req,res| @listener1_fired = true })
|
108
|
-
RHCP::Command.register_post_exec_listener(lambda { |req,res| @listener2_fired = true })
|
109
|
-
|
110
|
-
command.execute()
|
111
|
-
|
112
|
-
assert @listener1_fired
|
113
|
-
assert @listener2_fired
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_failing_listener
|
117
|
-
command = RHCP::Command.new("test_listener", "just some dumb command for the listener", lambda {
|
118
|
-
|req,res|
|
119
|
-
puts "While I think there could be something important to say right now, I just cannot remember what it might have been..."
|
120
|
-
res.result_text = "the test is working"
|
121
|
-
})
|
122
|
-
|
123
|
-
RHCP::Command.clear_post_exec_listeners()
|
124
|
-
RHCP::Command.register_post_exec_listener(lambda { |req,res| raise "this listener is dying"})
|
125
|
-
|
126
|
-
@listener1_fired = false
|
127
|
-
@listener2_fired = false
|
128
|
-
|
129
|
-
response = command.execute()
|
130
|
-
assert_not_nil response
|
131
|
-
assert_equal "the test is working", response.result_text
|
132
|
-
assert ! @listener1_fired
|
133
|
-
assert ! @listener2_fired
|
134
|
-
end
|
135
|
-
|
136
96
|
def test_enabled_through_context
|
137
97
|
command = RHCP::Command.new("context_test", "testing the context", lambda {
|
138
98
|
|req,res|
|
data/test/rhcp/rhcp.log
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Logfile created on Sat Nov 12 22:54:42 +0100 2011 by logger.rb/22285
|
2
|
+
D, [2011-11-12T22:54:42.004418 #8757] DEBUG -- : enabling command context_test because of context key host
|
3
|
+
D, [2011-11-12T22:54:42.004543 #8757] DEBUG -- : initializing request test with params first_paramthing
|
4
|
+
D, [2011-11-12T22:54:42.004588 #8757] DEBUG -- : request initialized : command 'test', params : first_param=thing
|
5
|
+
D, [2011-11-12T22:54:42.004623 #8757] DEBUG -- : gonna execute request >>test (first_paramthing)<<
|
6
|
+
D, [2011-11-12T22:54:42.004736 #8757] DEBUG -- : initializing request not working with params
|
7
|
+
D, [2011-11-12T22:54:42.004771 #8757] DEBUG -- : request initialized : command 'not working', params :
|
8
|
+
D, [2011-11-12T22:54:42.004802 #8757] DEBUG -- : gonna execute request >>not working ()<<
|
9
|
+
D, [2011-11-12T22:54:42.004922 #8757] DEBUG -- : initializing request test with params first_paramthe_value
|
10
|
+
D, [2011-11-12T22:54:42.004961 #8757] DEBUG -- : request initialized : command 'test', params : first_param=the_value
|
11
|
+
D, [2011-11-12T22:54:42.004997 #8757] DEBUG -- : gonna execute request >>test (first_paramthe_value)<<
|
12
|
+
D, [2011-11-12T22:54:42.005214 #8757] DEBUG -- : initializing request test with params does_not_existsingle value for non-existing param
|
13
|
+
D, [2011-11-12T22:54:42.005256 #8757] DEBUG -- : request initialized : command 'test', params : does_not_exist=single value for non-existing param
|
14
|
+
D, [2011-11-12T22:54:42.005291 #8757] DEBUG -- : gonna execute request >>test (does_not_existsingle value for non-existing param)<<
|
15
|
+
D, [2011-11-12T22:54:42.005413 #8757] DEBUG -- : initializing request test with params real_paramvalue for the real paramanother value for the real param
|
16
|
+
D, [2011-11-12T22:54:42.005452 #8757] DEBUG -- : request initialized : command 'test', params : real_param=value for the real param,another value for the real param
|
17
|
+
D, [2011-11-12T22:54:42.005513 #8757] DEBUG -- : gonna execute request >>test (real_paramvalue for the real paramanother value for the real param)<<
|
18
|
+
D, [2011-11-12T22:54:42.005661 #8757] DEBUG -- : initializing request test with params
|
19
|
+
D, [2011-11-12T22:54:42.005701 #8757] DEBUG -- : request initialized : command 'test', params :
|
20
|
+
D, [2011-11-12T22:54:42.005733 #8757] DEBUG -- : gonna execute request >>test ()<<
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhcp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 15
|
10
|
+
version: 0.2.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philipp Traeder
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-12 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,39 +44,40 @@ extra_rdoc_files: []
|
|
44
44
|
|
45
45
|
files:
|
46
46
|
- bin/rhcp_test_server
|
47
|
-
- lib/rhcp
|
48
|
-
- lib/rhcp/
|
49
|
-
- lib/rhcp/memcached_broker.rb
|
50
|
-
- lib/rhcp/logging_broker.rb
|
51
|
-
- lib/rhcp/broker.rb
|
47
|
+
- lib/rhcp.rb
|
48
|
+
- lib/rhcp/command_param.rb
|
52
49
|
- lib/rhcp/response.rb
|
53
|
-
- lib/rhcp/
|
54
|
-
- lib/rhcp/
|
50
|
+
- lib/rhcp/rhcp_exception.rb
|
51
|
+
- lib/rhcp/logging_broker.rb
|
55
52
|
- lib/rhcp/client/http_broker.rb
|
56
53
|
- lib/rhcp/client/context_aware_broker.rb
|
57
|
-
- lib/rhcp/
|
54
|
+
- lib/rhcp/client/command_stub.rb
|
55
|
+
- lib/rhcp/client/command_param_stub.rb
|
58
56
|
- lib/rhcp/http_exporter.rb
|
59
|
-
- lib/rhcp/
|
60
|
-
- lib/rhcp/command_param.rb
|
57
|
+
- lib/rhcp/dispatching_broker.rb
|
61
58
|
- lib/rhcp/request.rb
|
62
|
-
- lib/rhcp.rb
|
63
|
-
-
|
59
|
+
- lib/rhcp/broker.rb
|
60
|
+
- lib/rhcp/context.rb
|
61
|
+
- lib/rhcp/command.rb
|
62
|
+
- lib/rhcp/memcached_broker.rb
|
64
63
|
- test/rhcp/test_base.rb
|
64
|
+
- test/rhcp/command_param_test.rb
|
65
|
+
- test/rhcp/context_aware_broker_test.rb
|
66
|
+
- test/rhcp/rhcp.log
|
67
|
+
- test/rhcp/request_test.rb
|
68
|
+
- test/rhcp/tests_for_brokers.rb
|
65
69
|
- test/rhcp/http_exporter_test.rb
|
70
|
+
- test/rhcp/logging_broker_test.rb
|
66
71
|
- test/rhcp/http_test_server.rb
|
67
|
-
- test/rhcp/
|
68
|
-
- test/rhcp/
|
69
|
-
- test/rhcp/tests_for_brokers.rb
|
70
|
-
- test/rhcp/request_test.rb
|
72
|
+
- test/rhcp/dispatching_broker_test.rb
|
73
|
+
- test/rhcp/broker_test.rb
|
71
74
|
- test/rhcp/client/command_param_stub_test.rb
|
72
75
|
- test/rhcp/client/command_stub_test.rb
|
73
76
|
- test/rhcp/http_broker_test.rb
|
74
|
-
- test/rhcp/
|
75
|
-
- test/rhcp/context_test.rb
|
76
|
-
- test/rhcp/command_param_test.rb
|
77
|
+
- test/rhcp/response_test.rb
|
77
78
|
- test/rhcp/tests_for_writable_brokers.rb
|
78
|
-
- test/rhcp/
|
79
|
-
- test/rhcp/
|
79
|
+
- test/rhcp/context_test.rb
|
80
|
+
- test/rhcp/command_test.rb
|
80
81
|
has_rdoc: true
|
81
82
|
homepage: http://rubyforge.org/projects/rhcp
|
82
83
|
licenses: []
|