|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to you under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package ${package}; |
| 18 | + |
| 19 | +import org.apache.storm.topology.TopologyBuilder; |
| 20 | +import org.apache.storm.tuple.Fields; |
| 21 | +import org.apache.stormcrawler.ConfigurableTopology; |
| 22 | +import org.apache.stormcrawler.Constants; |
| 23 | +import org.apache.stormcrawler.bolt.FetcherBolt; |
| 24 | +import org.apache.stormcrawler.bolt.JSoupParserBolt; |
| 25 | +import org.apache.stormcrawler.bolt.SiteMapParserBolt; |
| 26 | +import org.apache.stormcrawler.bolt.URLPartitionerBolt; |
| 27 | +import org.apache.stormcrawler.solr.bolt.DeletionBolt; |
| 28 | +import org.apache.stormcrawler.solr.bolt.IndexerBolt; |
| 29 | +import org.apache.stormcrawler.solr.metrics.MetricsConsumer; |
| 30 | +import org.apache.stormcrawler.solr.persistence.SolrSpout; |
| 31 | +import org.apache.stormcrawler.solr.persistence.StatusUpdaterBolt; |
| 32 | + |
| 33 | +/** Dummy topology to play with the spouts and bolts on Solr */ |
| 34 | +public class CrawlTopology extends ConfigurableTopology { |
| 35 | + |
| 36 | + public static void main(String[] args) throws Exception { |
| 37 | + ConfigurableTopology.start(new CrawlTopology(), args); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected int run(String[] args) { |
| 42 | + TopologyBuilder builder = new TopologyBuilder(); |
| 43 | + |
| 44 | + builder.setSpout("spout", new SolrSpout()); |
| 45 | + |
| 46 | + builder.setBolt("partitioner", new URLPartitionerBolt()).shuffleGrouping("spout"); |
| 47 | + |
| 48 | + builder.setBolt("fetch", new FetcherBolt()) |
| 49 | + .fieldsGrouping("partitioner", new Fields("key")); |
| 50 | + |
| 51 | + builder.setBolt("sitemap", new SiteMapParserBolt()).localOrShuffleGrouping("fetch"); |
| 52 | + |
| 53 | + builder.setBolt("parse", new JSoupParserBolt()).localOrShuffleGrouping("sitemap"); |
| 54 | + |
| 55 | + builder.setBolt("indexer", new IndexerBolt()).localOrShuffleGrouping("parse"); |
| 56 | + |
| 57 | + builder.setBolt("status", new StatusUpdaterBolt()) |
| 58 | + .localOrShuffleGrouping("fetch", Constants.StatusStreamName) |
| 59 | + .localOrShuffleGrouping("sitemap", Constants.StatusStreamName) |
| 60 | + .localOrShuffleGrouping("parse", Constants.StatusStreamName) |
| 61 | + .localOrShuffleGrouping("indexer", Constants.StatusStreamName); |
| 62 | + |
| 63 | + builder.setBolt("deleter", new DeletionBolt()) |
| 64 | + .localOrShuffleGrouping("status", Constants.DELETION_STREAM_NAME); |
| 65 | + |
| 66 | + conf.registerMetricsConsumer(MetricsConsumer.class); |
| 67 | + |
| 68 | + return submit("crawl", conf, builder); |
| 69 | + } |
| 70 | +} |
0 commit comments