sfpagent 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sfpagent might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/bin/sfpagent +5 -0
- data/lib/sfpagent/agent.rb +8 -7
- data/lib/sfpagent/runtime.rb +5 -5
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/bin/sfpagent
CHANGED
@@ -16,6 +16,7 @@ EOS
|
|
16
16
|
|
17
17
|
opt :start, "Start the agent. If --daemon option is set true, then the agent will start as a daemon."
|
18
18
|
opt :stop, "Stop the daemon agent."
|
19
|
+
opt :restart, "Restart the daemon agent."
|
19
20
|
opt :status, "Print the status of the daemon agent."
|
20
21
|
opt :state, "Given a model, print the state of all modules. (Note: [model-file] should be specified.)"
|
21
22
|
opt :execute, "Given a model, execute a plan in given file. (Note: [model-file] should be specified.)"
|
@@ -44,6 +45,10 @@ if opts[:start]
|
|
44
45
|
elsif opts[:stop]
|
45
46
|
Sfp::Agent.stop
|
46
47
|
|
48
|
+
elsif opts[:restart]
|
49
|
+
Sfp::Agent.stop
|
50
|
+
Sfp::Agent.start(opts)
|
51
|
+
|
47
52
|
elsif opts[:status]
|
48
53
|
Sfp::Agent.status
|
49
54
|
|
data/lib/sfpagent/agent.rb
CHANGED
@@ -6,6 +6,7 @@ require 'thread'
|
|
6
6
|
require 'uri'
|
7
7
|
require 'net/http'
|
8
8
|
require 'logger'
|
9
|
+
require 'json'
|
9
10
|
|
10
11
|
module Sfp
|
11
12
|
module Agent
|
@@ -242,12 +243,13 @@ module Sfp
|
|
242
243
|
#
|
243
244
|
def self.execute_action(action)
|
244
245
|
logger = (@@config[:daemon] ? @@logger : Logger.new(STDOUT))
|
246
|
+
action_string = "#{action['name']} #{JSON.generate(action['parameters'])}"
|
245
247
|
begin
|
246
248
|
result = @@runtime.execute_action(action)
|
247
|
-
logger.info "Executing #{
|
249
|
+
logger.info "Executing #{action_string} " + (result ? "[OK]" : "[Failed]")
|
248
250
|
return result
|
249
251
|
rescue Exception => e
|
250
|
-
logger.info "Executing #{
|
252
|
+
logger.info "Executing #{action_string} [Failed] #{e}\n#{e.backtrace.join("\n")}"
|
251
253
|
logger.error "#{e}\n#{e.bracktrace.join("\n")}"
|
252
254
|
end
|
253
255
|
false
|
@@ -261,26 +263,25 @@ module Sfp
|
|
261
263
|
def self.load_modules(p={})
|
262
264
|
dir = p[:modules_dir]
|
263
265
|
|
264
|
-
logger = @@logger # (p[:daemon] ? @@logger : Logger.new(STDOUT))
|
265
266
|
@@modules = []
|
266
267
|
counter = 0
|
267
268
|
if dir != '' and File.exist?(dir)
|
268
|
-
logger.info "Modules directory: #{dir}"
|
269
|
+
@@logger.info "Modules directory: #{dir}"
|
269
270
|
Dir.entries(dir).each { |name|
|
270
271
|
next if name == '.' or name == '..' or File.file?("#{dir}/#{name}")
|
271
272
|
module_file = "#{dir}/#{name}/#{name}.rb"
|
272
273
|
next if not File.exist?(module_file)
|
273
274
|
begin
|
274
275
|
load module_file #require module_file
|
275
|
-
logger.info "Loading module #{dir}/#{name} [OK]"
|
276
|
+
@@logger.info "Loading module #{dir}/#{name} [OK]"
|
276
277
|
counter += 1
|
277
278
|
@@modules << name
|
278
279
|
rescue Exception => e
|
279
|
-
logger.warn "Loading module #{dir}/#{name} [Failed]\n#{e}"
|
280
|
+
@@logger.warn "Loading module #{dir}/#{name} [Failed]\n#{e}"
|
280
281
|
end
|
281
282
|
}
|
282
283
|
end
|
283
|
-
logger.info "Successfully loading #{counter} modules."
|
284
|
+
@@logger.info "Successfully loading #{counter} modules."
|
284
285
|
end
|
285
286
|
|
286
287
|
def self.get_schemata(module_name)
|
data/lib/sfpagent/runtime.rb
CHANGED
@@ -3,10 +3,9 @@ require 'thread'
|
|
3
3
|
class Sfp::Runtime
|
4
4
|
attr_reader :modules
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(model)
|
7
7
|
@mutex_procedure = Mutex.new
|
8
|
-
@
|
9
|
-
@root = @parser.root
|
8
|
+
@root = model
|
10
9
|
@modules = nil
|
11
10
|
end
|
12
11
|
|
@@ -122,15 +121,16 @@ class Sfp::Runtime
|
|
122
121
|
end
|
123
122
|
|
124
123
|
root = Sfp::Helper.deep_clone(@root)
|
125
|
-
root.accept(
|
124
|
+
root.accept(ParentEliminator)
|
126
125
|
@modules, state = get_object_state(root, root, as_sfp)
|
127
|
-
|
128
126
|
@modules.accept(ParentGenerator)
|
129
127
|
|
130
128
|
state
|
131
129
|
end
|
132
130
|
|
133
131
|
protected
|
132
|
+
ParentEliminator = Sfp::Visitor::ParentEliminator.new
|
133
|
+
|
134
134
|
ParentGenerator = Object.new
|
135
135
|
def ParentGenerator.visit(name, value, parent)
|
136
136
|
value['_parent'] = parent if value.is_a?(Hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfpagent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-08-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sfp
|
16
|
-
requirement: &
|
16
|
+
requirement: &19476000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.3.9
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19476000
|
25
25
|
description: A Ruby implementation of SFP agent.
|
26
26
|
email: herry13@gmail.com
|
27
27
|
executables:
|