pione 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +2 -1
  2. data/History.txt +11 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/bin/pione-log +5 -0
  6. data/example/CountChar/CountChar.pione +1 -1
  7. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
  8. data/lib/pione.rb +14 -35
  9. data/lib/pione/agent/input-generator.rb +38 -40
  10. data/lib/pione/agent/logger.rb +52 -19
  11. data/lib/pione/agent/rule-provider.rb +5 -8
  12. data/lib/pione/agent/task-worker.rb +25 -32
  13. data/lib/pione/agent/tuple-space-client.rb +22 -14
  14. data/lib/pione/command.rb +21 -0
  15. data/lib/pione/command/basic-command.rb +267 -84
  16. data/lib/pione/command/child-process.rb +21 -18
  17. data/lib/pione/command/daemon-process.rb +9 -8
  18. data/lib/pione/command/front-owner-command.rb +8 -25
  19. data/lib/pione/command/pione-broker.rb +27 -24
  20. data/lib/pione/command/pione-clean.rb +6 -6
  21. data/lib/pione/command/pione-client.rb +143 -128
  22. data/lib/pione/command/pione-log.rb +61 -0
  23. data/lib/pione/command/pione-relay-account-db.rb +40 -38
  24. data/lib/pione/command/pione-relay-client-db.rb +38 -42
  25. data/lib/pione/command/pione-relay.rb +19 -20
  26. data/lib/pione/command/pione-syntax-checker.rb +70 -45
  27. data/lib/pione/command/pione-task-worker.rb +56 -66
  28. data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
  29. data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
  30. data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
  31. data/lib/pione/location.rb +10 -0
  32. data/lib/pione/location/basic-location.rb +272 -0
  33. data/lib/pione/location/dropbox-location.rb +139 -0
  34. data/lib/pione/location/ftp-location.rb +156 -0
  35. data/lib/pione/location/local-location.rb +116 -0
  36. data/lib/pione/log.rb +10 -0
  37. data/lib/pione/log/domain-info.rb +72 -0
  38. data/lib/pione/log/process-log.rb +176 -0
  39. data/lib/pione/log/process-record.rb +189 -0
  40. data/lib/pione/log/xes-log.rb +105 -0
  41. data/lib/pione/model/assignment.rb +88 -80
  42. data/lib/pione/model/binary-operator.rb +74 -68
  43. data/lib/pione/model/block.rb +218 -207
  44. data/lib/pione/model/boolean.rb +123 -112
  45. data/lib/pione/model/call-rule.rb +72 -65
  46. data/lib/pione/model/data-expr.rb +596 -290
  47. data/lib/pione/model/float.rb +108 -103
  48. data/lib/pione/model/integer.rb +133 -129
  49. data/lib/pione/model/message.rb +79 -72
  50. data/lib/pione/model/package.rb +42 -38
  51. data/lib/pione/model/parameters.rb +265 -236
  52. data/lib/pione/model/rule-expr.rb +247 -242
  53. data/lib/pione/model/rule-io.rb +137 -133
  54. data/lib/pione/model/rule.rb +307 -292
  55. data/lib/pione/model/string.rb +110 -99
  56. data/lib/pione/model/variable-table.rb +300 -271
  57. data/lib/pione/model/variable.rb +88 -83
  58. data/lib/pione/option.rb +13 -0
  59. data/lib/pione/option/child-process-option.rb +19 -0
  60. data/lib/pione/{command-option → option}/common-option.rb +6 -5
  61. data/lib/pione/option/option-interface.rb +73 -0
  62. data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
  63. data/lib/pione/option/task-worker-owner-option.rb +24 -0
  64. data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
  65. data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
  66. data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
  67. data/lib/pione/parser/common-parser.rb +3 -2
  68. data/lib/pione/parser/expr-parser.rb +6 -1
  69. data/lib/pione/patch/em-ftpd-patch.rb +21 -0
  70. data/lib/pione/patch/rinda-patch.rb +31 -23
  71. data/lib/pione/rule-handler/action-handler.rb +35 -25
  72. data/lib/pione/rule-handler/basic-handler.rb +92 -18
  73. data/lib/pione/rule-handler/flow-handler.rb +104 -98
  74. data/lib/pione/rule-handler/root-handler.rb +11 -0
  75. data/lib/pione/system/common.rb +10 -0
  76. data/lib/pione/system/file-cache.rb +103 -84
  77. data/lib/pione/system/global.rb +67 -12
  78. data/lib/pione/system/init.rb +20 -0
  79. data/lib/pione/transformer/expr-transformer.rb +6 -1
  80. data/lib/pione/tuple-space/data-finder.rb +33 -6
  81. data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
  82. data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
  83. data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
  84. data/lib/pione/tuple-space/update-criteria.rb +8 -7
  85. data/lib/pione/tuple/base-location-tuple.rb +9 -0
  86. data/lib/pione/tuple/basic-tuple.rb +7 -7
  87. data/lib/pione/tuple/data-tuple.rb +5 -2
  88. data/lib/pione/tuple/lift-tuple.rb +14 -0
  89. data/lib/pione/tuple/rule-tuple.rb +1 -1
  90. data/lib/pione/tuple/task-tuple.rb +5 -1
  91. data/lib/pione/version.rb +1 -1
  92. data/pione.gemspec +5 -1
  93. data/test/location/spec_basic-location.rb +35 -0
  94. data/test/location/spec_ftp-location.rb +100 -0
  95. data/test/location/spec_local-location.rb +99 -0
  96. data/test/log/data/sample.log +1003 -0
  97. data/test/log/spec_xes-log.rb +11 -0
  98. data/test/model/spec_data-expr.rb +249 -6
  99. data/test/model/spec_data-expr.yml +45 -0
  100. data/test/parser/spec_expr-parser.yml +4 -0
  101. data/test/spec_data-finder.rb +13 -7
  102. data/test/spec_data-finder.yml +42 -13
  103. data/test/system/spec_file-cache.rb +39 -0
  104. data/test/test-util.rb +226 -1
  105. data/test/transformer/spec_expr-transformer.rb +12 -1
  106. metadata +107 -24
  107. data/bin/pione-search-log +0 -30
  108. data/lib/pione/command-option/basic-option.rb +0 -42
  109. data/lib/pione/command-option/child-process-option.rb +0 -17
  110. data/lib/pione/command-option/daemon-option.rb +0 -12
  111. data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
  112. data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
  113. data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
  114. data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
  115. data/lib/pione/resource/basic-resource.rb +0 -92
  116. data/lib/pione/resource/dropbox-resource.rb +0 -106
  117. data/lib/pione/resource/ftp.rb +0 -84
  118. data/lib/pione/resource/local.rb +0 -113
  119. data/lib/pione/tuple/base-uri-tuple.rb +0 -9
  120. data/lib/pione/tuple/shift-tuple.rb +0 -13
  121. data/lib/pione/util/log.rb +0 -79
  122. data/test/spec_resource.rb +0 -73
