我正在使用java类向Storm集群提交拓扑,我还计划使用java类来终止拓扑。但是根据风暴documentation,以下命令用于终止拓扑,并且没有Java方法(这有正当理由)
storm kill {stormname}
从java类调用shell脚本来杀死拓扑结构是否可以?什么是杀死拓扑的其他方法?
另外,如何获得在storm cluster中运行拓扑的状态?
答案 0 :(得分:16)
对于杀死拓扑,您可以尝试这个
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
答案 1 :(得分:3)
从Storm 1.0.0开始,从spout或bolt中删除拓扑需要您通过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");
}
请注意,这样做也会结束您的计划。