由于一个项目部分的脚本中用到了Flink的任务监控,要求的功能单一,使用yarn rest api进行请求,没有对接监控平台,用到的一些功能如下
CMD
查看指定任务的详细信息:
GET http://<rm http address:port>/ws/v1/cluster/apps/${appid}
监控任务:
curl 'http://<rm http address:port>/ws/v1/cluster/apps/${appid}//state'
GET http://<rm http address:port>/ws/v1/cluster/apps/${appid}//state
杀死任务:
curl -v -X PUT -d '{"state": "KILLED"}''http://<rm http address:port>/ws/v1/cluster/apps/${appid}'
PUT http://<rm http address:port>/ws/v1/cluster/apps/${appid}/state
查询集群调度器详情(包含队列详情):
GET http://<rm http address:port>/ws/v1/cluster/scheduler
JAVA / HttpClient
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
import com.alibaba.fastjson.JSON;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
public static void main(String[] args) throws InterruptedException {
HttpClient httpClient = new HttpClient();
// 查看某个任务信息
GetMethod getMethod = new GetMethod("http://ip:port/ws/v1/cluster/apps/appid");
String response = "";
try {
httpClient.executeMethod(getMethod);
response = getMethod.getResponseBodyAsString().trim();
response = JSON.toJSON(response).toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
//4.释放连接
getMethod.releaseConnection();
}
System.out.println(response);
}