add back missing multi-lang scripts
Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/9fad816f Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/9fad816f Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/9fad816f Branch: refs/heads/0.10.x-branch Commit: 9fad816fd5840d5ad7d2727db4c7dafe4f1355ba Parents: f7d2f7f Author: P. Taylor Goetz <ptgo...@gmail.com> Authored: Fri May 8 15:23:54 2015 -0400 Committer: P. Taylor Goetz <ptgo...@gmail.com> Committed: Fri May 8 15:23:54 2015 -0400 ---------------------------------------------------------------------- .../main/resources/resources/randomsentence.js | 93 ++++++++++++++++++++ .../main/resources/resources/splitsentence.py | 24 +++++ 2 files changed, 117 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/9fad816f/external/flux/flux-wrappers/src/main/resources/resources/randomsentence.js ---------------------------------------------------------------------- diff --git a/external/flux/flux-wrappers/src/main/resources/resources/randomsentence.js b/external/flux/flux-wrappers/src/main/resources/resources/randomsentence.js new file mode 100644 index 0000000..36fc5f5 --- /dev/null +++ b/external/flux/flux-wrappers/src/main/resources/resources/randomsentence.js @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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 for storm spout. Emits random sentences. + * The original class in java - storm.starter.spout.RandomSentenceSpout. + * + */ + +var storm = require('./storm'); +var Spout = storm.Spout; + + +var SENTENCES = [ + "the cow jumped over the moon", + "an apple a day keeps the doctor away", + "four score and seven years ago", + "snow white and the seven dwarfs", + "i am at two with nature"] + +function RandomSentenceSpout(sentences) { + Spout.call(this); + this.runningTupleId = 0; + this.sentences = sentences; + this.pending = {}; +}; + +RandomSentenceSpout.prototype = Object.create(Spout.prototype); +RandomSentenceSpout.prototype.constructor = RandomSentenceSpout; + +RandomSentenceSpout.prototype.getRandomSentence = function() { + return this.sentences[getRandomInt(0, this.sentences.length - 1)]; +} + +RandomSentenceSpout.prototype.nextTuple = function(done) { + var self = this; + var sentence = this.getRandomSentence(); + var tup = [sentence]; + var id = this.createNextTupleId(); + this.pending[id] = tup; + //This timeout can be removed if TOPOLOGY_SLEEP_SPOUT_WAIT_STRATEGY_TIME_MS is configured to 100 + setTimeout(function() { + self.emit({tuple: tup, id: id}, function(taskIds) { + self.log(tup + ' sent to task ids - ' + taskIds); + }); + done(); + },100); +} + +RandomSentenceSpout.prototype.createNextTupleId = function() { + var id = this.runningTupleId; + this.runningTupleId++; + return id; +} + +RandomSentenceSpout.prototype.ack = function(id, done) { + this.log('Received ack for - ' + id); + delete this.pending[id]; + done(); +} + +RandomSentenceSpout.prototype.fail = function(id, done) { + var self = this; + this.log('Received fail for - ' + id + '. Retrying.'); + this.emit({tuple: this.pending[id], id:id}, function(taskIds) { + self.log(self.pending[id] + ' sent to task ids - ' + taskIds); + }); + done(); +} + +/** + * Returns a random integer between min (inclusive) and max (inclusive) + */ +function getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +new RandomSentenceSpout(SENTENCES).run(); http://git-wip-us.apache.org/repos/asf/storm/blob/9fad816f/external/flux/flux-wrappers/src/main/resources/resources/splitsentence.py ---------------------------------------------------------------------- diff --git a/external/flux/flux-wrappers/src/main/resources/resources/splitsentence.py b/external/flux/flux-wrappers/src/main/resources/resources/splitsentence.py new file mode 100644 index 0000000..300105f --- /dev/null +++ b/external/flux/flux-wrappers/src/main/resources/resources/splitsentence.py @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# 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. +import storm + +class SplitSentenceBolt(storm.BasicBolt): + def process(self, tup): + words = tup.values[0].split(" ") + for word in words: + storm.emit([word]) + +SplitSentenceBolt().run() \ No newline at end of file