oml4r 2.8.0 → 2.9.pre.151.f020
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/oml4r.rb +44 -22
- metadata +5 -5
data/lib/oml4r.rb
CHANGED
@@ -32,6 +32,7 @@
|
|
32
32
|
require 'socket'
|
33
33
|
require 'monitor'
|
34
34
|
require 'thread'
|
35
|
+
require 'optparse'
|
35
36
|
|
36
37
|
#
|
37
38
|
# This is the OML4R module, which should be required by ruby applications
|
@@ -39,11 +40,15 @@ require 'thread'
|
|
39
40
|
#
|
40
41
|
module OML4R
|
41
42
|
|
42
|
-
VERSION = "2.
|
43
|
-
|
44
|
-
|
43
|
+
VERSION = "2.9.pre.151.f020"
|
44
|
+
VERSION_STRING = "OML4R Client V#{VERSION}"
|
45
|
+
COPYRIGHT = "Copyright 2009-2012, NICTA"
|
45
46
|
DEF_SERVER_PORT = 3003
|
46
47
|
|
48
|
+
PROTOCOL = 3
|
49
|
+
@loglevel = 0
|
50
|
+
class << self; attr_accessor :loglevel; end
|
51
|
+
|
47
52
|
#
|
48
53
|
# Measurement Point Class
|
49
54
|
# Ruby applications using this module should sub-class this MPBase class
|
@@ -101,7 +106,7 @@ module OML4R
|
|
101
106
|
o[:name] = name
|
102
107
|
o[:type] ||= :string
|
103
108
|
if o[:type] == :long
|
104
|
-
$stderr.puts "
|
109
|
+
$stderr.puts "WARN :long is deprecated use, :int32 instead"
|
105
110
|
o[:type] = :int32
|
106
111
|
end
|
107
112
|
__def__()[:p_def] << o
|
@@ -152,12 +157,12 @@ module OML4R
|
|
152
157
|
# replace channel names with channel object
|
153
158
|
self.each_mp do |klass, defs|
|
154
159
|
cna = @@channels[klass] || []
|
155
|
-
|
160
|
+
$stderr.puts "DEBUG '#{cna.inspect}', '#{klass}'" if OML4R.loglevel > 0
|
156
161
|
ca = cna.collect do |cname, domain|
|
157
162
|
# return it in an array as we need to add the channel specific index
|
158
163
|
[Channel[cname.to_sym, domain.to_sym]]
|
159
164
|
end
|
160
|
-
|
165
|
+
$stderr.puts "DEBUG Using channels '#{ca.inspect}" if OML4R.loglevel > 0
|
161
166
|
@@channels[klass] = ca.empty? ? [[Channel[]]] : ca
|
162
167
|
end
|
163
168
|
@@start_time = start_time
|
@@ -188,7 +193,7 @@ module OML4R
|
|
188
193
|
end
|
189
194
|
|
190
195
|
@@channels[self].each do |ca|
|
191
|
-
|
196
|
+
$stderr.puts "DEBUG Setting up channel '#{ca.inspect}" if OML4R.loglevel > 0
|
192
197
|
index = ca[0].send_schema(mp_name, defs[:p_def])
|
193
198
|
ca << index
|
194
199
|
end
|
@@ -210,11 +215,12 @@ module OML4R
|
|
210
215
|
# - & block = a block which defines the additional application-specific arguments
|
211
216
|
#
|
212
217
|
def self.init(argv, opts = {}, &block)
|
218
|
+
$stderr.puts("INFO #{VERSION_STRING} [Protocol V#{PROTOCOL}] #{COPYRIGHT}")
|
213
219
|
|
214
220
|
if d = (ENV['OML_EXP_ID'] || opts[:expID])
|
215
221
|
# XXX: It is still too early to complain about that. We need to be sure
|
216
222
|
# of the nomenclature before making user-visible changes.
|
217
|
-
|
223
|
+
$stderr.puts "WARN opts[:expID] and ENV['OML_EXP_ID'] are getting deprecated; please use opts[:domain] or ENV['OML_DOMAIN'] instead"
|
218
224
|
opts[:domain] ||= d
|
219
225
|
end
|
220
226
|
domain ||= ENV['OML_DOMAIN'] || opts[:domain]
|
@@ -233,24 +239,37 @@ module OML4R
|
|
233
239
|
appName = opts[:appName] || opts[:app]
|
234
240
|
|
235
241
|
if ENV['OML_URL'] || opts[:omlURL] || opts[:url]
|
236
|
-
raise '
|
242
|
+
raise 'ERROR neither OML_URL, :omlURL nor :url are valid. Do you mean OML_COLLECT or :omlCollect?'
|
243
|
+
end
|
244
|
+
if ENV['OML_SERVER'] || opts[:omlServer]
|
245
|
+
$stderr.puts "WARN opts[:omlServer] and ENV['OML_SERVER'] are getting deprecated; please use opts[:collect] or ENV['OML_COLLECT'] instead"
|
237
246
|
end
|
238
|
-
omlCollectUri = ENV['OML_SERVER'] || opts[:omlServer]
|
247
|
+
omlCollectUri = ENV['OML_COLLECT'] || ENV['OML_SERVER'] || opts[:collect] || opts[:omlServer]
|
239
248
|
noop = opts[:noop] || false
|
240
249
|
|
241
250
|
|
242
251
|
# Create a new Parser for the command line
|
243
|
-
require 'optparse'
|
244
252
|
op = OptionParser.new
|
245
253
|
# Include the definition of application's specific arguments
|
246
254
|
yield(op) if block
|
247
255
|
# Include the definition of OML specific arguments
|
248
|
-
op.on("--oml-file file", "Writes measurements to 'file'") { |name| omlCollectUri = "file:#{name}" }
|
249
256
|
op.on("--oml-id id", "Name to identify this app instance [#{nodeID || 'undefined'}]") { |name| nodeID = name }
|
250
|
-
op.on("--oml-
|
251
|
-
op.on("--oml-
|
252
|
-
op.on("--oml-
|
257
|
+
op.on("--oml-domain domain", "Name of experimental domain [#{domain || 'undefined'}] *EXPERIMENTAL*") { |name| domain = name }
|
258
|
+
op.on("--oml-collect uri", "URI of server to send measurements to") { |u| omlCollectUri = u }
|
259
|
+
op.on("--oml-log-level l", "Log level used (info: 0 .. debug: 1)") { |l| OML4R.loglevel = l.to_i; puts "-> #{OML4R.loglevel}" }
|
253
260
|
op.on("--oml-noop", "Do not collect measurements") { noop = true }
|
261
|
+
op.on("--oml-exp-id domain", "Obsolescent equivalent to --oml-domain domain") { |name|
|
262
|
+
domain = name
|
263
|
+
$stderr.puts "WARN Option --oml-exp-id is getting deprecated; please use '--oml-domain #{domain}' instead"
|
264
|
+
}
|
265
|
+
op.on("--oml-file localPath", "Obsolescent equivalent to --oml-collect file:localPath") { |name|
|
266
|
+
omlCollectUri = "file:#{name}"
|
267
|
+
$stderr.puts "WARN Option --oml-file is getting deprecated; please use '--oml-collect #{omlCollectUri}' instead"
|
268
|
+
}
|
269
|
+
op.on("--oml-server uri", "Obsolescent equivalent to --oml-collect uri") {|u|
|
270
|
+
omlCollectUri = u
|
271
|
+
$stderr.puts "WARN Option --oml-server is getting deprecated; please use '--oml-collect #{omlCollectUri}' instead"
|
272
|
+
}
|
254
273
|
op.on_tail("--oml-help", "Show this message") { $stderr.puts op; exit }
|
255
274
|
# XXX: This should be set by the application writer, not the command line
|
256
275
|
#op.on("--oml-appid APPID", "Application ID for OML [#{appName || 'undefined'}] *EXPERIMENTAL*") { |name| appID = name }
|
@@ -259,12 +278,12 @@ module OML4R
|
|
259
278
|
omlCollectUri ||= "file:#{appName}_#{nodeID}_#{domain}_#{Time.now.strftime("%Y-%m-%dt%H.%M.%S%z")}"
|
260
279
|
|
261
280
|
# Now parse the command line
|
262
|
-
|
281
|
+
$stderr.puts "DEBUG ARGV:>>> #{argv.inspect}" if OML4R.loglevel > 0
|
263
282
|
rest = op.parse(argv)
|
264
283
|
return if noop
|
265
284
|
|
266
285
|
unless domain && nodeID && appName
|
267
|
-
raise 'OML4R: Missing values for parameters :
|
286
|
+
raise 'OML4R: Missing values for parameters :domain (--oml-domain), :nodeID (--oml-id), or :appName (in code)!'
|
268
287
|
end
|
269
288
|
|
270
289
|
Channel.create(:default, omlCollectUri) if omlCollectUri
|
@@ -272,8 +291,8 @@ module OML4R
|
|
272
291
|
# Handle the defined Measurement Points
|
273
292
|
startTime = Time.now
|
274
293
|
Channel.init_all(domain, nodeID, appName, startTime)
|
275
|
-
msg = "
|
276
|
-
Object.const_defined?(:MObject) ? MObject.debug(:oml4r, msg) : $stderr.puts("
|
294
|
+
msg = "Collection URI is #{omlCollectUri}"
|
295
|
+
Object.const_defined?(:MObject) ? MObject.debug(:oml4r, msg) : $stderr.puts("INFO #{msg}")
|
277
296
|
|
278
297
|
rest || []
|
279
298
|
end
|
@@ -309,7 +328,7 @@ module OML4R
|
|
309
328
|
end
|
310
329
|
|
311
330
|
def self._create(key, domain, url)
|
312
|
-
#oml_opts = {:
|
331
|
+
#oml_opts = {:domain => 'image_load', :node_id => 'n1', :app_name => 'img_load'}
|
313
332
|
if url.start_with? 'file:'
|
314
333
|
proto, fname = url.split(':')
|
315
334
|
out = (fname == '-' ? $stdout : File.open(fname, "w+"))
|
@@ -403,9 +422,12 @@ module OML4R
|
|
403
422
|
|
404
423
|
|
405
424
|
def send_protocol_header(nodeID, appName, startTime)
|
406
|
-
@queue.push "protocol:
|
425
|
+
@queue.push "protocol: #{PROTOCOL}"
|
407
426
|
d = (@domain == :default) ? @@default_domain : @domain
|
408
427
|
raise "Missing domain name" unless d
|
428
|
+
# Protocol V4
|
429
|
+
#@queue.push "domain: #{d}"
|
430
|
+
#@queue.push "start-time: #{startTime.tv_sec}"
|
409
431
|
@queue.push "experiment-id: #{d}"
|
410
432
|
@queue.push "start_time: #{startTime.tv_sec}"
|
411
433
|
@queue.push "sender-id: #{nodeID}"
|
@@ -438,7 +460,7 @@ module OML4R
|
|
438
460
|
@out = nil
|
439
461
|
rescue Exception => ex
|
440
462
|
msg = "Exception while sending message to channel '#{@url}' (#{ex})"
|
441
|
-
Object.const_defined?(:MObject) ? MObject.warn(:oml4r, msg) : $stderr.puts("
|
463
|
+
Object.const_defined?(:MObject) ? MObject.warn(:oml4r, msg) : $stderr.puts("INFO #{msg}")
|
442
464
|
end
|
443
465
|
end
|
444
466
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oml4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.9.pre.151.f020
|
5
|
+
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- NICTA
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! '["Simple OML client library for Ruby"]'
|
15
15
|
email:
|
@@ -42,9 +42,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
45
|
-
- - ! '
|
45
|
+
- - ! '>'
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.3.1
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
50
|
rubygems_version: 1.8.23
|