sfpagent 0.2.7 → 0.2.8

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.

Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/sfpagent/bsig.rb +39 -32
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
data/lib/sfpagent/bsig.rb CHANGED
@@ -146,12 +146,12 @@ class Sfp::BSig
146
146
  operators.each do |operator|
147
147
  Thread.new {
148
148
  stat = execute_operator(operator, id, operators, mode)
149
- Sfp::Agent.logger.info "#{operator['name']}{#{JSON.generate(operator['parameters'])}} => #{stat}"
149
+ Sfp::Agent.logger.info "[#{mode}] #{operator['name']}{#{JSON.generate(operator['parameters'])}} => #{stat}"
150
150
  operators_lock.synchronize { status << stat }
151
151
  }
152
152
  end
153
153
  wait? { status.length >= operators.length }
154
- Sfp::Agent.logger.info "exec status: #{status.inspect}"
154
+ Sfp::Agent.logger.info "[#{mode}] exec status: #{status.inspect}"
155
155
  status.each { |stat|
156
156
  return :failure if stat == :failure
157
157
  return :ongoing if stat == :ongoing
@@ -168,39 +168,46 @@ class Sfp::BSig
168
168
  def execute_operator(operator, id, operators, mode)
169
169
  return :ongoing if not lock_operator(operator)
170
170
 
171
- Sfp::Agent.logger.info "[#{mode}] Selected operator: #{operator['id']}:#{operator['name']}{#{JSON.generate(operator['parameters'])}}"
171
+ status = :failure
172
172
 
173
- next_pi = operator['pi'] + 1
174
- pre_local, pre_remote = split_preconditions(operator)
175
-
176
- # debugging
177
- #Sfp::Agent.logger.info "[#{mode}] local-flaws: #{JSON.generate(pre_local)}, remote-flaws: #{JSON.generate(pre_remote)}"
178
-
179
- status = nil
180
- tries = MaxTries
181
173
  begin
182
- status = achieve_local_goal(id, pre_local, operators, next_pi, mode)
183
- if status == :no_flaw or status == :failure or not @enabled
184
- break
185
- elsif status == :ongoing
186
- sleep SleepTime
187
- tries += 1
188
- elsif status == :repaired
189
- tries = MaxTries
190
- end
191
- tries -= 1
192
- end until tries <= 0
193
-
194
- if status != :no_flaw or
195
- not achieve_remote_goal(id, pre_remote, next_pi, mode) or
196
- not invoke(operator, mode)
174
+ Sfp::Agent.logger.info "[#{mode}] Selected operator: #{operator['id']}:#{operator['name']}{#{JSON.generate(operator['parameters'])}}"
175
+
176
+ next_pi = operator['pi'] + 1
177
+ pre_local, pre_remote = split_preconditions(operator)
178
+
179
+ # debugging
180
+ #Sfp::Agent.logger.info "[#{mode}] local-flaws: #{JSON.generate(pre_local)}, remote-flaws: #{JSON.generate(pre_remote)}"
181
+
182
+ status = nil
183
+ tries = MaxTries
184
+ begin
185
+ status = achieve_local_goal(id, pre_local, operators, next_pi, mode)
186
+ if status == :no_flaw or status == :failure or not @enabled
187
+ break
188
+ elsif status == :ongoing
189
+ sleep SleepTime
190
+ tries += 1
191
+ elsif status == :repaired
192
+ tries = MaxTries
193
+ end
194
+ tries -= 1
195
+ end until tries <= 0
196
+
197
+ if status != :no_flaw or
198
+ not achieve_remote_goal(id, pre_remote, next_pi, mode) or
199
+ not invoke(operator, mode)
197
200
 
198
- unlock_operator(operator) if not operator.nil?
199
- return :failure
201
+ status = :failure
202
+ end
203
+
204
+ rescue Exception => exp
205
+ Sfp::Agent.logger.info "[#{mode}] Execute #{operator['name']}{#{operator['parameters']}} [Error]"
206
+ status = :failure
200
207
  end
201
-
208
+
202
209
  unlock_operator(operator) if not operator.nil?
203
- :repaired
210
+ status
204
211
  end
205
212
 
206
213
  def achieve_remote_goal(id, goal, pi, mode)
@@ -212,12 +219,12 @@ class Sfp::BSig
212
219
  agents_goal.each do |agent_name,agent_goal|
213
220
  Thread.new {
214
221
  stat = achieve_remote_agent_goal(agents, agent_name, agent_goal, id, pi, mode)
215
- Sfp::Agent.logger.info "remote goal => #{agent_name}: #{agent_goal.inspect} - #{stat}"
222
+ Sfp::Agent.logger.info "[#{mode}] remote goal => #{agent_name}: #{agent_goal.inspect} - #{stat}"
216
223
  lock.synchronize { status << stat }
217
224
  }
218
225
  end
219
226
  wait? { status.length >= agents_goal.length }
220
- Sfp::Agent.logger.info "achieve_remote_goal: #{status}"
227
+ Sfp::Agent.logger.info "[#{mode}] achieve_remote_goal: #{status}"
221
228
  status.each { |stat| return false if !stat }
222
229
  end
223
230
  true
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.2.7
4
+ version: 0.2.8
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: &20307740 !ruby/object:Gem::Requirement
16
+ requirement: &19482160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.3.12
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20307740
24
+ version_requirements: *19482160
25
25
  description: A Ruby implementation of SFP agent.
26
26
  email: herry13@gmail.com
27
27
  executables: