omf_rc 6.0.4.pre.1 → 6.0.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGNiZjU5MGViODBjNTc1MDU0MDE3Y2ZmMzY0ZTA0YjQwMWY2MThkMA==
4
+ Y2E5YTUyM2U4OWQzYjk2Y2RlMTBlMDZiOGJmYmY5ZTg3MTY0ZTJiOQ==
5
5
  data.tar.gz: !binary |-
6
- ZTFiYTZiYzQ0MzZiNjM1NDI1YTlhOTQ0MGZlZTEwYWUwMDlmNjU2MA==
6
+ MGQ2YmY4ZTY1NTM3ZjQyNjNhZjU0NTVmYjc4YzM4ZmVhNTlmNzg4Zg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MzFhMDI5ZTk5Zjg0YzY3NjI5YzIzMDNiMDYyNDFiYjc4YjIyNzkyNjk4NWNh
10
- MjYwM2NmMzc3MzJmMTU5NDFkMzA0MTE0N2VhMTM4NjViZTMzY2JlZTE3OWMz
11
- Y2ExOGE4ZmI5ZjI4YmYyYjgwOTY0M2UxZjNmOTdlN2YyMGE2OGM=
9
+ ZDEyM2VmZDViZDRkOTM0ZTZhYjY2YmQ2OGNmMGY1MzgzZDEwZjMzMjZiNTYy
10
+ MmRiMzY4ZmIxMmIxZTU5MGNkMDlkNDVlOTY2ZjRkODcyMTNjMzFmYmM4NmU2
11
+ YmI2YjhlNGMxYmEzOTdjYTg2MmJiYjg3ZTg3ZTkzYmU2ODc5NmY=
12
12
  data.tar.gz: !binary |-
13
- MGQ1OTExNjE5NjYwZjUxNTU4Njc2ZWNlOWVmODViZThlNThiMTNlN2YzOTZj
14
- MWE2MjZmMDJmZjZjMDVhMzEwNGU3ZGVkNDEwMTM3Mzk5NzliZGRkNTU0OGE5
15
- ODAzZGZhMmE4YjZhY2UxNzBhYjUwZWJkNzJhZjdkZWJmZmQzM2E=
13
+ MDQ3ZmEyMTlkNDhhMGI4NTRkY2IyY2UyZGYxNTIwOTU0ZmU0Mjk3M2E5NjA4
14
+ NTQxNTNiYjhlNmMxZGFjZTc1ODdkNTkxZTk0MWZkMTQ5MzRkMDQ3YzljMTk1
15
+ OGMwOTcwOGQxZjgyNTc4NDJjODIxMmVkZWY4ZWMzOWM3ZDA0Y2Q=
data/bin/omf_rc CHANGED
@@ -2,150 +2,219 @@
2
2
 
3
3
  abort "Please use Ruby 1.9.3 or higher" if RUBY_VERSION < "1.9.3"
4
4
 
5
+ # The following is to work around a bug in activesupport triggered by
6
+ # the JWT library which is used only in the AMQP transport, os it
7
+ # fails quietly if that library is not installed in XMPP deployments
8
+ begin; require 'json/jwt'; rescue Exception; end
9
+
5
10
  require 'optparse'
6
- require 'erb'
7
11
  require 'socket'
8
12
 
9
13
  require 'omf_rc'
10
14
  require 'omf_rc/resource_factory'
11
15
 
12
16
  $stdout.sync = true
13
- options = {}
14
- executable_name = File.basename($PROGRAM_NAME)
15
- oml_enabled = false
16
- gem_version = Gem::Specification.find_by_name('omf_rc').version.to_s
17
-
18
- begin
19
- oml_enabled = OML4R::init(ARGV, appName: executable_name) do |opts|
20
- opts.banner = "OMF Resource Controller version '#{gem_version}'\n"
21
- opts.banner += "Usage: #{executable_name} [options]"
22
-
23
- opts.on("-c CONFIGFILE", "Configuration File") do |file|
24
- options[:configfile] = file
25
- end
26
17
 
