omf_rc 6.0.7.1 → 6.0.8.pre.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b2e820a1934c20b23aa5c856ae703cf133a02754
4
- data.tar.gz: 54d8d9ba99a745bdbeef85260c66d71ef893012c
5
- SHA512:
6
- metadata.gz: f76a8aff1d31d9768c4999385594aef8bd2f0bd71ab117cd5defeecbfa91c349a282ca5d3381bff6a2d49daa5022fc38de9c4b0606224a599e2e9282ad5ec47a
7
- data.tar.gz: 8862865525de1f67d2e68d1766a4d7cba008aeb41ec63076f6571866f29f692801bf95272e9016dd1a4985ae3bc6847a7bc2c9d5afa4b56207fc6915e6137f5e
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2JmN2U2NmJlNTc4OGI5OWViYWZjNzdkMDg3MWZkYjFiNWFjMzhkNA==
5
+ data.tar.gz: !binary |-
6
+ NDk2NTEzZGY4MzYyYmZmNDA5OTY4MzNkOGY3MTBkMmY3M2RhN2NiZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ N2M2YmRkNmJjYTVkYWViZjRjOWUwZmQ1MDM4ZmQ3YTFmZWM4YWRiMjUxZTAw
10
+ OGU2OWI3YzlhNGJkN2IzM2E3YjI2YjRkNTY0ZDk0MmI5ZWNhZjM5NzA2OTky
11
+ YjE5NGUyMzhmYmI0Y2VlYWY0NDVjZDExOTk3M2ZlYjA3OWU5OTI=
12
+ data.tar.gz: !binary |-
13
+ N2Q5YjI4Y2MzYWU5ODgxNTM4NDgyZWZkMjg1NTQyNTU0ZmU3ZjE3MGQ5NGRj
14
+ NmE4ZDMwZjUxMWNhZGExYTRiMDg2YTQzY2VhZGIxZjM0MzcwNmFlMjU3NmEy
15
+ MjdkYmU5MzQ4ZDdmYjI4NDYzZGZhYWE5OWRkNWJhYjcxNTMzZTA=
data/bin/install_omf_rc CHANGED
@@ -44,30 +44,23 @@ end
44
44
 
45
45
  if options[:init]
46
46
  puts "Detecting operating system..."
47
-
47
+ FileUtils.cp "#{gem_root}/init/run_omf_rc.sh", "/usr/local/bin/run_omf_rc.sh"
48
48
  if !File.exist?("/etc/issue")
49
49
  abort "Unknown or unsupported operating system. Cannot install init script."
50
50
  end
51
-
52
- os=`awk 'NR==1 {print $1}' /etc/issue`.chomp
53
-
54
- if os.nil?
55
- abort "Unknown or unsupported operating system. Cannot install init script."
56
- end
57
-
58
- puts "'#{os}' found"
59
-
60
- FileUtils.cp "#{gem_root}/init/run_omf_rc.sh", "/usr/local/bin/run_omf_rc.sh"
61
-
62
- case os
63
- when "Ubuntu"
51
+ issue = File.read("/etc/issue")
52
+ if issue.include? "Ubuntu"
64
53
  FileUtils.cp "#{gem_root}/init/ubuntu", "/etc/init/omf_rc.conf"
65
54
  puts "Upstart script for Ubuntu has been installed. Execute 'start omf_rc' to run the daemon."
66
- when "Debian"
55
+ elsif issue.include? "Debian"
67
56
  FileUtils.cp "#{gem_root}/init/debian", "/etc/init.d/omf_rc"
68
57
  `update-rc.d omf_rc defaults`
69
58
  puts "Init script for Debian has been installed. Execute '/etc/init.d/omf_rc start' to run the daemon."
70
- when "Fedora"
59
+ elsif issue.include? "Angstrom"
60
+ FileUtils.cp "#{gem_root}/init/angstrom", "/etc/init.d/omf_rc"
61
+ `update-rc.d omf_rc defaults`
62
+ puts "Init script for Angstrom has been installed. Execute '/etc/init.d/omf_rc start' to run the daemon."
63
+ elsif issue.include? "Fedora"
71
64
  FileUtils.cp "#{gem_root}/init/fedora", "/etc/init.d/omf_rc"
72
65
  `chkconfig --add omf_rc`
73
66
  # older Fedora's don't use systemd
data/bin/omf_rc CHANGED
@@ -12,214 +12,8 @@ require 'socket'
12
12
 
13
13
  require 'omf_rc'
14
14
  require 'omf_rc/resource_factory'
15
+ require 'omf_rc/runner'
15
16
 
16
17
  $stdout.sync = true
17
18
 
18
- #
19
- # Class to start an OMF RC. The configuration parameters can be set
20
- # in decreasing priority through the command line, configuration
21
- # file and default settings (see @def_opts).
22
- #
23
- # For historic reasons and to make this implementation more interesting
24
- # there are two different config file formats. A 'normal' one inherited from
25
- # earlier version of OMF, and an 'advanced' one which is identical to the
26
- # format accepted by OmfCommon.init(). To maintain some level of sanity,
27
- # only one configuration file is accepted.
28
- #
29
- # Having said that, there is one exception and that relates to the 'oml'
30
- # configuration which is stripped out first and handed to the OML4R library
31
- # during command line parsing.
32
- #
33
- class OmfRcRunner
34
- def initialize()
35
- @options = {}
36
- @executable_name = File.basename($PROGRAM_NAME)
37
- @oml_enabled = false
38
- @gem_version = Gem::Specification.find_by_name('omf_rc').version.to_s
39
-
40
- @node_id = Socket.gethostname
41
-
42
- @def_opts = {
43
- uid: @node_id,
44
- uri: "xmpp:#{@node_id}-#{Process.pid}:#{@node_id}-#{Process.pid}@localhost",
45
- environment: 'production',
46
- debug: false
47
- }
48
- @copts = {}
49
-
50
- @gopts = {
51
- config_file: nil,
52
- adv_config_file: nil,
53
- logging_configfile: nil,
54
- environment: nil
55
- }
56
-
57
- @opts = {}
58
- @omlopts = {appName: @executable_name}
59
- end
60
-
61
- def run()
62
- setup()
63
- OmfCommon::Measure.enable if @oml_enabled
64
-
65
- OmfCommon.init(@gopts[:environment], @opts) do |el|
66
- # Load a customised logging set up if provided
67
- OmfCommon.load_logging_config(@gopts[:logging_configfile]) if @gopts[:logging_configfile]
68
-
69
- info "Starting OMF Resource Controller version '#{@gem_version}'"
70
-
71
- #el.on_int_signal do # Implementation missing
72
- Signal.trap("SIGINT") do
73
- # TODO: Should release resources first
74
- info "Stopping ..."
75
- OmfCommon.comm.disconnect
76
- end
77
-
78
- # Load extensions
79
- if @opts[:add_default_factories] != false
80
- OmfRc::ResourceFactory.load_default_resource_proxies
81
- end
82
-
83
- @opts[:factories].each do |f|
84
- if (req = f[:require])
85
- begin
86
- info "Try to load resource module '#{req}'"
87
- require(req)
88
- rescue LoadError => e
89
- error e.message
90
- end
91
- end
92
- end
93
-
94
- OmfCommon.comm.on_connected do |comm|
95
- info "Connected using #{comm.conn_info}"
96
-
97
- #if @opts[:auth] && @optss[:auth][:root_cert_dir]
98
- # OmfCommon::Auth::CertificateStore.instance.register_default_certs(@opts[:auth][:root_cert_dir])
99
- #end
100
- #OmfCommon::Auth::CertificateStore.instance.register(entity) if entity
101
-
102
- @opts[:resources].each do |res_opts|
103
- rtype = res_opts.delete(:type)
104
- res_creation_opts = res_opts.delete(:creation_opts)
105
- res_creation_opts ||= res_opts.delete(:create_opts)
106
- res_creation_opts ||= {}
107
- #res_opts[:certificate] = entity if entity
108
- begin
109
- OmfRc::ResourceFactory.create(rtype, res_opts, res_creation_opts)
110
- rescue => e
111
- error "#{e.message}\n#{e.backtrace.join("\n")}"
112
- end
113
- end
114
-
115
- end
116
- end
117
- info "Stopping OMF Resource Controller version '#{@gem_version}'"
118
- end
119
-
120
- def setup()
121
- oml_init() # calls parse_config_files()
122
- unless @opts[:communication][:url]
123
- puts "Error: Missing parameters to connect to a PubSub Server (see --help)"
124
- exit(1)
125
- end
126
-
127
- opts = @opts
128
- # TODO: This needs to be fixed
129
- if opts[:auth]
130
- if File.exist?(opts[:auth][:entity_cert]) && File.exist?(opts[:auth][:entity_key])
131
- entity = OmfCommon::Auth::Certificate.create_from_x509(File.read(opts[:auth][:entity_cert]),
132
- File.read(opts[:auth][:entity_key]))
133
- end
134
- end
135
- opts[:communication][:auth] = {} if entity
136
- end
137
-
138
- def parse_config_files()
139
- @opts = {communication: {}, resources: [], factories: [], add_default_factories: true}
140
- config_file = @gopts[:config_file]
141
- adv_config_file = @gopts[:adv_config_file]
142
- if config_file && adv_config_file
143
- puts "To avoid any unexpected surprises, you should stick to one form of config file"
144
- exit(1)
145
- end
146
-
147
- if !config_file && !adv_config_file
148
- puts "You must specify a config file"
149
- exit(1)
150
- end
151
-
152
- if config_file
153
- cfg_opts = OmfCommon.load_yaml(config_file, symbolize_keys: true, erb_process: true)
154
- copts = @def_opts.merge(cfg_opts.merge(@copts))
155
- @opts[:communication][:url] = copts[:uri]
156
- @opts[:resources] = copts[:resources] || [{ type: :node, uid: copts[:uid] }]
157
- @opts[:factories] = copts[:factories] if copts[:factories]
158
- if copts[:add_default_factories] == false
159
- @opts[:add_default_factories] = false
160
- end
161
- @gopts[:environment] ||= copts[:environment]
162
- @omlopts.merge(copts[:oml] || {}) {|k, v1, v2| v1 } # merge in place as OML may hold @omlopts
163
- end
164
-
165
- if adv_config_file
166
- aopts = OmfCommon.load_yaml(adv_config_file, symbolize_keys: true, erb_process: true)
167
- aenv = aopts.delete(:environment)
168
- @gopts[:environment] ||= @copts[:environment] || aenv || @def_opts[:environment]
169
- @opts.merge!(aopts)
170
- # need to do a merge! to update the hash passed into OML.init already
171
- @omlopts.merge!(@opts.delete(:oml) || {}) {|k, v1, v2| v1 || v2 } # merge in place as OML may hold @omlopts
172
- end
173
- end
174
-
175
- def oml_init
176
- begin
177
- @omlopts[:afterParse] = lambda {|o| parse_config_files() }
178
- @oml_enabled = OML4R::init(ARGV, @omlopts) do |op|
179
- op.banner = "OMF Resource Controller version '#{@gem_version}'\n"
180
- op.banner += "Usage: #{@executable_name} [options]"
181
-
182
- op.on("-c CONFIGFILE", "Configuration File") do |file|
183
- @gopts[:config_file] = file
184
- end
185
-
186
- op.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
187
- @gopts[:adv_config_file] = file
188
- end
189
-
190
- op.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
191
- @gopts[:logging_configfile] = file
192
- end
193
-
194
- # op.on("-u URI", "Communication URI [#{@def_opts[:uri]}") do |uri|
195
- # @copts[:uri] = uri
196
- # end
197
-
198
- op.on("-e ENVIRONMENT", "Environment (development, production ...) [#{@def_opts[:environment]}]") do |e|
199
- @gopts[:environment] = e
200
- end
201
-
202
- # op.on("-i UID", "UID (and pubsub topic) of the resource, [#{@def_opts[:uid]}]") do |uid|
203
- # @copts[:uid] = uid
204
- # end
205
-
206
- op.on("-v", "--version", "Show version") do
207
- puts "OMF Resource Controller version '#{@gem_version}'"
208
- exit
209
- end
210
-
211
- op.on("-h", "--help", "Show this message") do
212
- puts op
213
- exit
214
- end
215
- end
216
- rescue OML4R::MissingArgumentException => e
217
- puts "Warning: #{e.message} to instrument this RC, so it will run without instrumentation. (see --oml-help)"
218
- rescue => e
219
- puts e.message
220
- exit(1)
221
- end
222
- end
223
- end
224
-
225
- OmfRcRunner.new().run()
19
+ OmfRc::Runner.new.run
data/init/angstrom ADDED
@@ -0,0 +1,47 @@
1
+ #! /bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: omf-rc
4
+ # Required-Start: $ALL
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Start daemon at boot time
9
+ # Description: Enable service provided by daemon.
10
+ ### END INIT INFO
11
+
12
+ PATH=$PATH:/usr/bin:/usr/local/bin
13
+ DAEMON=/usr/local/bin/run_omf_rc.sh
14
+ [ -x "$DAEMON" ] || exit 0
15
+ NAME=omf_rc
16
+ PIDFILE=/var/run/$NAME.pid
17
+
18
+ start(){
19
+ echo -n "Starting OMF Resource Controller: $NAME"
20
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON 2>&1 | logger -t omf_rc &
21
+ echo "."
22
+ }
23
+
24
+ stop(){
25
+ echo -n "Stopping OMF Resource Controller: $NAME"
26
+ start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
27
+ echo "."
28
+ }
29
+
30
+ case "$1" in
31
+ start)
32
+ start
33
+ ;;
34
+ stop)
35
+ stop
36
+ ;;
37
+ restart)
38
+ stop
39
+ start
40
+ ;;
41
+ *)
42
+ echo "Usage: $0 {start|stop|restart}" >&2
43
+ exit 3
44
+ ;;
45
+ esac
46
+
47
+ :
@@ -123,11 +123,13 @@ class OmfRc::ResourceProxy::AbstractResource
123
123
  begin
124
124
  # Setup authentication related properties
125
125
  if (@certificate = @opts.delete(:certificate))
126
- OmfCommon::Auth::CertificateStore.instance.register(@certificate, t.address)
127
- else
128
- if (pcert = @opts.delete(:parent_certificate))
129
- @certificate = pcert.create_for(resource_address, @type, t.address)
130
- end
126
+ elsif (pcert = @opts.delete(:parent_certificate))
127
+ @certificate = pcert.dup
128
+ end
129
+
130
+ if @certificate
131
+ @certificate.resource_id = resource_address
132
+ OmfCommon::Auth::CertificateStore.instance.register(@certificate)
131
133
  end
132
134
 
133
135
  # Extend resource with Resource Module, can be obtained from Factory
@@ -386,9 +388,8 @@ class OmfRc::ResourceProxy::AbstractResource
386
388
  end
387
389
 
388
390
  objects_by_topic(topic.id.to_s).each do |obj|
389
- if OmfCommon::Measure.enabled?
390
- OmfRc::ResourceProxy::MPReceived.inject(Time.now.to_f, self.uid, topic, message.mid)
391
- end
391
+ OmfRc::ResourceProxy::MPReceived.inject(Time.now.to_f, self.uid,
392
+ topic.id.to_s, message.mid) if OmfCommon::Measure.enabled?
392
393
  execute_omf_operation(message, obj, topic)
393
394
  end
394
395
  end
@@ -492,7 +493,12 @@ class OmfRc::ResourceProxy::AbstractResource
492
493
  message.each_property do |key, value|
493
494
  method_name = "#{message.operation.to_s}_#{key}"
494
495
  p_value = message[key]
495
- response[key] ||= obj.__send__(method_name, p_value)
496
+
497
+ if namespaced_property?(key)
498
+ response[key, namespace] = obj.__send__(method_name, p_value)
499
+ else
500
+ response[key] = obj.__send__(method_name, p_value)
501
+ end
496
502
  end
497
503
  end
498
504
 
@@ -512,7 +518,13 @@ class OmfRc::ResourceProxy::AbstractResource
512
518
  request_props.each do |p_name|
513
519
  method_name = "request_#{p_name.to_s}"
514
520
  value = obj.__send__(method_name)
515
- response[p_name] = value if value
521
+ if value
522
+ if namespaced_property?(p_name)
523
+ response[p_name, namespace] = value
524
+ else
525
+ response[p_name] = value
526
+ end
527
+ end
516
528
  end
517
529
  end
518
530
 
@@ -567,10 +579,11 @@ class OmfRc::ResourceProxy::AbstractResource
567
579
  end
568
580
 
569
581
  # Just send to all topics, including group membership
570
- (membership_topics.map { |mt| mt[1] } + @topics).each { |t| t.publish(message) }
571
-
572
- OmfRc::ResourceProxy::MPPublished.inject(Time.now.to_f,
573
- self.uid, replyto, inform_message.mid) if OmfCommon::Measure.enabled?
582
+ (membership_topics.map { |mt| mt[1] } + @topics).each do |t|
583
+ t.publish(message)
584
+ OmfRc::ResourceProxy::MPPublished.inject(Time.now.to_f,
585
+ self.uid, t.id, message.mid) if OmfCommon::Measure.enabled?
586
+ end
574
587
  end
575
588
 
576
589
  def inform_status(props)
@@ -676,4 +689,11 @@ class OmfRc::ResourceProxy::AbstractResource
676
689
  end
677
690
  end
678
691
  end
692
+
693
+ # Check if a property has namespace associated
694
+ #
695
+ # @param [String] name of the property
696
+ def namespaced_property?(name)
697
+ respond_to?(:namespace) && name =~ /^(.+)__(.+)$/
698
+ end
679
699
  end
@@ -88,6 +88,7 @@ module OmfRc::ResourceProxy::Application
88
88
  property :app_id, :default => nil
89
89
  property :description, :default => ''
90
90
  property :binary_path, :default => nil
91
+ property :quiet, :default => false
91
92
  property :platform, :default => nil
92
93
  property :pkg_tarball, :default => nil
93
94
  property :tarball_install_path, :default => '/'
@@ -169,7 +170,7 @@ module OmfRc::ResourceProxy::Application
169
170
  msg: msg,
170
171
  seq: res.property.event_sequence,
171
172
  uid: res.uid
172
- }, :ALL)
173
+ }, :ALL) unless res.property.quiet
173
174
  end
174
175
  end
175
176
 
@@ -549,7 +550,7 @@ module OmfRc::ResourceProxy::Application
549
550
  o = res.property.oml
550
551
  ofile = "/tmp/#{res.uid}-#{Time.now.to_i}.xml"
551
552
  of = File.open(ofile,'w')
552
- of << "<omlc experiment='#{o.experiment}' id='#{o.id}'>\n"
553
+ of << "<omlc experiment='#{o.experiment}' id='#{o.id}_#{res.uid}'>\n"
553
554
  o.collection.each do |c|
554
555
  of << " <collect url='#{c.url}'>\n"
555
556
  c.streams.each do |m|
