pione 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/History.txt +9 -0
  2. data/Rakefile +13 -0
  3. data/bin/pione +5 -0
  4. data/bin/pione-compiler +5 -0
  5. data/example/ScoreAggregation/ScoreAggregation.pione +2 -0
  6. data/example/ScoreAggregation/bin/apply-template.rb +1 -1
  7. data/example/ScoreAggregation/bin/mean-summary.rb +1 -1
  8. data/example/ScoreAggregation/bin/total-mean.rb +1 -1
  9. data/example/ScoreAggregation/bin/total-statistics.rb +3 -3
  10. data/example/ScoreAggregation/pione-package.json +21 -0
  11. data/example/ScoreAggregation/scenario/case1/Scenario.pione +1 -0
  12. data/example/ScoreAggregation/scenario/case1/pione-scenario.json +36 -0
  13. data/lib/pione.rb +15 -2
  14. data/lib/pione/agent/basic-agent.rb +0 -1
  15. data/lib/pione/agent/job-terminator.rb +8 -3
  16. data/lib/pione/agent/task-worker.rb +9 -2
  17. data/lib/pione/command.rb +2 -0
  18. data/lib/pione/command/basic-command.rb +4 -0
  19. data/lib/pione/command/option.rb +4 -1
  20. data/lib/pione/command/pione-clean.rb +104 -17
  21. data/lib/pione/command/pione-client.rb +16 -3
  22. data/lib/pione/command/pione-command.rb +45 -0
  23. data/lib/pione/command/pione-compiler.rb +39 -0
  24. data/lib/pione/command/pione-log.rb +1 -0
  25. data/lib/pione/command/pione-task-worker.rb +6 -2
  26. data/lib/pione/command/pione-val.rb +1 -0
  27. data/lib/pione/front.rb +1 -0
  28. data/lib/pione/front/basic-front.rb +1 -1
  29. data/lib/pione/front/front-exception.rb +5 -1
  30. data/lib/pione/global.rb +3 -118
  31. data/lib/pione/global/broker-variable.rb +21 -8
  32. data/lib/pione/global/client-variable.rb +16 -8
  33. data/lib/pione/{system → global}/config.rb +2 -2
  34. data/lib/pione/global/global-exception.rb +40 -0
  35. data/lib/pione/global/input-generator-variable.rb +4 -1
  36. data/lib/pione/global/item.rb +168 -0
  37. data/lib/pione/global/log-variable.rb +64 -13
  38. data/lib/pione/global/network-variable.rb +4 -1
  39. data/lib/pione/global/package-variable.rb +25 -10
  40. data/lib/pione/global/path-variable.rb +62 -26
  41. data/lib/pione/global/relay-variable.rb +101 -36
  42. data/lib/pione/global/system-variable.rb +26 -9
  43. data/lib/pione/global/task-worker-variable.rb +19 -7
  44. data/lib/pione/global/tuple-space-notifier-variable.rb +60 -20
  45. data/lib/pione/lang.rb +0 -2
  46. data/lib/pione/lang/data-expr.rb +8 -0
  47. data/lib/pione/package/package-exception.rb +1 -1
  48. data/lib/pione/rule-engine/action-handler.rb +14 -12
  49. data/lib/pione/rule-engine/engine-exception.rb +11 -0
  50. data/lib/pione/rule-engine/flow-handler.rb +20 -11
  51. data/lib/pione/system.rb +1 -1
  52. data/lib/pione/system/file-cache.rb +1 -1
  53. data/lib/pione/system/init.rb +13 -15
  54. data/lib/pione/system/status.rb +30 -0
  55. data/lib/pione/system/system-exception.rb +0 -24
  56. data/lib/pione/test-helper.rb +8 -1
  57. data/lib/pione/test-helper/command-helper.rb +42 -15
  58. data/lib/pione/util.rb +1 -0
  59. data/lib/pione/util/embeded-expr-expander.rb +5 -11
  60. data/lib/pione/util/pnml-compiler.rb +97 -0
  61. data/lib/pione/util/profiler.rb +107 -0
  62. data/lib/pione/version.rb +1 -1
  63. data/man/pione-clean.1 +76 -0
  64. data/pione.gemspec +5 -2
  65. data/test/agent/spec_job-terminator.rb +41 -3
  66. data/test/command/data/pione-client/ActionError.pione +5 -0
  67. data/test/command/data/pione-compiler/Sequence.pnml +137 -0
  68. data/test/command/spec_pione-clean.rb +250 -5
  69. data/test/command/spec_pione-client.rb +57 -46
  70. data/test/command/spec_pione-command.rb +18 -0
  71. data/test/command/spec_pione-compiler.rb +13 -0
  72. data/test/global/spec_item.rb +77 -0
  73. data/test/lang/data/data-expr.yml +5 -0
  74. data/test/rule-engine/{spec_action-handler.pione → data/action-handler/BasicAction.pione} +0 -0
  75. data/test/rule-engine/data/action-handler/UsePackageScript.pione +17 -0
  76. data/test/rule-engine/spec_action-handler.rb +143 -80
  77. data/test/system/spec_status.rb +13 -0
  78. data/test/{tuple → tuple-space}/spec_basic-tuple.rb +0 -0
  79. data/test/{tuple → tuple-space}/spec_data-tuple.rb +0 -0
  80. data/test/{tuple → tuple-space}/spec_finished-tuple.rb +0 -0
  81. data/test/{tuple → tuple-space}/spec_message-tuple.rb +0 -0
  82. data/test/{tuple → tuple-space}/spec_task-tuple.rb +0 -0
  83. data/test/{tuple → tuple-space}/spec_touch-tuple.rb +0 -0
  84. data/test/{tuple → tuple-space}/spec_working-tuple.rb +0 -0
  85. data/test/{tuple → tuple-space}/tuple-behavior.rb +0 -0
  86. data/test/util/data/pnml/Sequence.pnml +137 -0
  87. data/test/util/spec_pnml-compiler.rb +21 -0
  88. data/test/util/spec_profiler.rb +53 -0
  89. metadata +75 -32
  90. data/example/ScoreAggregation/package.yml +0 -5
  91. data/example/ScoreAggregation/scenario/case1/scenario.yml +0 -29
  92. data/lib/pione/lang/interpolator-parser.rb +0 -44
  93. data/lib/pione/lang/interpolator-transformer.rb +0 -13
  94. data/test/lang/spec_interpolator-parser.rb +0 -5
  95. data/test/lang/spec_interpolator-transformer.rb +0 -15
