pione 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. data/.gitignore +2 -0
  2. data/.s3cfg +42 -0
  3. data/.travis.yml +18 -4
  4. data/.yardopts +1 -0
  5. data/Gemfile +3 -0
  6. data/History.txt +14 -0
  7. data/Procfile +7 -0
  8. data/Rakefile +25 -0
  9. data/bin/pione-interactive +6 -0
  10. data/bin/{pione-compiler → pione-notification-listener} +1 -1
  11. data/bin/{pione-broker → pione-task-worker-broker} +1 -1
  12. data/doc/man/pione-list-param.md +36 -0
  13. data/example/ActionError/ActionError.pione +9 -0
  14. data/example/ActionError/pione-package.json +15 -0
  15. data/example/CountChar/CountChar.pione +1 -1
  16. data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
  17. data/example/Touch/pione-package.json +15 -0
  18. data/lib/pione.rb +12 -0
  19. data/lib/pione/agent.rb +3 -3
  20. data/lib/pione/agent/basic-agent.rb +10 -4
  21. data/lib/pione/agent/input-generator.rb +3 -3
  22. data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
  23. data/lib/pione/agent/job-terminator.rb +2 -2
  24. data/lib/pione/agent/logger.rb +3 -3
  25. data/lib/pione/agent/messenger.rb +20 -9
  26. data/lib/pione/agent/notification-listener.rb +88 -0
  27. data/lib/pione/agent/task-worker-broker.rb +84 -0
  28. data/lib/pione/agent/task-worker.rb +3 -2
  29. data/lib/pione/agent/tuple-space-client.rb +1 -0
  30. data/lib/pione/agent/tuple-space-provider.rb +17 -35
  31. data/lib/pione/command.rb +33 -15
  32. data/lib/pione/command/action.rb +105 -0
  33. data/lib/pione/command/basic-command.rb +34 -376
  34. data/lib/pione/command/command-exception.rb +12 -11
  35. data/lib/pione/command/common.rb +198 -0
  36. data/lib/pione/command/option.rb +159 -204
  37. data/lib/pione/command/pione-action-exec.rb +85 -0
  38. data/lib/pione/command/pione-action-list.rb +43 -19
  39. data/lib/pione/command/pione-action-print.rb +79 -0
  40. data/lib/pione/command/pione-action.rb +8 -67
  41. data/lib/pione/command/pione-clean.rb +88 -68
  42. data/lib/pione/command/pione-client.rb +475 -332
  43. data/lib/pione/command/pione-command.rb +14 -31
  44. data/lib/pione/command/pione-compile.rb +90 -0
  45. data/lib/pione/command/pione-config-get.rb +53 -0
  46. data/lib/pione/command/pione-config-list.rb +64 -0
  47. data/lib/pione/command/pione-config-set.rb +59 -0
  48. data/lib/pione/command/pione-config-unset.rb +50 -0
  49. data/lib/pione/command/pione-config.rb +61 -0
  50. data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
  51. data/lib/pione/command/pione-diagnosis.rb +21 -0
  52. data/lib/pione/command/pione-interactive.rb +188 -0
  53. data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
  54. data/lib/pione/command/pione-lang-interactive.rb +146 -0
  55. data/lib/pione/command/pione-lang.rb +22 -0
  56. data/lib/pione/command/pione-log-format.rb +163 -0
  57. data/lib/pione/command/pione-log-list-id.rb +48 -0
  58. data/lib/pione/command/pione-log.rb +19 -101
  59. data/lib/pione/command/pione-notification-listener.rb +95 -0
  60. data/lib/pione/command/pione-package-add.rb +137 -0
  61. data/lib/pione/command/pione-package-build.rb +122 -0
  62. data/lib/pione/command/pione-package-show.rb +96 -0
  63. data/lib/pione/command/pione-package-update.rb +59 -0
  64. data/lib/pione/command/pione-package.rb +11 -139
  65. data/lib/pione/command/pione-task-worker-broker.rb +88 -0
  66. data/lib/pione/command/pione-task-worker.rb +148 -98
  67. data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
  68. data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
  69. data/lib/pione/command/pione-val.rb +39 -39
  70. data/lib/pione/command/spawner.rb +34 -27
  71. data/lib/pione/front.rb +4 -2
  72. data/lib/pione/front/basic-front.rb +86 -23
  73. data/lib/pione/front/client-front.rb +2 -2
  74. data/lib/pione/front/diagnosis-notification-front.rb +40 -0
  75. data/lib/pione/front/front-exception.rb +7 -1
  76. data/lib/pione/front/notification-listener-front.rb +36 -0
  77. data/lib/pione/front/notification-recipient-interface.rb +19 -0
  78. data/lib/pione/front/relay-front.rb +4 -4
  79. data/lib/pione/front/task-worker-broker-front.rb +19 -0
  80. data/lib/pione/front/task-worker-front.rb +2 -2
  81. data/lib/pione/front/tuple-space-provider-front.rb +3 -2
  82. data/lib/pione/global.rb +3 -1
  83. data/lib/pione/global/client-variable.rb +1 -1
  84. data/lib/pione/global/config.rb +63 -7
  85. data/lib/pione/global/diagnosis-variable.rb +26 -0
  86. data/lib/pione/global/item.rb +28 -5
  87. data/lib/pione/global/log-variable.rb +6 -5
  88. data/lib/pione/global/network-variable.rb +75 -4
  89. data/lib/pione/global/path-variable.rb +1 -1
  90. data/lib/pione/global/system-variable.rb +12 -12
  91. data/lib/pione/global/task-worker-broker-variable.rb +43 -0
  92. data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
  93. data/lib/pione/lang/boolean.rb +4 -0
  94. data/lib/pione/lang/data-expr.rb +1 -1
  95. data/lib/pione/lang/integer.rb +1 -1
  96. data/lib/pione/lang/string.rb +4 -0
  97. data/lib/pione/lang/type.rb +1 -1
  98. data/lib/pione/location.rb +1 -0
  99. data/lib/pione/location/data-location.rb +41 -13
  100. data/lib/pione/location/dropbox-location.rb +175 -56
  101. data/lib/pione/location/ftp-location.rb +4 -1
  102. data/lib/pione/location/http-location.rb +5 -3
  103. data/lib/pione/location/https-location.rb +4 -2
  104. data/lib/pione/location/local-location.rb +6 -3
  105. data/lib/pione/location/location-exception.rb +12 -0
  106. data/lib/pione/location/notification-scheme.rb +46 -0
  107. data/lib/pione/log.rb +8 -7
  108. data/lib/pione/log/debug.rb +9 -9
  109. data/lib/pione/log/domain-log.rb +6 -1
  110. data/lib/pione/log/message-log-receiver.rb +32 -0
  111. data/lib/pione/log/system-log.rb +62 -141
  112. data/lib/pione/model.rb +7 -0
  113. data/lib/pione/model/notification-listener-model.rb +29 -0
  114. data/lib/pione/model/task-worker-broker-model.rb +129 -0
  115. data/lib/pione/notification.rb +13 -0
  116. data/lib/pione/notification/address.rb +104 -0
  117. data/lib/pione/notification/exception.rb +10 -0
  118. data/lib/pione/notification/message.rb +109 -0
  119. data/lib/pione/notification/receiver.rb +90 -0
  120. data/lib/pione/notification/recipient.rb +68 -0
  121. data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
  122. data/lib/pione/notification/transmitter.rb +84 -0
  123. data/lib/pione/pnml.rb +35 -0
  124. data/lib/pione/pnml/annotation-extractor.rb +47 -0
  125. data/lib/pione/pnml/compiler.rb +176 -0
  126. data/lib/pione/pnml/input-merge-complement.rb +78 -0
  127. data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
  128. data/lib/pione/pnml/input-reduction.rb +80 -0
  129. data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
  130. data/lib/pione/pnml/io-expansion.rb +88 -0
  131. data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
  132. data/lib/pione/pnml/net-rewriter.rb +44 -0
  133. data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
  134. data/lib/pione/pnml/output-reduction.rb +86 -0
  135. data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
  136. data/lib/pione/pnml/pione-model.rb +417 -0
  137. data/lib/pione/pnml/pnml-exception.rb +23 -0
  138. data/lib/pione/pnml/pnml-model.rb +368 -0
  139. data/lib/pione/pnml/reader.rb +51 -0
  140. data/lib/pione/rule-engine/action-handler.rb +8 -6
  141. data/lib/pione/rule-engine/basic-handler.rb +5 -5
  142. data/lib/pione/rule-engine/engine-exception.rb +7 -6
  143. data/lib/pione/rule-engine/flow-handler.rb +27 -18
  144. data/lib/pione/system.rb +3 -1
  145. data/lib/pione/system/domain-dump.rb +34 -0
  146. data/lib/pione/system/file-cache.rb +92 -13
  147. data/lib/pione/system/init.rb +3 -0
  148. data/lib/pione/system/normalizer.rb +40 -0
  149. data/lib/pione/system/status.rb +5 -5
  150. data/lib/pione/system/system-exception.rb +14 -1
  151. data/lib/pione/task-worker-broker.rb +7 -0
  152. data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
  153. data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
  154. data/lib/pione/test-helper.rb +27 -0
  155. data/lib/pione/test-helper/command-helper.rb +9 -101
  156. data/lib/pione/tuple-space/basic-tuple.rb +1 -1
  157. data/lib/pione/tuple-space/tuple-definition.yml +4 -6
  158. data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
  159. data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
  160. data/lib/pione/util.rb +1 -2
  161. data/lib/pione/util/boolean-value.rb +62 -0
  162. data/lib/pione/util/completion.rb +111 -0
  163. data/lib/pione/util/evaluatable.rb +13 -27
  164. data/lib/pione/util/package-parameters-list.rb +15 -27
  165. data/lib/pione/util/zip.rb +8 -3
  166. data/lib/pione/version.rb +1 -1
  167. data/lib/rootage.rb +20 -0
  168. data/lib/rootage/action.rb +114 -0
  169. data/lib/rootage/argument.rb +46 -0
  170. data/lib/rootage/command.rb +218 -0
  171. data/lib/rootage/core.rb +532 -0
  172. data/lib/rootage/exception.rb +107 -0
  173. data/lib/rootage/help.rb +148 -0
  174. data/lib/rootage/help.txt.erb +31 -0
  175. data/lib/rootage/log.rb +226 -0
  176. data/lib/rootage/normalizer.rb +184 -0
  177. data/lib/rootage/option.rb +152 -0
  178. data/lib/rootage/scenario-test-result.erb +39 -0
  179. data/lib/rootage/scenario.rb +362 -0
  180. data/lib/rootage/test-helper.rb +115 -0
  181. data/man/pione-list-param.1 +44 -0
  182. data/misc/clock.rb +9 -0
  183. data/misc/machine-info.sh +21 -0
  184. data/misc/pione-completion.bash +238 -0
  185. data/misc/pione-completion.erb +53 -0
  186. data/misc/pione-completion.zsh +238 -0
  187. data/misc/pione.god +22 -0
  188. data/misc/ui.xml +23 -0
  189. data/pione.gemspec +3 -1
  190. data/test/agent/spec_basic-agent.rb +1 -1
  191. data/test/agent/spec_input-generator.rb +2 -2
  192. data/test/agent/spec_messenger.rb +6 -9
  193. data/test/agent/spec_notification-listener.rb +80 -0
  194. data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
  195. data/test/agent/spec_tuple-space-provider.rb +10 -6
  196. data/test/command/command-behavior.rb +3 -11
  197. data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
  198. data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
  199. data/test/command/spec_pione-action-exec.rb +16 -0
  200. data/test/command/spec_pione-action-list.rb +15 -10
  201. data/test/command/spec_pione-action-print.rb +14 -0
  202. data/test/command/spec_pione-action.rb +6 -19
  203. data/test/command/spec_pione-clean.rb +29 -46
  204. data/test/command/spec_pione-client.rb +29 -36
  205. data/test/command/spec_pione-command.rb +6 -6
  206. data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
  207. data/test/command/spec_pione-config-get.rb +47 -0
  208. data/test/command/spec_pione-config-list.rb +42 -0
  209. data/test/command/spec_pione-config-set.rb +38 -0
  210. data/test/command/spec_pione-config-unset.rb +44 -0
  211. data/test/command/spec_pione-config.rb +11 -0
  212. data/test/command/spec_pione-diagnosis-notification.rb +23 -0
  213. data/test/command/spec_pione-diagnosis.rb +11 -0
  214. data/test/command/spec_pione-lang-check-syntax.rb +12 -0
  215. data/test/command/spec_pione-lang.rb +11 -0
  216. data/test/command/spec_pione-log-format.rb +29 -0
  217. data/test/command/spec_pione-log-list-id.rb +17 -0
  218. data/test/command/spec_pione-log.rb +6 -20
  219. data/test/command/spec_pione-package-add.rb +55 -0
  220. data/test/command/spec_pione-package-build.rb +57 -0
  221. data/test/command/spec_pione-package-show.rb +72 -0
  222. data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
  223. data/test/command/spec_pione-package.rb +4 -104
  224. data/test/command/spec_pione-val.rb +10 -7
  225. data/test/global/spec_config.rb +50 -0
  226. data/test/global/spec_item.rb +1 -1
  227. data/test/literate-action/data/HelloWorld.md +1 -1
  228. data/test/location/location-behavior.rb +1 -1
  229. data/test/location/spec_dropbox-location.rb +39 -0
  230. data/test/location/spec_notification-scheme.rb +37 -0
  231. data/test/log/spec_debug.rb +5 -4
  232. data/test/log/spec_message-log-receiver.rb +13 -0
  233. data/test/log/spec_message-log.rb +6 -9
  234. data/test/log/spec_system-log.rb +5 -3
  235. data/test/notification/spec_address.rb +229 -0
  236. data/test/notification/spec_message.rb +30 -0
  237. data/test/notification/spec_receiver.rb +36 -0
  238. data/test/notification/spec_transmitter.rb +37 -0
  239. data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
  240. data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
  241. data/test/pnml/data/IOExpansionComplex.pnml +363 -0
  242. data/test/pnml/data/IOExpansionSimple.pnml +140 -0
  243. data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
  244. data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
  245. data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
  246. data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
  247. data/test/pnml/data/InputReductionComplex.pnml +192 -0
  248. data/test/pnml/data/InputReductionLong.pnml +344 -0
  249. data/test/pnml/data/InputReductionSimple.pnml +140 -0
  250. data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
  251. data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
  252. data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
  253. data/test/pnml/data/OutputReductionComplex.pnml +186 -0
  254. data/test/pnml/data/OutputReductionLong.pnml +344 -0
  255. data/test/pnml/data/OutputReductionSimple.pnml +140 -0
  256. data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
  257. data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
  258. data/test/pnml/data/SampleNet.pnml +238 -0
  259. data/test/pnml/spec_input-merge-complement.rb +40 -0
  260. data/test/pnml/spec_input-parallelization-complement.rb +50 -0
  261. data/test/pnml/spec_input-reduction.rb +113 -0
  262. data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
  263. data/test/pnml/spec_io-expansion.rb +126 -0
  264. data/test/pnml/spec_isolated-element-elimination.rb +25 -0
  265. data/test/pnml/spec_output-decomposition-complement.rb +40 -0
  266. data/test/pnml/spec_output-reduction.rb +114 -0
  267. data/test/pnml/spec_output-synchronization-complement.rb +62 -0
  268. data/test/pnml/spec_pione-element.rb +144 -0
  269. data/test/pnml/spec_pnml-element.rb +373 -0
  270. data/test/pnml/spec_reader.rb +16 -0
  271. data/test/rootage/spec_argument.rb +18 -0
  272. data/test/rootage/spec_command.rb +239 -0
  273. data/test/rootage/spec_core.rb +198 -0
  274. data/test/rootage/spec_scenario.rb +149 -0
  275. data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
  276. data/test/system/spec_file-cache.rb +6 -9
  277. data/test/tuple-space/spec_finished-tuple.rb +1 -1
  278. data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
  279. data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
  280. data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
  281. data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
  282. data/test/util/spec_boolean-value.rb +32 -0
  283. data/test/util/spec_completion.rb +22 -0
  284. data/test/util/spec_package-parameters-list.rb +39 -52
  285. data/test/util/spec_zip.rb +28 -1
  286. metadata +288 -47
  287. data/bin/pione-tuple-space-receiver +0 -5
  288. data/lib/pione/agent/broker.rb +0 -304
  289. data/lib/pione/agent/tuple-space-receiver.rb +0 -137
  290. data/lib/pione/command/pione-broker.rb +0 -104
  291. data/lib/pione/command/pione-compiler.rb +0 -57
  292. data/lib/pione/command/pione-relay-account-db.rb +0 -141
  293. data/lib/pione/command/pione-relay-client-db.rb +0 -118
  294. data/lib/pione/command/pione-relay.rb +0 -59
  295. data/lib/pione/command/pione-syntax-checker.rb +0 -214
  296. data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
  297. data/lib/pione/command/pione-update-package-info.rb +0 -53
  298. data/lib/pione/front/broker-front.rb +0 -22
  299. data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
  300. data/lib/pione/global/broker-variable.rb +0 -33
  301. data/lib/pione/system/domain-info.rb +0 -25
  302. data/lib/pione/util/pnml-compiler.rb +0 -168
  303. data/test/agent/spec_tuple-space-receiver.rb +0 -47
  304. data/test/util/spec_pnml-compiler.rb +0 -32
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- ruby -*-
3
-
4
- require 'pione'
5
- Pione::Command::PioneTupleSpaceReceiver.run(ARGV)
@@ -1,304 +0,0 @@
1
- module Pione
2
- module Agent
3
- # Broker is an agent for providing task workers to tuple space.
4
- class Broker < BasicAgent
5
- set_agent_type :broker, self
6
-
7
- #
8
- # instance methods
9
- #
10
-
11
- attr_reader :task_worker_resource # resource size of task worker
12
- attr_reader :tuple_space_lock # lock for tuple space table
13
-
14
- def initialize(option={})
15
- super()
16
-
17
- @task_workers = Array.new # known task worker fronts
18
- @tuple_space = Hash.new # known tuple space table
19
- @task_worker_resource = option[:task_worker_resource] || 1
20
- @sleeping_time = option[:sleeping_time] || 1
21
- @spawnings = 0 # number of current spawning task worker
22
- @tuple_space_lock = Monitor.new
23
- @task_worker_lock = Monitor.new # lock for task worker table
24
-
25
- @option = option
26
- @option[:spawn_task_worker] = true unless @option.has_key?(:spawn_task_worker)
27
-
28
- # balancer
29
- @balancer = Global.broker_task_worker_balancer.new(self)
30
- end
31
-
32
- # Return number of task workers the broker manages.
33
- def quantity
34
- @task_worker_lock.synchronize {@task_workers.size}
35
- end
36
-
37
- # Add the tuple space.
38
- def add_tuple_space(tuple_space)
39
- uuid = tuple_space.uuid
40
-
41
- # update tuple space table with the id
42
- @tuple_space_lock.synchronize {@tuple_space[uuid] = tuple_space}
43
-
44
- # wakeup chain thread if it sleeps
45
- @chain_threads.list.each do |thread|
46
- if thread[:agent_state] and thread[:agent_state].current?(:sleep)
47
- thread.run
48
- end
49
- end
50
- end
51
-
52
- # Get the tuple space.
53
- def get_tuple_space(tuple_space_id)
54
- @tuple_space_lock.synchronize {@tuple_space[tuple_space_id]}
55
- end
56
-
57
- # Return known tuple spaces.
58
- def tuple_spaces
59
- @tuple_space_lock.synchronize {@tuple_space.values}
60
- end
61
-
62
- # Return excess number of workers belongs to this broker.
63
- def excess_task_workers
64
- @task_worker_lock.synchronize do
65
- @task_worker_resource - @task_workers.size - @spawnings
66
- end
67
- end
68
-
69
- # Create a task worker for the server. This method returns true if we
70
- # suceeded to spawn the task worker, or returns false.
71
- def create_task_worker(tuple_space)
72
- res = true
73
-
74
- @task_worker_lock.synchronize do
75
- @spawnings += 1
76
-
77
- # spawn a new process of pione-task-worker command
78
- if @option[:spawn_task_worker]
79
- begin
80
- spawner = Command::PioneTaskWorker.spawn(Global.features, tuple_space.uuid)
81
- @task_workers << spawner.child_front
82
- spawner.when_terminated {delete_task_worker(spawner.child_front)}
83
- rescue Command::SpawnError => e
84
- Log::Debug.system("broker agent failed to spawn a task worker.")
85
- res = false
86
- end
87
- else
88
- @task_workers << Agent::TaskWorker.start(tuple_space, Global.expressional_features, @env)
89
- end
90
-
91
- @spawnings -= 1
92
- end
93
-
94
- return res
95
- end
96
-
97
- def delete_task_worker(worker)
98
- @task_worker_lock.synchronize {@task_workers.delete(worker)}
99
- end
100
-
101
- # Terminate first task worker that satisfies the condition. Return true if
102
- def terminate_task_worker_if(&condition)
103
- @task_worker_lock.synchronize do
104
- @task_workers.each do |worker|
105
- if condition.call(worker)
106
- worker.terminate
107
- @task_workers.delete(worker)
108
- return true
109
- end
110
- end
111
- end
112
- return false
113
- end
114
-
115
- # Delete unavilable tuple space servers.
116
- def check_tuple_space
117
- @tuple_space_lock.synchronize do
118
- @tuple_space.delete_if do |_, space|
119
- not(Util.ignore_exception {timeout(1) {space.ping}})
120
- end
121
- end
122
- end
123
-
124
- # Update tuple space list.
125
- def update_tuple_space_list(tuple_spaces)
126
- Thread.new do
127
- begin
128
- @tuple_space_lock.synchronize do
129
- # clear and update tuple space list
130
- @tuple_space = {}
131
- tuple_spaces.each do |tuple_space|
132
- Util.ignore_exception {timeout(1) {add_tuple_space(tuple_space)}}
133
- end
134
-
135
- timeout(1) do
136
- Log::Debug.presence_notification do
137
- "broker agent updated tuple space table: %s" % [@tuple_space.values.map{|space| space.__drburi}]
138
- end
139
- end
140
- end
141
- rescue Exception => e
142
- check_tuple_space
143
- end
144
- end
145
- return true
146
- end
147
-
148
- #
149
- # agent activities
150
- #
151
-
152
- define_transition :count_tuple_space
153
- define_transition :balance_task_worker
154
- define_transition :sleep
155
- define_transition :check_tuple_space
156
- define_transition :check_task_worker_life
157
-
158
- chain :init => [:count_tuple_space, :check_task_worker_life]
159
- chain :count_tuple_space => lambda {|agent, res|
160
- res > 0 ? :balance_task_worker : :sleep
161
- }
162
- chain :balance_task_worker => lambda {|agent, rebalance|
163
- rebalance ? :balance_task_worker : :sleep
164
- }
165
- chain :sleep => :count_tuple_space
166
- chain :check_tuple_space => :count_tuple_space
167
- chain :check_task_worker_life => :check_task_worker_life
168
-
169
- define_exception_handler Restart => :check_tuple_space
170
-
171
- #
172
- # transitions
173
- #
174
-
175
- def transit_to_count_tuple_space
176
- @tuple_space.size
177
- end
178
-
179
- def transit_to_balance_task_worker
180
- @balancer.balance
181
- end
182
-
183
- def transit_to_check_tuple_space
184
- check_tuple_space
185
- end
186
-
187
- def transit_to_sleep
188
- if @tuple_space.size == 0 or excess_task_workers == 0
189
- sleep 3
190
- else
191
- sleep 1
192
- end
193
- end
194
-
195
- def transit_to_check_task_worker_life
196
- @task_worker_lock.synchronize do
197
- @task_workers.delete_if do |worker|
198
- begin
199
- timeout(1) { worker.ping }
200
- false
201
- rescue Exception => e
202
- true
203
- end
204
- end
205
- end
206
- sleep 1
207
- end
208
-
209
- # Send bye message to tuple spaces when the broker is destroyed.
210
- def transit_to_terminate
211
- @tuple_space_lock.synchronize do
212
- @tuple_space.each do |_, tuple_space|
213
- Util.ignore_exception {timeout(1) {tuple_space.bye}}
214
- end
215
- end
216
- end
217
- end
218
-
219
- # TaskWorkerBalancer is a base class for balancing task workers.
220
- class TaskWorkerBalancer
221
- # Create a new balancer.
222
- def initialize(broker)
223
- @broker = broker
224
- end
225
-
226
- # Execute task worker balancing. If this method returned true, broker
227
- # executes rebalance chain with no span. If false, broker sleeps a little.
228
- def balance
229
- raise NotImplementedError
230
- end
231
- end
232
-
233
- # EasyBalancer is a balancer by ratios of tuple space and task worker.
234
- class EasyTaskWorkerBalancer < TaskWorkerBalancer
235
- # see Balancer.new
236
- def initialize(broker)
237
- @broker = broker
238
- end
239
-
240
- # Balance task worker ratio by creating a new task worker in minimum
241
- # tuple space or killing a task worker in maximum.
242
- def balance
243
- ratios = calc_resource_ratios
244
- min = ratios.values.min
245
- max = ratios.values.max
246
- min_server = ratios.key(min)
247
- max_server = ratios.key(max)
248
-
249
- return false unless min_server
250
- return false unless max_server
251
-
252
- if @broker.excess_task_workers > 0 and min_server
253
- return create_task_worker(min_server)
254
- else
255
- return adjust_task_worker(min_server, max_server)
256
- end
257
- end
258
-
259
- # Calculate resource ratios of tuple space servers.
260
- def calc_resource_ratios(revision={})
261
- ratio = {}
262
- # make ratio table
263
- @broker.tuple_space_lock.synchronize do
264
- @broker.tuple_spaces.each do |tuple_space|
265
- rev = revision.has_key?(tuple_space) ? revision[tuple_space] : 0
266
- current = timeout(1){tuple_space.current_task_worker_size} + rev
267
- resource = tuple_space.task_worker_resource
268
- # minimum resource is 1
269
- resource = 1 unless resource > 0
270
- ratio[tuple_space] = current / resource.to_f
271
- end
272
- end
273
- return ratio
274
- end
275
-
276
- # Creates a new task worker.
277
- def create_task_worker(min_server)
278
- return @broker.create_task_worker(min_server)
279
- end
280
-
281
- # Adjusts task worker size between tuple space servers.
282
- def adjust_task_worker(min_server, max_server)
283
- revision = {min_server => 1, max_server => -1}
284
- new_ratios = calc_resource_ratios(revision)
285
-
286
- # failed to calculate tuple space ratio
287
- return unless new_ratios.has_key?(min_server)
288
- return unless new_ratios.has_key?(max_server)
289
-
290
- # kill a task worker for moving worker from max server to min server
291
- if new_ratios[min_server] < new_ratios[max_server]
292
- if @broker.terminate_task_worker_if do |worker|
293
- worker.tuple_space == max_server && worker.states.any?{|s| s.current?(:take_task)}
294
- end
295
- return true
296
- end
297
- end
298
-
299
- # failed to adjust task workers
300
- return false
301
- end
302
- end
303
- end
304
- end
@@ -1,137 +0,0 @@
1
- module Pione
2
- module Agent
3
- class TupleSpaceReceiver < BasicAgent
4
- #
5
- # instance methods
6
- #
7
-
8
- # notification handler threads
9
- attr_reader :notification_handlers
10
-
11
- def initialize(broker_front)
12
- super()
13
- @broker_front = broker_front # broker front
14
- @tuple_space = {} # tuple space table
15
- @tuple_space_lock = Mutex.new # lock for tuple space table
16
- @notification_handlers = ThreadGroup.new
17
- end
18
-
19
- def tuple_spaces
20
- @tuple_space_lock.synchronize {@tuple_space.keys}
21
- end
22
-
23
- #
24
- # agent activities
25
- #
26
-
27
- define_transition :receive_packet
28
- define_transition :update_broker
29
- define_transition :sleep
30
-
31
- chain :init => [:receive_packet, :update_broker]
32
- chain :receive_packet => :receive_packet
33
- chain :update_broker => :sleep
34
- chain :sleep => :update_broker
35
-
36
- #
37
- # transitions
38
- #
39
-
40
- def transit_to_init
41
- @tuple_space = {}
42
- @socket = open_socket
43
- end
44
-
45
- # Receive tuple space servers and update the table.
46
- def transit_to_receive_packet
47
- # receive a presence notification
48
- data, addr = @socket.recvfrom(1024)
49
- ip_address = addr[3]
50
- port = Marshal.load(data).to_i
51
-
52
- # handle the notification in new thread
53
- thread = Util::FreeThreadGenerator.generate do
54
- handle_presence_notification(ip_address, port)
55
- end
56
- @notification_handlers.add(thread)
57
- rescue IOError => e
58
- Log::Debug.presence_notification("receiver agent received bad data from %s, so it ignored and reopen socket" % ip_address)
59
- reopen_socket
60
- end
61
-
62
- # Close receiver socket.
63
- def transit_to_terminate
64
- # kill threads of presence notification handler
65
- @notification_handlers.list.each {|thread| thread.kill.join}
66
- # close socket
67
- @socket.close unless @socket.closed?
68
- end
69
-
70
- def transit_to_update_broker
71
- # update tuple space server list
72
- @tuple_space_lock.synchronize do
73
- # check timespan
74
- @tuple_space.delete_if do |server, time|
75
- (Time.now - time) > Global.tuple_space_receiver_disconnect_time
76
- end
77
- end
78
-
79
- # update broker's tuple spaces
80
- timeout(3) do
81
- @tuple_space_lock.synchronize do
82
- @broker_front.update_tuple_space_list(@tuple_space.keys)
83
- end
84
- end
85
- rescue DRb::DRbConnError, Timeout::Error => e
86
- Log::SystemLog.fatal("tuple space receiver failed to connect pione-broker: %s" % e.message)
87
- raise ConnectionError.new
88
- end
89
-
90
- def transit_to_sleep
91
- sleep 1
92
- end
93
-
94
- #
95
- # helper methods
96
- #
97
-
98
- private
99
-
100
- # Open a receiver socket.
101
- def open_socket
102
- socket = UDPSocket.open
103
- socket.bind(Socket::INADDR_ANY, Global.presence_port)
104
- socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
105
- return socket
106
- end
107
-
108
- def reopen_socket
109
- @socket.close
110
- @socket = open_socket
111
- end
112
-
113
- def handle_presence_notification(ip_address, port)
114
- # build a reference to provider front
115
- provider_front = DRbObject.new_with_uri("druby://%s:%s" % [ip_address, port])
116
-
117
- # check connection
118
- Timeout.timeout(3) {provider_front.ping}
119
-
120
- @tuple_space_lock.synchronize do
121
- @tuple_space[provider_front.tuple_space] = Time.now
122
- end
123
-
124
- Log::Debug.presence_notification do
125
- "receiver agent received a presence notification from provider \"%s\"" % provider_front.__drburi
126
- end
127
- rescue Timeout::Error
128
- Log::Debug.presence_notification do
129
- "receiver agent ignored the provider \"%s\" that seems to be something bad " % provider_front.__drburi
130
- end
131
- rescue DRb::DRbConnError, DRbPatch::ReplyReaderError => e
132
- reopen_socket
133
- Log::Debug.presence_notification("tuple space receiver disconnected: %s" % e)
134
- end
135
- end
136
- end
137
- end
@@ -1,104 +0,0 @@
1
- module Pione
2
- module Command
3
- # PioneBroker is a command that starts activity of broker agent. This
4
- # command will spawn +pione-task-worker+ and +pione-tuple-space-receiver+
5
- # commands.
6
- class PioneBroker < BasicCommand
7
- #
8
- # basic informations
9
- #
10
-
11
- command_name("pione-broker") do |cmd|
12
- "front: %s, task_worker: %s" % [Global.front.uri, cmd.option[:task_worker]]
13
- end
14
- command_banner "Run broker agent to launch task workers."
15
- command_front Front::BrokerFront
16
-
17
- #
18
- # options
19
- #
20
-
21
- use_option :color
22
- use_option :daemon
23
- use_option :debug
24
- use_option :features
25
- use_option :my_ip_address
26
- use_option :task_worker
27
-
28
- validate_option do |option|
29
- unless option[:task_worker] > 0
30
- abort("error: no task worker resources")
31
- end
32
- end
33
-
34
- #
35
- # instance method
36
- #
37
-
38
- attr_reader :agent
39
-
40
- #
41
- # command lifecycle: setup phase
42
- #
43
-
44
- setup_phase :timeout => 10
45
- setup :agent
46
- setup :tuple_space_receiver
47
-
48
- # Create a broker agent.
49
- def setup_agent
50
- @agent = Agent::Broker.new(task_worker_resource: option[:task_worker])
51
- end
52
-
53
- # Spawn a pione-tuple-space-receiver process.
54
- def setup_tuple_space_receiver
55
- spawner = PioneTupleSpaceReceiver.spawn
56
- spawner.when_terminated do
57
- unless termination?
58
- abort("%s is terminated because child tuple space receiver is dead." % command_name)
59
- end
60
- end
61
- @tuple_space_receiver = spawner.child_front
62
- rescue SpawnError =>e
63
- abort(e.message)
64
- end
65
-
66
- #
67
- # command lifecycle: action phase
68
- #
69
-
70
- execute :start_banner
71
- execute :agent
72
-
73
- # Declare pione-broker start.
74
- def execute_start_banner
75
- Log::SystemLog.info "pione-broker starts the activity (#%s)" % Process.pid
76
- end
77
-
78
- # Start broker agent activity and wait it to be terminated.
79
- def execute_agent
80
- @agent.start
81
- @agent.wait_until_terminated(nil)
82
- end
83
-
84
- #
85
- # command lifecycle: termination phase
86
- #
87
-
88
- termination_phase :timeout => 15
89
- terminate :child_process, :module => CommonCommandAction
90
- terminate :agent
91
- terminate :end_banner
92
-
93
- # Terminate broker agent.
94
- def terminate_agent
95
- @agent.terminate if @agent and not(@agent.terminated?)
96
- end
97
-
98
- # Declare pione-broker end.
99
- def terminate_end_banner
100
- Log::SystemLog.info "pione-broker ends the activity (status: %s, #%s)" % [Global.exit_status, Process.pid]
101
- end
102
- end
103
- end
104
- end