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
data/History.txt CHANGED
@@ -1,5 +1,14 @@
1
1
  # History
2
2
 
3
+ ## 0.3.1(2013/10/29)
4
+
5
+ * Fixed performance bug.
6
+ * Enable to generate profile reports of rule application.
7
+ * Added PNML compiler.
8
+ * Changed to stop processing when action rule happens error.
9
+ * Improved pione-clean command and the document, see `man pione-clean`.
10
+ * Added `pione` facade command.
11
+
3
12
  ## 0.3.0(2013/10/20)
4
13
 
5
14
  * Improved multi-inheritance package system.
data/Rakefile CHANGED
@@ -69,3 +69,16 @@ task 'clean' do
69
69
  sh "rm -rf output/*"
70
70
  sh "rm -rf log.txt"
71
71
  end
72
+
73
+ #
74
+ # man
75
+ #
76
+
77
+ def generate_man(src, dest)
78
+ sh "pandoc -s --from=markdown+pandoc_title_block --to=man %s > %s" % [src, dest]
79
+ end
80
+
81
+ desc "generate man documents"
82
+ task "man" do
83
+ generate_man("doc/man/pione-clean.md", "man/pione-clean.1")
84
+ end
data/bin/pione ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+
4
+ require 'pione'
5
+ Pione::Command::PioneCommand.run(ARGV)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+
4
+ require 'pione'
5
+ Pione::Command::PioneCompiler.run(ARGV)
@@ -1,3 +1,5 @@
1
+ .@ PackageName :: "ScoreAggregation"
2
+
1
3
  #
2
4
  # Main Flow
3
5
  #
@@ -4,7 +4,7 @@ require "pione"
4
4
  require "erb"
5
5
 
6
6
  title = Pione.val "$*"
7
- content = Location[Pione.val("$I[1]")].read
7
+ content = Pione::Location[Pione.val("$I[1]")].read
8
8
  template = Pione.val "$I[2]"
9
9
 
10
10
  puts ERB.new(File.read(template)).result(binding)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "pione"
4
4
 
5
- means = Pione.val("$I[1]").split(":").map{|filename| File.read(filename).chomp.to_f}
5
+ means = Pione.val('$I[1].join(":")').split(":").map{|filename| File.read(filename).chomp.to_f}
6
6
 
7
7
  10.times do |i|
8
8
  count = means.select{|mean| i*10 <= mean and mean < (i+1)*10}.size
@@ -3,7 +3,7 @@
3
3
  require "pione"
4
4
 
5
5
  # info
6
- means = Pione.val "$I[1]"
6
+ means = Pione.val '$I[1].join(":")'
7
7
 
8
8
  # calc & output
9
9
  totals = means.split(":").map{|filename| File.read(filename).chomp.to_f}
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "pione"
4
4
 
5
- name_list = Pione.val "$*"
6
- scores_f = Pione.val "$I[1]"
7
- means_f = Pione.val "$I[2]"
5
+ name_list = Pione.val '$*.join(":")'
6
+ scores_f = Pione.val '$I[1].join(":")'
7
+ means_f = Pione.val '$I[2].join(":")'
8
8
 
9
9
  total_mean = Pione::Location[Pione.val("$I[3]")].read.to_f
10
10
 
@@ -0,0 +1,21 @@
1
+ {
2
+ "PackageName": "ScoreAggregation",
3
+ "Parents": [
4
+
5
+ ],
6
+ "Documents": [
7
+ "ScoreAggregation.pione"
8
+ ],
9
+ "Scenarios": [
10
+ "scenario/case1"
11
+ ],
12
+ "Bins": [
13
+ "bin/total-statistics.rb",
14
+ "bin/apply-template.rb",
15
+ "bin/mean-summary.rb",
16
+ "bin/personal-bar-graph.sh",
17
+ "bin/personal-pre-statistics.rb",
18
+ "bin/total-mean.rb",
19
+ "bin/histgram-graph.sh"
20
+ ]
21
+ }
@@ -0,0 +1 @@
1
+ .@ ScenarioName :: "case1"
@@ -0,0 +1,36 @@
1
+ {
2
+ "ScenarioName": "case1",
3
+ "ParamSet": null,
4
+ "Inputs": [
5
+ "input/S.score",
6
+ "input/W.score",
7
+ "input/G.score",
8
+ "input/Q.score",
9
+ "input/M.score",
10
+ "input/X.score",
11
+ "input/V.score",
12
+ "input/L.score",
13
+ "input/K.score",
14
+ "input/F.score",
15
+ "input/J.score",
16
+ "input/Z.score",
17
+ "input/I.score",
18
+ "input/E.score",
19
+ "input/D.score",
20
+ "input/H.score",
21
+ "input/U.score",
22
+ "input/C.score",
23
+ "input/A.score",
24
+ "input/P.score",
25
+ "input/R.score",
26
+ "input/B.score",
27
+ "input/stat-template.erb",
28
+ "input/N.score",
29
+ "input/Y.score",
30
+ "input/T.score",
31
+ "input/O.score"
32
+ ],
33
+ "Outputs": [
34
+
35
+ ]
36
+ }
data/lib/pione.rb CHANGED
@@ -1,12 +1,25 @@
1
1
  Thread.abort_on_exception = true
