zillabyte 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,10 +5,13 @@ module Zillabyte
5
5
 
6
6
  module Storm
7
7
 
8
+ class UserEndCycleException < Exception
9
+ end
10
+
8
11
  module Protocol
9
12
 
10
13
  class << self
11
- attr_accessor :mode, :pending_commands, :pipe_name, :pipe_to_java, :pipe_from_java
14
+ attr_accessor :mode, :emits, :end_cycle_policy, :pending_commands, :pipe_name, :pipe_to_java, :pipe_from_java
12
15
  end
13
16
 
14
17
  self.pending_commands = []
@@ -85,18 +88,46 @@ module Zillabyte
85
88
  if (args.size == 1)
86
89
  tuple = args[0]
87
90
  elsif(args.size == 2)
88
- stream = args[0]
89
- tuple = args[1]
91
+ if(args[0].instance_of?(String))
92
+ stream = args[0]
93
+ tuple = args[1]
94
+ elsif(args[0].instance_of?(Hash))
95
+ tuple = args[0]
96
+ meta = args[1]
97
+ end
90
98
  else
91
99
  stream = args[0]
92
100
  tuple = args[1]
93
101
  meta = args[2]
94
102
  end
95
103
 
104
+ if !stream.nil? and !Storm::Protocol.emits.member?(stream)
105
+ fail "Exception in #{Storm::Protocol.mode}: " + "\"#{stream}\" is not a declared stream. Please either remove it from \"emit\" (if there's only one output stream) or declare it in an \"emits\" clause.\n"
106
+ end
107
+ if stream.nil?
108
+ if Storm::Protocol.emits.size == 1
109
+ stream = Storm::Protocol.emits.first
110
+ else
111
+ fail "Exception in #{Storm::Protocol.mode}: " + "No stream specified in \"emit\" but multiple streams declared in \"emits\". Please specify which stream to emit to in \"emit\"."
112
+ end
113
+ end
114
+
96
115
  m = {:command => :emit, :tuple => tuple, :stream => stream, :meta => meta}
97
116
  send_msg_to_parent m
98
117
  end
99
118
 
119
+ def end_cycle()
120
+ if !Storm::Protocol.mode == "source"
121
+ fail "Exception in #{Storm::Protocol.mode}: " + "\"end_cycle\" is only valid in \"source\" operations."
122
+ else
123
+ if Storm::Protocol.end_cycle_policy == :explicit
124
+ raise UserEndCycleException, "cycle ended"
125
+ # else
126
+ # fail "Exception in source: " + "\"end_cycle\" received but \"end_cycle_policy\" was not set to \"explicit\"."
127
+ end
128
+ end
129
+ end
130
+
100
131
  def ack(tup)
101
132
  send_msg_to_parent :command => :ack, :id => tup.id
102
133
  end
@@ -125,9 +156,9 @@ module Zillabyte
125
156
  class Source
126
157
  include Storm::Protocol
127
158
 
128
- def open(conf, context); end
159
+ def begin_cycle(conf, context); end
129
160
 
130
- def next_batch; end
161
+ def next_tuple; end
131
162
 
132
163
  def ack(id); end
133
164
 
@@ -135,19 +166,24 @@ module Zillabyte
135
166
  Storm::Protocol.mode = 'source'
136
167
  Storm::Protocol.pipe_name = pipe_name
137
168
  setup_pipes
138
- open(*handshake)
169
+ handshake
139
170
 
140
171
  while true
141
172
  begin
142
173
  msg = read_command
143
174
  case msg['command']
175
+ when 'begin_cycle'
176
+ begin_cycle
144
177
  when 'next'
145
- next_batch
178
+ next_tuple
146
179
  when 'ack'
147
180
  ack(msg['id'])
148
181
  when 'fail'
149
182
  fail(msg['id'])
150
183
  end
184
+ rescue UserEndCycleException => e
185
+ m = {:command => :end_cycle}
186
+ send_msg_to_parent m
151
187
  rescue SignalException => e