@@ -346,6 +346,14 @@ module OmfRc::ResourceProxyDSL
346
346
  alias_method "orig_request_#{request_name}", "request_#{request_name}"
347
347
  end
348
348
 
349
+ def namespace(ns_prefix, ns_href)
350
+ define_method("namespace") do
351
+ { ns_prefix => ns_href }
352
+ end
353
+ end
354
+
355
+ alias_method :ns, :namespace
356
+
349
357
  # Define internal property. Refer to options section to see supported options.
350
358
  #
351
359
  # @param [Symbol] name of the property
@@ -0,0 +1,180 @@
1
+ # Copyright (c) 2013 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
+ module OmfRc
7
+ # Class to start an OMF RC. The configuration parameters can be set
8
+ # in decreasing priority through the command line, configuration
9
+ # file and default settings (see @def_opts).
10
+ #
11
+ # For historic reasons and to make this implementation more interesting
12
+ # there are two different config file formats. A 'normal' one inherited from
13
+ # earlier version of OMF, and an 'advanced' one which is identical to the
14
+ # format accepted by OmfCommon.init(). To maintain some level of sanity,
15
+ # only one configuration file is accepted.
16
+ #
17
+ # Having said that, there is one exception and that relates to the 'oml'
18
+ # configuration which is stripped out first and handed to the OML4R library
19
+ # during command line parsing.
20
+ #
21
+ class Runner
22
+ include Hashie
23
+
24
+ attr_accessor :gopts, :copts, :def_opts
25
+ attr_accessor :opts
26
+
27
+ def initialize()
28
+ @executable_name = File.basename($PROGRAM_NAME)
29
+ @oml_enabled = false
30
+ @gem_version = OmfCommon.version_of('omf_common')
31
+
32
+ @node_id = Socket.gethostname
33
+
34
+ @def_opts = Mash.new(
35
+ environment: 'production',
36
+ resources: [ { type: :node, uid: @node_id }],
37
+ factories: [],
38
+ communication: { url: "xmpp://#{@node_id}-#{Process.pid}:#{@node_id}-#{Process.pid}@localhost" },
39
+ add_default_factories: true,
40
+ )
41
+
42
+ @gopts = Mash.new(
43
+ config_file: nil,
44
+ adv_config_file: nil,
45
+ logging_configfile: nil,
46
+ environment: nil
47
+ )
48
+
49
+ @opts = Mash.new
50
+
51
+ @omlopts = {appName: @executable_name}
52
+ end
53
+
54
+ def run()
55
+ oml_init() # calls parse_config_files()
56
+
57
+ OmfCommon::Measure.enable if @oml_enabled
58
+
59
+ OmfCommon.init(@opts[:environment], @opts.to_hash) do |el|
60
+ # Load a customised logging set up if provided
61
+ OmfCommon.load_logging_config(@opts[:logging_configfile])
62
+
63
+ info "Starting OMF Resource Controller version '#{@gem_version}'"
64
+
65
+ Signal.trap("SIGINT") do
66
+ # TODO: Should release resources first
67
+ info "Stopping ..."
68
+ OmfCommon.comm.disconnect
69
+ end
70
+
71
+ # Load extensions
72
+ if @opts[:add_default_factories] != false
73
+ OmfRc::ResourceFactory.load_default_resource_proxies
74
+ end
75
+
76
+ @opts[:factories].each do |f|
77
+ if (req = f[:require])
78
+ begin
79
+ info "Try to load resource module '#{req}'"
80
+ require(req)
81
+ rescue LoadError => e
82
+ error e.message
83
+ end
84
+ end
85
+ end
86
+
87
+ OmfCommon.comm.on_connected do |comm|
88
+ info "Connected using #{comm.conn_info}"
89
+
90
+ rc_cert = OmfCommon.load_credentials(@opts[:credentials])
91
+
92
+ @opts[:resources].each do |res_opts|
93
+ rtype = res_opts.delete(:type)
94
+ res_creation_opts = res_opts.delete(:creation_opts)
95
+ res_creation_opts ||= res_opts.delete(:create_opts)
96
+ res_creation_opts ||= {}
97
+ res_opts[:certificate] = rc_cert
98
+ begin
99
+ OmfRc::ResourceFactory.create(rtype, res_opts, res_creation_opts)
100
+ rescue => e
101
+ error "#{e.message}\n#{e.backtrace.join("\n")}"
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+ info "Stopping OMF Resource Controller version '#{@gem_version}'"
108
+ end
109
+
110
+ def parse_config_files()
111
+ config_file = @gopts[:config_file]
112
+
113
+ if config_file.nil?
114
+ puts "You must specify a config file"
115
+ exit(1)
116
+ else
117
+ cfg_opts = Mash.new(OmfCommon.load_yaml(config_file, symbolize_keys: true, erb_process: true))
118
+
119
+ @opts.merge!(@def_opts.merge(cfg_opts))
120
+
121
+ # Legacy support uri & uid opt could also configure comm & resource
122
+ cfg_opts.each do |k, v|
123
+ case k.to_sym
124
+ when :uri
125
+ @opts[:communication][:url] = v
126
+ when :uid
127
+ @opts[:resources][0][:type] = :node
128
+ @opts[:resources][0][:uid] = v
129
+ else
130
+ @opts[k] = v
131
+ end
132
+ end
133
+
134
+ @omlopts.merge(@opts[:instrumentation] || {}) { |k, v1, v2| v1 } # merge in place as OML may hold @omlopts
135
+ end
136
+ end
137
+
138
+ def oml_init
139
+ begin
140
+ @omlopts[:afterParse] = lambda {|o| parse_config_files() }
141
+ @oml_enabled = OML4R::init(ARGV, @omlopts) do |op|
142
+ op.banner = "OMF Resource Controller version '#{@gem_version}'\n"
143
+ op.banner += "Usage: #{@executable_name} [options]"
144
+
145
+ op.on("-c CONFIGFILE", "Configuration File") do |file|
146
+ @gopts[:config_file] = file
147
+ end
148
+
149
+ op.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
150
+ @gopts[:adv_config_file] = file
151
+ end
152
+
153
+ op.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
154
+ @gopts[:logging_configfile] = file
155
+ end
156
+
157
+ op.on("-e ENVIRONMENT", "Environment (development, production ...) [#{@def_opts[:environment]}]") do |e|
158
+ @gopts[:environment] = e
159
+ end
160
+
161
+ op.on("-v", "--version", "Show version") do
162
+ puts "OMF Resource Controller version '#{@gem_version}'"
163
+ exit
164
+ end
165
+
166
+ op.on("-h", "--help", "Show this message") do
167
+ puts op
168
+ exit
169
+ end
170
+ end
171
+ rescue OML4R::MissingArgumentException => e
172
+ puts "Warning: #{e.message} to instrument this RC, so it will run without instrumentation. (see --oml-help)"
173
+ rescue => e
174
+ puts e.message
175
+ #puts e.backtrace
176
+ exit(1)
177
+ end
178
+ end
179
+ end
180
+ end
@@ -3,6 +3,8 @@
3
3
  # You should find a copy of the License in LICENSE.TXT or at http://opensource.org/licenses/MIT.
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
+ require 'omf_common/version'
7
+
6
8
  module OmfRc
7
- VERSION = "6.0.7.1"
9
+ VERSION = OmfCommon.version_of('omf_rc')
8
10
  end
data/omf_rc.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "em-minitest-spec", "~> 1.1.1"
26
26
  s.add_development_dependency "pry"
27
27
  s.add_development_dependency "simplecov"
28
- s.add_runtime_dependency "omf_common", "= 6.0.7.1"
28
+ s.add_runtime_dependency "omf_common", "= #{OmfCommon::VERSION}"
29
29
  s.add_runtime_dependency "cocaine", "~> 0.3.0"
30
30
  s.add_runtime_dependency "mocha"
31
31
  end
@@ -0,0 +1,8 @@
1
+ ---
2
+ # default topic name is this machine's hostname
3
+ # default xmpp user name/password is "hostname-pid"
4
+ # this is to ensure that every RC has its own topic and XMPP account
5
+ :uid: <%= Socket.gethostname %>
6
+ :uri: xmpp://<%= "#{Socket.gethostname}-#{Process.pid}" %>:<%= "#{Socket.gethostname}-#{Process.pid}" %>@somewhere
7
+ :environment: production
8
+ :debug: false
@@ -0,0 +1,92 @@
1
+ # EXISTING options
2
+
3
+ # By default it loads node proxy, and this is its id
4
+ uid: bob
5
+
6
+ # How to connect to pubsub server
7
+ uri: xmpp://remote
8
+
9
+ # Which environment to use, the value is the one of pre-defined ones in omf_common
10
+ environment: development
11
+
12
+ # Load an external file contains Logging configuration
13
+ logging_configfile: config/my_logging.rb
14
+
15
+ # If load default type factories
16
+ add_default_factories: true
17
+
18
+ # Additional resources which can be created by this RC
19
+ factories:
20
+ - require: omf_rc_openflow
21
+
22
+ # Customise what proxy to load
23
+ resources:
24
+ - type: my_resource
25
+ # Can initialise resource properties
26
+ uid: resource_1
27
+ my_prop: foo
28
+ membership:
29
+ - g1
30
+
31
+ # Can set resource creation options
32
+ creation_opts:
33
+ send_backtrace: true
34
+
35
+ # END of EXISTING options
36
+
37
+
38
+ # Option to be MODIFIED
39
+
40
+ # This used to be called 'auth', but it is really about loading
41
+ # credentials (certificates) during RC bootstrap. Name it 'credentials' makes more sense.
42
+
43
+ credentials:
44
+ root_cert_dir: ~/omf_keys/root/
45
+ entity_cert: ~/omf_keys/rc.pem
46
+ entity_key: ~/omf_keys/rc_key.pem
47
+
48
+ # END of Option to be MODIFIED
49
+
50
+ # NEW options (used to be defined in 'advanced configuration file')
51
+
52
+ # Basically everything that can be initialised using OmfCommon.init
53
+
54
+ communication:
55
+ type: :xmpp
56
+ url: xmpp://localhost
57
+
58
+ auth:
59
+ authenticate: true
60
+ pdp:
61
+ constructor: TestPDP
62
+ trust:
63
+ - adam
64
+
65
+ eventloop:
66
+ type: :em
67
+
68
+ logging:
69
+
70
+ level:
71
+ default: debug
72
+
73
+ appenders:
74
+ stdout:
75
+ date_pattern: "%H:%M:%S"
76
+ pattern: "%d %5l %c{2}: %m\n"
77
+ color_scheme: none
78
+
79
+ # END of NEW options
80
+
81
+ # OML options
82
+
83
+ instrumentation:
84
+ oml-id: id # Name to identify this app instance [undefined]
85
+ oml-domain: domain # Name of experimental domain [undefined] *EXPERIMENTAL*
86
+ oml-collect: uri # URI of server to send measurements to
87
+ oml-protocol: 4 # Protocol number [4]
88
+ oml-log-level: l # Log level used (info: 1 .. debug: 0)
89
+ oml-noop: # Do not collect measurements
90
+ oml-config: file # File holding OML configuration parameters
91
+
92
+ # END of OML options
@@ -9,7 +9,7 @@ require 'omf_rc/resource_proxy_dsl'
9
9
  describe OmfRc::ResourceProxyDSL do
10
10
  before do
11
11
  mock_comm_in_res_proxy
12
- mock_topics_in_res_proxy(resources: [:mp0, :mrp0, :up0])
12
+ mock_topics_in_res_proxy(resources: [:mp0, :mrp0, :up0, :f0])
13
13
 
14
14
  module OmfRc::Util::MockUtility
15
15
  include OmfRc::ResourceProxyDSL
@@ -69,6 +69,14 @@ describe OmfRc::ResourceProxyDSL do
69
69
 
70
70
  register_proxy :useless_proxy
71
71
  end
72
+
73
+ module OmfRc::ResourceProxy::Foo
74
+ include OmfRc::ResourceProxyDSL
75
+
76
+ register_proxy :foo
77
+
78
+ namespace :foo, "http://schema/foo"
79
+ end
72
80
  end
73
81
 
74
82
  after do
@@ -144,4 +152,11 @@ describe OmfRc::ResourceProxyDSL do
144
152
  lambda { mock_proxy.configure_init_only_prop }.must_raise NoMethodError
145
153
  end
146
154
  end
155
+
156
+ describe "when namespace specified" do
157
+ it "must define namespace in the resource proxy" do
158
+ foo = OmfRc::ResourceFactory.create(:foo, uid: :f0)
159
+ foo.namespace.must_equal({foo: "http://schema/foo"})
160
+ end
161
+ end
147
162
  end
@@ -0,0 +1,49 @@
1
+ # Copyright (c) 2013 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 'test_helper'
7
+ require 'omf_rc/runner'
8
+
9
+ describe OmfRc::Runner do
10
+ describe 'when loading a configuration yaml file' do
11
+ before do
12
+ @r = OmfRc::Runner.new
13
+ end
14
+
15
+ it 'must initialise options properly' do
16
+ @r.gopts[:config_file] = "#{FIXTURE_DIR}/omf_rc.yml"
17
+ @r.parse_config_files
18
+
19
+ @r.opts[:add_default_factories].must_equal true
20
+
21
+ @r.opts[:factories][0][:require].must_equal 'omf_rc_openflow'
22
+
23
+ @r.opts[:resources][0][:membership].must_equal ['g1']
24
+
25
+ @r.opts[:credentials][:root_cert_dir].must_equal '~/omf_keys/root/'
26
+ @r.opts[:credentials][:entity_cert].must_equal '~/omf_keys/rc.pem'
27
+ @r.opts[:credentials][:entity_key].must_equal '~/omf_keys/rc_key.pem'
28
+
29
+ @r.opts[:communication][:url].must_equal "xmpp://localhost"
30
+ @r.opts[:communication][:auth][:pdp][:trust].must_equal ['adam']
31
+
32
+ @r.opts[:instrumentation]['oml-domain'].must_equal 'domain'
33
+ end
34
+
35
+ it 'must support a very minimal configure file with proper defaults' do
36
+ @r.gopts[:config_file] = "#{FIXTURE_DIR}/omf_rc.simple.yml"
37
+ @r.parse_config_files
38
+
39
+ @r.opts[:add_default_factories].must_equal true
40
+ @r.opts[:resources][0][:type].must_equal :node
41
+
42
+ node_id = Socket.gethostname
43
+ user = "#{node_id}-#{Process.pid}"
44
+
45
+ @r.opts[:resources][0][:uid].must_equal node_id
46
+ @r.opts[:communication][:url].must_equal "xmpp://#{user}:#{user}@somewhere"
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_rc
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.7.1
4
+ version: 6.0.8.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 6.0.7.1
75
+ version: 6.0.8.pre.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 6.0.7.1
82
+ version: 6.0.8.pre.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: cocaine
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,14 +98,14 @@ dependencies:
98
98
  name: mocha
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Resource controller of OMF, a generic framework for controlling and managing
@@ -128,6 +128,7 @@ files:
128
128
  - config/config.yml
129
129
  - config/config_with_authentication.yml.example
130
130
  - config/config_with_extensions.yml.example
131
+ - init/angstrom
131
132
  - init/debian
132
133
  - init/fedora
133
134
  - init/run_omf_rc.sh
@@ -144,6 +145,7 @@ files:
144
145
  - lib/omf_rc/resource_proxy/virtual_machine_factory.rb
145
146
  - lib/omf_rc/resource_proxy/wlan.rb
146
147
  - lib/omf_rc/resource_proxy_dsl.rb
148
+ - lib/omf_rc/runner.rb
147
149
  - lib/omf_rc/util/common_tools.rb
148
150
  - lib/omf_rc/util/hostapd.rb
149
151
  - lib/omf_rc/util/ip.rb
@@ -163,6 +165,8 @@ files:
163
165
  - test/fixture/iw/info
164
166
  - test/fixture/iw/link
165
167
  - test/fixture/lsmod
168
+ - test/fixture/omf_rc.simple.yml
169
+ - test/fixture/omf_rc.yml
166
170
  - test/fixture/oml.hash
167
171
  - test/fixture/oml.spec
168
172
  - test/fixture/oml.xml
@@ -179,6 +183,7 @@ files:
179
183
  - test/omf_rc/resource_proxy/application_spec.rb
180
184
  - test/omf_rc/resource_proxy/node_spec.rb
181
185
  - test/omf_rc/resource_proxy_dsl_spec.rb
186
+ - test/omf_rc/runner_spec.rb
182
187
  - test/omf_rc/util/common_tools_spec.rb
183
188
  - test/omf_rc/util/ip_spec.rb
184
189
  - test/omf_rc/util/iw_spec.rb
@@ -194,44 +199,18 @@ require_paths:
194
199
  - lib
195
200
  required_ruby_version: !ruby/object:Gem::Requirement
196
201
  requirements:
197
- - - '>='
202
+ - - ! '>='
198
203
  - !ruby/object:Gem::Version
199
204
  version: 1.9.3
200
205
  required_rubygems_version: !ruby/object:Gem::Requirement
201
206
  requirements:
202
- - - '>='
207
+ - - ! '>'
203
208
  - !ruby/object:Gem::Version
204
- version: '0'
209
+ version: 1.3.1
205
210
  requirements: []
206
211
  rubyforge_project: omf_rc
207
- rubygems_version: 2.0.6
212
+ rubygems_version: 2.0.7
208
213
  signing_key:
209
214
  specification_version: 4
210
215
  summary: OMF resource controller
211
- test_files:
212
- - test/fixture/ip/addr_show
213
- - test/fixture/iw/help
214
- - test/fixture/iw/info
215
- - test/fixture/iw/link
216
- - test/fixture/lsmod
217
- - test/fixture/oml.hash
218
- - test/fixture/oml.spec
219
- - test/fixture/oml.xml
220
- - test/fixture/sys/class/ieee80211/phy0/device/uevent
221
- - test/fixture/sys/class/ieee80211/phy0/uevent
222
- - test/fixture/sys/class/net/eth0/device/uevent
223
- - test/fixture/sys/class/net/eth0/uevent
224
- - test/fixture/sys/class/net/wlan0/device/uevent
225
- - test/fixture/sys/class/net/wlan0/uevent
226
- - test/omf_rc/deferred_process_spec.rb
227
- - test/omf_rc/message_process_error_spec.rb
228
- - test/omf_rc/resource_factory_spec.rb
229
- - test/omf_rc/resource_proxy/abstract_resource_spec.rb
230
- - test/omf_rc/resource_proxy/application_spec.rb
231
- - test/omf_rc/resource_proxy/node_spec.rb
232
- - test/omf_rc/resource_proxy_dsl_spec.rb
233
- - test/omf_rc/util/common_tools_spec.rb
234
- - test/omf_rc/util/ip_spec.rb
235
- - test/omf_rc/util/iw_spec.rb
236
- - test/omf_rc/util/mod_spec.rb
237
- - test/test_helper.rb
216
+ test_files: []