omf_ec 6.1.8 → 6.1.9.pre.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.
@@ -39,7 +39,7 @@ module OmfEc
39
39
  results = []
40
40
  all_groups? do |g|
41
41
  plan = g.app_contexts.size * g.members.values.uniq.size
42
- actual = state.count { |v| v.joined?(g.address("application")) && v[:state] == "stopped" }
42
+ actual = state.count { |v| v.joined?(g.address("application")) && v[:state] == "created" }
43
43
  results << (plan == actual) unless (plan == 0)
44
44
  end
45
45
  !results.include?(false)
@@ -88,7 +88,7 @@ module OmfEc::Context
88
88
  # - if this context's param_values has a property which also exists in
89
89
  # the app def and if that property has an assigned value, then
90
90
  # use that value for the properties of this context
91
- p = original.merge({type: 'application', state: 'stopped'})
91
+ p = original.merge({type: 'application', state: 'created'})
92
92
  @param_values.each do |k,v|
93
93
  if p[:parameters].key?(k)
94
94
  p[:parameters][k][:value] = v.kind_of?(OmfEc::ExperimentProperty) ? v.value : v
data/lib/omf_ec/dsl.rb CHANGED
@@ -189,9 +189,14 @@ module OmfEc
189
189
  end
190
190
 
191
191
  # Define an event
192
- def def_event(name, &trigger)
192
+ #
193
+ # @param [Symbol] name of the event
194
+ #
195
+ # @param [Hash] opts additional options
196
+ # @option opts [Fixnum] :every indicates non-reactive style event checking, i.e. trigger will be evaluated periodically with :every as interval
197
+ def def_event(name, opts = {}, &trigger)
193
198
  raise ArgumentError, 'Need a trigger callback' if trigger.nil?
194
- OmfEc.experiment.add_event(name, trigger)
199
+ OmfEc.experiment.add_event(name, opts, trigger)
195
200
  end
196
201
 
197
202
  # Create an alias name of an event
@@ -16,7 +16,7 @@ module OmfEc
16
16
 
17
17
  include MonitorMixin
18
18
 
19
- attr_accessor :name, :oml_uri, :app_definitions, :property, :cmdline_properties, :show_graph, :nodes
19
+ attr_accessor :name, :sliceID, :oml_uri, :js_url, :app_definitions, :property, :cmdline_properties, :show_graph, :nodes
20
20
  attr_reader :groups, :sub_groups, :state
21
21
 
22
22
  # MP only used for injecting metadata
@@ -32,6 +32,7 @@ module OmfEc
32
32
  def initialize
33
33
  super
34
34
  @id = Time.now.utc.iso8601(3)
35
+ @sliceID = nil
35
36
  @state ||= [] #TODO: we need to keep history of all the events and not ovewrite them
36
37
  @groups ||= []
37
38
  @nodes ||= []
@@ -144,11 +145,21 @@ module OmfEc
144
145
  @events.find { |v| v[:name] == name || v[:aliases].include?(name) }
145
146
  end
146
147
 
147
- def add_event(name, trigger)
148
+ def add_event(name, opts, trigger)
148
149
  self.synchronize do
149
150
  warn "Event '#{name}' has already been defined. Overwriting it now." if event(name)
150
151
  @events.delete_if { |e| e[:name] == name }
151
- @events << { name: name, trigger: trigger, aliases: [] }
152
+ @events << { name: name, trigger: trigger, aliases: [] }.merge(opts)
153
+ add_periodic_event(event(name)) if opts[:every]
154
+ end
155
+ end
156
+
157
+ def clear_events
158
+ self.synchronize do
159
+ @events.each do |e|
160
+ e[:periodic_timer].cancel if e[:periodic_timer]
161
+ end
162
+ @events = []
152
163
  end
153
164
  end
154
165
 
@@ -162,20 +173,40 @@ module OmfEc
162
173
  instance.id
163
174
  end
164
175
 
176
+ # Unique slice id (Class method)
177
+ def self.sliceID
178
+ instance.sliceID
179
+ end
180
+
165
181
  # Parsing user defined events, checking conditions against internal state, and execute callbacks if triggered
166
182
  def process_events
167
183
  self.synchronize do
168
- @events.find_all { |v| v[:callbacks] && !v[:callbacks].empty? }.each do |event|
169
- if event[:trigger].call(@state)
170
- @events.delete(event) if event[:consume_event]
171
- event_names = ([event[:name]] + event[:aliases]).join(', ')
172
- info "Event triggered: '#{event_names}'"
173
-
174
- # Last in first serve callbacks
175
- event[:callbacks].reverse.each do |callback|
176
- callback.call
177
- end
178
- end
184
+ @events.find_all { |v| v[:every].nil? }.each do |event|
185
+ eval_trigger(event)
186
+ end
187
+ end
188
+ end
189
+
190
+ def add_periodic_event(event)
191
+ event[:periodic_timer] = OmfCommon.el.every(event[:every]) do
192
+ self.synchronize do
193
+ eval_trigger(event)
194
+ end
195
+ end
196
+ end
197
+
198
+ def eval_trigger(event)
199
+ if event[:callbacks] && !event[:callbacks].empty? && event[:trigger].call(@state)
200
+ # Periodic check event
201
+ event[:periodic_timer].cancel if event[:periodic_timer]
202
+
203
+ @events.delete(event) if event[:consume_event]
204
+ event_names = ([event[:name]] + event[:aliases]).join(', ')
205
+ info "Event triggered: '#{event_names}'"
206
+
207
+ # Last in first serve callbacks
208
+ event[:callbacks].reverse.each do |callback|
209
+ callback.call
179
210
  end
180
211
  end
181
212
  end
@@ -210,6 +241,9 @@ module OmfEc
210
241
  info "Release applications and network interfaces"
211
242
  info "Exit in 15 seconds..."
212
243
 
244
+ # Make sure that all defined events are removed
245
+ OmfEc.experiment.clear_events
246
+
213
247
  OmfCommon.el.after(10) do
214
248
  allGroups do |g|
215
249
  g.resources[type: 'application'].release unless g.app_contexts.empty?
@@ -240,6 +274,7 @@ module OmfEc
240
274
 
241
275
  def start
242
276
  info "Experiment: #{OmfEc.experiment.id} starts"
277
+ info "Slice: #{OmfEc.experiment.sliceID}" unless OmfEc.experiment.sliceID.nil?
243
278
  OmfEc.experiment.log_metadata("state", "running")
244
279
 
245
280
  allGroups do |g|
@@ -45,6 +45,21 @@ module OmfEc::Graph
45
45
  msb
46
46
  end
47
47
 
48
+ # Define the measurement stream to be visualized in
49
+ # the graph through a raw SQL query string.
50
+ # The optional 'context' parameter defines
51
+ # the context in which the stream is used in the graph. This
52
+ # is necessary for graphs, such as 'networks' which need
53
+ # more than one MS to describe the visualization.
54
+ #
55
+ # @param sql
56
+ # @param context
57
+ #
58
+ def sql(raw_sql, context = :default)
59
+ @ms[context] = raw_sql
60
+ raw_sql
61
+ end
62
+
48
63
  # Defines the mapping of columns in the measurement tuples to properties
49
64
  # of the visualization.
50
65
  #
@@ -76,7 +91,8 @@ module OmfEc::Graph
76
91
  info "REPORT:POSTFIX: #{URI.encode(@postfix)}" if @postfix
77
92
  @ms.each do |ctxt, a|
78
93
  a.each do |ms|
79
- info "REPORT:MS:#{ctxt}: #{URI.encode(ms.sql)}"
94
+ sql = ms.is_a?(String) ? ms : ms.sql
95
+ info "REPORT:MS:#{ctxt}: #{URI.encode(sql)}"
80
96
  end
81
97
  end
82
98
  info "REPORT:MAPPING: #{URI.encode(@mapping.to_json)}"
data/lib/omf_ec/group.rb CHANGED
@@ -5,8 +5,10 @@
5
5
 
6
6
  require 'securerandom'
7
7
  require 'monitor'
8
+ require 'omf_ec/group_ext'
8
9
 
9
10
  module OmfEc
11
+
10
12
  # Group instance used in experiment script
11
13
  #
12
14
  # @!attribute name [String] name of the resource
@@ -16,9 +18,12 @@ module OmfEc
16
18
  # @!attribute apps [Array] holding applications to be added to group
