10

I am using a Java class to submit a topology to a Storm cluster and I also plan to use a 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?

moosehead42
  • 411
  • 4
  • 18
mbgsuirp
  • 618
  • 1
  • 8
  • 20

2 Answers2

17

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
Vishal John
  • 4,231
  • 25
  • 41
  • can you kindly tell me that how can i submit topology programmatically? – Mr37037 Oct 25 '14 at 18:48
  • 1
    @Mr37037 : If you want to know how to submit topology to remote cluster, you can check this link : [submitting-topology-to-remote-storm](http://nishutayaltech.blogspot.in/2014/06/submitting-topology-to-remote-storm.html) – Nishu Tayal Feb 24 '15 at 08:55
  • This seems like solution for cluster mode, how to do the same for topologies running in local mode. – Saurabh Jul 24 '18 at 10:08
4

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.

Nav
  • 19,885
  • 27
  • 92
  • 135