我已經解決了此基礎上@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
}
你是如何設法克服以下錯誤'了java.lang.RuntimeException:找到多個defaults.yaml資源。你可能將Storm jar與你的拓撲jar捆綁在一起。 – manthosh
「找到多個defaults.yaml資源,您可能會將Storm jar與您的拓撲jar捆綁在一起。」不要在你的拓撲jar中包含Storm jar,爲了達到這個目的,如果你正在使用maven,那麼在你的風暴依賴中增加這條線提供了 。 –
abhi
其給予'java.lang.RuntimeException:集羣上已經存在名爲'mytopology'的拓撲 –