{
// Read topology file created by petrelbuilder.
StormTopology topology = readTopology();
// Get topology-specific configuration from the JAR.
Config conf = new Config();
InputStream stream = ResourceLoader.getResourceAsStream("resources/__topology__.yaml", GenericTopology.class);
try
{
Yaml yaml = new Yaml();
Map localConf = (Map) yaml.load(new InputStreamReader(stream));
conf.putAll(localConf);
}
finally
{
// Close stream
stream.close();
}
// Read __submitter__.yaml to get submitter user and hostname
// information. Include it in the config.
stream = ResourceLoader.getResourceAsStream("resources/__submitter__.yaml", GenericTopology.class);
try
{
Yaml yaml = new Yaml();
Map submitterConf = (Map) yaml.load(new InputStreamReader(stream));
conf.putAll(submitterConf);
}
finally
{
// Close stream
stream.close();
}
if (args!=null && args.length > 0)
{
StormSubmitter.submitTopology(args[0], conf, topology);
}
else
{
// Force some conservative settings to try and avoid overloading a
// local machine's CPU or memory.
conf.setDebug(true);
conf.setNumWorkers(1);
conf.setMaxTaskParallelism(1);
final LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test topology", conf, topology);
Runtime.getRuntime().addShutdownHook(new Thread() {