使用 Yarn REST API 的几种方式



由于一个项目部分的脚本中用到了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);
}

官网地址

这篇文章有一部分返回参数的释义

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值