152
188
  raise
153
189
  rescue Exception => e
@@ -181,7 +217,7 @@ module Zillabyte
181
217
  raise
182
218
  rescue Exception => e
183
219
  fail 'Exception in each: ' + e.message + ' - ' + e.backtrace.join('\n')
184
- break
220
+ # We may recover from this, but let JVM decide
185
221
  end
186
222
  done
187
223
  end
@@ -229,18 +265,16 @@ module Zillabyte
229
265
  def initialize(harness, progress)
230
266
  @harness = harness
231
267
  @progress = progress
268
+ Storm::Protocol.emits = harness._emits
269
+ Storm::Protocol.end_cycle_policy = harness._end_cycle_policy
232
270
  end
233
271
 
234
- def open(*args)
235
- self.instance_exec(*args, &@harness._prepare) if @harness._prepare
236
- #@harness._prepare.call(self, *args) if @harness._prepare
272
+ def begin_cycle(*args)
273
+ self.instance_exec(*args, &@harness._begin_cycle) if @harness._begin_cycle
237
274
  end
238
275
 
239
- def next_batch
240
- #@harness._next_batch.call(self)
241
- # Executes the block @harness._next_batch in the context of the class self (i.e. exposes all methods of self to
242
- # the block).
243
- self.instance_eval &@harness._next_batch
276
+ def next_tuple
277
+ self.instance_eval &@harness._next_tuple
244
278
  end
245
279
 
246
280
  end
@@ -250,18 +284,15 @@ module Zillabyte
250
284
  def initialize(harness, progress)
251
285
  @harness = harness
252
286
  @progress = progress
287
+ Storm::Protocol.emits = harness._emits
253
288
  end
254
289
 
255
290
  def execute(*args)
256
- #@harness._execute.call(self, *args)
257
- # Executes the block @harness._next_batch in the context of the class self (i.e. exposes all methods of self to
258
- # the block). Also allows you to pass in arguments to the block in *args.
259
291
  self.instance_exec *args, &@harness._execute
260
292
  end
261
293
 
262
294
  def prepare(*args)
263
295
  self.instance_exec(*args, &@harness._prepare) if @harness._prepare
264
- #@harness._prepare.call(self, *args) if @harness._prepare
265
296
  end
266
297
 
267
298
  end
@@ -271,20 +302,18 @@ module Zillabyte
271
302
  def initialize(harness, progress)
272
303
  @harness = harness
273
304
  @progress = progress
305
+ Storm::Protocol.emits = harness._emits
274
306
  end
275
307
 
276
308
  def begin_group(*args)
277
- #@harness._begin_group.call(*args)
278
309
  self.instance_exec *args, &@harness._begin_group
279
310
  end
280
311
 
281
312
  def aggregate(*args)
282
- #@harness._aggregate.call(*args)
283
313
  self.instance_exec *args, &@harness._aggregate
284
314
  end
285
315
 
286
316
  def end_group(*args)
287
- #@harness._end_group.call(self, *args)
288
317
  self.instance_exec *args, &@harness._end_group
289
318
  end
290
319
 
@@ -1,10 +1,10 @@
1
1
  class Zillabyte::Harness::Source
2
- attr_accessor :_name, :_type, :_matches, :_relation, :_emits, :_prepare, :_next_batch, :_flow_flag
2
+ attr_accessor :_name, :_type, :_matches, :_relation, :_emits, :_end_cycle_policy, :_begin_cycle, :_next_tuple
3
3
 
4
- def initialize(flow_flag)
4
+ def initialize()
5
5
  @_name = "source_"+Zillabyte::Harness::Counter.get()
6
6
  @_type = 'source'
7
- @_flow_flag = flow_flag
7
+ @_end_cycle_policy = :null_emit
8
8
  end
9
9
 
10
10
  def matches(v, options = {})
@@ -20,29 +20,23 @@ class Zillabyte::Harness::Source
20
20
  @_name = v
21
21
  end
22
22
 
23
- def emits(v)
24
- if(@_flow_flag)
25
- @_emits = v
26
- else
27
- @_emits = []
28
- v.each do |relation|
29
- temit = []
30
- relation[1].each do |column|
31
- column.each do |col, type|
32
- temit << col
33
- end
34
- end
35
- @_emits << [relation[0], temit]
36
- end
23
+ def emits(*v)
24
+ @_emits = *v
25
+ end
26
+
27
+ def end_cycle_policy(v)
28
+ allowed_policies = [:null_emit, :explicit]
29
+ if(allowed_policies.member?(v))
30
+ @_end_cycle_policy = v
37
31
  end
38
32
  end
39
33
 
40
- def prepare(&block)
41
- @_prepare = block
34
+ def begin_cycle(&block)
35
+ @_begin_cycle = block
42
36
  end
43
37
 
44
- def next_batch(&block)
45
- @_next_batch = block
38
+ def next_tuple(&block)
39
+ @_next_tuple = block
46
40
  end
47
41
 
48
42
  end
@@ -0,0 +1,86 @@
1
+ require "json"
2
+
3
+ class Zillabyte::Harness::Stream
4
+ attr_accessor :_name, :_app, :_previous_node_name
5
+
6
+ def initialize(name, app, previous_node_name)
7
+ @_name = name
8
+ @_app = app
9
+ @_previous_node_name = previous_node_name
10
+ end
11
+
12
+ def each(&block)
13
+ h = Zillabyte::Harness::Each.new()
14
+ # Does the block take 0 arguments? If so it's not just an execute block.
15
+ if(block.arity == 0)
16
+ h.instance_eval(&block)
17
+ # Takes more than 0? Then it takes |tuple| and is an execute block. Give it a generated stream name.
18
+ else
19
+ h._emits = ["stream_"+Zillabyte::Harness::Counter.get()]
20
+ h._has_emit = true
21
+ h._execute = block
22
+ end
23
+ Zillabyte::Harness::Helper.check_name("each", h._name, {})
24
+ #Zillabyte::Harness::Helper.check_emits("each", h._emits, @_streams) || @_branched
25
+ @_app._nodes << h
26
+ if(@_app._options[:command] == :info)
27
+ info_hash = {"name" => h._name, "type" => h._type, "consumes" => @_name}
28
+ info_hash["emits"] = h._emits
29
+ Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_app._info_file)
30
+ elsif(@_app._options[:command] == :execute and @_app._options[:name] == h._name)
31
+ pipe_name = @_app._options[:pipe]
32
+ c = Zillabyte::Harness::EachController.new(h, progress = Zillabyte::Common::Progress.new)
33
+ c.run(pipe_name)
34
+ end
35
+
36
+ output_streams = []
37
+ h._emits.each do |stream|
38
+ output_streams << Zillabyte::Harness::Stream.new(stream, @_app, h._name)
39
+ end
40
+ output_streams = output_streams[0] if output_streams.size == 1
41
+ output_streams
42
+ end
43
+
44
+ def aggregate(&block)
45
+ h = Zillabyte::Harness::Aggregate.new()
46
+ #yield(h)
47
+ h.instance_eval(&block)
48
+ Zillabyte::Harness::Helper.check_name("aggregate", h._name, @_names)
49
+ if(@_branched)
50
+ Zillabyte::Harness::Helper.check_consumes(h, @_streams)
51
+ else
52
+ if(h._consumes)
53
+ h._consumes = nil
54
+ end
55
+ end
56
+ Zillabyte::Harness::Helper.check_group_by("aggregate", h, @_nodes, @_streams)
57
+ @_branched = Zillabyte::Harness::Helper.check_emits("aggregate", h._emits, @_streams) || @_branched
58
+ @_nodes << h
59
+ if(@_options[:command] == :info)
60
+ info_hash = {"name" => h._name, "type" => h._type, "group_by" => h._group_by, "emits" => h._emits}
61
+ if(h._consumes)
62
+ info_hash["consumes"] = h._consumes
63
+ end
64
+ Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
65
+ elsif(@_options[:command] == :execute)
66
+ pipe_name = @_options[:pipe]
67
+ if(@_options[:name] == h._name)
68
+ c = Zillabyte::Harness::AggregateController.new(h, Zillabyte::Common::Progress.new)
69
+ c.run(pipe_name)
70
+ end
71
+ end
72
+ end
73
+
74
+ def sink(&block)
75
+ h = Zillabyte::Harness::Sink.new()
76
+ #yield(h)
77
+ h.instance_eval(&block)
78
+ # Zillabyte::Harness::Helper.check_sink(h, @_nodes)
79
+ @_app._nodes << h
80
+ if(@_app._options[:command] == :info)
81
+ info_hash = {"name" => h._name, "type" => h._type, "columns" => h._columns, "relation" => h._relation || h._name, "consumes" => @_name}
82
+ Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_app._info_file)
83
+ end
84
+ end
85
+
86
+ end
@@ -1,3 +1,3 @@
1
1
  module Zillabyte
