sfpagent 0.2.8 → 0.2.9

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 CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
@@ -68,7 +68,7 @@ class Sfp::BSig
68
68
  if exec_status == :failure
69
69
  Sfp::Agent.logger.error "[main] Executing BSig model [Failed]"
70
70
  sleep SleepTime
71
- elsif exec_status == :no_flaw
71
+ elsif exec_status == :no_flaw or exec_status == :pending
72
72
  sleep SleepTime
73
73
  end
74
74
  end
@@ -102,7 +102,7 @@ class Sfp::BSig
102
102
  # @return
103
103
  # :no_flaw => there is no goal-flaw
104
104
  # :failure => there is a failure on achieving the goal
105
- # :ongoing => the selected operator is being executed
105
+ # :pending => the selected operator is being executed
106
106
  # :repaired => some goal-flaws have been repaired, but the goal may have other flaws
107
107
  #
108
108
  def sequential_achieve_local_goal(id, goal, operators, pi, mode)
@@ -127,12 +127,14 @@ class Sfp::BSig
127
127
  # @return
128
128
  # :no_flaw => there is no goal-flaw
129
129
  # :failure => there is a failure on achieving the goal
130
- # :ongoing => the selected operator is being executed
130
+ # :pending => the selected operator is being executed
131
131
  # :repaired => some goal-flaws have been repaired, but the goal may have other flaws
132
132
  #
133
133
  def achieve_local_goal(id, goal, operators, pi, mode)
134
134
  current = get_current_state
135
135
  flaws = compute_flaws(goal, current)
136
+ Sfp::Agent.logger.info "[#{mode}] flaws: #{flaws.inspect}"
137
+
136
138
  return :no_flaw if flaws.length <= 0
137
139
 
138
140
  operators = select_operators(flaws, operators, pi)
@@ -142,19 +144,19 @@ class Sfp::BSig
142
144
 
143
145
  total = operators.length
144
146
  status = []
145
- operators_lock = Mutex.new
147
+ lock = Mutex.new
146
148
  operators.each do |operator|
147
149
  Thread.new {
148
150
  stat = execute_operator(operator, id, operators, mode)
149
- Sfp::Agent.logger.info "[#{mode}] #{operator['name']}{#{JSON.generate(operator['parameters'])}} => #{stat}"
150
- operators_lock.synchronize { status << stat }
151
+ Sfp::Agent.logger.info "[#{mode}] Execute_operator: #{operator['name']}#{JSON.generate(operator['parameters'])} => #{stat}"
152
+ lock.synchronize { status << stat }
151
153
  }
152
154
  end
153
155
  wait? { status.length >= operators.length }
154
156
  Sfp::Agent.logger.info "[#{mode}] exec status: #{status.inspect}"
155
157
  status.each { |stat|
156
158
  return :failure if stat == :failure
157
- return :ongoing if stat == :ongoing
159
+ return :pending if stat == :pending
158
160
  }
159
161
  :repaired
160
162
  end
@@ -166,18 +168,18 @@ class Sfp::BSig
166
168
  end
167
169
 
168
170
  def execute_operator(operator, id, operators, mode)
169
- return :ongoing if not lock_operator(operator)
171
+ return :pending if not lock_operator(operator)
170
172
 
171
173
  status = :failure
172
174
 
173
175
  begin
174
- Sfp::Agent.logger.info "[#{mode}] Selected operator: #{operator['id']}:#{operator['name']}{#{JSON.generate(operator['parameters'])}}"
176
+ Sfp::Agent.logger.info "[#{mode}] Selected operator: #{operator['id']}:#{operator['name']}#{JSON.generate(operator['parameters'])}"
175
177
 
176
178
  next_pi = operator['pi'] + 1
177
179
  pre_local, pre_remote = split_preconditions(operator)
178
180
 
179
181
  # debugging
180
- #Sfp::Agent.logger.info "[#{mode}] local-flaws: #{JSON.generate(pre_local)}, remote-flaws: #{JSON.generate(pre_remote)}"
182
+ Sfp::Agent.logger.info "[#{mode}] local-flaws: #{JSON.generate(pre_local)}, remote-flaws: #{JSON.generate(pre_remote)}"
181
183
 
182
184
  status = nil
183
185
  tries = MaxTries
@@ -185,14 +187,16 @@ class Sfp::BSig
185
187
  status = achieve_local_goal(id, pre_local, operators, next_pi, mode)
186
188
  if status == :no_flaw or status == :failure or not @enabled
187
189
  break
188
- elsif status == :ongoing
190
+ elsif status == :pending
189
191
  sleep SleepTime
190
192
  tries += 1
191
193
  elsif status == :repaired
192
194
  tries = MaxTries
193
195
  end
194
196
  tries -= 1
195
- end until tries <= 0
197
+ end until tries <= 0 and @enabled
198
+
199
+ Sfp::Agent.logger.info "[#{mode}] achieve_local_goal => #{status}"
196
200
 
197
201
  if status != :no_flaw or
198
202
  not achieve_remote_goal(id, pre_remote, next_pi, mode) or
@@ -263,7 +267,7 @@ class Sfp::BSig
263
267
  status = achieve_local_goal(bsig['id'], goal, bsig['operators'], pi, :satisfier)
264
268
  if status == :no_flaw or status == :failure or not @enabled
265
269
  break
266
- elsif status == :ongoing
270
+ elsif status == :pending
267
271
  sleep SleepTime
268
272
  tries += 1
269
273
  elsif status == :repaired
@@ -329,12 +333,14 @@ class Sfp::BSig
329
333
 
330
334
  def send_goal_to_agent(agent, id, goal, pi, agent_name='', mode)
331
335
  begin
332
- data = {'id' => id,
333
- 'goal' => JSON.generate(goal),
334
- 'pi' => pi}
335
- Sfp::Agent.logger.info "[#{mode}] Request goal to #{agent_name} [WAIT]"
336
+ data = {
337
+ 'id' => id,
338
+ 'goal' => JSON.generate(goal),
339
+ 'pi' => pi
340
+ }
341
+ Sfp::Agent.logger.info "[#{mode}] Request goal to #{agent_name}@#{agent['sfpAddress']}:#{agent['sfpPort']} [WAIT]"
336
342
  code, _ = put_data(agent['sfpAddress'], agent['sfpPort'], SatisfierPath, data)
337
- Sfp::Agent.logger.info "[#{mode}] Request goal to #{agent_name} - status: #{code}"
343
+ Sfp::Agent.logger.info "[#{mode}] Request goal to #{agent_name}@#{agent['sfpAddress']}:#{agent['sfpPort']} #{code}"
338
344
  (code == '200')
339
345
  rescue Exception => exp
340
346
  Sfp::Agent.logger.info "[#{mode}] Request goal to #{agent_name} - error: #{exp}\n#{exp.bracktrace.join("\n")}"
@@ -28,7 +28,7 @@ module Sfp::Helper::Net
28
28
  http_request(uri, req, open_timeout, read_timeout)
29
29
  end
30
30
 
31
- private
31
+ protected
32
32
  def create_uri(address, port, path)
33
33
  address = address.to_s.strip
34
34
  port = port.to_s.strip
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.8
4
+ version: 0.2.9
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: &19482160 !ruby/object:Gem::Requirement
16
+ requirement: &7372320 !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: *19482160
24
+ version_requirements: *7372320
25
25
  description: A Ruby implementation of SFP agent.
26
26
  email: herry13@gmail.com
27
27
  executables: