2013-04-03 66 views
14

我在使用IDE向生产集群提交拓扑结构时遇到问题Must submit topologies using the 'storm' client script so that StormSubmitter knows which jar to upload,而如果我在命令行中使用storm jar命令执行它,它的运行就像天堂一样。我从githublink中看到过相同的例子。如何使用IDE在风暴生产集群中提交拓扑结构

提交拓扑我使用这些集线

conf.put(Config.NIMBUS_HOST, NIMBUS_NODE); 
    conf.put(Config.NIMBUS_THRIFT_PORT,6627); 
    conf.put(Config.STORM_ZOOKEEPER_PORT,2181); 
    conf.put(Config.STORM_ZOOKEEPER_SERVERS,ZOOKEEPER_ID); 
    conf.setNumWorkers(20); 
    conf.setMaxSpoutPending(5000); 
    StormSubmitter submitter = new StormSubmitter(); 
    submitter.submitTopology("test", conf, builder.createTopology()); 

的请给我建议,如果这是运行在正确的方法呢?

回答

21

那么找到了解决方案。当我们运行“storm jar”时,它会在提交的jar中触发storm.jar的属性标志。因此,如果我们想通过程序提交一个罐子里,然后简单地设置标志这样

System.setProperty("storm.jar", <path-to-jar>);

例如:

System.setProperty("storm.jar", "/Users/programming/apache-storm-1.0.1/lib/storm-core-1.0.1.jar"); 
StormSubmitter.submitTopology("myTopology", config, builder.createTopology()); 
+1

你是如何设法克服以下错误'了java.lang.RuntimeException:找到多个defaults.yaml资源。你可能将Storm jar与你的拓扑jar捆绑在一起。 – manthosh

+2

“找到多个defaults.yaml资源,您可能会将Storm jar与您的拓扑jar捆绑在一起。”不要在你的拓扑jar中包含Storm jar,为了达到这个目的,如果你正在使用maven,那么在你的风暴依赖中增加这条线提供了。 – abhi

+0

其给予'java.lang.RuntimeException:集群上已经存在名为'mytopology'的拓扑 –

5

提交拓扑远程风暴集群,你需要上传的jar使用NimbusClient将机器提交给群集。
你可以做这样的:

Map storm_conf = Utils.readStormConfig(); 
storm_conf.put("nimbus.host", "<Nimbus Machine IP>"); 
Client client = NimbusClient.getConfiguredClient(storm_conf) 
           .getClient(); 
String inputJar = "C:\\workspace\\TestStormRunner\\target\\TestStormRunner-0.0.1-SNAPSHOT-jar-with-dependencies.jar"; 
NimbusClient nimbus = new NimbusClient(storm_conf, "<Nimbus Machine IP>", 
           <Nimbus Machine Port>); 
// upload topology jar to Cluster using StormSubmitter 
String uploadedJarLocation = StormSubmitter.submitJar(storm_conf, 
           inputJar); 

String jsonConf = JSONValue.toJSONString(storm_conf); 
nimbus.getClient().submitTopology("testtopology", 
         <uploadedJarLocation>, jsonConf, builder.createTopology()); 

这里是工作示例:Submitting a topology to Remote Storm Cluster

3

我已经解决了此基础上@abhi和@Nishu Tayal的回答这个问题,我想我的后代码在这里:

public static void submitLocalTopologyWay1(String topologyName, Config topologyConf, 
     StormTopology topology, String localJar) { 
    try { 
     //get default storm config 
     Map defaultStormConf = Utils.readStormConfig(); 
     defaultStormConf.putAll(topologyConf); 

     //set JAR 
     System.setProperty("storm.jar",localJar); 

     //submit topology 
     StormSubmitter.submitTopology(topologyName, defaultStormConf, topology); 

    } catch (Exception e) { 
     String errorMsg = "can't deploy topology " + topologyName + ", " + e.getMessage(); 
     System.out.println(errorMsg); 
     e.printStackTrace(); 
    } 
} 

public static void submitLocalTopologyWay2(String topologyName, Config topologyConf, 
     StormTopology topology, String localJar) { 
    try { 
     //get nimbus client 
     Map defaultStormConf = Utils.readStormConfig(); 
     defaultStormConf.putAll(topologyConf); 
     Client client = NimbusClient.getConfiguredClient(defaultStormConf).getClient(); 

     //upload JAR 
     String remoteJar = StormSubmitter.submitJar(defaultStormConf, localJar); 

     //submit topology 
     client.submitTopology(topologyName, remoteJar, JSONValue.toJSONString(topologyConf), topology); 

    } catch (Exception e) { 
     String errorMsg = "can't deploy topology " + topologyName + ", " + e.getMessage(); 
     System.out.println(errorMsg); 
     e.printStackTrace(); 
    } 
} 

然后这里是一个测试,你必须首先建立你的代码到一个JAR文件。

public void testSubmitTopologySubmitLocalTopologyWay1() { 
    Config config = new Config(); 
    config.put(Config.NIMBUS_HOST,"9.119.84.179"); 
    config.put(Config.NIMBUS_THRIFT_PORT, 6627); 
    config.put(Config.STORM_ZOOKEEPER_SERVERS, Arrays.asList("9.119.84.177","9.119.84.178","9.119.84.176")); 
    config.put(Config.STORM_ZOOKEEPER_PORT,2181); 

    config.put(Config.TOPOLOGY_WORKERS, 3); 

    RemoteSubmitter.submitLocalTopologyWay1("word-count-test-1", config, 
      WordCountTopology.buildTopology(), // your topology 
      "C:\\MyWorkspace\\project\\storm-sample-0.0.1-SNAPSHOT-jar-with-dependencies.jar");//the JAR file 
}