def test_constructor(self): builder = TopologyBuilder("WordCount") self.assertEqual(builder.topology_name, "WordCount") with self.assertRaises(AssertionError): TopologyBuilder("Topology") with self.assertRaises(AssertionError): TopologyBuilder(123) with self.assertRaises(AssertionError): TopologyBuilder(None)
def test_add_spec(self): builder = TopologyBuilder("Test") with self.assertRaises(ValueError): builder.add_spec(HeronComponentSpec(None, "path", True, 1)) with self.assertRaises(TypeError): builder.add_spec(None) self.assertEqual(len(builder._specs), 0) # add 10 specs specs = [] for i in range(10): specs.append(HeronComponentSpec(str(i), "path", True, 1)) builder.add_spec(*specs) self.assertEqual(len(builder._specs), 10)
def run(self, name, config=None): if name is None or not isinstance(name, str): raise RuntimeError("Job Name has to be a string") bldr = TopologyBuilder(name=name) stage_names = {} bldr = self._build(bldr, stage_names) if config is not None: if not isinstance(config, dict): raise RuntimeError("config has to be a dict") bldr.set_config(config) bldr.build_and_submit()
import sys import heron.api.src.python.api_constants as constants from heron.api.src.python import Grouping, TopologyBuilder from heron.examples.src.python.spout import WordSpout from heron.examples.src.python.bolt import HalfAckBolt # Topology is defined using a topology builder # Refer to multi_stream_topology for defining a topology by subclassing Topology if __name__ == '__main__': if len(sys.argv) != 2: print "Topology's name is not specified" sys.exit(1) builder = TopologyBuilder(name=sys.argv[1]) word_spout = builder.add_spout("word_spout", WordSpout, par=2) half_ack_bolt = builder.add_bolt( "half_ack_bolt", HalfAckBolt, par=2, inputs={word_spout: Grouping.fields('word')}, config={constants.TOPOLOGY_TICK_TUPLE_FREQ_SECS: 10}) topology_config = { constants.TOPOLOGY_ENABLE_ACKING: True, constants.TOPOLOGY_MAX_SPOUT_PENDING: 100000000, constants.TOPOLOGY_MESSAGE_TIMEOUT_SECS: 300 }
import sys import heron.api.src.python.api_constants as constants from heron.api.src.python import Grouping, TopologyBuilder from heron.api.src.python.bolt import SlidingWindowBolt from heron.examples.src.python.spout import WordSpout from heron.examples.src.python.bolt import WindowSizeBolt # Topology is defined using a topology builder # Refer to multi_stream_topology for defining a topology by subclassing Topology if __name__ == '__main__': if len(sys.argv) != 2: print "Topology's name is not specified" sys.exit(1) builder = TopologyBuilder(name=sys.argv[1]) word_spout = builder.add_spout("word_spout", WordSpout, par=2) count_bolt = builder.add_bolt( "count_bolt", WindowSizeBolt, par=2, inputs={word_spout: Grouping.fields('word')}, config={ SlidingWindowBolt.WINDOW_DURATION_SECS: 10, SlidingWindowBolt.WINDOW_SLIDEINTERVAL_SECS: 2 }) topology_config = { constants.TOPOLOGY_RELIABILITY_MODE: constants.TopologyReliabilityMode.ATLEAST_ONCE
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. '''Example WordCountTopology''' import sys import heron.api.src.python.api_constants as constants from heron.api.src.python import Grouping, TopologyBuilder from heron.examples.src.python.spout import WordSpout from heron.examples.src.python.bolt import CountBolt # Topology is defined using a topology builder # Refer to multi_stream_topology for defining a topology by subclassing Topology if __name__ == '__main__': if len(sys.argv) != 2: print "Topology's name is not specified" sys.exit(1) builder = TopologyBuilder(name=sys.argv[1]) word_spout = builder.add_spout("word_spout", WordSpout, par=2) count_bolt = builder.add_bolt("count_bolt", CountBolt, par=2, inputs={word_spout: Grouping.fields('word')}, config={constants.TOPOLOGY_TICK_TUPLE_FREQ_SECS: 10}) topology_config = {constants.TOPOLOGY_ENABLE_ACKING: True} builder.set_config(topology_config) builder.build_and_submit()