omf_rc_shm 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +45 -17
- data/config/test.rb +38 -53
- data/lib/omf_rc/resource_proxy/scheduled_application.rb +15 -17
- data/lib/omf_rc/resource_proxy/shm_node.rb +10 -4
- data/lib/omf_rc_shm/app.rb +4 -0
- data/lib/omf_rc_shm/version.rb +1 -1
- data/test/scheduled_app_tester.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWI4OGY2NmNkZDk0ZjFkYzA5NTUyNzA4MzZkYWFmMzUxNjMzMjc0NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2ZjMGIzNzQ4OWEyY2Y1NTlkNGRkNTY5NjJjYjAxMTI3NDA2MjFkZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTlmZGQ3YWVkZmVkZmExODc2YzI2NzI2ODYwM2ZmZjZkOWQwMjdhZjNhNzEy
|
10
|
+
OWNhY2E4NDM3ZTNiZjIxNDVjOTdjYTMyMGFkNTUxMjNiOTM3ZGRiMWMzZGVi
|
11
|
+
MjQ1YTgxYjhjYTYxMWY5NzkxYTAwYmE5N2YyODk0YWNiZTI3OTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2Y5M2U2ZGNiOWIwZjUzNTRjNjJjZTMwZjhhNmQ2NDgxZGZlNzkyNWQzZWE1
|
14
|
+
Zjk3MGEzYmYyNDljN2MzYTNlNzg4NGMwODNiNjgxNDczZDhlNDRiYjYxMjAz
|
15
|
+
ZDlhY2IyM2I0ZWE4ODhlMDljNDlmMDZhNTgzNDQ5MGM0MDA0MTM=
|
data/README.md
CHANGED
@@ -26,23 +26,51 @@ Configure OmfRc to load SHM extension, simply modify '/etc/omf_rc/config.yml' to
|
|
26
26
|
:factories:
|
27
27
|
- :require: omf_rc_shm
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
## Define applications
|
30
|
+
|
31
|
+
app_definition_file for shm_node simply defines the applications it runs.
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
App.define(
|
36
|
+
"otr2", {
|
37
|
+
schedule: "* * * * *",
|
38
|
+
timeout: 20,
|
39
|
+
binary_path: "/usr/bin/otr2",
|
40
|
+
use_oml: true,
|
41
|
+
parameters: {
|
42
|
+
udp_local_host: { cmd: "--udp:local_host", value: "0.0.0.0" }
|
43
|
+
},
|
44
|
+
oml: {
|
45
|
+
experiment: "otr2_#{Time.now.to_i}",
|
46
|
+
id: "otr2",
|
47
|
+
available_mps: [
|
48
|
+
{
|
49
|
+
mp: "udp_in",
|
50
|
+
fields: [
|
51
|
+
{ field: "flow_id", type: :long },
|
52
|
+
{ field: "seq_no", type: :long },
|
53
|
+
{ field: "pkt_length", type: :long },
|
54
|
+
{ field: "dst_host", type: :string },
|
55
|
+
{ field: "dst_port", type: :long }
|
56
|
+
]
|
57
|
+
}
|
58
|
+
],
|
59
|
+
collection: [
|
60
|
+
{
|
61
|
+
url: "tcp://0.0.0.0:3003",
|
62
|
+
streams: [
|
63
|
+
{
|
64
|
+
mp: "udp_in",
|
65
|
+
interval: 3
|
66
|
+
}
|
67
|
+
]
|
68
|
+
}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
}
|
72
|
+
)
|
73
|
+
|
46
74
|
|
47
75
|
## Usage
|
48
76
|
|
data/config/test.rb
CHANGED
@@ -1,54 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
a.defProperty("cbr_size", "Size of packet [bytes]", '--cbr:size', {:dynamic => true, :type => :integer})
|
40
|
-
a.defProperty("cbr_rate", "Data rate of the flow [kbps]", '--cbr:rate', {:dynamic => true, :type => :integer})
|
41
|
-
a.defProperty("exp_size", "Size of packet [bytes]", '--exp:size', {:dynamic => true, :type => :integer})
|
42
|
-
a.defProperty("exp_rate", "Data rate of the flow [kbps]", '--exp:rate', {:dynamic => true, :type => :integer})
|
43
|
-
a.defProperty("exp_ontime", "Average length of burst [msec]", '--exp:ontime', {:dynamic => true, :type => :integer})
|
44
|
-
a.defProperty("exp_offtime", "Average length of idle time [msec]", '--exp:offtime', {:dynamic => true, :type => :integer})
|
45
|
-
a.defMeasurement('udp_out') do |m|
|
46
|
-
m.defMetric('ts',:float)
|
47
|
-
m.defMetric('flow_id',:long)
|
48
|
-
m.defMetric('seq_no',:long)
|
49
|
-
m.defMetric('pkt_length',:long)
|
50
|
-
m.defMetric('dst_host',:string)
|
51
|
-
m.defMetric('dst_port',:long)
|
52
|
-
end
|
53
|
-
end
|
1
|
+
App.define(
|
2
|
+
"otr2", {
|
3
|
+
schedule: "* * * * *",
|
4
|
+
timeout: 20,
|
5
|
+
binary_path: "/usr/bin/otr2",
|
6
|
+
use_oml: true,
|
7
|
+
parameters: {
|
8
|
+
udp_local_host: { cmd: "--udp:local_host", value: "0.0.0.0" }
|
9
|
+
},
|
10
|
+
oml: {
|
11
|
+
experiment: "otr2_#{Time.now.to_i}",
|
12
|
+
id: "otr2",
|
13
|
+
available_mps: [
|
14
|
+
{
|
15
|
+
mp: "udp_in",
|
16
|
+
fields: [
|
17
|
+
{ field: "flow_id", type: :long },
|
18
|
+
{ field: "seq_no", type: :long },
|
19
|
+
{ field: "pkt_length", type: :long },
|
20
|
+
{ field: "dst_host", type: :string },
|
21
|
+
{ field: "dst_port", type: :long }
|
22
|
+
]
|
23
|
+
}
|
24
|
+
],
|
25
|
+
collection: [
|
26
|
+
{
|
27
|
+
url: "tcp:0.0.0.0:3003",
|
28
|
+
streams: [
|
29
|
+
{
|
30
|
+
mp: "udp_in",
|
31
|
+
interval: 3
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
)
|
54
39
|
|
@@ -96,7 +96,7 @@ module OmfRc::ResourceProxy::ScheduledApplication
|
|
96
96
|
property :oml, :default => Hashie::Mash.new
|
97
97
|
property :oml_logfile, :default => nil
|
98
98
|
property :oml_loglevel, :default => nil
|
99
|
-
property :schedule, :default =>
|
99
|
+
property :schedule, :default => 'now'
|
100
100
|
property :timeout, :default => 0
|
101
101
|
property :timeout_kill_signal, :default => 'TERM'
|
102
102
|
property :file_change_listener, :default => nil
|
@@ -282,8 +282,16 @@ module OmfRc::ResourceProxy::ScheduledApplication
|
|
282
282
|
# @!method switch_to_unscheduled
|
283
283
|
work('switch_to_unscheduled') do |res|
|
284
284
|
if res.property.state == :scheduled
|
285
|
-
info "Removing cron job for #{res.property.app_id}
|
285
|
+
info "Removing cron job for '#{res.property.app_id}'"
|
286
286
|
CronEdit::Crontab.Remove res.property.app_id
|
287
|
+
pid_file = "#{res.property.app_log_dir}/#{res.property.app_id}.pid.log"
|
288
|
+
File.readlines(pid_file).each do |line|
|
289
|
+
begin
|
290
|
+
Process.kill(res.property.timeout_kill_signal, line.to_i)
|
291
|
+
info "Killing process #{line.to_i}"
|
292
|
+
rescue Errno::ESRCH
|
293
|
+
end
|
294
|
+
end
|
287
295
|
res.property.file_change_listener.stop
|
288
296
|
res.property.state = :unscheduled
|
289
297
|
end
|
@@ -316,27 +324,18 @@ module OmfRc::ResourceProxy::ScheduledApplication
|
|
316
324
|
File.delete(stderr_file) if File.exist?(stderr_file)
|
317
325
|
File.delete(stdout_file) if File.exist?(stdout_file)
|
318
326
|
File.delete(pid_file) if File.exist?(pid_file)
|
319
|
-
|
320
|
-
|
327
|
+
cmd = "ruby -e 'extend Process
|
328
|
+
pid = spawn(\"#{res.build_command_line}\", :out=>[\"#{stdout_file}\", \"a\"], :err=>[\"#{stderr_file}\", \"a\"])
|
321
329
|
`echo \#{pid} >> #{pid_file}`
|
322
330
|
fork {
|
323
331
|
sleep #{res.property.timeout}
|
324
|
-
|
332
|
+
kill(\"#{res.property.timeout_kill_signal}\", pid)
|
325
333
|
} if #{res.property.timeout} > 0
|
326
|
-
|
334
|
+
waitpid(pid)
|
327
335
|
`echo Process \#{pid} exited with code: \#{$?.exitstatus} >> #{stderr_file}`'"
|
328
|
-
cmd.gsub!(/[\n]+/, ";")
|
329
|
-
# cmd = "#{res.build_command_line} 2>>#{stderr_file} 1>>#{stdout_file};"
|
330
|
-
# if res.property.timeout > 0
|
331
|
-
# cmd = "timeout -s #{res.property.timeout_kill_signal} #{res.property.timeout} #{cmd}"
|
332
|
-
# end
|
336
|
+
cmd.gsub!(/[\n]+/, ";") # make it a one-liner
|
333
337
|
info "Adding cron job for '#{res.property.app_id}' with schedule '#{res.property.schedule}' and command '#{cmd}'"
|
334
338
|
CronEdit::Crontab.Add res.property.app_id, "#{res.property.schedule} #{cmd}"
|
335
|
-
# ExecApp.new(res.property.app_id,
|
336
|
-
# res.build_command_line,
|
337
|
-
# res.property.map_err_to_out) do |event_type, app_id, msg|
|
338
|
-
# res.process_event(res, event_type, app_id, msg)
|
339
|
-
# end
|
340
339
|
res.property.file_change_callback = Proc.new do |modified, added, removed|
|
341
340
|
removed.each do |file|
|
342
341
|
res.property.file_read_offset[file]=nil
|
@@ -345,7 +344,6 @@ Process.waitpid(pid)
|
|
345
344
|
files.each do |file|
|
346
345
|
if file.include? stderr_file or file.include? stdout_file
|
347
346
|
res.property.file_read_offset[file]=0 if res.property.file_read_offset[file].nil?
|
348
|
-
p res.property.file_read_offset[file]
|
349
347
|
data = IO.read(file,nil,res.property.file_read_offset[file])
|
350
348
|
res.property.file_read_offset[file]+=data.length
|
351
349
|
data.split(/\r?\n/).each do |line|
|
@@ -4,6 +4,7 @@ module OmfRc::ResourceProxy::ShmNode
|
|
4
4
|
register_proxy :shm_node
|
5
5
|
|
6
6
|
property :app_definition_file
|
7
|
+
property :oml_uri
|
7
8
|
|
8
9
|
request :cron_jobs do |node|
|
9
10
|
node.children.find_all { |v| v.type =~ /scheduled_application/ }.map do |v|
|
@@ -14,14 +15,19 @@ module OmfRc::ResourceProxy::ShmNode
|
|
14
15
|
hook :after_initial_configured do |node|
|
15
16
|
OmfRcShm.app.load_definition(node.request_app_definition_file)
|
16
17
|
|
17
|
-
OmfRcShm.app.definitions.each do |
|
18
|
-
info "Got definition #{
|
19
|
-
|
20
|
-
|
18
|
+
OmfRcShm.app.definitions.each do |name, app_opts|
|
19
|
+
info "Got definition #{app_opts.inspect}, now schedule them..."
|
20
|
+
app_opts[:hrn] = name
|
21
|
+
|
21
22
|
s_app = OmfRc::ResourceFactory.create(:scheduled_application, app_opts)
|
22
23
|
OmfCommon.el.after(5) do
|
23
24
|
s_app.configure_state(:scheduled)
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
hook :before_ready do
|
30
|
+
system "crontab -r"
|
31
|
+
end
|
32
|
+
|
27
33
|
end
|
data/lib/omf_rc_shm/app.rb
CHANGED
data/lib/omf_rc_shm/version.rb
CHANGED
@@ -20,10 +20,10 @@ def run_test(app)
|
|
20
20
|
|
21
21
|
# Configure the 'binary_path' and 'parameters' properties of the App Proxy
|
22
22
|
app.configure(binary_path: "sleep 5",
|
23
|
-
oml_configfile: "/
|
23
|
+
# oml_configfile: "/some/file",
|
24
24
|
timeout: 3,
|
25
25
|
# use_oml: true,
|
26
|
-
schedule: "now"
|
26
|
+
schedule: "* * * * *") # or use "now"
|
27
27
|
|
28
28
|
# Start the application 2 seconds later
|
29
29
|
OmfCommon.eventloop.after 1 do
|
@@ -31,7 +31,7 @@ def run_test(app)
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Stop the application another 10 seconds later
|
34
|
-
OmfCommon.eventloop.after
|
34
|
+
OmfCommon.eventloop.after 150 do
|
35
35
|
app.configure(state: :unscheduled)
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_rc_shm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NICTA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|