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
@@ -1,113 +0,0 @@
1
- module Pione
2
- module Resource
3
- # Local represents local path resources.
4
- class Local < BasicResource
5
- # Creates a local resource handler with URI.
6
- # @param [String, URI] uri
7
- # URI of a local path
8
- def initialize(uri)
9
- @uri = uri.kind_of?(::URI::Generic) ? uri : ::URI.parse(uri)
10
- raise ArgumentError unless @uri.kind_of?(URIScheme::LocalScheme)
11
- @path = Pathname.new(uri.path)
12
- end
13
-
14
- # (see BasicResource#create)
15
- def create(data)
16
- @path.dirname.mkpath unless @path.dirname.exist?
17
- @path.open("w+"){|file| file.write(data)}
18
- end
19
-
20
- # (see BasicResource#read)
21
- def read
22
- @path.exist? ? @path.read : (raise NotFound.new(@uri))
23
- end
24
-
25
- # (see BasicResource#update)
26
- def update(data)
27
- if @path.exist?
28
- @path.open("w+"){|file| file.write(data)}
29
- else
30
- raise NotFound.new(@uri)
31
- end
32
- end
33
-
34
- # (see BasicResource#delete)
35
- def delete
36
- @path.delete if @path.exist?
37
- end
38
-
39
- # (see BasicResource#mtime)
40
- def mtime
41
- @path.mtime
42
- end
43
-
44
- # (see BasicResource#entries)
45
- def entries
46
- @path.entries.select{|entry| (@path + entry).file?}.map do |entry|
47
- Resource[::URI.parse("local:%s" % (@path + entry).expand_path)]
48
- end
49
- rescue Errno::ENOENT
50
- raise NotFound.new(self)
51
- end
52
-
53
- # (see BasicResource#basename)
54
- def basename
55
- @path.basename.to_s
56
- end
57
-
58
- # (see BasicResource#exist?)
59
- def exist?
60
- @path.exist?
61
- end
62
-
63
- # Makes symbolic link from the resource to the destination.
64
- # @param [String] dest
65
- # destination path
66
- # @return [void]
67
- def link_to(dest)
68
- dir = File.dirname(dest)
69
- FileUtils.makedirs(dir) unless Dir.exist?(dir)
70
- FileUtils.symlink(@path, dest)
71
- end
72
-
73
- # Moves the source to the resource and makes reverse link.
74
- # @param [String] src
75
- # source path
76
- # @return [void]
77
- def link_from(src)
78
- swap(src)
79
- end
80
-
81
- # Swaps the source file and the resource file. This method moves the
82
- # other file to the resource path and creates a symbolic link from
83
- # distination to source.
84
- # @param [String] other
85
- # swap target
86
- # @return [void]
87
- def swap(other)
88
- unless File.ftype(other) == "file"
89
- raise ArgumentError.new(other)
90
- end
91
- dir = @path.dirname
92
- dir.mkpath unless dir.exist?
93
- FileUtils.mv(other, @path)
94
- FileUtils.symlink(@path, other)
95
- end
96
-
97
- # Swaps the resouce file and the other resouce file.
98
- # @param [Local] other
99
- # swap target
100
- def shift_from(other)
101
- raise ArgumentError.new(other) unless other.kind_of?(self.class)
102
- unless File.ftype(other.path) == "file"
103
- raise ArgumentError.new(other)
104
- end
105
- dir = @path.dirname
106
- dir.mkpath unless dir.exist?
107
- FileUtils.mv(other.path, @path)
108
- end
109
- end
110
-
111
- @@schemes['local'] = Local
112
- end
113
- end
@@ -1,9 +0,0 @@
1
- module Pione
2
- module Tuple
3
- # BaseURITuple represents base location information of resource.
4
- class BaseURITuple < BasicTuple
5
- # base uri of all resources on the server
6
- define_format [:base_uri, :uri]
7
- end
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- module Pione
2
- module Tuple
3
- # ShiftTuple represents resource shift information.
4
- class ShiftTuple < BasicTuple
5
- define_format [:shift,
6
- # old uri
7
- [:old_uri, String],
8
- # new uri
9
- [:new_uri, String]
10
- ]
11
- end
12
- end
13
- end
@@ -1,79 +0,0 @@
1
- module Pione
2
- module Util
3
- # Log is a representation for logging.
4
- # @example
5
- # Log.new do
6
- # add_record(
7
- # component: "tuple-space-server",
8
- # key: "action",
9
- # value: "start"
10
- # )
11
- # end
12
- #
13
- class Log
14
- # Log::Record is a key-value line for log. A record consisted of following items:
15
- # - application
16
- # - component
17
- # - key
18
- # - value
19
- class Record
20
- attr_reader :components
21
- attr_reader :key
22
- attr_reader :value
23
-
24
- # Creates a log record.
25
- def initialize(components, key, value)
26
- @components = components.kind_of?(Array) ? components : [components]
27
- @key = key
28
- @value = value
29
- end
30
-
31
- def application
32
- "" # "pione"
33
- end
34
-
35
- # Format as a string.
36
- # i.e.
37
- # 2012-04-25T14:48:57.791+09:00 A35D pione.rule-provider.status: initialized
38
- def format(logid, time)
39
- resource = [application, components, key].flatten.compact.join(".")
40
- "%s %s %s: %s" % [time, logid, resource, value.to_json]
41
- end
42
- end
43
-
44
- attr_reader :records
45
-
46
- # Creatas a new log record.
47
- def initialize
48
- @records = []
49
- yield self if block_given?
50
- end
51
-
52
- def add_record(*args)
53
- @records << Record.new(*args)
54
- end
55
-
56
- def timestamp=(time)
57
- @time = time
58
- end
59
-
60
- # Format as string.
61
- # i.e.
62
- # 2012-04-25T14:48:57.791+09:00 A35D .task-worker.action: "take_task"
63
- # 2012-04-25T14:48:57.791+09:00 A35D .task-worker.object: ...
64
- def format
65
- logid = generate_logid
66
- time = @time.iso8601(3)
67
- @records.map{|record| record.format(logid, time)}.join("\n")
68
- end
69
-
70
- private
71
-
72
- IDCHAR = ("A".."Z").to_a + (0..9).to_a.map{|i|i.to_s}
73
-
74
- def generate_logid(i=4)
75
- i > 0 ? IDCHAR[rand(IDCHAR.size)] + generate_logid(i-1) : ""
76
- end
77
- end
78
- end
79
- end
@@ -1,73 +0,0 @@
1
- require 'tempfile'
2
- require_relative 'test-util'
3
-
4
- describe 'Resource' do
5
- describe 'Local' do
6
- before do
7
- path = Tempfile.new("spec_resource_").path
8
- @uri = ::URI.parse("local:#{path}")
9
- @local = Resource[@uri]
10
- end
11
-
12
- it 'should create a file' do
13
- @local.create("abc")
14
- File.read(@uri.path).should == "abc"
15
- end
16
-
17
- it 'should read a file' do
18
- @local.create("abc")
19
- @local.read.should == "abc"
20
- @local.read.should == "abc"
21
- @local.read.should.not == "def"
22
- File.delete(@uri.path)
23
- should.raise(Resource::NotFound) { @local.read }
24
- end
25
-
26
- it 'should update a file' do
27
- @local.create("abc")
28
- @local.read.should == "abc"
29
- @local.update("defg")
30
- @local.read.should == "defg"
31
- @local.update("hi")
32
- @local.read.should == "hi"
33
- end
34
-
35
- it 'should delete a file' do
36
- should.not.raise { @local.delete }
37
- @local.create("abc")
38
- @local.delete
39
- end
40
- end
41
-
42
- begin
43
- @uri = URI("ftp://anonymous:test@localhost/pione/test-a.txt")
44
- @ftp = Resource[@uri]
45
- @ftp.create("abc")
46
- @ftp.delete
47
-
48
- describe 'FTP' do
49
- before do
50
- path = Tempfile.new("spec_resource_").path
51
- # @uri = URI("ftp://anonymous:test@localhost/pione/test-a.txt")
52
- # @ftp = Resource[@uri]
53
- end
54
-
55
- it 'should create a file and read it' do
56
- @ftp.create("abc")
57
- @ftp.read.should == "abc"
58
- @ftp.delete
59
- end
60
-
61
- it 'should update a file' do
62
- @ftp.create("abc")
63
- @ftp.read.should == "abc"
64
- @ftp.update("defg")
65
- @ftp.read.should == "defg"
66
- @ftp.update("hi")
67
- @ftp.read.should == "hi"
68
- @ftp.delete
69
- end
70
- end
71
- rescue Errno::ECONNREFUSED
72
- end
73
- end