@@ -309,8 +309,12 @@ module Pione
309
309
  end
310
310
 
311
311
  def execute_job_terminator
312
- @job_terminator = Agent::JobTerminator.start(@tuple_space) do
313
- terminate
312
+ @job_terminator = Agent::JobTerminator.start(@tuple_space) do |status|
313
+ if status.error?
314
+ abort("pione-client catched the error: %s" % status.exception.message)
315
+ else
316
+ terminate
317
+ end
314
318
  end
315
319
  end
316
320
 
@@ -402,6 +406,7 @@ module Pione
402
406
  terminate :process_job => :spawner_thread
403
407
  terminate :child_process, :module => CommonCommandAction
404
408
  terminate :process_job => :process_manager
409
+ terminate :process_job => :job_terminator
405
410
  terminate :process_job => :task_worker
406
411
  terminate :process_job => :input_generator
407
412
  terminate :process_job => :logger
@@ -415,11 +420,19 @@ module Pione
415
420
  @spawner_threads.list.each {|thread| thread.kill}
416
421
  end
417
422
 
418
- # Terminate process manager
423
+ # Terminate process manager. Be careful that pione-client main thread
424
+ # waits to stop the process manager's chain thread, so agents pione-client
425
+ # has cannot terminate maybe. You need to terminate it after process
426
+ # manager terminated.
419
427
  def terminate_process_manager
420
428
  @process_manager.terminate if @process_manager
421
429
  end
422
430
 
431
+ # Terminate job terminator.
432
+ def terminate_job_terminator
433
+ @job_terminator.terminate if @job_terminator and not(@job_terminator.terminated?)
434
+ end
435
+
423
436
  # Terminate task worker agents.
424
437
  def terminate_task_worker
425
438
  if option[:stand_alone] and @task_workers
