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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGVlZDhmOTQ2NzU5MWZhOTg0ODQ0MjAyMmVkODU0Mzg0ZDY3YmUyMA==
4
+ YWI4OGY2NmNkZDk0ZjFkYzA5NTUyNzA4MzZkYWFmMzUxNjMzMjc0NA==
5
5
  data.tar.gz: !binary |-
6
- OGE1NmNkOWJmMDFjMGNhOWMxNWU1ZGY3YmIyYTZjODE4NmQxNzQwYg==
6
+ M2ZjMGIzNzQ4OWEyY2Y1NTlkNGRkNTY5NjJjYjAxMTI3NDA2MjFkZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjQwYWVkNjUwYzVlMWUwNTM3NTVkNzhlYzJjNDNiMjIxNWFjOTZkMmRhYTY2
10
- MTg1Mjg2NzI0MWZhODVlNjU4MjAwNjQ3ZWNkYjViNjg2NTllM2RlOGFhZjYw
11
- ZjAzYjA3ZjEwMGI4ZjgwNGUxNzUwNDUxYjlhZmYyODUyMTNiOTI=
9
+ ZTlmZGQ3YWVkZmVkZmExODc2YzI2NzI2ODYwM2ZmZjZkOWQwMjdhZjNhNzEy
10
+ OWNhY2E4NDM3ZTNiZjIxNDVjOTdjYTMyMGFkNTUxMjNiOTM3ZGRiMWMzZGVi
11
+ MjQ1YTgxYjhjYTYxMWY5NzkxYTAwYmE5N2YyODk0YWNiZTI3OTA=
12
12
  data.tar.gz: !binary |-
13
- YTE2MTMxYTgzMmNhMzdiNDZjOTc4YmQ0NzFmNzQ3Y2NkNjAyODczNmEzMjQ4
14
- NzdjOGMzODY4YWQzZmIxOGI5YzYzMDljOTYzODZkMGE4NjIzNTJmY2QxMzEw
15
- NDFhNWZjYmY0OGI0ZmE4MmJhYmUyYjNhZTBjMTBjNDk1M2EyNjY=
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
- Where app_definition_file for shm_node simply defines the applications it runs using OEDL defApplication syntax.
30
-
31
- Example of defApplication:
32
-
33
- defApplication('otr2') do |a|
34
- a.schedule = "* 18 * * *"
35
- a.binary_path = "/usr/bin/otr2"
36
- a.defProperty('udp_local_host', 'IP address of this Destination node', '--udp:local_host', { :type => :string, :dynamic => false })
37
- a.defProperty('udp_local_port', 'Receiving Port of this Destination node', '--udp:local_port', { :type => :integer, :dynamic => false })
38
- a.defMeasurement('udp_in') do |m|
39
- m.defMetric('flow_id',:long)
40
- m.defMetric('seq_no',:long)
41
- m.defMetric('pkt_length',:long)
42
- m.defMetric('dst_host',:string)
43
- m.defMetric('dst_port',:long)
44
- end
45
- end
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
- defApplication('otr2') do |a|
2
- a.schedule = "* * * * *"
3
- a.timeout = 20
4
- a.binary_path = "/usr/bin/otr2"
5
- a.description = <<TEXT
6
- otr is a configurable traffic sink. It contains port to receive
7
- packet streams via various transport options, such as TCP and UDP.
8
- This version 2 is compatible with OMLv2.
9
- TEXT
10
-
11
- a.defProperty('udp_local_host', 'IP address of this Destination node', '--udp:local_host', {:type => :string, :dynamic => false})
12
- a.defProperty('udp_local_port', 'Receiving Port of this Destination node', '--udp:local_port', {:type => :integer, :dynamic => false})
13
- a.defMeasurement('udp_in') do |m|
14
- m.defMetric('flow_id',:long)
15
- m.defMetric('seq_no',:long)
16
- m.defMetric('pkt_length',:long)
17
- m.defMetric('dst_host',:string)
18
- m.defMetric('dst_port',:long)
19
- end
20
- end
21
-
22
- defApplication('otg2') do |a|
23
- a.schedule = "* * * * *"
24
- a.timeout = 20
25
- a.binary_path = "/usr/bin/otg2"
26
- a.description = <<TEXT
27
- OTG is a configurable traffic generator. It contains generators
28
- producing various forms of packet streams and port for sending
29
- these packets via various transports, such as TCP and UDP.
30
- This version 2 is compatible with OMLv2
31
- TEXT
32
-
33
- a.defProperty('generator', 'Type of packet generator to use (cbr or expo)', '-g', {:type => :string, :dynamic => false})
34
- a.defProperty('udp_broadcast', 'Broadcast', '--udp:broadcast', {:type => :integer, :dynamic => false})
35
- a.defProperty('udp_dst_host', 'IP address of the Destination', '--udp:dst_host', {:type => :string, :dynamic => false})
36
- a.defProperty('udp_dst_port', 'Destination Port to send to', '--udp:dst_port', {:type => :integer, :dynamic => false})
37
- a.defProperty('udp_local_host', 'IP address of this Source node', '--udp:local_host', {:type => :string, :dynamic => false})
38
- a.defProperty('udp_local_port', 'Local Port of this source node', '--udp:local_port', {:type => :integer, :dynamic => false})
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 => "now"
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} with command #{res.build_command_line}"
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
- #cmd = "#{res.build_command_line} 2>>#{stderr_file} 1>>#{stdout_file}; echo \"Application exited with code: $? \" >>#{stderr_file}"
320
- cmd = "ruby -e 'pid = spawn(\"#{res.build_command_line}\", :out=>[\"#{stdout_file}\", \"a\"], :err=>[\"#{stderr_file}\", \"a\"])
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
- Process.kill(\"#{res.property.timeout_kill_signal}\", pid)
332
+ kill(\"#{res.property.timeout_kill_signal}\", pid)
325
333
  } if #{res.property.timeout} > 0
326
- Process.waitpid(pid)
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 |d|
18
- info "Got definition #{d.inspect}, now schedule them..."
19
- app_id = d[0]
20
- app_opts = d[1].properties.merge(hrn: app_id, use_oml: true)
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
@@ -17,5 +17,9 @@ module OmfRcShm
17
17
  def load_definition(file_path)
18
18
  eval(File.read(file_path))
19
19
  end
20
+
21
+ def self.define(app_name, app_opts)
22
+ self.instance.definitions[app_name] = app_opts
23
+ end
20
24
  end
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module OmfRcShm
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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: "/Users/cdw/tempo/omf_rc_shm/README.md",
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 200 do
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.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-05 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler