如何以编程方式终止Apache Storm拓扑?

svmlkihl  于 2022-12-09  发布在  Apache
关注(0)|答案(2)|浏览(115)

我正在使用Java类向Storm集群提交拓扑,还计划使用Java类终止拓扑。但根据storm documentation,以下命令用于终止拓扑,并且没有Java方法(这有合理的原因)。

storm kill {stormname}

那么从Java类调用一个shell脚本来取消拓扑是否合适呢?还有什么其他方法可以取消拓扑呢?
另外,如何获取 Storm 集群中运行拓扑的状态?

pxy2qtax

pxy2qtax1#

要删除拓扑,可以尝试以下操作

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
t1qtbnec

t1qtbnec2#

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

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");
}

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

相关问题