Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically kill a storm topology?

I am using a java class to submit a topology to the storm cluster and I also plan to use java class to kill the topology. But as per storm documentation, the following command is used to kill a topology and there is no Java method (and this has valid reasons)

storm kill {stormname}

So is it fine to call a shell script from java class to kill the topology? What are the other ways to kill topology?

Also, how to get the status of running topologies in storm cluster?

like image 941
mbgsuirp Avatar asked Dec 27 '13 10:12

mbgsuirp


2 Answers

For killing topology you can try this

import backtype.storm.generated.KillOptions
import backtype.storm.generated.Nimbus.Client;
import backtype.storm.utils.NimbusClient
import backtype.storm.utils.Utils

Map conf = Utils.readStormConfig();
Client client = NimbusClient.getConfiguredClient(conf).getClient();
KillOptions killOpts = new KillOptions();
//killOpts.set_wait_secs(waitSeconds); // time to wait before killing
client.killTopologyWithOpts(topology_name, killOpts); //provide topology name

To get the status of topology running

Client client = NimbusClient.getConfiguredClient(conf).getClient();
List<TopologySummary> topologyList = client.getClusterInfo.get_topologies();
// loop through the list and check if the required topology name is present in the list
// if not it's not running
like image 144
Vishal John Avatar answered Oct 09 '22 18:10

Vishal John


As of Storm 1.0.0, killing a topology from within a spout or bolt needs you to specify the nimbus host location via nimbus.seeds (or if you aren't doing it through code, you need to specify the nimbus.seeds in the storm.yaml file):

import org.apache.storm.utils.NimbusClient;
import org.apache.storm.utils.Utils;

void somewhereInASpoutOrBolt() {
Map conf = Utils.readStormConfig();
conf.put("nimbus.seeds", "localhost");

NimbusClient cc = NimbusClient.getConfiguredClient(conf);

Nimbus.Client client = cc.getClient();
client.killTopology("MyStormTopologyName");
}

Do note that doing so will end your program too.

like image 45
Nav Avatar answered Oct 09 '22 18:10

Nav