@@ -107,13 +107,18 @@ module Pione
107
107
  integer |
108
108
  string |
109
109
  ticket |
110
- data_name |
110
+ data_expr |
111
111
  rule_expr |
112
112
  feature_expr |
113
113
  parameters |
114
114
  variable
115
115
  }
116
116
 
117
+ # +data_expr+ matches data expressions.
118
+ rule(:data_expr) {
119
+ data_name | keyword_null.as(:data_null)
120
+ }
121
+
117
122
  # @!attribute [r] rule_expr
118
123
  # +rule_expr+ matches rule expressions.
119
124
  # @return [Parslet::Atoms::Entity] +rule_expr+ atom
@@ -0,0 +1,21 @@
1
+ module EM::FTPD
2
+ class Server
3
+ COMMANDS << "mdtm"
4
+
5
+ # get the file's mtime
6
+ def cmd_mdtm(param)
7
+ send_unauthorised and return unless logged_in?
8
+ send_param_required and return if param.nil?
9
+
10
+ path = build_path(param)
11
+
12
+ @driver.mtime(path) do |result|
13
+ if result.kind_of?(Time)
14
+ send_response result.strftime("213 %Y%m%d%H%M%S%L")
15
+ else
16
+ send_response "550 file not available"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -127,17 +127,14 @@ module Rinda
127
127
  @bin = {}