2
2
 
3
3
  #
4
- # load libraries
4
+ # setup bundler
5
5
  #
6
6
 
7
- # bundler
8
7
  require 'bundler/setup' rescue nil
9
8
 
9
+ #
10
+ # initialize profiler
11
+ #
12
+
13
+ require 'pione/util/profiler'
14
+ if targets = ENV["PIONE_PROFILE"]
15
+ Pione::Util::Profiler.init
16
+ Pione::Util::Profiler.targets.concat(targets.split(":"))
17
+ end
18
+
19
+ #
20
+ # load libraries
21
+ #
22
+
10
23
  # standard
11
24
  require 'set'
12
25
  require 'socket'
@@ -229,7 +229,6 @@ module Pione
229
229
  state = nil
230
230
 
231
231
  Thread.new {
232
-
233
232
  # kill all chain threads
234
233
  @chain_threads.list.each do |thread|
235
234
  state = thread[:agent_state] # save last state
@@ -26,12 +26,17 @@ module Pione
26
26
  #
27
27
 
28
28
  def transit_to_wait
29
- read(TupleSpace::CommandTuple.new(name: "terminate"))
29
+ tuple = read(TupleSpace::CommandTuple.new(name: "terminate"))
30
+ status = System::Status.success
31
+ unless tuple.args.empty?
32
+ status = tuple.args.first
33
+ end
34
+ return status
30
35
  end
31
36
 
32
- def transit_to_fire
37
+ def transit_to_fire(status)
33
38
  Log::Debug.system("job terminator fires the action %s." % @action)
34
- @action.call
39
+ @action.call(status)
35
40
  end
36
41
  end
37
42
  end
@@ -74,7 +74,14 @@ module Pione
74
74
  engine = make_engine(task)
75
75
 
76
76
  # start the engine
77
- @execution_thread = Thread.new {engine.handle}
77
+ @execution_thread = Thread.new do
78
+ begin
79
+ engine.handle
80
+ rescue RuleEngine::ActionError => e
81
+ write(TupleSpace::CommandTuple.new("terminate", [System::Status.error(e)]))
82
+ terminate
83
+ end
84
+ end
78
85
 
79
86
  # spawn child task worker if flow
80
87
  if engine.rule_definition.rule_type == "flow"
@@ -135,7 +142,7 @@ module Pione
135
142
  # child worker loop
136
143
  while @execution_thread.alive? do
137
144
  if @execution_thread.status == "sleep"
138
- if child_agent.nil? or not(child_agent.terminated?)
145
+ if child_agent.nil? or child_agent.terminated?
139
146
  # when there isn't active child agent
140
147
  child_agent = self.class.new(tuple_space_server, @features, @env)
141
148
  child_agent.once = true
data/lib/pione/command.rb CHANGED
@@ -7,6 +7,7 @@ require 'pione/command/command-exception'
7
7
  require 'pione/command/spawner'
8
8
  require 'pione/command/option'
9
9
  require 'pione/command/basic-command'
10
+ require 'pione/command/pione-command'
10
11
  require 'pione/command/pione-client'
11
12
  require 'pione/command/pione-task-worker'
12
13
  require 'pione/command/pione-broker'
@@ -21,4 +22,5 @@ require 'pione/command/pione-syntax-checker'
21
22
  require 'pione/command/pione-log'
22
23
  require 'pione/command/pione-val'
23
24
  require 'pione/command/pione-package'
25
+ require 'pione/command/pione-compiler'
24
26
 
@@ -39,6 +39,10 @@ module Pione
39
39
  end
40
40
  end
41
41
 
42
+ def option_parser_mode(mode)
43
+ @option_definition.parser_mode = mode
44
+ end
45
+
42
46
  # Set progaram name or return the name.
43
47
  def command_name(name=nil, &b)
44
48
  if name
@@ -41,12 +41,15 @@ module Pione
41
41
 
42
42
  # OptionDefinition is a class for holding option definitions.
43
43
  class OptionDefinition
44
+ attr_accessor :parser_mode
45
+
44
46
  # Creata a command option context.
45
47
  def initialize
46
48
  extend OptionInterface
47
49
  @items = [] # option item definitions
48
50
  @default = {} # default value table
49
51
  @validators = [] # option validators
52
+ @parser_mode = :parse!
50
53
  end
51
54
 
52
55
  def item(name)
@@ -73,7 +76,7 @@ module Pione
73
76
 
74
77
  # setup option parser
75
78
  @items.sort{|a,b| a.long <=> b.long}.each {|item| setup_item(command_name, opt, data, item)}
76
- end.parse!(argv)
79
+ end.send(@parser_mode, argv)
77
80
 
78
81
  # check option's validness
79
82
  check(data)
@@ -8,7 +8,8 @@ module Pione
8
8
  #
9
9
 
10
10
  command_name "pione-clean"
11
- command_banner "Clean working directories and file cache directories."
11
+ command_banner "remove PIONE's temporary files, cache, and etc."
12
+ PioneCommand.add_subcommand("clean", self)
12
13
 
13
14
  #
14
15
  # options
@@ -16,6 +17,45 @@ module Pione
16
17
 
17
18
  use_option :debug
18
19
 
20
+ # --older option
21
+ define_option(:older) do |item|
22
+ item.long = '--older=DATE'
23
+ item.desc = 'remove file older than the date'
24
+ item.default = false
25
+ item.value = proc do |str|
26
+ begin
27
+ Date.iso8601(str)
28
+ rescue ArgumentError
29
+ begin
30
+ Date.today - str.to_i
31
+ rescue
32
+ abort("invalid value of older option: %s" % str)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ # --type option
39
+ define_option(:type) do |item|
40
+ item.long = '--type=NAME'
41
+ item.desc = 'remove only files of the type'
42
+ item.default = false
43
+ item.value = proc do |name|
44
+ case name
45
+ when "temporary"
46
+ :temporary
47
+ when "file-cache"
48
+ :file_cache
49
+ when "package-cache"
50
+ :package_cache
51
+ when "profile"
52
+ :profile
53
+ else
54
+ abort("unknown type: %s" % str)
55
+ end
56
+ end
57
+ end
58
+
19
59
  #
20
60
  # command lifecycle: setup phase
21
61
  #
@@ -30,34 +70,81 @@ module Pione
30
70
  # command lifecycle: execution phase
31
71
  #
32
72
 
33
- execute :remove_working_directory
34
- execute :remove_cache_directory
35
- execute :remove_ppg_cache
36
- execute :remove_directory_cache
73
+ execute :remove_temporary
74
+ execute :remove_file_cache
75
+ execute :remove_package_cache
76
+ execute :remove_profile
37
77
 
38
- def execute_remove_working_directory
39
- FileUtils.remove_entry_secure(Global.working_directory_root)
78
+ # Remove temporary files. This removes working files based on temporary
79
+ # directory's mtime.
80
+ def execute_remove_temporary
81
+ if type?(:temprary)
82
+ Location[Global.my_temporary_directory].each_entry do |entry|
83
+ if delete?(entry)
84
+ FileUtils.remove_entry_secure(entry.path)
85
+ end
86
+ end
87
+ end
40
88
  end
41
89
 
42
- def execute_remove_cache_directory
43
- FileUtils.remove_entry_secure(Global.file_cache_directory_root)
90
+ # Remove file cache files. This removes it base on cache directory's mtime.
91
+ def execute_remove_file_cache
92
+ if type?(:file_cache)
93
+ Location[Global.my_file_cache_directory].each_entry do |entry|
94
+ if delete?(entry)
95
+ FileUtils.remove_entry_secure(entry.path)
96
+ end
97
+ end
98
+ end
44
99
  end
45
100
 
46
- def execute_remove_ppg_cache
47
- Global.ppg_package_cache_directory.each_entry do |entry|
48
- unless @db.has_digest?(Package::PackageFilename.parse(entry.basename).digest)
49
- entry.delete
101
+ # Remove package cache files.
102
+ def execute_remove_package_cache
103
+ if type?(:package_cache)
104
+ # remove PPG package
105
+ Global.ppg_package_cache_directory.each_entry do |entry|
106
+ unless @db.has_digest?(Package::PackageFilename.parse(entry.basename).digest)
107
+ if delete?(entry)
108
+ entry.delete
109
+ end
110
+ end
111
+ end
112
+
113
+ # remove directory package
114
+ Global.directory_package_cache_directory.each_entry do |entry|
115
+ unless @db.has_digest?(entry.basename)
116
+ if delete?(entry)
117
+ entry.delete
118
+ end
119
+ end
50
120
  end
51
121
  end
52
122
  end
53
123
 
54
- def execute_remove_directory_cache
55
- Global.directory_package_cache_directory.each_entry do |entry|
56
- unless @db.has_digest?(entry.basename)
57
- entry.delete
124
+ # Remove profile reports.
125
+ def execute_remove_profile
126
+ if type?(:profile)
127
+ Location[Global.profile_report_directory].each_entry do |entry|
128
+ if delete?(entry)
129
+ entry.delete
130
+ end
58
131
  end
59
132
  end
60
133
  end
134
+
135
+ #
136
+ # helper methods
137
+ #
138
+
139
+ # Return true if the entry has the type.
140
+ def type?(type)
141
+ option[:type].nil? or option[:type] == type
142
+ end
143
+
144
+ # Return true if the entry should be removed.
145
+ def delete?(entry)
146
+ option[:older].nil? or option[:older] >= entry.mtime.to_date
147
+ end
61
148
  end
62
149
  end
63
150
  end