27
- opts.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
28
- options[:advanced_configfile] = file
29
- end
30
-
31
- opts.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
32
- options[:logging_configfile] = file
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
+ el.stop
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
33
116
  end
34
-
35
- opts.on("-u URI", "Communication URI (xmpp://user:password@domain)") do |uri|
36
- options[:uri] = uri
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)
37
125
  end
38
-
39
- opts.on("-e ENVIRONMENT", "Environment (development, production ...)") do |environment|
40
- options[:environment] = environment
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
41
134
  end
42
-
43
- opts.on("-i UID", "UID (and pubsub topic) of the resource, defaults to hostname") do |uid|
44
- options[:uid] = uid
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)
45
145
  end
46
-
47
- opts.on("-v", "--version", "Show version") do
48
- puts "OMF Resource Controller version '#{gem_version}'"
49
- exit
146
+
147
+ if config_file
148
+ cfg_opts = OmfCommon.load_yaml(config_file, symbolize_keys: true, erb_process: true)
149
+ copts = @def_opts.merge(cfg_opts.merge(@copts))
150
+ @opts[:communication][:url] = copts[:uri]
151
+ @opts[:resources] = copts[:resources] || [{ type: :node, uid: copts[:uid] }]
152
+ @opts[:factories] = copts[:factories] if copts[:factories]
153
+ if copts[:add_default_factories] == false
154
+ @opts[:add_default_factories] = false
155
+ end
156
+ @gopts[:environment] ||= copts[:environment]
157
+ @omlopts.merge(copts[:oml] || {}) {|k, v1, v2| v1 } # merge in place as OML may hold @omlopts
50
158
  end
51
-
52
- opts.on("-h", "--help", "Show this message") do
53
- puts opts
54
- exit
159
+
160
+ if adv_config_file
161
+ aopts = OmfCommon.load_yaml(adv_config_file, symbolize_keys: true, erb_process: true)
162
+ aenv = aopts.delete(:environment)
163
+ @gopts[:environment] ||= @copts[:environment] || aenv || @def_opts[:environment]
164
+ @opts.merge!(aopts)
165
+ # need to do a merge! to update the hash passed into OML.init already
166
+ @omlopts.merge!(@opts.delete(:oml) || {}) {|k, v1, v2| v1 || v2 } # merge in place as OML may hold @omlopts
55
167
  end
56
168
  end
57
- rescue OML4R::MissingArgumentException => e
58
- puts "Warning: #{e.message} to instrument this RC, so it will run without instrumentation. (see --oml-help)"
59
- rescue => e
60
- puts e.message
61
- exit(1)
62
- end
63
-
64
- if !options[:configfile].nil?
65
- cfg_options = YAML.load(ERB.new(File.read(options[:configfile])).result)
66
- options = cfg_options.merge(options)
67
- end
68
-
69
- if options[:resources].nil? || options[:resources].empty?
70
- options[:uid] ||= Socket.gethostname
71
- options[:resources] = [{ type: :node, uid: options[:uid] }]
72
- end
73
-
74
- OmfCommon::Measure.enable if oml_enabled
75
-
76
- options[:environment] ||= :development
77
-
78
- if options[:uri]
79
- common_options = { communication: { url: options[:uri] } }
80
- else
81
- common_options = {}
82
- end
83
-
84
- if !options[:advanced_configfile].nil?
85
- a_cfg_options = (YAML.load_file(options[:advanced_configfile]))
86
- common_options = a_cfg_options.merge(common_options)
87
- end
88
-
89
- unless common_options[:communication] && common_options[:communication][:url]
90
- puts "Error: Missing parameters to connect to a PubSub Server (see --help)"
91
- exit(1)
92
- end
93
-
94
- if options[:auth]
95
- if File.exist?(options[:auth][:entity_cert]) && File.exist?(options[:auth][:entity_key])
96
- entity = OmfCommon::Auth::Certificate.create_from_x509(File.read(options[:auth][:entity_cert]),
97
- File.read(options[:auth][:entity_key]))
98
- end
99
- end
100
-
101
- common_options[:communication][:auth] = {} if entity
102
-
103
- OmfCommon.init(options[:environment].to_sym, common_options) do |el|
104
- # Load a customised logging set up if provided
105
- OmfCommon.load_logging_config(options[:logging_configfile])
106
-
107
- # Load extensions
108
- if options[:add_default_factories] != false
109
- OmfRc::ResourceFactory.load_default_resource_proxies
110
- end
111
-
112
- if options[:factories]
113
- options[:factories].each do |f|
114
- if (req = f[:require])
115
- begin
116
- info "Try to load resource module '#{req}'"
117
- require(req)
118
- rescue LoadError => e
119
- error e.message
169
+
170
+ def oml_init
171
+ begin
172
+ @omlopts[:afterParse] = lambda {|o| parse_config_files() }
173
+ @oml_enabled = OML4R::init(ARGV, @omlopts) do |op|
174
+ op.banner = "OMF Resource Controller version '#{@gem_version}'\n"
175
+ op.banner += "Usage: #{@executable_name} [options]"
176
+
177
+ op.on("-c CONFIGFILE", "Configuration File") do |file|
178
+ @gopts[:config_file] = file
179
+ end
180
+
181
+ op.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
182
+ @gopts[:adv_config_file] = file
183
+ end
184
+
185
+ op.on("--log_config CONFIGFILE", "Logging Configuration File") do |file|
186
+ @gopts[:logging_configfile] = file
187
+ end
188
+
189
+ op.on("-u URI", "Communication URI [#{@def_opts[:uri]}") do |uri|
190
+ @copts[:uri] = uri
191
+ end
192
+
193
+ op.on("-e ENVIRONMENT", "Environment (development, production ...) [#{@def_opts[:environment]}]") do |e|
194
+ @gopts[:environment] = e
195
+ end
196
+
197
+ op.on("-i UID", "UID (and pubsub topic) of the resource, [#{@def_opts[:uid]}]") do |uid|
198
+ @copts[:uid] = uid
199
+ end
200
+
201
+ op.on("-v", "--version", "Show version") do
202
+ puts "OMF Resource Controller version '#{@gem_version}'"
203
+ exit
204
+ end
205
+
206
+ op.on("-h", "--help", "Show this message") do
207
+ puts opts
208
+ exit
120
209
  end
121
210
  end
211
+ rescue OML4R::MissingArgumentException => e
212
+ puts "Warning: #{e.message} to instrument this RC, so it will run without instrumentation. (see --oml-help)"
213
+ rescue => e
214
+ puts e.message
215
+ exit(1)
122
216
  end
123
217
  end
124
-
125
- info "Starting OMF Resource Controller version '#{gem_version}'"
126
-
127
- OmfCommon.comm.on_connected do |comm|
128
- info "Connected using #{comm.conn_info}"
129
-
130
- if options[:auth] && options[:auth][:root_cert_dir]
131
- OmfCommon::Auth::CertificateStore.instance.register_default_certs(options[:auth][:root_cert_dir])
132
- end
133
- OmfCommon::Auth::CertificateStore.instance.register(entity) if entity
134
-
135
- options[:resources].each do |res_opts|
136
- rtype = res_opts.delete(:type)
137
- res_creation_opts = res_opts.delete(:creation_opts)
138
- res_creation_opts ||= res_opts.delete(:create_opts)
139
- res_creation_opts ||= {}
140
- res_opts[:certificate] = entity if entity
141
- begin
142
- OmfRc::ResourceFactory.create(rtype, res_opts, res_creation_opts)
143
- rescue => e
144
- error "#{e.message}\n#{e.backtrace.join("\n")}"
145
- end
146
- end
147
-
148
- end
149
218
  end
150
- info "Stopping OMF Resource Controller version '#{gem_version}'"
151
219
 
220
+ OmfRcRunner.new().run()
@@ -4,7 +4,7 @@
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
6
  # This module defines a Resource Proxy (RP) for an Application.
7
- # For a detailed usage tutorial see {file:doc/RESOURCE\_PROXY.mkd Resource Proxy tutorial}
7
+ # For a detailed usage tutorial see {file:doc/DEVELOPERS.mkd Resource Proxy tutorial}
8
8
  #
9
9
  # Utility dependencies: platform_toos, common_tools
10
10
  #
@@ -15,7 +15,7 @@
15
15
  # - pkg_ubuntu (String) the name of the Ubuntu package for this app
16
16
  # - pkg_fedora (String) the name of the Fedora package for this app
17
17
  # - state (String) the state of this Application RP
18
- # (stopped, running, paused, installed, completed)
18
+ # (stopped, running, paused, installed)
19
19
  # - installed (Boolean) is this application installed? (default false)
20
20
  # - force_tarball_install (Boolean) if true then force the installation
21
21
  # from tarball even if other distribution-specific installation are
@@ -150,7 +150,7 @@ module OmfRc::ResourceProxy::Application
150
150
  event_type.to_s.include?('EXIT') &&
151
151
  msg == "0"
152
152
  if event_type == 'EXIT'
153
- res.property.state = app_id.include?("_INSTALL") ? :stopped : :completed
153
+ res.property.state = :stopped
154
154
  res.inform(:status, {
155
155
  status_type: 'APP_EVENT',
156
156
  event: event_type.to_s.upcase,
@@ -249,10 +249,6 @@ module OmfRc::ResourceProxy::Application
249
249
  # stopped, running, paused, installing. The semantic of each states are:
250
250
  #
251
251
  # - stopped: the initial state for an Application RP
252
- # - completed: the final state for an application RP. When the application
253
- # has been executed and its execution is finished, it enters this state.
254
- # When the application is completed it cannot change state again
255
- # TODO: maybe in future OMF, we could consider allowing an app to be reset?
256
252
  # - running: upon entering in this state, a new instance of the application is
257
253
  # started, the Application RP stays in this state until the
258
254
  # application instance is finished or paused. The Application RP can
@@ -342,9 +338,9 @@ module OmfRc::ResourceProxy::Application
342
338
  ExecApp[id].signal('TERM')
343
339
  sleep 4
344
340
  # finally, try sending KILL signal
345
- ExecApp[id].kill('KILL') unless ExecApp[id].nil?
341
+ ExecApp[id].signal('KILL') unless ExecApp[id].nil?
346
342
  end
347
- res.property.state = :completed
343
+ res.property.state = :stopped
348
344
  rescue => err
349
345
  end
350
346
  end
@@ -376,7 +372,7 @@ module OmfRc::ResourceProxy::Application
376
372
  res.property.state = :running
377
373
  # do more things here...
378
374
  else
379
- # cannot run as we are still installing or already completed
375
+ # cannot run as we are still installing
380
376
  res.log_inform_warn "Cannot switch to running state as current state is '#{res.property.state}'"
381
377
  end
382
378
  end
@@ -4,5 +4,5 @@
4
4
  # By downloading or using this software you accept the terms and the liability disclaimer in the License.
5
5
 
6
6
  module OmfRc
7
- VERSION = "6.0.4.pre.1"
7
+ VERSION = "6.0.4"
8
8
  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.4.pre.1"
28
+ s.add_runtime_dependency "omf_common", "~> 6.0.4"
29
29
  s.add_runtime_dependency "cocaine", "~> 0.3.0"
30
30
  s.add_runtime_dependency "mocha"
31
31
  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.4.pre.1
4
+ version: 6.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - NICTA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 6.0.4.pre.1
75
+ version: 6.0.4
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.4.pre.1
82
+ version: 6.0.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: cocaine
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -199,9 +199,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
199
  version: 1.9.3
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - ! '>'
202
+ - - ! '>='
203
203
  - !ruby/object:Gem::Version
204
- version: 1.3.1
204
+ version: '0'
205
205
  requirements: []
206
206
  rubyforge_project: omf_rc
207
207
  rubygems_version: 2.0.7