backtype.storm.tuple.Fields Java Examples
The following examples show how to use
backtype.storm.tuple.Fields.
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: TridentWordCount.java From jstorm with Apache License 2.0 | 6 votes |
public static StormTopology buildTopology(LocalDRPC drpc) { FixedBatchSpout spout = new FixedBatchSpout(new Fields("sentence"), 3, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person")); spout.setCycle(true); TridentTopology topology = new TridentTopology(); TridentState wordCounts = topology.newStream("spout1", spout).parallelismHint(16) .each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word")) .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")) .parallelismHint(16); topology.newDRPCStream("words", drpc).each(new Fields("args"), new Split(), new Fields("word")) .groupBy(new Fields("word")) .stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")) .each(new Fields("count"), new FilterNull()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); return topology.build(); }
Example #2
Source File: BatchAckerTest.java From jstorm with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException { Config conf = JStormHelper.getConfig(args); int spoutParallelism = JStormUtils.parseInt(conf.get(SPOUT_PARALLELISM_HINT), 1); int splitParallelism = JStormUtils.parseInt(conf.get(SPLIT_PARALLELISM_HINT), 2); int countParallelism = JStormUtils.parseInt(conf.get(COUNT_PARALLELISM_HINT), 2); boolean isValueSpout = JStormUtils.parseBoolean(conf.get("is.value.spout"), false); TransactionTopologyBuilder builder = new TransactionTopologyBuilder(); if (isValueSpout) builder.setSpoutWithAck("spout", new BatchAckerValueSpout(), spoutParallelism); else builder.setSpoutWithAck("spout", new BatchAckerSpout(), spoutParallelism); builder.setBoltWithAck("split", new BatchAckerSplit(), splitParallelism).localOrShuffleGrouping("spout");; builder.setBoltWithAck("count", new BatchAckerCount(), countParallelism).fieldsGrouping("split", new Fields("word")); String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\."); String topologyName = className[className.length - 1]; StormSubmitter.submitTopology(topologyName, conf, builder.createTopology()); }
Example #3
Source File: KvStatefulBoltExecutor.java From jstorm with Apache License 2.0 | 6 votes |
@Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { createState(context); prepare(stormConf, context, collector, keyRangeState); Map<GlobalStreamId, Grouping> sources = context.getSources(context.getThisComponentId()); for (Map.Entry<GlobalStreamId, Grouping> entry : sources.entrySet()) { GlobalStreamId stream = entry.getKey(); Grouping grouping = entry.getValue(); Grouping._Fields groupingFields = Thrift.groupingType(grouping); if (Grouping._Fields.FIELDS.equals(groupingFields)) { Fields fields = new Fields(Thrift.fieldGrouping(grouping)); fieldGrouping.put(stream.get_streamId(), fields); } } LOG.info("Source fieldgrouping streams: {}", fieldGrouping); }
Example #4
Source File: WorkerTopologyContext.java From incubator-heron with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public WorkerTopologyContext( StormTopology topology, Map stormConf, Map<Integer, String> taskToComponent, Map<String, List<Integer>> componentToSortedTasks, Map<String, Map<String, Fields>> componentToStreamToFields, String stormId, String codeDir, String pidDir, Integer workerPort, List<Integer> workerTasks, Map<String, Object> defaultResources, Map<String, Object> userResources ) { super(topology, stormConf, taskToComponent, componentToSortedTasks, componentToStreamToFields, stormId); throw new RuntimeException("WorkerTopologyContext should never be init this way"); }
Example #5
Source File: TridentSlidingCountWindowTest.java From jstorm with Apache License 2.0 | 6 votes |
@Test public void testTridentSlidingCountWindow() { WindowsStoreFactory windowsStoreFactory = new InMemoryWindowsStoreFactory(); FixedLimitBatchSpout spout = new FixedLimitBatchSpout(SPOUT_LIMIT, new Fields("sentence"), SPOUT_BATCH_SIZE, new Values("the cow jumped over the moon"), new Values("the man went to the store and bought some candy"), new Values("four score and seven years ago"), new Values("how many apples can you eat"), new Values("to be or not to be the person")); TridentTopology tridentTopology = new TridentTopology(); Stream stream = tridentTopology.newStream("spout1", spout).parallelismHint(16) .each(new Fields("sentence"), new Split(), new Fields("word")) .window(windowConfig, windowsStoreFactory, new Fields("word"), new CountAsAggregator(), new Fields("count")) .peek(new ValidateConsumer()); Map config = new HashMap(); config.put(Config.TOPOLOGY_NAME, "TridentSlidingCountWindowTest"); JStormUnitTestRunner.submitTopology(tridentTopology.build(), null, 120, null); }
Example #6
Source File: HBaseAuditLogApplication.java From eagle with Apache License 2.0 | 6 votes |
@Override public StormTopology execute(Config config, StormEnvironment environment) { TopologyBuilder builder = new TopologyBuilder(); KafkaSpoutProvider provider = new KafkaSpoutProvider(); IRichSpout spout = provider.getSpout(config); HBaseAuditLogParserBolt bolt = new HBaseAuditLogParserBolt(); int numOfSpoutTasks = config.getInt(SPOUT_TASK_NUM); int numOfParserTasks = config.getInt(PARSER_TASK_NUM); int numOfJoinTasks = config.getInt(JOIN_TASK_NUM); int numOfSinkTasks = config.getInt(SINK_TASK_NUM); builder.setSpout("ingest", spout, numOfSpoutTasks); BoltDeclarer boltDeclarer = builder.setBolt("parserBolt", bolt, numOfParserTasks); boltDeclarer.fieldsGrouping("ingest", new Fields(StringScheme.STRING_SCHEME_KEY)); HBaseResourceSensitivityDataJoinBolt joinBolt = new HBaseResourceSensitivityDataJoinBolt(config); BoltDeclarer joinBoltDeclarer = builder.setBolt("joinBolt", joinBolt, numOfJoinTasks); joinBoltDeclarer.fieldsGrouping("parserBolt", new Fields("f1")); StormStreamSink sinkBolt = environment.getStreamSink("hbase_audit_log_stream",config); BoltDeclarer kafkaBoltDeclarer = builder.setBolt("kafkaSink", sinkBolt, numOfSinkTasks); kafkaBoltDeclarer.fieldsGrouping("joinBolt", new Fields("user")); return builder.createTopology(); }
Example #7
Source File: WordCount.java From storm-benchmark with Apache License 2.0 | 6 votes |
@Override public StormTopology getTopology(Config config) { final int spoutNum = BenchmarkUtils.getInt(config, SPOUT_NUM, DEFAULT_SPOUT_NUM); final int spBoltNum = BenchmarkUtils.getInt(config, SPLIT_NUM, DEFAULT_SPLIT_BOLT_NUM); final int cntBoltNum = BenchmarkUtils.getInt(config, COUNT_NUM, DEFAULT_COUNT_BOLT_NUM); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout(SPOUT_ID, spout, spoutNum); builder.setBolt(SPLIT_ID, new SplitSentence(), spBoltNum).localOrShuffleGrouping( SPOUT_ID); builder.setBolt(COUNT_ID, new Count(), cntBoltNum).fieldsGrouping(SPLIT_ID, new Fields(SplitSentence.FIELDS)); return builder.createTopology(); }
Example #8
Source File: TridentReach.java From jstorm with Apache License 2.0 | 6 votes |
public static void test() { TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("spout", new InOrderSpout(), 8); builder.setBolt("count", new Check(), 8).fieldsGrouping("spout", new Fields("c1")); conf.setMaxSpoutPending(20); String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\."); String topologyName = className[className.length - 1]; if (isLocal) { drpc = new LocalDRPC(); } try { JStormHelper.runTopology(buildTopology(drpc), topologyName, conf, 60, new DrpcValidator(), isLocal); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Assert.fail("Failed"); } }
Example #9
Source File: WordCountTopology.java From jstorm with Apache License 2.0 | 6 votes |
public static void test() { TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("spout", new RandomSentenceSpout(), 5); builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout"); builder.setBolt("count", new WordCount(), 12).fieldsGrouping("split", new Fields("word")); Config conf = new Config(); conf.setDebug(true); String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\."); String topologyName = className[className.length - 1]; try { JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Assert.fail("Failed"); } }
Example #10
Source File: ClojureSpout.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { for (String stream : _fields.keySet()) { StreamInfo info = _fields.get(stream); declarer.declareStream(stream, info.is_direct(), new Fields(info.get_output_fields())); } }
Example #11
Source File: SparkRunningJobApp.java From eagle with Apache License 2.0 | 5 votes |
@Override public StormTopology execute(Config config, StormEnvironment environment) { //1. trigger prepare conf SparkRunningJobAppConfig sparkRunningJobAppConfig = SparkRunningJobAppConfig.newInstance(config); //2. prepare topology TopologyBuilder topologyBuilder = new TopologyBuilder(); final String spoutName = SparkRunningJobAppConfig.JOB_FETCH_SPOUT_NAME; final String boltName = SparkRunningJobAppConfig.JOB_PARSE_BOLT_NAME; int parallelism = sparkRunningJobAppConfig.getJobExtractorConfig().jobFetchSpoutParallism; int tasks = sparkRunningJobAppConfig.getJobExtractorConfig().jobFetchSpoutTasksNum; if (parallelism > tasks) { parallelism = tasks; } topologyBuilder.setSpout( spoutName, new SparkRunningJobFetchSpout( sparkRunningJobAppConfig.getJobExtractorConfig(), sparkRunningJobAppConfig.getEndpointConfig(), sparkRunningJobAppConfig.getZkStateConfig()), parallelism ).setNumTasks(tasks); parallelism = sparkRunningJobAppConfig.getJobExtractorConfig().jobParseBoltParallism; tasks = sparkRunningJobAppConfig.getJobExtractorConfig().jobParseBoltTasksNum; if (parallelism > tasks) { parallelism = tasks; } topologyBuilder.setBolt(boltName, new SparkRunningJobParseBolt( sparkRunningJobAppConfig.getZkStateConfig(), sparkRunningJobAppConfig.getEagleServiceConfig(), sparkRunningJobAppConfig.getEndpointConfig(), sparkRunningJobAppConfig.getJobExtractorConfig()), parallelism).setNumTasks(tasks).fieldsGrouping(spoutName, new Fields("appId")); return topologyBuilder.createTopology(); }
Example #12
Source File: Node.java From jstorm with Apache License 2.0 | 5 votes |
public Node(String streamId, String name, Fields allOutputFields) { this.nodeId = UUID.randomUUID().toString(); this.allOutputFields = allOutputFields; this.streamId = streamId; this.name = name; this.creationIndex = INDEX.incrementAndGet(); }
Example #13
Source File: Latency.java From flink-perf with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ParameterTool pt = ParameterTool.fromArgs(args); int par = pt.getInt("para"); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("source0", new Generator(pt), pt.getInt("sourceParallelism")); int i = 0; for(; i < pt.getInt("repartitions", 1) - 1;i++) { System.out.println("adding source"+i+" --> source"+(i+1)); builder.setBolt("source"+(i+1), new PassThroughBolt(pt), pt.getInt("sinkParallelism")).fieldsGrouping("source" + i, new Fields("id")); } System.out.println("adding final source"+i+" --> sink"); builder.setBolt("sink", new Sink(pt), pt.getInt("sinkParallelism")).fieldsGrouping("source"+i, new Fields("id")); Config conf = new Config(); conf.setDebug(false); //System.exit(1); if (!pt.has("local")) { conf.setNumWorkers(par); StormSubmitter.submitTopologyWithProgressBar("throughput-"+pt.get("name", "no_name"), conf, builder.createTopology()); } else { conf.setMaxTaskParallelism(par); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("throughput", conf, builder.createTopology()); Thread.sleep(300000); cluster.shutdown(); } }
Example #14
Source File: ContextMaker.java From jstorm with Apache License 2.0 | 5 votes |
public WorkerTopologyContext makeWorkerTopologyContext(StormTopology topology) { Map stormConf = workerData.getStormConf(); String topologyId = workerData.getTopologyId(); HashMap<String, Map<String, Fields>> componentToStreamToFields = workerData.generateComponentToStreamToFields(topology); return new WorkerTopologyContext(topology, stormConf, workerData.getTasksToComponent(), workerData.getComponentToSortedTasks(), componentToStreamToFields, topologyId, resourcePath, workerId, workerData.getPort(), workerTasks, workerData.getDefaultResources(), workerData.getUserResources()); }
Example #15
Source File: TransactionalWordsTest.java From jstorm with Apache License 2.0 | 5 votes |
@Test public void test_transaction_word() { try { MemoryTransactionalSpout spout = new MemoryTransactionalSpout(DATA, new Fields("word"), PARTITION_TAKE_PER_BATCH); TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder("top-n-words", "spout", spout, 2); builder.setBolt("count", new KeyedCountUpdater(), 5).fieldsGrouping("spout", new Fields("word")); builder.setBolt("bucketize", new Bucketize()).shuffleGrouping("count"); builder.setBolt("buckets", new BucketCountUpdater(), 5).fieldsGrouping("bucketize", new Fields("bucket")); LocalCluster cluster = new LocalCluster(); Config config = new Config(); config.setDebug(true); config.setMaxSpoutPending(3); cluster.submitTopology("top-n-topology", config, builder.buildTopology()); JStormUtils.sleepMs(60 * 1000); assertEquals(false, outOfOrder.get() ); assertNotSame(0, receiveCounter1.get()); assertNotSame(0, receiveCounter2.get()); //cluster.killTopology("top-n-topology"); //cluster.shutdown(); } catch (Exception e) { e.printStackTrace(); Assert.fail("Failed to run simple transaction"); } }
Example #16
Source File: ClojureBolt.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { for (String stream : _fields.keySet()) { StreamInfo info = _fields.get(stream); declarer.declareStream(stream, info.is_direct(), new Fields(info.get_output_fields())); } }
Example #17
Source File: GeneralTopologyContext.java From jstorm with Apache License 2.0 | 5 votes |
/** * Gets the declared output fields for the specified component/stream. */ public Fields getComponentOutputFields(String componentId, String streamId) { Fields ret = _componentToStreamToFields.get(componentId).get(streamId); if (ret == null) { throw new IllegalArgumentException("No output fields defined for component:stream " + componentId + ":" + streamId); } return ret; }
Example #18
Source File: FileReadSpoutTest.java From storm-benchmark with Apache License 2.0 | 5 votes |
@Test public void shouldDeclareOutputFields() { FileReadSpout spout = new FileReadSpout(false, reader); spout.declareOutputFields(declarer); verify(declarer, times(1)).declare(any(Fields.class)); }
Example #19
Source File: CorrelationSpout.java From eagle with Apache License 2.0 | 5 votes |
/** * the only output field is for StreamEvent. * * @param declarer */ @Override public void declareOutputFields(OutputFieldsDeclarer declarer) { for (int i = 0; i < numOfRouterBolts; i++) { String streamId = StreamIdConversion.generateStreamIdBetween(spoutName, routeBoltName + i); declarer.declareStream(streamId, new Fields(AlertConstants.FIELD_0)); LOG.info("declare stream between spout and streamRouterBolt " + streamId); } }
Example #20
Source File: Stream.java From jstorm with Apache License 2.0 | 5 votes |
@Override public Stream each(Fields inputFields, Function function, Fields functionFields) { projectionValidation(inputFields); return _topology.addSourcedNode(this, new ProcessorNode(_topology.getUniqueStreamId(), _name, TridentUtils.fieldsConcat(getOutputFields(), functionFields), functionFields, new EachProcessor(inputFields, function))); }
Example #21
Source File: Stream.java From jstorm with Apache License 2.0 | 5 votes |
public TridentState persistentAggregate(StateSpec spec, Fields inputFields, CombinerAggregator agg, Fields functionFields) { projectionValidation(inputFields); // replaces normal aggregation here with a global grouping because it needs to be consistent across batches return new ChainedAggregatorDeclarer(this, new GlobalAggScheme()) .aggregate(inputFields, agg, functionFields) .chainEnd() .partitionPersist(spec, functionFields, new CombinerAggStateUpdater(agg), functionFields); }
Example #22
Source File: FeatureGrouping.java From StormCV with Apache License 2.0 | 5 votes |
/** * Constructs a featureGrouping for the specified feature name. Features with this name will be routed * randomly. * @param featureName * @throws InstantiationException */ public FeatureGrouping(String featureName) throws InstantiationException{ this.featureName = featureName; FeatureSerializer serializer = new FeatureSerializer(); Fields fields = serializer.getFields(); indexes = new ArrayList<Integer>(); for(int i=0; i<fields.size(); i++){ if(fields.get(i).equals(FeatureSerializer.NAME)){ nameIndex = i; } } if(nameIndex == -1)throw new InstantiationException("No index found for feature name: "+featureName); }
Example #23
Source File: SalesTopology.java From storm-cassandra-cql with Apache License 2.0 | 5 votes |
public static StormTopology buildTopology() { LOG.info("Building topology."); TridentTopology topology = new TridentTopology(); SalesSpout spout = new SalesSpout(); Stream inputStream = topology.newStream("sales", spout); SalesMapper mapper = new SalesMapper(); inputStream.partitionPersist( new CassandraCqlIncrementalStateFactory<String, Number>(new Sum(), mapper), new Fields("price", "state", "product"), new CassandraCqlIncrementalStateUpdater<String, Number>()); return topology.build(); }
Example #24
Source File: TileGrouping.java From StormCV with Apache License 2.0 | 5 votes |
@Override public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { this.targetTasks = targetTasks; Fields tupleFields = context.getComponentOutputFields(stream); for(int i=0; i<tupleFields.size(); i++){ if(tupleFields.get(i).equals(CVParticleSerializer.STREAMID)){ streamIdIndex = i; }else if(tupleFields.get(i).equals(CVParticleSerializer.SEQUENCENR)){ sequenceNrIndex = i; } } }
Example #25
Source File: MasterBatchCoordinator.java From jstorm with Apache License 2.0 | 5 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { // in partitioned example, in case an emitter task receives a later transaction than it's emitted so far, // when it sees the earlier txid it should know to emit nothing declarer.declareStream(BATCH_STREAM_ID, new Fields("tx")); declarer.declareStream(COMMIT_STREAM_ID, new Fields("tx")); declarer.declareStream(SUCCESS_STREAM_ID, new Fields("tx")); }
Example #26
Source File: TridentMinMaxOfVehiclesTopology.java From jstorm with Apache License 2.0 | 5 votes |
/** * Creates a topology which demonstrates min/max operations on tuples of * stream which contain vehicle and driver fields with values * {@link TridentMinMaxOfVehiclesTopology.Vehicle} and * {@link TridentMinMaxOfVehiclesTopology.Driver} respectively. */ public static StormTopology buildVehiclesTopology() { Fields driverField = new Fields(Driver.FIELD_NAME); Fields vehicleField = new Fields(Vehicle.FIELD_NAME); Fields allFields = new Fields(Vehicle.FIELD_NAME, Driver.FIELD_NAME); FixedBatchSpout spout = new FixedBatchSpout(allFields, 10, Vehicle.generateVehicles(20)); spout.setCycle(true); TridentTopology topology = new TridentTopology(); Stream vehiclesStream = topology.newStream("spout1", spout).each(allFields, new Debug("##### vehicles")); Stream slowVehiclesStream = vehiclesStream.min(new SpeedComparator()).each(vehicleField, new Debug("#### slowest vehicle")); Stream slowDriversStream = slowVehiclesStream.project(driverField).each(driverField, new Debug("##### slowest driver")); vehiclesStream.max(new SpeedComparator()).each(vehicleField, new Debug("#### fastest vehicle")) .project(driverField).each(driverField, new Debug("##### fastest driver")); vehiclesStream.minBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField, new Debug("#### least efficient vehicle")); vehiclesStream.maxBy(Vehicle.FIELD_NAME, new EfficiencyComparator()).each(vehicleField, new Debug("#### most efficient vehicle")); return topology.build(); }
Example #27
Source File: TestPlannerSpout.java From jstorm with Apache License 2.0 | 4 votes |
public TestPlannerSpout(boolean isDistributed) { this(new Fields("field1", "field2"), isDistributed); }
Example #28
Source File: FastWordCountTransactionTimeWindowTopology.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("word")); }
Example #29
Source File: StockTicksSpout.java From hadoop-arch-book with Apache License 2.0 | 4 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) { outputFieldsDeclarer.declare(new Fields("tick")); }
Example #30
Source File: KeyedCountingBatchBolt.java From jstorm with Apache License 2.0 | 4 votes |
@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("tx", "key", "count")); }