我正在致力於應用程序從java
應用程序執行spark
批量應用程序。從Java應用程序啓動並監控Spark應用程序
有一個主線程啓動線程來啓動spark
應用程序。它使用zookeeper
在將啓動spark
應用程序的機器中找到leader
。 Main
方法是這樣的:
public static void main(String[] args) throws IOException {
final int id = Integer.valueOf(args[0]);
final String zkURL = args[1];
final ExecutorService service = Executors.newSingleThreadExecutor();
final Future<?> status = service.submit(new ProcessNode(id, zkURL));
try {
status.get();
} catch (InterruptedException | ExecutionException e) {
LOG.fatal(e.getMessage(), e);
service.shutdown();
}
一旦leader
選擇,下面的代碼將在其上運行啓動spark
應用。
protected Boolean executeCommand() {
try {
final Runtime rt = Runtime.getRuntime();
final Process proc = rt.exec("sh start-sparkapp.sh");
final int exitVal = proc.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
System.out.println(" commandToExecute exited with code: " + exitVal);
proc.destroy();
} catch (final Exception e) {
System.out.println("Exception occurred while Launching process : " + e.getMessage());
return Boolean.FALSE;
}
return Boolean.TRUE;
}
但是這開始長時間運行spark
工作。所以我相信,只有當spark
工作完成時,代碼的下一部分纔會被執行。我的要求是,只要spark
應用程序啓動,控制權轉到代碼的下一部分,我在監視相同的spark
應用程序的狀態。即我啓動了spark
應用程序,並從相同的java
應用程序監視spark
應用程序的狀態。 假設我有一個方法montior
用於監視應用
public String monitor(ApplicationId id)
任何建議的狀態如何實現這一目標?
標記「apache-spark」是否合理? – suj1th