issue #5 - support for namespaced topology class
This commit is contained in:
parent
0051ef6fec
commit
f482f3124a
|
@ -234,7 +234,7 @@ configure topology_name do |env|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
The `configure` statement is **optional**.
|
The `configure` statement is **required**.
|
||||||
|
|
||||||
- `topology_name` — alternate topology name (**default** is topology class name)
|
- `topology_name` — alternate topology name (**default** is topology class name)
|
||||||
- `env` — is set to `:local` or `:cluster` for you to set enviroment specific configurations
|
- `env` — is set to `:local` or `:cluster` for you to set enviroment specific configurations
|
||||||
|
|
|
@ -3,6 +3,8 @@ require 'examples/native/split_sentence_bolt'
|
||||||
require 'examples/native/word_count_bolt'
|
require 'examples/native/word_count_bolt'
|
||||||
|
|
||||||
class ClusterWordCountTopology
|
class ClusterWordCountTopology
|
||||||
|
RedStorm::Configuration.topology_class = self
|
||||||
|
|
||||||
def start(base_class_path, env)
|
def start(base_class_path, env)
|
||||||
builder = TopologyBuilder.new
|
builder = TopologyBuilder.new
|
||||||
builder.setSpout('1', JRubySpout.new(base_class_path, "RandomSentenceSpout"), 5)
|
builder.setSpout('1', JRubySpout.new(base_class_path, "RandomSentenceSpout"), 5)
|
||||||
|
|
|
@ -4,6 +4,8 @@ require 'examples/native/exclamation_bolt'
|
||||||
# this example topology uses the Storm TestWordSpout and our own JRuby ExclamationBolt
|
# this example topology uses the Storm TestWordSpout and our own JRuby ExclamationBolt
|
||||||
|
|
||||||
class LocalExclamationTopology
|
class LocalExclamationTopology
|
||||||
|
RedStorm::Configuration.topology_class = self
|
||||||
|
|
||||||
def start(base_class_path, env)
|
def start(base_class_path, env)
|
||||||
builder = TopologyBuilder.new
|
builder = TopologyBuilder.new
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ end
|
||||||
# this example topology uses the Storm TestWordSpout and our own JRuby ExclamationBolt
|
# this example topology uses the Storm TestWordSpout and our own JRuby ExclamationBolt
|
||||||
|
|
||||||
class LocalExclamationTopology2
|
class LocalExclamationTopology2
|
||||||
|
RedStorm::Configuration.topology_class = self
|
||||||
|
|
||||||
def start(base_class_path, env)
|
def start(base_class_path, env)
|
||||||
builder = TopologyBuilder.new
|
builder = TopologyBuilder.new
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ class RedisWordSpout
|
||||||
end
|
end
|
||||||
|
|
||||||
class LocalRedisWordCountTopology
|
class LocalRedisWordCountTopology
|
||||||
|
RedStorm::Configuration.topology_class = self
|
||||||
|
|
||||||
def start(base_class_path, env)
|
def start(base_class_path, env)
|
||||||
builder = TopologyBuilder.new
|
builder = TopologyBuilder.new
|
||||||
builder.setSpout('1', JRubySpout.new(base_class_path, "RedisWordSpout"), 1)
|
builder.setSpout('1', JRubySpout.new(base_class_path, "RedisWordSpout"), 1)
|
||||||
|
|
|
@ -2,20 +2,25 @@ require 'examples/native/random_sentence_spout'
|
||||||
require 'examples/native/split_sentence_bolt'
|
require 'examples/native/split_sentence_bolt'
|
||||||
require 'examples/native/word_count_bolt'
|
require 'examples/native/word_count_bolt'
|
||||||
|
|
||||||
class LocalWordCountTopology
|
|
||||||
def start(base_class_path, env)
|
|
||||||
builder = TopologyBuilder.new
|
|
||||||
builder.setSpout('1', JRubySpout.new(base_class_path, "RandomSentenceSpout"), 5)
|
|
||||||
builder.setBolt('2', JRubyBolt.new(base_class_path, "SplitSentenceBolt"), 8).shuffleGrouping('1')
|
|
||||||
builder.setBolt('3', JRubyBolt.new(base_class_path, "WordCountBolt"), 12).fieldsGrouping('2', Fields.new("word"))
|
|
||||||
|
|
||||||
conf = Config.new
|
module Examples
|
||||||
conf.setDebug(true)
|
class LocalWordCountTopology
|
||||||
conf.setMaxTaskParallelism(3)
|
RedStorm::Configuration.topology_class = self
|
||||||
|
|
||||||
cluster = LocalCluster.new
|
def start(base_class_path, env)
|
||||||
cluster.submitTopology("word-count", conf, builder.createTopology)
|
builder = TopologyBuilder.new
|
||||||
sleep(5)
|
builder.setSpout('1', JRubySpout.new(base_class_path, "RandomSentenceSpout"), 5)
|
||||||
cluster.shutdown
|
builder.setBolt('2', JRubyBolt.new(base_class_path, "SplitSentenceBolt"), 8).shuffleGrouping('1')
|
||||||
|
builder.setBolt('3', JRubyBolt.new(base_class_path, "WordCountBolt"), 12).fieldsGrouping('2', Fields.new("word"))
|
||||||
|
|
||||||
|
conf = Config.new
|
||||||
|
conf.setDebug(true)
|
||||||
|
conf.setMaxTaskParallelism(3)
|
||||||
|
|
||||||
|
cluster = LocalCluster.new
|
||||||
|
cluster.submitTopology("word-count", conf, builder.createTopology)
|
||||||
|
sleep(5)
|
||||||
|
cluster.shutdown
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -2,33 +2,35 @@ require 'examples/simple/random_sentence_spout'
|
||||||
require 'examples/simple/split_sentence_bolt'
|
require 'examples/simple/split_sentence_bolt'
|
||||||
require 'examples/simple/word_count_bolt'
|
require 'examples/simple/word_count_bolt'
|
||||||
|
|
||||||
class WordCountTopology < RedStorm::SimpleTopology
|
module RedStorm
|
||||||
spout RandomSentenceSpout, :parallelism => 5
|
class WordCountTopology < SimpleTopology
|
||||||
|
spout RandomSentenceSpout, :parallelism => 5
|
||||||
bolt SplitSentenceBolt, :parallelism => 8 do
|
|
||||||
source RandomSentenceSpout, :shuffle
|
bolt SplitSentenceBolt, :parallelism => 8 do
|
||||||
end
|
source RandomSentenceSpout, :shuffle
|
||||||
|
end
|
||||||
bolt WordCountBolt, :parallelism => 12 do
|
|
||||||
source SplitSentenceBolt, :fields => ["word"]
|
bolt WordCountBolt, :parallelism => 12 do
|
||||||
end
|
source SplitSentenceBolt, :fields => ["word"]
|
||||||
|
|
||||||
configure :word_count do |env|
|
|
||||||
case env
|
|
||||||
when :local
|
|
||||||
debug true
|
|
||||||
max_task_parallelism 3
|
|
||||||
when :cluster
|
|
||||||
debug true
|
|
||||||
num_workers 20
|
|
||||||
max_spout_pending(1000);
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
on_submit do |env|
|
configure :word_count do |env|
|
||||||
if env == :local
|
case env
|
||||||
sleep(5)
|
when :local
|
||||||
cluster.shutdown
|
debug true
|
||||||
|
max_task_parallelism 3
|
||||||
|
when :cluster
|
||||||
|
debug true
|
||||||
|
num_workers 20
|
||||||
|
max_spout_pending(1000);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
on_submit do |env|
|
||||||
|
if env == :local
|
||||||
|
sleep(5)
|
||||||
|
cluster.shutdown
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -3,6 +3,7 @@ module RedStorm
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'red_storm/version'
|
require 'red_storm/version'
|
||||||
|
require 'red_storm/configuration'
|
||||||
require 'red_storm/application'
|
require 'red_storm/application'
|
||||||
require 'red_storm/simple_bolt'
|
require 'red_storm/simple_bolt'
|
||||||
require 'red_storm/simple_spout'
|
require 'red_storm/simple_spout'
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
module RedStorm
|
||||||
|
module Configuration
|
||||||
|
extend self
|
||||||
|
|
||||||
|
@topology_class = nil
|
||||||
|
|
||||||
|
def topology_class=(clazz)
|
||||||
|
@topology_class = clazz
|
||||||
|
end
|
||||||
|
|
||||||
|
def topology_class
|
||||||
|
@topology_class
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'red_storm/configuration'
|
||||||
|
|
||||||
module RedStorm
|
module RedStorm
|
||||||
|
|
||||||
class SimpleTopology
|
class SimpleTopology
|
||||||
|
@ -88,6 +90,7 @@ module RedStorm
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configure(name = nil, &configure_block)
|
def self.configure(name = nil, &configure_block)
|
||||||
|
Configuration.topology_class = self
|
||||||
@topology_name = name if name
|
@topology_name = name if name
|
||||||
@configure_block = configure_block if block_given?
|
@configure_block = configure_block if block_given?
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ java_import 'redstorm.storm.jruby.JRubySpout'
|
||||||
java_package 'redstorm'
|
java_package 'redstorm'
|
||||||
|
|
||||||
# TopologyLauncher is the application entry point when launching a topology. Basically it will
|
# TopologyLauncher is the application entry point when launching a topology. Basically it will
|
||||||
# call require on the specified Ruby topology/project class file path and call its start method
|
# call require on the specified Ruby topology class file path and call its start method
|
||||||
class TopologyLauncher
|
class TopologyLauncher
|
||||||
|
|
||||||
java_signature 'void main(String[])'
|
java_signature 'void main(String[])'
|
||||||
|
@ -35,12 +35,12 @@ class TopologyLauncher
|
||||||
end
|
end
|
||||||
env = args[0].to_sym
|
env = args[0].to_sym
|
||||||
class_path = args[1]
|
class_path = args[1]
|
||||||
clazz = camel_case(class_path.split('/').last.split('.').first)
|
|
||||||
|
|
||||||
puts("RedStorm v#{RedStorm::VERSION} starting topology #{clazz} in #{env.to_s} environment")
|
|
||||||
|
|
||||||
require class_path
|
require class_path
|
||||||
Object.module_eval(clazz).new.start(class_path, env)
|
|
||||||
|
topology_name = RedStorm::Configuration.topology_class.respond_to?(:topology_name) ? "/#{RedStorm::Configuration.topology_class.topology_name}" : ''
|
||||||
|
puts("RedStorm v#{RedStorm::VERSION} starting topology #{RedStorm::Configuration.topology_class.name}#{topology_name} in #{env.to_s} environment")
|
||||||
|
RedStorm::Configuration.topology_class.new.start(class_path, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module RedStorm
|
module RedStorm
|
||||||
VERSION = '0.2.1'
|
VERSION = '0.3.0'
|
||||||
end
|
end
|
Loading…
Reference in New Issue