INFO-调用MammutOpenApi获取线上任务相关信息
更新时间: 2024-03-11 02:53:26
阅读 2924
调用MammutOpenApi获取线上任务相关信息
功能说明
适用模块
中台api
具体说明
调用MammutOpenApi获取线上任务相关信息
使用示例
开发者账号密码获取方式
- 先使用需要获取开发者账号密码的用户登陆猛犸平台
http://xxxxxxxx.com/main#/activity/dashboard
- 保留猛犸页面网址部分,后缀部分改为
https://xxxxxxxx.com/api/user/apikey/set?email= xx@xxxxxxxxxx.com
其中https://xxxxxxxx.com
就是登陆后猛犸页面地址email=xx@xx
就是指通过该邮箱账户设置openapi的 apikey 和 masterkey。 - 接下来调用
/api/user/apikey/get
接口用来获取之前通过set接口设置的两个keyhttps:// xxxxxxxx.com/api/user/apikey/get?email= xx@xx
- 以admin账号为例执行结果如下图: http://xxxxxxxx.com//api/user/apikey/set?email=admin.mammut@163.com
代码样例
导入相关依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.32</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
代码示例:
package org.example;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Encoder;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
/***********************************
*@Desc TODO
*@ClassName MammutOnlineTaskDemo
*@Author DLX
*@Data 2021/8/16 14:23
*@Since JDK1.8
*@Version 1.0
***********************************/
public class MammutOnlineTaskDemo {
//服务器地址需要更换成自己环境的
public static String HOST = "http://easydemo-workbench.163yun.com/";
//app_key 需要更换成自己的api_key
public static String API_KEY = "a8c31124-XXXX-XXXX-XXXX-43257a053980";
//秘钥用来生成token 需要更换成自己的master_key
public static String MASTER_KEY = "b1e66e05-XXXX-XXXX-XXXX-711acff4587e";
protected RestTemplate restApiTemplate;
private BASE64Encoder base64en;
// private MessageDigest md5;
public MammutOnlineTaskDemo() throws NoSuchAlgorithmException {
restApiTemplate = new RestTemplate();
base64en = new BASE64Encoder();
}
/* 获取token
* */
public String getToken(String uri) throws UnsupportedEncodingException,NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
return base64en.encode(md5.digest((MASTER_KEY + uri).getBytes("utf-8")));
}
/*
测试函数
*/
public void test(String uri) {
try {
String token = getToken(uri);
Map<String, Object> param = new HashMap<String, Object>();
param.put("apiKey", URLEncoder.encode(API_KEY,"utf-8"));
param.put("token", URLEncoder.encode(token, "utf-8"));
param.put("product","bdms");
param.put("clusterId","easyops-cluster");
param.put("page","1");
param.put("count","10");
param.put("status","0");
param.put("taskType","1");
param.put("creator","user@mesg.netease.com");
String url = HOST + uri;
JSONObject result = restApiTemplate.postForObject(url, param, JSONObject.class);
System.out.println(result.toJSONString());
} catch (UnsupportedEncodingException e) {
} catch (NoSuchAlgorithmException e2) {
}
}
public static void main(String[] args) throws NoSuchAlgorithmException{
MammutOnlineTaskDemo mammutOnlineTask = new MammutOnlineTaskDemo();
mammutOnlineTask.test("/v1/openapi/etlops/onlinetask/list");
}
}
获取线上任务信息列表API相关信息
请求信息
POST: /v1/openapi/etlops/onlinetask/list
请求头:
名称 | 默认值 | 描述 |
---|---|---|
Content-Type | application/json | - |
请求参数:哈希
名称 | 类型 | 描述 | 必需 | 默认 |
---|---|---|---|---|
clusterId | String | 集群ID | 是 | hz1 |
product | String | 产品账号 | 是 | intern |
page | Number | 分页,第几页,从1开始 | 是 | 1 |
count | Number | 每⻚条数 | 是 | 25 |
status | Number | 线上任务状态。0全部,1未调度,2已调度 | 是 | 0 |
taskType | Number | 线上任务类型,0任务组任务,1作业流任务,2节点任务 | 是 | 1 |
creator | String | 任务创建⼈ email,不传为全部,可传递多个 email,以英⽂逗号 隔,且各个email前后不能包含空格 | 否 | user@corp.netease.com |
releaser | String | 任务提交⼈ email,不传为全部,可传递多个 email,以英⽂逗号 隔,且各个email前后不能包含空格 | 否 | user@corp.netease.com |
nodeType | String | 若任务为节点类型,可传,不传为全部 | 否 | - |
apiKey | String | 开发者账号 | 是 | 96479111-4159-805a-bda8-f5765ddc4768 |
token | String | 开发者账号 | 是 | qajHvy6W1uykxOB74Od6UA%3D%3D |
范例展示:
{
"apiKey": "96479111-4159-805a-bda8-f5765ddc4768",
"token": "qajHvy6W1uykxOB74Od6UA%3D%3D",
"product": "intern",
"clusterId": "hz1",
"page": 1,
"count": 25,
"status": 0,
"taskType": 1,
"creator": "user@corp.netease.com",
"releaser": "user@corp.netease.com",
"nodeType": "YPnr9PeJIK"
}
响应信息
响应头:
名称 | 默认值 | 描述 |
---|---|---|
Content-Type | application/json | - |
返回数据:哈希
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
code | Number | 状态码 | 200 |
msg | String | 状态描述。若code不等于200,则返回简短的出错原因 | success |
result | Object | 任务list | - |
范例展示:
{
"code":200,
"msg":"success",
"result":{
"total":10,
"tasks":[
{
"taskName":"flow_task",
"creator":"user@corp.netease.com",
"releaser":"user@corp.netease.com",
"flows":[
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
}
]
},
{
"taskName":"flow_task",
"creator":"user@corp.netease.com",
"releaser":"user@corp.netease.com",
"flows":[
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
}
]
},
{
"taskName":"flow_task",
"creator":"user@corp.netease.com",
"releaser":"user@corp.netease.com",
"flows":[
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
},
{
"flowName":"flow_task",
"scheduleStatus":1,
"modifiedTime":1547983636000,
"firstExecTime":1548415636000,
"lastExecTime":1548847636000,
"nextExecTime":1548761716000,
"period":"1d",
"submitter":"user@corp.netease.com"
}
]
}
]
}
}
作者:邓崃翔
文档反馈
以上内容对您是否有帮助?