Java 如何以编程方式终止storm拓扑?

Java 如何以编程方式终止storm拓扑?,java,apache-storm,Java,Apache Storm,我正在使用一个java类向storm集群提交一个拓扑,我还计划使用java类终止拓扑。但是根据storm,以下命令用于终止拓扑,并且没有Java方法(这是有充分理由的) 那么,从java类调用shell脚本来终止拓扑是否合适?还有什么方法可以杀死拓扑 另外,如何获取storm cluster中正在运行的拓扑的状态?要终止拓扑,您可以尝试以下方法 import backtype.storm.generated.KillOptions import backtype.storm.generated.

我正在使用一个java类向storm集群提交一个拓扑,我还计划使用java类终止拓扑。但是根据storm,以下命令用于终止拓扑,并且没有Java方法(这是有充分理由的)

那么,从java类调用shell脚本来终止拓扑是否合适?还有什么方法可以杀死拓扑


另外,如何获取storm cluster中正在运行的拓扑的状态?

要终止拓扑,您可以尝试以下方法

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
Client-Client=NimbusClient.getConfiguredClient(conf.getClient();
List topologyList=client.getClusterInfo.get_Topologys();
//循环浏览列表并检查列表中是否存在所需的拓扑名称
//如果没有,它就没有运行

从Storm 1.0.0开始,从喷口或螺栓内杀死拓扑需要您通过
nimbus.seeds
指定nimbus主机位置(或者如果您不是通过代码执行此操作,则需要在
Storm.yaml
文件中指定nimbus.seeds):


请注意,这样做也会结束您的程序。

您能告诉我如何以编程方式提交拓扑吗?@Mr37037:如果您想知道如何将拓扑提交到远程群集,可以查看此链接:这似乎是群集模式的解决方案,如何对在本地模式下运行的拓扑执行同样的操作。
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
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");
}