2013-04-03 103 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 
}