Java Code Examples for org.apache.storm.StormSubmitter#submitTopology()
The following examples show how to use
org.apache.storm.StormSubmitter#submitTopology() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FullPullerTopology.java From DBus with Apache License 2.0 | 6 votes |
private void start(StormTopology topology, boolean runAsLocal) throws Exception { Config conf = new Config(); conf.put(FullPullConstants.FULL_SPLITTER_TOPOLOGY_ID, fullSplitterTopologyId); conf.put(FullPullConstants.FULL_PULLER_TOPOLOGY_ID, fullPullerTopologyId); conf.put(FullPullConstants.DS_NAME, topologyId); conf.put(FullPullConstants.ZKCONNECT, zkConnect); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, commonConfSplit.getProperty(FullPullConstants.TOPOLOGY_WORKER_CHILDOPTS)); //设置message超时时间为,保证每个分片都能在该内拉完数据 conf.setMessageTimeoutSecs(Integer.parseInt(commonConfSplit.getProperty(FullPullConstants.STORM_MESSAGE_TIMEOUT))); conf.setMaxSpoutPending(Integer.parseInt(commonConfSplit.getProperty(FullPullConstants.STORM_MAX_SPOUT_PENDING))); conf.setNumWorkers(Integer.parseInt(commonConfSplit.getProperty(FullPullConstants.STORM_NUM_WORKERS))); conf.setDebug(true); if (runAsLocal) { conf.setMaxTaskParallelism(3); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(topologyName, conf, topology); } else { StormSubmitter.submitTopology(topologyName, conf, topology); } }
Example 2
Source File: TopologyStarter.java From breeze with Apache License 2.0 | 6 votes |
@Override public void run() { properties.put(Config.TOPOLOGY_NAME, ID); Config config = stormConfig(properties); ApplicationContext spring = SingletonApplicationContext.loadXml(config, MAIN_CONTEXT); try { StormTopology topology = spring.getBean(ID, StormTopology.class); Properties systemProperties = System.getProperties(); if (systemProperties.containsKey(LOCAL_RUN_PARAM)) { String timeout = systemProperties.getProperty(LOCAL_RUN_PARAM); if (! hasText(timeout)) timeout = LOCAL_RUN_DEFAULT_TIMEOUT; long ms = 1000L * Integer.parseInt(timeout); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(ID, config, topology); sleep(ms); cluster.shutdown(); } else StormSubmitter.submitTopology(ID, config, topology); } catch (Exception e) { e.printStackTrace(); exit(255); } }
Example 3
Source File: PerformanceTestTopology.java From jstorm with Apache License 2.0 | 6 votes |
public static void SetRemoteTopology() throws Exception { String streamName = (String) conf.get(Config.TOPOLOGY_NAME); if (streamName == null) { String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\."); streamName = className[className.length - 1]; } TopologyBuilder builder = new TopologyBuilder(); int spout_Parallelism_hint = Utils.getInt(conf.get(TOPOLOGY_SPOUT_PARALLELISM_HINT), 1); int bolt_Parallelism_hint = Utils.getInt(conf.get(TOPOLOGY_BOLT_PARALLELISM_HINT), 2); builder.setSpout("spout", new TestSpout(), spout_Parallelism_hint); BoltDeclarer boltDeclarer = builder.setBolt("bolt", new TestBolt(), bolt_Parallelism_hint); // localFirstGrouping is only for jstorm // boltDeclarer.localFirstGrouping(SequenceTopologyDef.SEQUENCE_SPOUT_NAME); boltDeclarer.shuffleGrouping("spout"); // .addConfiguration(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 60); StormSubmitter.submitTopology(streamName, conf, builder.createTopology()); }
Example 4
Source File: DBusLogProcessorTopology.java From DBus with Apache License 2.0 | 6 votes |
private void start(StormTopology topology, boolean runAsLocal) throws Exception { Config conf = new Config(); conf.put(com.creditease.dbus.commons.Constants.ZOOKEEPER_SERVERS, zkConnect); conf.put(Constants.TOPOLOGY_ID, topologyId); conf.setMessageTimeoutSecs(Integer.parseInt(properties.getProperty(Constants.LOG_MESSAGE_TIMEOUT))); //conf.setMaxSpoutPending(30); conf.setDebug(true); conf.setNumWorkers(Integer.parseInt(properties.getProperty(Constants.LOG_NUMWORKERS))); if (runAsLocal) { conf.setMaxTaskParallelism(10); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(topologyName, conf, topology); } else { StormSubmitter.submitTopology(topologyName, conf, topology); } }
Example 5
Source File: MultiSpoutExclamationTopology.java From incubator-heron with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("word0", new TestWordSpout(), 2); builder.setSpout("word1", new TestWordSpout(), 2); builder.setSpout("word2", new TestWordSpout(), 2); builder.setBolt("exclaim1", new ExclamationBolt(), 2) .shuffleGrouping("word0") .shuffleGrouping("word1") .shuffleGrouping("word2"); Config conf = new Config(); conf.setDebug(true); conf.setMaxSpoutPending(10); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError"); if (args != null && args.length > 0) { conf.setNumWorkers(3); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { LocalCluster cluster = new LocalCluster(); cluster.submitTopology("test", conf, builder.createTopology()); Utils.sleep(10000); cluster.killTopology("test"); cluster.shutdown(); } }
Example 6
Source File: StreamToEs.java From elasticsearch-hadoop with Apache License 2.0 | 6 votes |
public static void submitJob(String principal, String keytab, String esNodes) throws Exception { List doc1 = Collections.singletonList("{\"reason\" : \"business\",\"airport\" : \"SFO\"}"); List doc2 = Collections.singletonList("{\"participants\" : 5,\"airport\" : \"OTP\"}"); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("Input", new TestSpout(ImmutableList.of(doc1, doc2), new Fields("json"), true)); builder.setBolt("ES", new EsBolt("storm-test")) .shuffleGrouping("Input") .addConfiguration(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 2); // Nimbus needs to be started with the cred renewer and credentials plugins set in its config file Config conf = new Config(); List<Object> plugins = new ArrayList<Object>(); plugins.add(AutoElasticsearch.class.getName()); conf.put(Config.TOPOLOGY_AUTO_CREDENTIALS, plugins); conf.put(ConfigurationOptions.ES_NODES, esNodes); conf.put(ConfigurationOptions.ES_SECURITY_AUTHENTICATION, "kerberos"); conf.put(ConfigurationOptions.ES_NET_SPNEGO_AUTH_ELASTICSEARCH_PRINCIPAL, "HTTP/[email protected]"); conf.put(ConfigurationOptions.ES_INPUT_JSON, "true"); StormSubmitter.submitTopology("test-run", conf, builder.createTopology()); }
Example 7
Source File: StatisticTopology.java From storm-statistic with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); /** * 设置spout和bolt的dag(有向无环图) */ KafkaSpout kafkaSpout = createKafkaSpout(); builder.setSpout("id_kafka_spout", kafkaSpout); builder.setBolt("id_convertIp_bolt", new ConvertIPBolt()).shuffleGrouping("id_kafka_spout"); // 通过不同的数据流转方式,来指定数据的上游组件 builder.setBolt("id_statistic_bolt", new StatisticBolt()).shuffleGrouping("id_convertIp_bolt"); // 通过不同的数据流转方式,来指定数据的上游组件 // 使用builder构建topology StormTopology topology = builder.createTopology(); String topologyName = KafkaStormTopology.class.getSimpleName(); // 拓扑的名称 Config config = new Config(); // Config()对象继承自HashMap,但本身封装了一些基本的配置 // 启动topology,本地启动使用LocalCluster,集群启动使用StormSubmitter if (args == null || args.length < 1) { // 没有参数时使用本地模式,有参数时使用集群模式 LocalCluster localCluster = new LocalCluster(); // 本地开发模式,创建的对象为LocalCluster localCluster.submitTopology(topologyName, config, topology); } else { StormSubmitter.submitTopology(topologyName, config, topology); } }
Example 8
Source File: TridentReach.java From storm-net-adapter with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Config conf = new Config(); StormSubmitter.submitTopology("reach", conf, buildTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { Thread.sleep(2000); System.out.println("REACH: " + drpc.execute("reach", "aaa")); System.out.println("REACH: " + drpc.execute("reach", "foo.com/blog/1")); System.out.println("REACH: " + drpc.execute("reach", "engineering.twitter.com/blog/5")); } }
Example 9
Source File: App.java From java-study with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // TODO Auto-generated method stub //定义一个拓扑 TopologyBuilder builder=new TopologyBuilder(); builder.setSpout(str1, new TestSpout()); builder.setBolt(str2, new TestBolt()).shuffleGrouping(str1); Config conf = new Config(); conf.put("test", "test"); try{ //运行拓扑 if(args !=null&&args.length>0){ //有参数时,表示向集群提交作业,并把第一个参数当做topology名称 System.out.println("远程模式"); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else{//没有参数时,本地提交 //启动本地模式 System.out.println("本地模式"); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("111" ,conf, builder.createTopology() ); // Thread.sleep(2000); // //关闭本地集群 // cluster.shutdown(); } }catch (Exception e){ e.printStackTrace(); } }
Example 10
Source File: MysqlExtractorTopology.java From DBus with Apache License 2.0 | 5 votes |
public void buildTopology(String[] args) { //TODO if (parseCommandArgs(args) != 0) { return; } TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("CanalClientSpout", new CanalClientSpout(), 1); builder.setBolt("KafkaProducerBolt", new KafkaProducerBolt(), 1).shuffleGrouping("CanalClientSpout"); Config conf = new Config(); conf.put(Constants.ZOOKEEPER_SERVERS, zkServers); conf.put(Constants.EXTRACTOR_TOPOLOGY_ID, extractorTopologyId); logger.info(Constants.ZOOKEEPER_SERVERS + "=" + zkServers); logger.info(Constants.EXTRACTOR_TOPOLOGY_ID + "=" + extractorTopologyId); conf.setNumWorkers(1); conf.setMaxSpoutPending(50); conf.setMessageTimeoutSecs(120); if (!runAsLocal) { conf.setDebug(false); try { //StormSubmitter.submitTopology("extractorTopologyId", conf, builder.createTopology()); StormSubmitter.submitTopology(extractorTopologyId, conf, builder.createTopology()); } catch (Exception e) { e.printStackTrace(); } } else { conf.setDebug(false); LocalCluster cluster = new LocalCluster(); //cluster.submitTopology("extractorTopologyId", conf, builder.createTopology()); cluster.submitTopology(extractorTopologyId, conf, builder.createTopology()); } }
Example 11
Source File: ExclamationTopology.java From incubator-heron with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); int parallelism = 2; int spouts = parallelism; builder.setSpout("word", new TestWordSpout(Duration.ofMillis(50)), spouts); int bolts = 2 * parallelism; builder.setBolt("exclaim1", new ExclamationBolt(), bolts) .shuffleGrouping("word"); Config conf = new Config(); conf.setDebug(true); conf.setMaxSpoutPending(10); conf.setMessageTimeoutSecs(600); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, "-XX:+HeapDumpOnOutOfMemoryError"); if (args != null && args.length > 0) { conf.setNumWorkers(parallelism); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { System.out.println("Topology name not provided as an argument, running in simulator mode."); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("test", conf, builder.createTopology()); Utils.sleep(10000); cluster.killTopology("test"); cluster.shutdown(); } }
Example 12
Source File: ManualDRPC.java From storm-net-adapter with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); DRPCSpout spout = new DRPCSpout("exclamation"); builder.setSpout("drpc", spout); builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc"); builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim"); Config conf = new Config(); StormSubmitter.submitTopology("exclaim", conf, builder.createTopology()); try (DRPCClient drpc = DRPCClient.getConfiguredClient(conf)) { System.out.println(drpc.execute("exclamation", "aaa")); System.out.println(drpc.execute("exclamation", "bbb")); } }
Example 13
Source File: TopologyApp.java From springBoot-study with Apache License 2.0 | 5 votes |
public void runStorm(String[] args) { // 定义一个拓扑 TopologyBuilder builder = new TopologyBuilder(); // 设置1个Executeor(线程),默认一个 builder.setSpout(Constants.KAFKA_SPOUT, new KafkaInsertDataSpout(), 1); // shuffleGrouping:表示是随机分组 // 设置1个Executeor(线程),和两个task builder.setBolt(Constants.INSERT_BOLT, new InsertBolt(), 1).setNumTasks(1).shuffleGrouping(Constants.KAFKA_SPOUT); Config conf = new Config(); //设置一个应答者 conf.setNumAckers(1); //设置一个work conf.setNumWorkers(3); try { // 有参数时,表示向集群提交作业,并把第一个参数当做topology名称 // 没有参数时,本地提交 if (args != null && args.length > 0) { logger.info("运行远程模式"); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { // 启动本地模式 logger.info("运行本地模式"); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("TopologyApp", conf, builder.createTopology()); } } catch (Exception e) { logger.error("storm启动失败!程序退出!",e); System.exit(1); } logger.info("storm启动成功..."); }
Example 14
Source File: DBusRouterTopology.java From DBus with Apache License 2.0 | 5 votes |
private void start(StormTopology topology, boolean runAsLocal) throws Exception { Config conf = new Config(); conf.put(com.creditease.dbus.commons.Constants.ZOOKEEPER_SERVERS, zkConnect); conf.put(Constants.TOPOLOGY_ID, topologyId); conf.put(Constants.TOPOLOGY_ALIAS, alias); conf.put(Constants.ROUTER_PROJECT_NAME, projectName); String workerChildOpts = routerConf.getProperty(DBusRouterConstants.STORM_TOPOLOGY_WORKER_CHILDOPTS, "-Xmx2g"); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, workerChildOpts); int msgTimeout = Integer.valueOf(routerConf.getProperty(DBusRouterConstants.STORM_MESSAGE_TIMEOUT, "10")); conf.setMessageTimeoutSecs(msgTimeout); int maxSpoutPending = Integer.valueOf(routerConf.getProperty(DBusRouterConstants.STORM_MAX_SPOUT_PENDING, "100")); conf.setMaxSpoutPending(maxSpoutPending); conf.setDebug(true); int numWorks = Integer.valueOf(routerConf.getProperty(DBusRouterConstants.STORM_NUM_WORKS, "1")); conf.setNumWorkers(numWorks); if (runAsLocal) { conf.setMaxTaskParallelism(10); LocalCluster cluster = new LocalCluster(); cluster.submitTopology(topologyName, conf, topology); } else { StormSubmitter.submitTopology(topologyName, conf, topology); } }
Example 15
Source File: KafkaStormWordCountTopology.java From Building-Data-Streaming-Applications-with-Apache-Kafka with MIT License | 5 votes |
public static void main(String[] args) throws Exception { String zkConnString = "localhost:2181"; String topic = "words"; BrokerHosts hosts = new ZkHosts(zkConnString); SpoutConfig kafkaSpoutConfig = new SpoutConfig(hosts, topic, "/" + topic, "wordcountID"); kafkaSpoutConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime(); kafkaSpoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); TopologyBuilder topologyBuilder = new TopologyBuilder(); topologyBuilder.setSpout("kafkaspout", new KafkaSpout(kafkaSpoutConfig)); topologyBuilder.setBolt("stringsplit", new StringToWordsSpliterBolt()).shuffleGrouping("kafkaspout"); topologyBuilder.setBolt("counter", new WordCountCalculatorBolt()).shuffleGrouping("stringsplit"); Config config = new Config(); config.setDebug(true); if (args != null && args.length > 1) { config.setNumWorkers(3); StormSubmitter.submitTopology(args[1], config, topologyBuilder.createTopology()); } else { // Cap the maximum number of executors that can be spawned // for a component to 3 config.setMaxTaskParallelism(3); // LocalCluster is used to run locally LocalCluster cluster = new LocalCluster(); cluster.submitTopology("KafkaLocal", config, topologyBuilder.createTopology()); // sleep try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block cluster.killTopology("KafkaToplogy"); cluster.shutdown(); } cluster.shutdown(); } }
Example 16
Source File: StormKafkaProcess.java From BigData with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws InterruptedException, InvalidTopologyException, AuthorizationException, AlreadyAliveException { String topologyName = "TSAS";// 元组名 // Zookeeper主机地址,会自动选取其中一个 ZkHosts zkHosts = new ZkHosts("192.168.230.128:2181,192.168.230.129:2181,192.168.230.131:2181"); String topic = "trademx"; String zkRoot = "/storm";// storm在Zookeeper上的根路径 String id = "tsaPro"; // 创建SpoutConfig对象 SpoutConfig spontConfig = new SpoutConfig(zkHosts, topic, zkRoot, id); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("kafka", new KafkaSpout(spontConfig), 2); builder.setBolt("AccBolt", new AccBolt()).shuffleGrouping("kafka"); builder.setBolt("ToDbBolt", new ToDbBolt()).shuffleGrouping("AccBolt"); Config config = new Config(); config.setDebug(false); if (args.length == 0) { // 本地运行,用于测试 LocalCluster localCluster = new LocalCluster(); localCluster.submitTopology(topologyName, config, builder.createTopology()); Thread.sleep(1000 * 3600); localCluster.killTopology(topologyName); localCluster.shutdown(); } else { // 提交至集群运行 StormSubmitter.submitTopology(topologyName, config, builder.createTopology()); } }
Example 17
Source File: App.java From springBoot-study with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // TODO Auto-generated method stub //定义一个拓扑 TopologyBuilder builder=new TopologyBuilder(); builder.setSpout(str1, new TestSpout()); builder.setBolt(str2, new TestBolt()).shuffleGrouping(str1); Config conf = new Config(); conf.put("test", "test"); try{ //运行拓扑 if(args !=null&&args.length>0){ //有参数时,表示向集群提交作业,并把第一个参数当做topology名称 System.out.println("远程模式"); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else{//没有参数时,本地提交 //启动本地模式 System.out.println("本地模式"); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("111" ,conf, builder.createTopology() ); // Thread.sleep(2000); // //关闭本地集群 // cluster.shutdown(); } }catch (Exception e){ e.printStackTrace(); } }
Example 18
Source File: IPFraudDetectionTopology.java From Building-Data-Streaming-Applications-with-Apache-Kafka with MIT License | 4 votes |
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException { Intialize(args[0]); logger.info("Successfully loaded Configuration "); BrokerHosts hosts = new ZkHosts(zkhost); SpoutConfig spoutConfig = new SpoutConfig(hosts, inputTopic, "/" + KafkaBroker, consumerGroup); spoutConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); spoutConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime(); KafkaSpout kafkaSpout = new KafkaSpout(spoutConfig); String[] partNames = {"status_code"}; String[] colNames = {"date", "request_url", "protocol_type", "status_code"}; DelimitedRecordHiveMapper mapper = new DelimitedRecordHiveMapper().withColumnFields(new Fields(colNames)) .withPartitionFields(new Fields(partNames)); HiveOptions hiveOptions; //make sure you change batch size and all paramtere according to requirement hiveOptions = new HiveOptions(metaStoreURI, dbName, tblName, mapper).withTxnsPerBatch(250).withBatchSize(2) .withIdleTimeout(10).withCallTimeout(10000000); logger.info("Creating Storm Topology"); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("KafkaSpout", kafkaSpout, 1); builder.setBolt("frauddetect", new FraudDetectorBolt()).shuffleGrouping("KafkaSpout"); builder.setBolt("KafkaOutputBolt", new IPFraudKafkaBolt(zkhost, "kafka.serializer.StringEncoder", KafkaBroker, outputTopic), 1) .shuffleGrouping("frauddetect"); builder.setBolt("HiveOutputBolt", new IPFraudHiveBolt(), 1).shuffleGrouping("frauddetect"); builder.setBolt("HiveBolt", new HiveBolt(hiveOptions)).shuffleGrouping("HiveOutputBolt"); Config conf = new Config(); if (args != null && args.length > 1) { conf.setNumWorkers(3); logger.info("Submiting topology to storm cluster"); StormSubmitter.submitTopology(args[1], conf, builder.createTopology()); } else { // Cap the maximum number of executors that can be spawned // for a component to 3 conf.setMaxTaskParallelism(3); // LocalCluster is used to run locally LocalCluster cluster = new LocalCluster(); logger.info("Submitting topology to local cluster"); cluster.submitTopology("KafkaLocal", conf, builder.createTopology()); // sleep try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block logger.error("Exception ocuured" + e); cluster.killTopology("KafkaToplogy"); logger.info("Shutting down cluster"); cluster.shutdown(); } cluster.shutdown(); } }
Example 19
Source File: StormUtils.java From bullet-storm with Apache License 2.0 | 4 votes |
/** * This function can be used to wire up the source of the records to Bullet. The name of the last component in your * topology and the {@link TopologyBuilder} used to create your topology should be provided. That topology * will be wired up with Bullet reading from your component that produces the {@link com.yahoo.bullet.record.BulletRecord}. * * @param config The non-null, validated {@link BulletStormConfig} that contains the necessary configuration. * @param recordComponent The non-null name of the component used in your topology that is the source of records for Bullet. * @param builder The non-null {@link TopologyBuilder} that was used to create your topology. * @throws Exception if there were issues creating the topology. */ public static void submit(BulletStormConfig config, String recordComponent, TopologyBuilder builder) throws Exception { Objects.requireNonNull(config); Objects.requireNonNull(recordComponent); Objects.requireNonNull(builder); String name = config.getAs(BulletStormConfig.TOPOLOGY_NAME, String.class); Number querySpoutParallelism = config.getAs(BulletStormConfig.QUERY_SPOUT_PARALLELISM, Number.class); Number querySpoutCPULoad = config.getAs(BulletStormConfig.QUERY_SPOUT_CPU_LOAD, Number.class); Number querySpoutMemoryOnHeapLoad = config.getAs(BulletStormConfig.QUERY_SPOUT_MEMORY_ON_HEAP_LOAD, Number.class); Number querySpoutMemoryOffHeapLoad = config.getAs(BulletStormConfig.QUERY_SPOUT_MEMORY_OFF_HEAP_LOAD, Number.class); // Tick parallelism must be 1 otherwise multiple ticks will get delivered to a component Number tickSpoutParallelism = BulletStormConfig.TICK_SPOUT_PARALLELISM; Number tickSpoutCPULoad = config.getAs(BulletStormConfig.TICK_SPOUT_CPU_LOAD, Number.class); Number tickSpoutMemoryOnheapLoad = config.getAs(BulletStormConfig.TICK_SPOUT_MEMORY_ON_HEAP_LOAD, Number.class); Number tickSpoutMemoryOffHeapLoad = config.getAs(BulletStormConfig.TICK_SPOUT_MEMORY_OFF_HEAP_LOAD, Number.class); Number filterBoltParallelism = config.getAs(BulletStormConfig.FILTER_BOLT_PARALLELISM, Number.class); Number filterBoltCPULoad = config.getAs(BulletStormConfig.FILTER_BOLT_CPU_LOAD, Number.class); Number filterBoltMemoryOnheapLoad = config.getAs(BulletStormConfig.FILTER_BOLT_MEMORY_ON_HEAP_LOAD, Number.class); Number filterBoltMemoryOffHeapLoad = config.getAs(BulletStormConfig.FILTER_BOLT_MEMORY_OFF_HEAP_LOAD, Number.class); Number joinBoltParallelism = config.getAs(BulletStormConfig.JOIN_BOLT_PARALLELISM, Number.class); Number joinBoltCPULoad = config.getAs(BulletStormConfig.JOIN_BOLT_CPU_LOAD, Number.class); Number joinBoltMemoryOnHeapLoad = config.getAs(BulletStormConfig.JOIN_BOLT_MEMORY_ON_HEAP_LOAD, Number.class); Number joinBoltMemoryOffHeapLoad = config.getAs(BulletStormConfig.JOIN_BOLT_MEMORY_OFF_HEAP_LOAD, Number.class); Number resultBoltParallelism = config.getAs(BulletStormConfig.RESULT_BOLT_PARALLELISM, Number.class); Number resultBoltCPULoad = config.getAs(BulletStormConfig.RESULT_BOLT_CPU_LOAD, Number.class); Number resultBoltMemoryOnHeapLoad = config.getAs(BulletStormConfig.RESULT_BOLT_MEMORY_ON_HEAP_LOAD, Number.class); Number resultBoltMemoryOffHeapLoad = config.getAs(BulletStormConfig.RESULT_BOLT_MEMORY_OFF_HEAP_LOAD, Number.class); Number loopBoltParallelism = config.getAs(BulletStormConfig.LOOP_BOLT_PARALLELISM, Number.class); Number loopBoltCPULoad = config.getAs(BulletStormConfig.LOOP_BOLT_CPU_LOAD, Number.class); Number loopBoltMemoryOnHeapLoad = config.getAs(BulletStormConfig.LOOP_BOLT_MEMORY_ON_HEAP_LOAD, Number.class); Number loopBoltMemoryOffHeapLoad = config.getAs(BulletStormConfig.LOOP_BOLT_MEMORY_OFF_HEAP_LOAD, Number.class); builder.setSpout(QUERY_COMPONENT, new QuerySpout(config), querySpoutParallelism) .setCPULoad(querySpoutCPULoad).setMemoryLoad(querySpoutMemoryOnHeapLoad, querySpoutMemoryOffHeapLoad); builder.setSpout(TICK_COMPONENT, new TickSpout(config), tickSpoutParallelism) .setCPULoad(tickSpoutCPULoad).setMemoryLoad(tickSpoutMemoryOnheapLoad, tickSpoutMemoryOffHeapLoad); // Hook in the source of the BulletRecords builder.setBolt(FILTER_COMPONENT, new FilterBolt(recordComponent, config), filterBoltParallelism) .shuffleGrouping(recordComponent) .allGrouping(QUERY_COMPONENT, QUERY_STREAM) .allGrouping(QUERY_COMPONENT, METADATA_STREAM) .allGrouping(TICK_COMPONENT, TICK_STREAM) .setCPULoad(filterBoltCPULoad).setMemoryLoad(filterBoltMemoryOnheapLoad, filterBoltMemoryOffHeapLoad); builder.setBolt(JOIN_COMPONENT, new JoinBolt(config), joinBoltParallelism) .fieldsGrouping(QUERY_COMPONENT, QUERY_STREAM, new Fields(ID_FIELD)) .fieldsGrouping(QUERY_COMPONENT, METADATA_STREAM, new Fields(ID_FIELD)) .fieldsGrouping(FILTER_COMPONENT, DATA_STREAM, new Fields(ID_FIELD)) .allGrouping(TICK_COMPONENT, TICK_STREAM) .setCPULoad(joinBoltCPULoad).setMemoryLoad(joinBoltMemoryOnHeapLoad, joinBoltMemoryOffHeapLoad); builder.setBolt(TopologyConstants.RESULT_COMPONENT, new ResultBolt(config), resultBoltParallelism) .shuffleGrouping(JOIN_COMPONENT, RESULT_STREAM) .setCPULoad(resultBoltCPULoad).setMemoryLoad(resultBoltMemoryOnHeapLoad, resultBoltMemoryOffHeapLoad); // Hook in the Loop Bolt only if windowing is enabled boolean isWindowingDisabled = config.getAs(BulletConfig.WINDOW_DISABLE, Boolean.class); if (isWindowingDisabled) { log.info("Windowing is disabled. Skipping hooking in the Loop Bolt..."); } else { builder.setBolt(LOOP_COMPONENT, new LoopBolt(config), loopBoltParallelism) .shuffleGrouping(JOIN_COMPONENT, FEEDBACK_STREAM) .setCPULoad(loopBoltCPULoad).setMemoryLoad(loopBoltMemoryOnHeapLoad, loopBoltMemoryOffHeapLoad); } Config stormConfig = new Config(); // Metrics Boolean enableMetrics = (Boolean) config.get(BulletStormConfig.TOPOLOGY_METRICS_ENABLE); if (enableMetrics) { List<String> classNames = config.getAs(BulletStormConfig.TOPOLOGY_METRICS_CLASSES, List.class); classNames.forEach(className -> ReflectionUtils.registerMetricsConsumer(className, stormConfig, config)); } // Put the rest of the other possible custom Storm settings without checking their types stormConfig.putAll(config.getCustomStormSettings()); StormSubmitter.submitTopology(name, stormConfig, builder.createTopology()); }
Example 20
Source File: CustomGroupingTopology.java From incubator-heron with Apache License 2.0 | 3 votes |
public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("word", new TestWordSpout(), 2); builder.setBolt("mybolt", new MyBolt(), 2) .customGrouping("word", new MyCustomStreamGrouping()); Config conf = new Config(); conf.setNumWorkers(2); StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); }