2 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
Vijay建議的上述方法適用于當(dāng)前正在運(yùn)行的應(yīng)用程序。
但似乎您的要求是獲取所有應(yīng)用程序。
問(wèn)題:是否有任何Java API可以幫助解析和匹配使用Main類名和用戶名?
請(qǐng)參閱 hadoop 文檔 YarnClient ...這里
基本上,有哪個(gè)會(huì)得到所有的應(yīng)用程序。YarnClient
getApplications
摘要 列表 get 應(yīng)用程序(EnumSet 應(yīng)用程序狀態(tài)) 獲取與集群中給定應(yīng)用程序狀態(tài)匹配的應(yīng)用程序的報(bào)告(應(yīng)用程序報(bào)告)。
您可以嘗試類似這樣的東西,它將定期打印所有應(yīng)用程序
import org.apache.hadoop.yarn.client.api.YarnClient
public class YarnMonitor {
public static void main(String [] args) throws Exception{
SparkContext sc = new SparkContext(new SparkConf().setMaster("yarn").setAppName("Yarn Monitor"));
YarnClient yarnClient = YarnClient.createYarnClient();
YarnConfiguration yarnConf = new YarnConfiguration(SparkHadoopUtil.get().newConfiguration(sc.getConf()));
while(true){ // periodically loop and get currently running apps
yarnClient = YarnClient.createYarnClient();
List<ApplicationReport> applications = yarnClient.getApplications();
for (ApplicationReport application : applications) {
System.out.println(application.getName());
}
Thread.sleep(1000); // sleep for 1000 ms
}
}

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以在當(dāng)前 spark 應(yīng)用程序代碼本身中獲取應(yīng)用程序 ID。
這里是示例(Scala)代碼片段java也具有相同的api。
// create spark configuration
SparkConf conf = new SparkConf().setMaster("local");
conf.set("spark.app.name", "test");
// create a spark context
SparkContext sc = new SparkContext(conf);
// get the application id
String appId = sc.applicationId();
// print the application id
System.out.println("Application id: " + appId);
// stop the spark context
sc.stop();
請(qǐng)嘗試這個(gè)。
添加回答
舉報(bào)