@@ -0,0 +1,45 @@
1
+ module Pione
2
+ module Command
3
+ # PioneCommand is a facade command for PIONE's various functions.
4
+ class PioneCommand < BasicCommand
5
+ # subcommand table
6
+ @subcommand = {}
7
+
8
+ class << self
9
+ attr_reader :subcommand
10
+
11
+ # Add the subcommand.
12
+ def add_subcommand(name, command)
13
+ @subcommand[name] = command
14
+ end
15
+ end
16
+
17
+ #
18
+ # basic informations
19
+ #
20
+
21
+ option_parser_mode :order!
22
+ command_name "pione"
23
+ command_banner "PIONE is a rule-based workflow engine."
24
+
25
+ #
26
+ # options
27
+ #
28
+
29
+ #
30
+ # command lifecycle: execution phase
31
+ #
32
+
33
+ execute :subcommand
34
+
35
+ def execute_subcommand
36
+ name = @argv.first
37
+ if cmd = self.class.subcommand[name]
38
+ cmd.run(@argv.drop(1))
39
+ else
40
+ abort("no such subcommand: %s" % name)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ module Pione
2
+ module Command
3
+ # PionePackage is a command body of "pione-package".
4
+ class PioneCompiler < BasicCommand
5
+ #
6
+ # basic informations
7
+ #
8
+
9
+ command_name "pione-compiler"
10
+ command_banner "pione-compiler translates from PNML to PIONE document."
11
+
12
+ #
13
+ # options
14
+ #
15
+
16
+ use_option :debug
17
+
18
+ #
19
+ # command lifecycle: execution phase
20
+ #
21
+
22
+ setup :source
23
+
24
+ def setup_source
25
+ @source = @argv.first
26
+ end
27
+
28
+ #
29
+ # command lifecycle: execution phase
30
+ #
31
+
32
+ execute :compile_to_pnml
33
+
34
+ def execute_compile_to_pnml
35
+ print Util::PNMLCompiler.new(Location[@source]).compile
36
+ end
37
+ end
38
+ end
39
+ end
@@ -8,6 +8,7 @@ module Pione
8
8
 
9
9
  command_name "pione-log"
10
10
  command_banner "View and convert PIONE log."
11
+ PioneCommand.add_subcommand("log", self)
11
12
 
12
13
  #
13
14
  # options
@@ -108,8 +108,12 @@ module Pione
108
108
 
109
109
  # Create a job terminator and setup the action.
110
110
  def setup_job_terminator
111
- @job_terminator = Agent::JobTerminator.new(@tuple_space) do
112
- terminate
111
+ @job_terminator = Agent::JobTerminator.new(@tuple_space) do |status|
112
+ if status.error?
113
+ abort("pione-task-worker catched the error: %s" % status.exception.message)
114
+ else
115
+ terminate
116
+ end
113
117
  end
114
118
  end
115
119
 
@@ -8,6 +8,7 @@ module Pione
8
8
 
9
9
  command_name "pione-val"
10
10
  command_banner "Get the evaluation result value of the PIONE expression."
11
+ PioneCommand.add_subcommand("val", self)
11
12
 
12
13
  #
13
14
  # options
data/lib/pione/front.rb CHANGED
@@ -3,6 +3,7 @@ module Pione
3
3
  module Front; end
4
4
  end
5
5
 
6
+ require 'pione/front/front-exception'
6
7
  require 'pione/front/basic-front'
7
8
  require 'pione/front/client-front'
8
9
  require 'pione/front/broker-front'
@@ -63,7 +63,7 @@ module Pione
63
63
  begin
64
64
  DRb.start_service(build_front_server_uri(enum.next), self, config)
65
65
  rescue StopIteration => e
66
- raise FrontError.new(self, e)
66
+ raise
67
67
  rescue
68
68
  retry
69
69
  end
@@ -2,9 +2,13 @@ module Pione
2
2
  module Front
3
3
  # FrontError is raised when front server cannnot start.
4
4
  class FrontError < StandardError
5
+ def initialize(front, exception)
6
+ @front = front
7
+ @exception = exception
8
+ end
5
9
 
6
10
  def message
7
- "You couldn't start front server(%s)." % self.class.name
11
+ "You couldn't start front server(%s): %s" % [@front.class.name, @exception.message]
8
12
  end
9
13
  end
10
14
 
data/lib/pione/global.rb CHANGED
@@ -2,126 +2,11 @@ module Pione
2
2
  # Global is a table of global variables in PIONE system. It defines variable
