import java.util.Arrays;
import java.util.List;
import storm.trident.TridentTopology;
import trident.kafka.KafkaConfig;
import trident.kafka.OpaqueTridentKafkaSpout;
import trident.kafka.StringScheme;
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.tuple.Fields;
public class ImpressionTopology {
private static final String IMPRESSION_SPOUT = "KAFKA_IMPRESSION_SPOUT";
private static final String KAFKA_TOPIC = "ad_server"; //------ MODIFY THIS TOO
private static final String KAKFA_HOST_PORT = "10.0.1.27:9092"; //------ THIS THING TOO
public static void main(String[] args) throws Exception {
Config stormconfig = new Config();
//stormconfig.setDebug(true);
List<String> hosts = Arrays.asList(KAKFA_HOST_PORT);
System.out.println(""+hosts.get(0));
KafkaConfig kafkaConf = new KafkaConfig(KafkaConfig.StaticHosts.fromHostString(hosts, 1),KAFKA_TOPIC );
kafkaConf.scheme = new StringScheme();
System.out.println(""+kafkaConf);
TridentTopology tridentTopology = new TridentTopology();
tridentTopology.newStream(IMPRESSION_SPOUT, new OpaqueTridentKafkaSpout(kafkaConf))
.each(new Fields("str"), new ImpressionKeyValueSplitFuncion(), new Fields("key", "raw"))
.parallelismHint(3)
.partitionPersist(new HBaseFactory(),
new Fields("key", "raw"), new TridentHBaseUpdater());
System.out.println("About to start the cluster");
if (args.length == 0) {
System.out.println("Working in Local Cluster Mode");
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", stormconfig, tridentTopology.build());
System.out.println("Finished submitting local closter");
} else {
System.out.println("Starting storm submitter topology");
System.out.println(" [====] "+tridentTopology);
stormconfig.setNumWorkers(3);
StormSubmitter.submitTopology(args[0], stormconfig, tridentTopology.build());
System.out.println("Finished submitting the topology");
}
}
}