128
128
  end
129
129
 
130
- # Adds the tuple.
130
+ # Add the tuple into the tuple space.
131
+ #
131
132
  # @param [Array] tuple
132
133
  # the tuple
133
134
  # @return [void]
134
135
  def add(tuple)
135
136
  if dom = domain(tuple)
136
- unless @bin[dom]
137
- @bin[dom] = tuple
138
- else
139
- raise RedundantTupleError.new(tuple.value)
140
- end
137
+ @bin[dom] = tuple
141
138
  else
142
139
  raise RuntimeError
143
140
  end
@@ -527,7 +524,7 @@ module Rinda
527
524
  :finished => TupleBag::DomainTupleBin,
528
525
  :working => TupleBag::DomainTupleBin,
529
526
  :data => TupleBag::DataTupleBin,
530
- :shift => TupleBag::HashTupleBin
527
+ :lift => TupleBag::HashTupleBin
531
528
  )
532
529
  @mutex = Mutex.new
533
530
  end
@@ -542,12 +539,12 @@ module Rinda
542
539
  end
543
540
 
544
541
  def read(tuple, sec=nil)
545
- shift_tuple(real_read(tuple, sec))
542
+ lift_tuple(real_read(tuple, sec))
546
543
  end
547
544
 
548
545
  def read_all(tuple)
549
546
  real_read_all(tuple).map do |res|
550
- shift_tuple(res)
547
+ lift_tuple(res)
551
548
  end
552
549
  end
553
550
 
@@ -730,28 +727,39 @@ module Rinda
730
727
  end
731
728
  end
732
729
 
733
- def shift_tuple(tuple)
730
+ # Lift the location of the tuple.
731
+ #
732
+ # @param tuple [BasicTuple]
733
+ # tuple
734
+ # @return [BasicTuple]
735
+ # lifted tuple
736
+ def lift_tuple(tuple)
734
737
  if Pione::Tuple[tuple.first]
735
- if pos = Pione::Tuple[tuple.first].uri_position
736
- if new_uri = shift_uri(tuple[pos])
738
+ if pos = Pione::Tuple[tuple.first].location_position
739
+ if new_location = lift_location(tuple[pos])
737
740
  tuple = tuple.clone
738
- tuple[pos] = new_uri
741
+ tuple[pos] = new_location
739
742
  end
740
743
  end
741
744
  end
742
745
  return tuple
743
746
  end
744
747
 
745
- def shift_uri(uri, old=[])
746
- return nil if old.include?(uri)
747
-
748
- template = TemplateEntry.new([:shift, uri, nil])
749
- if shift_tuple = @bag.find(template)
750
- next_uri = shift_tuple[2]
751
- if last_uri = shift_uri(next_uri, old + [uri])
752
- next_uri = last_uri
753
- end
754
- return next_uri
748
+ # Lift the location.
749
+ #
750
+ # @param location [Location::BasicLocation]
751
+ # location that lift from
752
+ # @param history [Array<Location::BasicLocation>]
753
+ # history of lifted location
754
+ # @return [Location::BasicLocation or nil]
755
+ # new location
756
+ def lift_location(location, history=[])
757
+ return nil if history.include?(location)
758
+
759
+ template = TemplateEntry.new([:lift, location, nil])
760
+ if lift_tuple = @bag.find(template)
761
+ new_location = lift_tuple[2]
762
+ return lift_location(new_location, history << location) || new_location
755
763
  end
756
764
  return nil
757
765
  end
@@ -22,8 +22,8 @@ module Pione
22
22
  write_shell_script {|path| call_shell_script(path) }