3
3
  # names, initial values, and configuration conditions. You can set and get
4
4
  # value by calling item named method.
5
- module Global
6
- #
7
- # variables
8
- #
9
-
10
- # these variables should be with prefix and postfix because of name colloision
11
- @__names__ = Array.new # variable names
12
- @__configurable__ = Hash.new # variable configurability
13
- @__lazy_initializer__ = Hash.new # variable initializers
14
- @__dependencies__ = Hash.new {|h, k| h[k] = []} # dependency table
15
- @__updater__ = Hash.new # updaters for computed item
16
-
17
- class << self
18
- # Define an internal item. The item cannot be configured by user.
19
- def define_internal_item(name, initial_value=nil, &initializer)
20
- define_item(name, false, initial_value, :initializer => initializer)
21
- end
22
-
23
- # Define an external item. The item can be configured by user.
24
- def define_external_item(name, initial_value=nil, &initializer)
25
- define_item(name, true, initial_value, :initializer => initializer)
26
- end
27
-
28
- # Define a computed item. The item cannote be configured by user.
29
- def define_computed_item(name, dependencies, &updater)
30
- define_item(name, false, nil, :dependencies => dependencies, :updater => updater)
31
- end
32
-
33
- # Get value of the variable.
34
- def get(name)
35
- val = instance_variable_get("@%s" % name)
36
- if val.nil?
37
- # call lazy initializer
38
- if @__lazy_initializer__.has_key?(name)
39
- set(name, @__lazy_initializer__[name].call)
40
- end
41
-
42
- # call initial updater
43
- if @__updater__.has_key?(name)
44
- update(name)
45
- end
46
-
47
- # get value
48
- get(name)
49
- else
50
- return val
51
- end
52
- end
53
-
54
- # Set value of the variable.
55
- def set(name, val)
56
- # set value
57
- instance_variable_set("@%s" % name, val)
58
-
59
- # update dependecies
60
- @__dependencies__[name].each do |dependency|
61
- update(dependency)
62
- end
63
- end
64
-
65
- # Update the computed item.
66
- def update(name)
67
- set(name, @__updater__[name].call)
68
- end
69
-
70
- # Return true if the variable is configurable.
71
- def configurable?(name)
72
- @__configurable__[name]
73
- end
74
-
75
- # Return all variable names.
76
- def all_names
77
- @__names__
78
- end
79
-
80
- private
81
-
82
- # Define a new global variable.
83
- def define_item(name, configurable, initial_value=nil, option)
84
- # setup informations
85
- @__names__ << name
86
- @__configurable__[name]= configurable
87
- @__lazy_initializer__[name] = option[:initializer] if option[:initializer]
88
- @__updater__[name] = option[:updater] if option[:updater]
89
-
90
- # build dependency table for computed items
91
- if option[:dependencies]
92
- option[:dependencies].each do |dependency|
93
- @__dependencies__[dependency] << name
94
- end
95
- end
96
-
97
- # set reader and writer
98
- define_variable_reader(name)
99
- define_variable_writer(name)
100
-
101
- # set initial value
102
- unless initial_value.nil?
103
- set(name, initial_value)
104
- end
105
- end
106
-
107
- # Define reader method of the variable.
108
- def define_variable_reader(name)
109
- singleton_class.module_eval do |mod|
110
- define_method(name) {get(name)}
111
- end
112
- end
113
-
114
- # Define writer method of the variable.
115
- def define_variable_writer(name)
116
- singleton_class.module_eval do |mod|
117
- define_method("set_%s" % name) {|val| set(name, val)}
118
- define_method("%s=" % name) {|val| set(name, val)}
119
- end
120
- end
121
- end
122
- end
5
+ module Global; end
123
6
  end
124
7
 
8
+ require 'pione/global/item'
9
+ require 'pione/global/config'
125
10
  require 'pione/global/system-variable'
126
11
  require 'pione/global/path-variable'
127
12
  require 'pione/global/network-variable'
@@ -1,20 +1,33 @@
1
1
  module Pione
2
2
  module Global
3
3
  # broker-front port range begin
4
- define_external_item(:broker_front_port_range_begin, 41000)
4
+ define_external_item(:broker_front_port_range_begin) do |item|
5
+ item.desc = "start port number of broker front"
6
+ item.init = 41000
7
+ end
5
8
 
