Search in sources :

Example 1 with LinearDRPCTopologyBuilder

use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.

the class ReachTopology method main.

public static void main(String[] args) throws Exception {
    LinearDRPCTopologyBuilder builder = construct();
    Config conf = new Config();
    conf.setNumWorkers(6);
    if (args.length != 0) {
        try {
            Map yamlConf = LoadConf.LoadYaml(args[0]);
            if (yamlConf != null) {
                conf.putAll(yamlConf);
            }
        } catch (Exception e) {
            System.out.println("Input " + args[0] + " isn't one yaml ");
        }
        StormSubmitter.submitTopology(TOPOLOGY_NAME, conf, builder.createRemoteTopology());
    } else {
        conf.setMaxTaskParallelism(3);
        LocalDRPC drpc = new LocalDRPC();
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology(TOPOLOGY_NAME, conf, builder.createLocalTopology(drpc));
        JStormUtils.sleepMs(10000);
        String[] urlsToTry = new String[] { "foo.com/blog/1", "engineering.twitter.com/blog/5", "notaurl.com" };
        for (String url : urlsToTry) {
            System.out.println("Reach of " + url + ": " + drpc.execute(TOPOLOGY_NAME, url));
        }
        cluster.shutdown();
        drpc.shutdown();
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) Config(backtype.storm.Config) LocalDRPC(backtype.storm.LocalDRPC) LinearDRPCTopologyBuilder(backtype.storm.drpc.LinearDRPCTopologyBuilder) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LinearDRPCTopologyBuilder

use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.

the class ReachTopology method construct.

public static LinearDRPCTopologyBuilder construct() {
    LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder(TOPOLOGY_NAME);
    builder.addBolt(new GetTweeters(), 1);
    builder.addBolt(new GetFollowers(), 1).shuffleGrouping();
    builder.addBolt(new PartialUniquer(), 1).fieldsGrouping(new Fields("id", "follower"));
    builder.addBolt(new CountAggregator(), 1).fieldsGrouping(new Fields("id"));
    return builder;
}
Also used : Fields(backtype.storm.tuple.Fields) LinearDRPCTopologyBuilder(backtype.storm.drpc.LinearDRPCTopologyBuilder)

Example 3 with LinearDRPCTopologyBuilder

use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.

the class BasicDRPCTopologyTest method testBasicDRPCTopology.

@Test
public void testBasicDRPCTopology() {
    LinearDRPCTopologyBuilder topologyBuilder = new LinearDRPCTopologyBuilder("exclamation");
    topologyBuilder.addBolt(new BasicDRPCTopology.ExclaimBolt(), 3);
    Config config = new Config();
    config.put(Config.TOPOLOGY_NAME, "BasicDRPCTopologyTest");
    LocalDRPC localDRPC = new LocalDRPC();
    JStormUnitTestDRPCValidator validator = new JStormUnitTestDRPCValidator(localDRPC) {

        @Override
        public boolean validate(Map config) {
            String result = executeLocalDRPC("exclamation", "hello");
            assertEquals("hello!", result);
            result = executeLocalDRPC("exclamation", "goodbye");
            assertEquals("goodbye!", result);
            return true;
        }
    };
    try {
        JStormUnitTestRunner.submitTopology(topologyBuilder.createLocalTopology(localDRPC), config, 120, validator);
    } finally {
        localDRPC.shutdown();
    }
}
Also used : Config(backtype.storm.Config) LocalDRPC(backtype.storm.LocalDRPC) JStormUnitTestDRPCValidator(com.jstorm.example.unittests.utils.JStormUnitTestDRPCValidator) BasicDRPCTopology(org.apache.storm.starter.BasicDRPCTopology) LinearDRPCTopologyBuilder(backtype.storm.drpc.LinearDRPCTopologyBuilder) Map(java.util.Map) Test(org.junit.Test)

Example 4 with LinearDRPCTopologyBuilder

use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.

the class BasicDRPCTopology method testDrpc.

public static void testDrpc() {
    LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("exclamation");
    builder.addBolt(new ExclaimBolt(), 3);
    Config conf = new Config();
    LocalDRPC drpc = new LocalDRPC();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("drpc-demo", conf, builder.createLocalTopology(drpc));
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    }
    try {
        for (String word : new String[] { "hello", "goodbye" }) {
            System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word));
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Failed to run DRPC Test");
    }
    drpc.shutdown();
    cluster.shutdown();
}
Also used : LocalCluster(backtype.storm.LocalCluster) Config(backtype.storm.Config) LocalDRPC(backtype.storm.LocalDRPC) LinearDRPCTopologyBuilder(backtype.storm.drpc.LinearDRPCTopologyBuilder)

Aggregations

LinearDRPCTopologyBuilder (backtype.storm.drpc.LinearDRPCTopologyBuilder)4 Config (backtype.storm.Config)3 LocalDRPC (backtype.storm.LocalDRPC)3 LocalCluster (backtype.storm.LocalCluster)2 Map (java.util.Map)2 Fields (backtype.storm.tuple.Fields)1 JStormUnitTestDRPCValidator (com.jstorm.example.unittests.utils.JStormUnitTestDRPCValidator)1 HashMap (java.util.HashMap)1 BasicDRPCTopology (org.apache.storm.starter.BasicDRPCTopology)1 Test (org.junit.Test)1