23
23
  # collect outputs
24
24
  collect_outputs
25
- # write resouces
26
- write_output_resources
25
+ # write output data
26
+ write_output_data
27
27
  # write tuples
28
28
  write_output_tuples
29
29
  # write environment info
@@ -54,9 +54,12 @@ module Pione
54
54
  end
55
55
 
56
56
  # Make a working directory.
57
+ #
58
+ # @return [Pathname]
59
+ # path of working directory
57
60
  def make_working_directory
58
61
  # build directory path
59
- task_dirname = ID.domain_id(
62
+ dirname = ID.domain_id(
60
63
  @rule.expr.package.name,
61
64
  @rule.expr.name,
62
65
  @inputs,
@@ -64,20 +67,20 @@ module Pione
64
67
  )
65
68
 
66
69
  # create a directory
67
- path = Global.working_directory + task_dirname
68
- FileUtils.makedirs(path)
69
-
70
- return path
70
+ return (Global.working_directory + dirname).tap{|path| path.mkpath}
71
71
  end
72
72
 
73
73
  # Synchronize input data into working directory.
74
74
  def setup_working_directory
75
75
  @inputs.flatten.each do |input|
76
76
  # get file path in working directory
77
- path = File.join(@working_directory, input.name)
77
+ wd_location = @working_directory + input.name
78
78
  # create a link to cache
79
- cache_path = FileCache.get(input.uri)
80
- FileUtils.symlink(cache_path, path, {:force => true})
79
+ cache_location = FileCache.get(input.location)
80
+ wd_location.make_symlink(cache_location.path)
81
+ unless wd_location.exist?
82
+ raise RuleExecutionError.new(self)
83
+ end
81
84
  end
82
85
  end
83
86
 
@@ -122,12 +125,14 @@ module Pione
122
125
 
123
126
  # Make output tuple by name.
124
127
  def make_output_tuple_with_time(name)
125
- time = File.mtime(File.join(@working_directory, name))
126
- uri = make_output_resource_uri(name).to_s
127
- Tuple[:data].new(name: name, domain: @domain, uri: uri, time: time)
128
+ time = (@working_directory + name).mtime
129
+ location = make_output_location(name)
130
+ Tuple[:data].new(name: name, domain: @domain, location: location, time: time)
128
131
  end
129
132
 
130
133
  # Collect output data by names from working directory.
134
+ #
135
+ # @return [void]
131
136
  def collect_outputs
132
137
  list = Dir.entries(@working_directory)
133
138
  @rule.outputs.each_with_index do |output, i|
@@ -145,18 +150,22 @@ module Pione
145
150
  end
146
151
  end
147
152
 
148
- # Write resources for output data.
149
- def write_output_resources
153
+ # Write output data with caching.
154
+ #
155
+ # @return [void]
156
+ def write_output_data
150
157
  @outputs.flatten.compact.each do |output|
151
- path = File.join(@working_directory, output.name)
152
- FileCache.put(path, output.uri)
158
+ src = Location[@working_directory + output.name]
159
+ dest = output.location
160
+ FileCache.put(src, dest)
153
161
  end
154
162
  end
155
163
 
156
- # Writes action environment information file.
164
+ # Write action environment information file.
165
+ #
166
+ # @return [void]
157
167
  def write_env_info
158
- path = File.join(@working_directory, ".pione-env")
159
- File.open(path, "w+") do |out|
168
+ (@working_directory + ".pione-env").open("w+") do |out|
160
169
  @variable_table.variables.each do |var|
161
170
  val = @variable_table.get(var)
162
171
  out.puts "%s: %s" % [var.name, val.textize]
@@ -164,13 +173,14 @@ module Pione
164
173
  end
165
174
  end
166
175
 
167
- # Writes resources for other intermediate files.
176
+ # Write resources for other intermediate files.
177
+ #
178
+ # @return [void]
168
179
  def write_other_resources
169
- Dir.new(@working_directory).each do |name|
170
- path = File.join(@working_directory, name)
180
+ @working_directory.entries.each do |name|
181
+ path = @working_directory + name
171
182
  if File.ftype(path) == "file"
172
- uri = make_resource_uri(name, @domain)
173
- Resource[uri].link_from(path)
183
+ Location[path].move(make_location(name, @domain))
174
184
  end
175
185
  end
176
186
  end
@@ -1,5 +1,5 @@
1
1
  module Pione
2
- # RuleHandler is a handler for rule execution.
2
+ # RuleHandler is a handler for rule application.
3
3
  module RuleHandler
4
4
  # Exception class for rule execution failure.
5
5
  class RuleExecutionError < StandardError
@@ -27,13 +27,19 @@ module Pione
27
27
  attr_reader :inputs
28
28
  attr_reader :outputs
29
29
  attr_reader :params
30
- attr_reader :base_uri
30
+ attr_reader :original_params
31
+ attr_reader :base_location
32
+ attr_reader :dry_run
31
33
  attr_reader :task_id
32
34
  attr_reader :domain
33
35
  attr_reader :variable_table
34
36
  attr_reader :call_stack
37
+ attr_reader :domain_location
38
+ attr_reader :rule_process_record
39
+ attr_reader :task_process_record
35
40
 
36
41
  # Create a new handler for rule.
42
+ #
37
43
  # @param [TupleSpaceServer] ts_server
38
44
  # tuple space server
39
45
  # @param [Rule] rule
@@ -60,15 +66,42 @@ module Pione
60
66
  @content = rule.body
61
67
  @domain = get_handling_domain(opts)
62
68
  @variable_table = VariableTable.new(@params.data)
63
- @base_uri = read(Tuple[:base_uri].any).uri
64
- @dry_run = begin read0(Tuple[:dry_run].any).availability rescue false end
69
+ @base_location = read!(Tuple[:base_location].any).location
70
+ @dry_run = begin read!(Tuple[:dry_run].any).availability rescue false end
65
71
  @task_id = ID.task_id(@inputs, @params)
66
72
  @call_stack = call_stack
73
+ @domain_location = make_location("", @domain)
74
+
75
+ caller = @call_stack[-1]
76
+
77
+ # build rule process record
78
+ @rule_process_record = Log::RuleProcessRecord.new.tap do |record|
79
+ record.name = "&%s:%s" % [@rule.expr.package.name, @rule.expr.name]
80
+ record.rule_type = @rule.rule_type
81
+ record.caller = caller.split("_").first.tap do |dname|
82
+ if dname.include?("-")
83
+ package, name = dname.split("-")
84
+ break "&%s:%s" % [package, name]
85
+ else
86
+ break "&root:Root"
87
+ end
88
+ end if caller
89
+ end
90
+
91
+ # build task process record
92
+ @task_process_record = Log::TaskProcessRecord.new.tap do |record|
93
+ record.name = handler_digest
94
+ record.rule_name = "&%s:%s" % [@rule.expr.package.name, @rule.expr.name]
95
+ record.rule_type = @rule.rule_type
96
+ record.inputs = @inputs.flatten.map{|input| input.name}.join(",")
97
+ record.parameters = @params.textize
98
+ end
67
99
 
68
100
  setup_variable_table
69
101
  end
70
102
 
71
- # Puts environment variable into pione variable table.
103
+ # Put environment variable into pione variable table.
104
+ #
72
105
  # @param [Hash{String => String}] env
73
106
  # environment table
74
107
  # @return [void]
@@ -78,10 +111,15 @@ module Pione
78
111
  end
79
112
  end
80
113
 
81
- # Handles the rule and returns the outputs.
114
+ # Handle the rule and returns the outputs.
115
+ #
82
116
  # @return [Array<Data,Array<Data>>]
83
117
  # outputs
84
118
  def handle
119
+ # put rule and task process log
120
+ process_log(@task_process_record.merge(transition: "start"))
121
+ process_log(@rule_process_record.merge(transition: "start"))
122
+
85
123
  name = self.class.message_name
86
124
 
87
125
  # show begin message
@@ -93,6 +131,9 @@ module Pione
93
131
  debug_message("%s:%s" % [i, domain], 1)
94
132
  end
95
133
 
134
+ # save rule condition informations
135
+ save_rule_condition_infos
136
+
96
137
  # execute the rule
97
138
  outputs = execute
98
139
 
@@ -112,6 +153,10 @@ module Pione
112
153
  # show end message
113
154
  user_message_end "End %s Rule: %s" % [name, handler_digest]
114
155
 
156
+ # put rule and task process log
157
+ process_log(@rule_process_record.merge(transition: "complete"))
158
+ process_log(@task_process_record.merge(transition: "complete"))
159
+
115
160
  return outputs.compact
116
161
  end
117
162
 
@@ -141,7 +186,15 @@ module Pione
141
186
 
142
187
  private
143
188
 
189
+ # Save domain information file.
190
+ #
191
+ # @return [void]
192
+ def save_rule_condition_infos
193
+ Log::DomainInfo.new(self).save
194
+ end
195
+
144
196
  # Executes the rule.
197
+ #
145
198
  # @return [Array<Data,Array<Data>>]
146
199
  # outputs
147
200
  # @api private
@@ -159,31 +212,48 @@ module Pione
159
212
  )