17
19
  class Group
18
20
  include MonitorMixin
21
+ extend GroupExt
19
22
 
20
23
  attr_accessor :name, :id, :net_ifs, :members, :app_contexts, :execs
21
- attr_reader :topic
24
+ attr_reader :topic, :g_aliases
25
+
26
+ fwd_method_to_aliases :startApplications, :stopApplications, :startApplication
22
27
 
23
28
  # @param [String] name name of the group
24
29
  # @param [Hash] opts
@@ -31,6 +36,8 @@ module OmfEc
31
36
  self.members = {}
32
37
  self.app_contexts = []
33
38
  self.execs = []
39
+ # To record group 2 group relationship
40
+ @g_aliases = []
34
41
 
35
42
  @resource_topics = {}
36
43
 
@@ -68,6 +75,7 @@ module OmfEc
68
75
  names.each do |name|
69
76
  if (g = OmfEc.experiment.group(name))# resource to add is a group
70
77
  @members.merge!(g.members)
78
+ @g_aliases << g
71
79
  else
72
80
  OmfEc.experiment.nodes << name unless OmfEc.experiment.nodes.include?(name)
73
81
  @members[name] = nil
@@ -127,6 +135,94 @@ module OmfEc
127
135
 
128
136
  alias_method :prototype, :addPrototype
129
137
 
130
- include OmfEc::Backward::Group
138
+ def resource_group(type)
139
+ "#{self.id}_#{type.to_s}"
140
+ end
141
+
142
+ # Create an application for the group and start it
143
+ #
144
+ def exec(command)
145
+ name = SecureRandom.uuid
146
+
147
+ self.synchronize do
148
+ self.execs << name
149
+ end
150
+ create_resource(name, type: 'application', binary_path: command)
151
+
152
+ e_name = "#{self.name}_application_#{name}_created"
153
+
154
+ resource_group_name = self.address("application")
155
+
156
+ def_event e_name do |state|
157
+ state.find_all { |v| v[:hrn] == name && v[:membership] && v[:membership].include?(resource_group_name)}.size >= self.members.values.sort.uniq.size
158
+ end
159
+
160
+ on_event e_name do
161
+ resources[type: 'application', name: name].state = :running
162
+ end
163
+ end
164
+
165
+ # Start ONE application by name
166
+ def startApplication(app_name)
167
+ if self.app_contexts.find { |v| v.name == app_name }
168
+ resources[type: 'application', name: app_name].state = :running
169
+ else
170
+ warn "No application with name '#{app_name}' defined in group #{self.name}. Nothing to start"
171
+ end
172
+ end
173
+
174
+ # Start ALL applications in the group
175
+ def startApplications
176
+ if self.app_contexts.empty?
177
+ warn "No applications defined in group #{self.name}. Nothing to start"
178
+ else
179
+ resources[type: 'application'].state = :running
180
+ end
181
+ end
182
+
183
+ # Stop ALL applications in the group
184
+ def stopApplications
185
+ if self.app_contexts.empty?
186
+ warn "No applications defined in group #{self.name}. Nothing to stop"
187
+ else
188
+ resources[type: 'application'].state = :stopped
189
+ end
190
+ end
191
+
192
+ def addApplication(name, location = nil, &block)
193
+ app_cxt = OmfEc::Context::AppContext.new(name,location,self)
194
+ block.call(app_cxt) if block
195
+ self.app_contexts << app_cxt
196
+ end
197
+
198
+ # @example
199
+ # group('actor', 'node1', 'node2') do |g|
200
+ # g.net.w0.ip = '0.0.0.0'
201
+ # g.net.e0.ip = '0.0.0.1'
202
+ # end
203
+ def net
204
+ self.net_ifs ||= []
205
+ self
206
+ end
207
+
208
+ def method_missing(name, *args, &block)
209
+ if name =~ /w(\d+)/
210
+ net = self.net_ifs.find { |v| v.conf[:if_name] == "wlan#{$1}" }
211
+ if net.nil?
212
+ net = OmfEc::Context::NetContext.new(:type => 'wlan', :if_name => "wlan#{$1}", :index => $1)
213
+ self.net_ifs << net
214
+ end
215
+ net
216
+ elsif name =~ /e(\d+)/
217
+ net = self.net_ifs.find { |v| v.conf[:if_name] == "eth#{$1}" }
218
+ if net.nil?
219
+ net = OmfEc::Context::NetContext.new(:type => 'net', :if_name => "eth#{$1}", :index => $1)
220
+ self.net_ifs << net
221
+ end
222
+ net
223
+ else
224
+ super
225
+ end
226
+ end
131
227
  end
132
228
  end
@@ -0,0 +1,19 @@
1
+ module OmfEc
2
+ module GroupExt
3
+ @@methods_to_fwd = []
4
+
5
+ def fwd_method_to_aliases(*m)
6
+ @@methods_to_fwd += m.flatten
7
+ end
8
+
9
+ def method_added(m)
10
+ if @@methods_to_fwd.delete(m)
11
+ alias_method "#{m}_without_fwd_to_aliases", m
12
+ define_method m do |*args, &block|
13
+ method("#{m}_without_fwd_to_aliases").call(*args, &block)
14
+ self.g_aliases.each { |g| g.send(m, *args, &block) }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/omf_ec/runner.rb CHANGED
@@ -97,11 +97,17 @@ module OmfEc
97
97
  remove_cmd_opts_from_argv("--name", "--experiment", e_name)
98
98
  end
99
99
 
100
- op.on("--slice SLICE_NAME", "Slice name [Deprecated]") do |slice|
100
+ op.on("--slice SLICE_NAME", "Slice name [optional]") do |slice|
101
101
  @cmd_opts[:slice] = slice
102
+ OmfEc.experiment.sliceID = slice
102
103
  remove_cmd_opts_from_argv("--slice", slice)
103
104
  end
104
105
 
106
+ op.on("--job_service URL", "URL to the JobService [optional]") do |url|
107
+ OmfEc.experiment.js_url = url
108
+ remove_cmd_opts_from_argv("--job_service", url)
109
+ end
110
+
105
111
  op.on("--oml_uri URI", "URI for the OML data collection of experiment applications") do |uri|
106
112
  @cmd_opts[:oml_uri] = uri
107
113
  remove_cmd_opts_from_argv("--oml_uri", uri)
data/lib/omf_ec.rb CHANGED
@@ -6,7 +6,6 @@
6
6
  require "omf_common"
7
7
  require 'omf_ec/core_ext/hash'
8
8
  require 'omf_ec/backward/dsl'
9
- require 'omf_ec/backward/group'
10
9
  require 'omf_ec/backward/app_definition'
11
10
  require 'omf_ec/backward/default_events'
12
11
  require 'omf_ec/backward/core_ext/array'
@@ -20,7 +20,7 @@ describe OmfEc::Experiment do
20
20
 
21
21
  it "must be able to add event" do
22
22
  trigger = proc { 1 }
23
- @experiment.add_event('bob', trigger)
23
+ @experiment.add_event('bob', {}, trigger)
24
24
  @experiment.event('bob')[:name].must_equal "bob"
25
25
  @experiment.event('bob')[:trigger].call.must_equal 1
26
26
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_ec
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.8
5
- prerelease:
4
+ version: 6.1.9.pre.2
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - NICTA
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-10 00:00:00.000000000 Z
12
+ date: 2014-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - '='
100
100
  - !ruby/object:Gem::Version
101
- version: 6.1.8
101
+ version: 6.1.9.pre.2
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 6.1.8
109
+ version: 6.1.9.pre.2
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: sequel
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -154,7 +154,6 @@ files:
154
154
  - lib/omf_ec/backward/default_events.rb
155
155
  - lib/omf_ec/backward/dsl.rb
156
156
  - lib/omf_ec/backward/exp/testbed.rb
157
- - lib/omf_ec/backward/group.rb
158
157
  - lib/omf_ec/backward/timeout_resources.rb
159
158
  - lib/omf_ec/context.rb
160
159
  - lib/omf_ec/context/app_context.rb
@@ -168,6 +167,7 @@ files:
168
167
  - lib/omf_ec/graph.rb
169
168
  - lib/omf_ec/graph/graph_description.rb
170
169
  - lib/omf_ec/group.rb
170
+ - lib/omf_ec/group_ext.rb
171
171
  - lib/omf_ec/parameter.rb