2
- VERSION = "0.0.16" unless defined?(VERSION)
2
+ VERSION = "0.0.17" unless defined?(VERSION)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillabyte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - zillabyte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-01 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.10
47
+ version: 0.0.17
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.10
54
+ version: 0.0.17
55
55
  description: The Official Zillabyte Gem
56
56
  email:
57
57
  - gem@zillabyte.com
@@ -61,17 +61,15 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ruby/lib/zillabyte/common/progress.rb
63
63
  - ruby/lib/zillabyte/harness/aggregate.rb
64
+ - ruby/lib/zillabyte/harness/app.rb
64
65
  - ruby/lib/zillabyte/harness/counter.rb
65
66
  - ruby/lib/zillabyte/harness/each.rb
66
67
  - ruby/lib/zillabyte/harness/groupby.rb
67
68
  - ruby/lib/zillabyte/harness/helper.rb
68
69
  - ruby/lib/zillabyte/harness/live_delegator.rb
69
- - ruby/lib/zillabyte/harness/simple_aggregate.rb
70
- - ruby/lib/zillabyte/harness/simple_function.rb
71
- - ruby/lib/zillabyte/harness/simple_source.rb
72
70
  - ruby/lib/zillabyte/harness/sink.rb
73
71
  - ruby/lib/zillabyte/harness/source.rb
74
- - ruby/lib/zillabyte/harness/topology.rb
72
+ - ruby/lib/zillabyte/harness/stream.rb
75
73
  - ruby/lib/zillabyte/harness/tuple.rb
76
74
  - ruby/lib/zillabyte/harness.rb
77
75
  - ruby/lib/zillabyte/version.rb
@@ -97,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
95
  version: '0'
98
96
  requirements: []
99
97
  rubyforge_project:
100
- rubygems_version: 2.0.7
98
+ rubygems_version: 2.1.10
101
99
  signing_key:
102
100
  specification_version: 4
103
101
  summary: The Official Zillabyte Gem