160
213
  end
161
214
 
162
- # Makes resource uri.
163
- def make_resource_uri(name, domain)
215
+ # Make location by data name and the domain.
216
+ #
217
+ # @param name [String]
218
+ # data name
219
+ # @param domain [String]
220
+ # domain of the data
221
+ # @return [BasicLocation]
222
+ # the location
223
+ def make_location(name, domain)
164
224
  if domain == "root" || domain.nil?
165
- return URI.parse(@base_uri) + "./%s" % name
225
+ return @base_location + "./%s" % name
166
226
  else
167
227
  # make relative path
168
228
  rule_name = domain.split("_")[0..-2].join("_")
169
229
  digest = domain.split("_").last
170
230
  path = "./.%s/%s/%s" % [rule_name, digest, name]
171
231
 
172
- # make uri
173
- return URI.parse(@base_uri) + path
232
+ # make location
233
+ return @base_location + path
174
234
  end
175
235
  end
176
236
 
177
- # Makes output resource uri.
178
- def make_output_resource_uri(name)
237
+ # Make output data location by the name.
238
+ #
239
+ # @param name [String]
240
+ # data name
241
+ # @return [BasicLocation]
242
+ # output data location
243
+ def make_output_location(name)
179
244
  # get parent domain or root domain
180
- make_resource_uri(name, @call_stack.last)
245
+ make_location(name, @call_stack.last)
181
246
  end
182
247
 
183
- # Make output tuple by name.
248
+ # Make output tuple by the name.
249
+ #
250
+ # @param name [String]
251
+ # data name
252
+ # @return [Tuple::DataTuple]
253
+ # data tuple
184
254
  def make_output_tuple(name)
185
- uri = make_output_resource_uri(name).to_s
186
- Tuple[:data].new(name: name, domain: @domain, uri: uri, time: nil)
255
+ location = make_output_location(name)
256
+ Tuple[:data].new(name: name, domain: @domain, location: location, time: nil)
187
257
  end
188
258
 
189
259
  # Setup variable table. The following variables are introduced in variable
@@ -205,7 +275,11 @@ module Pione
205
275
  "%s([%s],{%s})" % [
206
276
  @rule.rule_path,
207
277
  @inputs.map{|i|
208
- i.kind_of?(Array) ? "[%s, ...]" % i[0].name : i.name
278
+ if i.kind_of?(Array)
279
+ i.empty? ? "[]" : "[%s, ...]" % i[0].name
280
+ else
281
+ i.name
282
+ end
209
283
  }.join(","),
210
284
  params
211
285
  ]