【问题标题】:How to programmatically kill a storm topology?如何以编程方式杀死风暴拓扑?
【发布时间】:2014-01-14 22:56:56
【问题描述】:

我正在使用 java 类向风暴集群提交拓扑,并且我还计划使用 java 类来终止拓扑。但是根据暴风documentation,下面的命令是用来杀死一个拓扑的,并且没有Java方法(这是有正当理由的)

storm kill {stormname}

那么从 java 类中调用 shell 脚本来终止拓扑可以吗?杀死拓扑的其他方法是什么?

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

【问题讨论】:

    标签: java apache-storm


    【解决方案1】:

    要杀死拓扑,你可以试试这个

    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
    

    【讨论】:

    • 您能告诉我如何以编程方式提交拓扑吗?
    • @Mr37037 : 如果你想知道如何提交拓扑到远程集群,你可以查看这个链接:submitting-topology-to-remote-storm
    • 这似乎是集群模式的解决方案,如何为在本地模式下运行的拓扑做同样的事情。
    【解决方案2】:

    从 Storm 1.0.0 开始,从 spout 或 bolt 中终止拓扑需要您通过 nimbus.seeds 指定 nimbus 主机位置(或者如果您不是通过代码执行此操作,则需要指定 nimbus。 storm.yaml 文件中的种子):

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 2018-07-19
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2013-08-06
      • 1970-01-01
      相关资源
      最近更新 更多