172
172
  - lib/omf_ec/property.rb
173
173
  - lib/omf_ec/prototype.rb
@@ -199,12 +199,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
199
  required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  none: false
201
201
  requirements:
202
- - - ! '>='
202
+ - - ! '>'
203
203
  - !ruby/object:Gem::Version
204
- version: '0'
205
- segments:
206
- - 0
207
- hash: -3601576826864806014
204
+ version: 1.3.1
208
205
  requirements: []
209
206
  rubyforge_project: omf_ec
210
207
  rubygems_version: 1.8.23
@@ -1,110 +0,0 @@
1
- # Copyright (c) 2012 National ICT Australia Limited (NICTA).
2
- # This software may be used and distributed solely under the terms of the MIT license (License).
3
- # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
- # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
-
6
- require 'securerandom'
7
-
8
- module OmfEc
9
- module Backward
10
- module Group
11
- # The following are ODEL 5 methods
12
-
13
- def resource_group(type)
14
- "#{self.id}_#{type.to_s}"
15
- end
16
-
17
- # Create an application for the group and start it
18
- #
19
- def exec(command)
20
- name = SecureRandom.uuid
21
-
22
- self.synchronize do
23
- self.execs << name
24
- end
25
- create_resource(name, type: 'application', binary_path: command)
26
-
27
- e_name = "#{self.name}_application_#{name}_created"
28
-
29
- resource_group_name = self.address("application")
30
-
31
- def_event e_name do |state|
32
- state.find_all { |v| v[:hrn] == name && v[:membership] && v[:membership].include?(resource_group_name)}.size >= self.members.values.sort.uniq.size
33
- end
34
-
35
- on_event e_name do
36
- resources[type: 'application', name: name].state = :running
37
- end
38
- end
39
-
40
- def startApplication(app_name)
41
- if self.app_contexts.find { |v| v.name == app_name }
42
- resources[type: 'application', name: app_name].state = :running
43
- else
44
- warn "No application with name '#{app_name}' defined in group #{self.name}. Nothing to start"
45
- end
46
- end
47
-
48
- def startApplication(app_name)
49
- if self.app_contexts.find { |v| v.name == app_name }
50
- resources[type: 'application', name: app_name].state = :running
51
- else
52
- warn "No application with name '#{app_name}' defined in group #{self.name}. Nothing to start"
53
- end
54
- end
55
-
56
- def startApplications
57
- if self.app_contexts.empty?
58
- warn "No applications defined in group #{self.name}. Nothing to start"
59
- else
60
- resources[type: 'application'].state = :running
61
- end
62
- end
63
-
64
- def stopApplications
65
- if self.app_contexts.empty?
66
- warn "No applications defined in group #{self.name}. Nothing to stop"
67
- else
68
- resources[type: 'application'].state = :stopped
69
- end
70
- end
71
-
72
- def addApplication(name, location = nil, &block)
73
- app_cxt = OmfEc::Context::AppContext.new(name,location,self)
74
- block.call(app_cxt) if block
75
- self.app_contexts << app_cxt
76
- end
77
-
78
- # @example
79
- # group('actor', 'node1', 'node2') do |g|
80
- # g.net.w0.ip = '0.0.0.0'
81
- # g.net.e0.ip = '0.0.0.1'
82
- # end
83
- def net
84
- self.net_ifs ||= []
85
- self
86
- end
87
-
88
- def method_missing(name, *args, &block)
89
- if name =~ /w(\d+)/
90
- net = self.net_ifs.find { |v| v.conf[:if_name] == "wlan#{$1}" }
91
- if net.nil?
92
- net = OmfEc::Context::NetContext.new(:type => 'wlan', :if_name => "wlan#{$1}", :index => $1)
93
- self.net_ifs << net
94
- end
95
- net
96
- elsif name =~ /e(\d+)/
97
- net = self.net_ifs.find { |v| v.conf[:if_name] == "eth#{$1}" }
98
- if net.nil?
99
- net = OmfEc::Context::NetContext.new(:type => 'net', :if_name => "eth#{$1}", :index => $1)
100
- self.net_ifs << net
101
- end
102
- net
103
- else
104
- super
105
- end
106
- end
107
-
108
- end
109
- end
110
- end