我正在使用一个Java类来向Storm集群提交拓扑,并计划使用一个Java类来杀死这个拓扑。但是根据Storm的文档,杀死拓扑使用以下命令,而没有Java方法(这有其有效的原因)。
storm kill {stormname}
从Java类调用Shell脚本来杀死拓扑是否可行?还有哪些其他方法可以杀死拓扑?
此外,如何获取Storm集群中正在运行的拓扑的状态?
我正在使用一个Java类来向Storm集群提交拓扑,并计划使用一个Java类来杀死这个拓扑。但是根据Storm的文档,杀死拓扑使用以下命令,而没有Java方法(这有其有效的原因)。
storm kill {stormname}
从Java类调用Shell脚本来杀死拓扑是否可行?还有哪些其他方法可以杀死拓扑?
此外,如何获取Storm集群中正在运行的拓扑的状态?
对于杀死拓扑结构,你可以尝试这个。
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
从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");
}