6
9
  # broker-front port range end
7
- define_external_item(:broker_front_port_range_end, 41999)
10
+ define_external_item(:broker_front_port_range_end) do |item|
11
+ item.desc = "end port number of broker front"
12
+ item.init = 41099
13
+ end
8
14
 
9
15
  # broker-front port range
10
- define_internal_item(:broker_front_port_range) do
11
- Range.new(
12
- Global.broker_front_port_range_begin,
13
- Global.broker_front_port_range_end
14
- )
16
+ define_computed_item(:broker_front_port_range, [:broker_front_port_range_begin, :broker_front_port_range_end]) do |item|
17
+ item.desc = "port range of broker front"
18
+ item.define_updater do
19
+ Range.new(
20
+ Global.broker_front_port_range_begin,
21
+ Global.broker_front_port_range_end
22
+ )
23
+ end
15
24
  end
16
25
 
17
26
  # balancer method
18
- define_external_item(:broker_task_worker_balancer) {Agent::EasyTaskWorkerBalancer}
27
+ define_external_item(:broker_task_worker_balancer) do |item|
28
+ item.desc = "balancer method of task worker broker"
29
+ item.init = "Pione::Agent::EasyTaskWorkerBalancer"
30
+ item.define_updater {|val| eval(val)}
31
+ end
19
32
  end
20
33
  end
@@ -1,18 +1,26 @@
1
1
  module Pione
2
2
  module Global
3
3
  # This is a begin number of port range for client's front.
4
- define_external_item(:client_front_port_range_begin, 40000)
4
+ define_external_item(:client_front_port_range_begin) do |item|
5
+ item.desc = "start port number of client front"
6
+ item.init = 40000
7
+ end
5
8
 
6
9
  # This is an end number of port range for client's front.
7
- define_external_item(:client_front_port_range_end, 40099)
10
+ define_external_item(:client_front_port_range_end) do |item|
11
+ item.desc = "end port number of client front"
12
+ item.init = 40099
13
+ end
8
14
 
9
15
  # This is port range for client's front.
10
- define_computed_item(:client_front_port_range,
11
- [:client_front_port_range_begin, :client_front_port_range_end]) do
12
- Range.new(
13
- Global.client_front_port_range_begin,
14
- Global.client_front_port_range_end
15
- )
16
+ define_computed_item(:client_front_port_range, [:client_front_port_range_begin, :client_front_port_range_end]) do |item|
17
+ item.desc = "port range of broker front"
18
+ item.define_updater do
19
+ Range.new(
20
+ Global.client_front_port_range_begin,
21
+ Global.client_front_port_range_end
22
+ )
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -1,5 +1,5 @@
1
1
  module Pione
2
- module System
2
+ module Global
3
3
  # Config is a class for setting PIONE system configuration.
4
4
  class Config
5
5
  # Load configuration and apply it to global settings.
@@ -23,7 +23,7 @@ module Pione
23
23
  def apply
24
24
  @table.each do |key, val|
25
25
  key = key.to_sym
26
- if Global.all_names.include?(key) and Global.configurable?(key)
26
+ if Global.item[key] and Global.item[key].configurable?
27
27
  Global.set(key, val)
28
28
  else
29
29
  raise UnconfigurableVariableError.new(key)
@@ -0,0 +1,40 @@
1
+ module Pione
2
+ module Global
3
+ class GlobalError < StandardError; end
4
+
5
+ # UnknownItem is raised when unknown global item is referred.
6
+ class UnknownItem < GlobalError
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+
11
+ def message
12
+ "item '%s' is unknown as global variables" % @name
13
+ end
14
+ end
15
+
16
+ # This exception class is raised when configuration file is in invalid format.
17
+ class InvalidConfigFile < GlobalError
18
+ # config file path
19
+ attr_reader :path
20
+
21
+ def initialize(path)
22
+ @path = path
23
+ end
24
+
25
+ def message
26
+ "invalid format configuration file: %s" % @path
27
+ end
28
+ end
29
+
30
+ class UnconfigurableVariableError < GlobalError
31
+ def initialize(name)
32
+ @name = name
33
+ end
34
+
35
+ def message
36
+ "global variable \"%s\" is unconfigurable." % @name
37
+ end
38
+ end
39
+ end
40
+ end