如何以编程方式杀死风暴拓扑?
问题内容:
我正在使用Java类向拓扑集群提交拓扑,并且我还计划使用Java类取消拓扑。但是根据storm
文档,以下命令用于终止拓扑,并且没有Java方法(这有正当的理由)
storm kill {stormname}
那么从Java类中调用Shell脚本杀死拓扑就可以了吗?还有其他杀死拓扑的方法吗?
另外,如何获取风暴群集中正在运行的拓扑的状态?
问题答案:
要杀死拓扑,您可以尝试以下方法
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
获取拓扑运行状态
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