@@ -1,144 +0,0 @@
1
- require 'optparse'
2
-
3
- class Zillabyte::Harness::SimpleAggregate
4
- attr_accessor :_nodes, :_relation, :_matches, :_group_by, :_emits, :_begin_group, :_aggregate, :_end_group, :_name, :_info_file, :_options
5
-
6
- def self.build(*args, &block)
7
- h = Zillabyte::Harness::SimpleAggregate.new()
8
- #yield(h)
9
- h.instance_eval(&block)
10
- h._name = h._name
11
- Zillabyte::Harness::Helper.check_name("simple_aggregate", h._name, {})
12
- Zillabyte::Harness::Helper.check_emits("simple_aggregate", h._emits, {})
13
- generic_emits = h.get_generic_emits
14
-
15
- h._nodes = []
16
- h._options = Zillabyte::Harness::Helper.opt_parser()
17
-
18
- if(h._options[:command] == :info)
19
- h._info_file = File.open(h._options[:file],"w+")
20
- hash = {"language" => "ruby", "name" => h._name}
21
- Zillabyte::Harness::Helper.write_hash_to_file(hash, h._info_file)
22
- end
23
-
24
- h.build_source()
25
- fn = h.build_aggregate(generic_emits)
26
- h.build_sink()
27
-
28
- if(h._options[:command] == :execute and h._options[:name] == h._name)
29
- pipe_name = h._options[:pipe]
30
- c = Zillabyte::Harness::AggregateController.new(fn, progress = Zillabyte::Common::Progress.new)
31
- c.run(pipe_name)
32
- end
33
-
34
- h
35
- end
36
-
37
- def name(v)
38
- @_name = v
39
- end
40
-
41
- def matches(v, options = {})
42
- case v
43
- when String
44
- @_relation = { :query => v, :options => options.is_a?(Hash) ? options : {} }
45
- when Array
46
- @_matches = v
47
- end
48
- end
49
-
50
- def group_by(v)
51
- @_group_by = v
52
- end
53
-
54
- def emits(v)
55
- @_emits = v
56
- end
57
-
58
- def begin_group(&block)
59
- @_begin_group = block
60
- end
61
-
62
- def aggregate(&block)
63
- @_aggregate = block
64
- end
65
-
66
- def end_group(&block)
67
- @_end_group = block
68
- end
69
-
70
- def get_generic_emits()
71
- generic_emits = []
72
- @_emits.each do |relation|
73
- temit = []
74
- relation[1].each do |column|
75
- column.each do |col, type|
76
- temit << col
77
- end
78
- end
79
- generic_emits << [relation[0], temit]
80
- end
81
- generic_emits
82
- end
83
-
84
- def build_source()
85
- h = Zillabyte::Harness::Source.new(false)
86
- h._matches = @_matches if @_matches
87
- h._relation = @_relation if @_relation
88
- Zillabyte::Harness::Helper.check_source("simple_aggregate", h)
89
- @_nodes << h
90
- if(@_options[:command] == :info)
91
- info_hash = {"name" => h._name, "type" => h._type}
92
- if(h._relation)
93
- info_hash["relation"] = h._relation
94
- elsif(h._matches)
95
- info_hash["matches"] = h._matches
96
- end
97
- Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
98
- end
99
- end
100
-
101
- def build_aggregate(generic_emits)
102
- h = Zillabyte::Harness::Aggregate.new()
103
- h._name = @_name
104
- h._emits = generic_emits
105
- h._group_by = @_group_by
106
- h._begin_group = @_begin_group
107
- h._aggregate = @_aggregate
108
- h._end_group = @_end_group
109
- Zillabyte::Harness::Helper.check_group_by("simple_aggregate", h, @_nodes, {})
110
- @_nodes << h
111
- if(@_options[:command] == :info)
112
- info_hash = {"name" => h._name, "type" => h._type, "emits" => h._emits, "group_by" => h._group_by}
113
- Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
114
- end
115
- h
116
- end
117
-
118
- def build_sink()
119
- # Construct the sink...
120
- n_sinks = @_emits.length
121
- @_emits.each do |emit|
122
- h = Zillabyte::Harness::Sink.new()
123
- h._name = emit[0]
124
- columns = emit[1]
125
- columns.each do |col|
126
- col.each do |cname, ctype|
127
- h.column(cname, ctype)
128
- end
129
- end
130
- if(n_sinks > 1)
131
- h._consumes = h._name
132
- end
133
- @_nodes << h
134
- if(@_options[:command] == :info)
135
- info_hash = {"name" => h._name, "type" => h._type, "columns" => h._columns, "relation" => h._relation || h._name}
136
- if(h._consumes)
137
- info_hash["consumes"] = h._consumes
138
- end
139
- Zillabyte::Harness::Helper.write_hash_to_file(info_hash, @_info_file)
140
- end
141
- end
142
- end
143
-
144
- end