任务执行(Execution)接口
更新时间:2024-08-16
创建任务执行
接口描述
可以通过如下两种方式创建任务执行:
- 引用一个已存在的模板(参考请求示例1)
- 在创建执行时动态创建一个模板(参考请求示例2)
请求结构
- method:POST
- URL:/api/logic/oos/v2/execution
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
execution | Execution | 任务执行 | 是 | RequestBody参数 |
请求示例 1
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseExecutionRequest request = new BaseExecutionRequest();
13Template template = new Template();
14template.setName("test_oos_template4");
15template.setRef("tpl-******nP");
16template.setLinear(true);
17request.setTemplate(template);
18
19// call
20BaseExecutionResponse execution = oosClient.createExecution(request);
响应示例 1
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "d-******UMgb1M"
7 }
8}
9
请求示例 2
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12BaseExecutionRequest request = new BaseExecutionRequest();
13Template template = new Template();
14template.setName("test_oos_template");
15template.setLinear(true);
16Operator stopBcc = new Operator();
17stopBcc.setName("stop_bcc");
18stopBcc.setOperator("BCE::BCC::StopInstance");
19stopBcc.setRetries(0);
20stopBcc.setRetryInterval(60000);
21stopBcc.setTimeout(3600000);
22
23Map<String, Object> properties = new HashMap<>();
24properties.put("instances", Collections.singletonList(
25 Collections.singletonMap("instanceId", "i-******kK") // 待关机的实例 Id
26));
27stopBcc.setProperties(properties);
28template.setOperators(Collections.singletonList(stopBcc));
29request.setTemplate(template);
30// call
31BaseExecutionResponse execution = oosClient.createExecution(request);
响应示例 2
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "d-******UMgb1M"
7 }
8}
9
查看任务执行
接口描述
查看任务执行的详情
请求结构
- method:GET
- URL:/api/logic/oos/v2/execution?{Query参数}
请求参数
名称 | 类型 | 描述 | 是否必须 | 参数位置 |
---|---|---|---|---|
id | String | 任务执行ID | 否 | Query参数 |
请求示例 1
Java
1// config of client
2String endpoint = "http://oos.bj.baidubce.com";
3String userId = "a0d04************************ce4";
4String ak = "ALTA*******************CYG";
5String sk = "b2c5************************3ac1";
6// create oos client
7OosClientConfiguration config = new OosClientConfiguration();
8config.setCredentials(new DefaultBceCredentials(ak, sk));
9config.setEndpoint(endpoint);
10OosClient oosClient = new OosClient(config);
11// request params definition
12String executionId = "d-*********34r";
13 // call
14BaseExecutionResponse execution = oosClient.getExecutionDetail(executionId);
响应示例 1
JSON
1{
2 "success": true,
3 "msg": "",
4 "code": 200,
5 "result": {
6 "id": "d-*********34r",
7 "template": {
8 "name": "test_oos_template",
9 "type": "INDIVIDUAL",
10 "tags": [],
11 "linear": true,
12 "links": [],
13 "operators": [
14 {
15 "name": "stop_bcc",
16 "operator": "BCE::BCC::StopInstance",
17 "retries": 0,
18 "retryInterval": 60000,
19 "timeout": 3600000,
20 "manually": false,
21 "scheduleDelayMilli": 0,
22 "pauseOnFailure": false,
23 "properties": {
24 "instanceId": {
25 "Ref": "instanceId"
26 },
27 "instances": [
28 {
29 "instanceId": "i-******kK"
30 }
31 ]
32 },
33 "initContext": {}
34 }
35 ],
36 "properties": []
37 },
38 "createdTimestamp": 1713941313268,
39 "updatedTimestamp": 1713941326534,
40 "finishedTimestamp": 1713941326534,
41 "state": "SUCCESS",
42 "properties": {},
43 "tasks": [
44 {
45 "id": "t-*****************dMGNa",
46 "revision": 79917077,
47 "createdTimestamp": 1713941313269,
48 "updatedTimestamp": 1713941326532,
49 "finishedTimestamp": 1713941326532,
50 "state": "SUCCESS",
51 "operator": {
52 "name": "stop_bcc",
53 "operator": "BCE::BCC::StopInstance",
54 "retries": 0,
55 "retryInterval": 60000,
56 "timeout": 3600000,
57 "manually": false,
58 "scheduleDelayMilli": 0,
59 "pauseOnFailure": false,
60 "properties": {},
61 "initContext": {
62 "instanceId": {
63 "Ref": "instanceId"
64 },
65 "instances": [
66 {
67 "instanceId": "i-******kK"
68 }
69 ]
70 }
71 },
72 "initContext": {
73 "instanceId": {
74 "Ref": "instanceId"
75 },
76 "instances": [
77 {
78 "instanceId": "i-******kK"
79 }
80 ]
81 },
82 "context": {},
83 "outputContext": {
84 "instances": [
85 {
86 "instanceId": "i-******kK"
87 }
88 ]
89 },
90 "tries": 0,
91 "children": []
92 }
93 ],
94 "tags": [],
95 "trigger": "MANUAL"
96 }
97}
98