任务执行(Execution)接口
所有文档
menu

运维编排 OOS

任务执行(Execution)接口

创建任务执行

接口描述

可以通过如下两种方式创建任务执行:

  • 引用一个已存在的模板(参考请求示例1)
  • 在创建执行时动态创建一个模板(参考请求示例2)

请求结构

  • method:POST
  • URL:/api/logic/oos/v2/execution

请求参数

名称 类型 描述 是否必须 参数位置
execution Execution 任务执行 RequestBody参数

请求示例 1

// config of client
String endpoint = "http://oos.bj.baidubce.com";
String userId = "a0d04************************ce4";
String ak = "ALTA*******************CYG";
String sk = "b2c5************************3ac1";
// create oos client
OosClientConfiguration config = new OosClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ak, sk));
config.setEndpoint(endpoint);
OosClient oosClient = new OosClient(config);
// request params definition
BaseExecutionRequest request = new BaseExecutionRequest();
Template template = new Template();
template.setName("test_oos_template4");
template.setRef("tpl-******nP");
template.setLinear(true);
request.setTemplate(template);

// call
BaseExecutionResponse execution = oosClient.createExecution(request);

响应示例 1

{
    "success": true,
    "msg": "",
    "code": 200,
    "result": {
        "id": "d-******UMgb1M"
    }
}
 

请求示例 2

// config of client
String endpoint = "http://oos.bj.baidubce.com";
String userId = "a0d04************************ce4";
String ak = "ALTA*******************CYG";
String sk = "b2c5************************3ac1";
// create oos client
OosClientConfiguration config = new OosClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ak, sk));
config.setEndpoint(endpoint);
OosClient oosClient = new OosClient(config);
// request params definition
BaseExecutionRequest request = new BaseExecutionRequest();
Template template = new Template();
template.setName("test_oos_template");
template.setLinear(true);
Operator stopBcc = new Operator();
stopBcc.setName("stop_bcc");
stopBcc.setOperator("BCE::BCC::StopInstance");
stopBcc.setRetries(0);
stopBcc.setRetryInterval(60000);
stopBcc.setTimeout(3600000);

Map<String, Object> properties = new HashMap<>();
properties.put("instances", Collections.singletonList(
        Collections.singletonMap("instanceId", "i-******kK") // 待关机的实例 Id
));
stopBcc.setProperties(properties);
template.setOperators(Collections.singletonList(stopBcc));
request.setTemplate(template);
// call
BaseExecutionResponse execution = oosClient.createExecution(request);

响应示例 2

{
    "success": true,
    "msg": "",
    "code": 200,
    "result": {
        "id": "d-******UMgb1M"
    }
}
 

查看任务执行

接口描述

查看任务执行的详情

请求结构

  • method:GET
  • URL:/api/logic/oos/v2/execution?{Query参数}

请求参数

名称 类型 描述 是否必须 参数位置
id String 任务执行ID Query参数

请求示例 1

// config of client
String endpoint = "http://oos.bj.baidubce.com";
String userId = "a0d04************************ce4";
String ak = "ALTA*******************CYG";
String sk = "b2c5************************3ac1";
// create oos client
OosClientConfiguration config = new OosClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ak, sk));
config.setEndpoint(endpoint);
OosClient oosClient = new OosClient(config);
// request params definition
String executionId = "d-*********34r";
 // call
BaseExecutionResponse execution = oosClient.getExecutionDetail(executionId);

响应示例 1

{
    "success": true,
    "msg": "",
    "code": 200,
    "result": {
        "id": "d-*********34r",
        "template": {
            "name": "test_oos_template",
            "type": "INDIVIDUAL",
            "tags": [],
            "linear": true,
            "links": [],
            "operators": [
                {
                    "name": "stop_bcc",
                    "operator": "BCE::BCC::StopInstance",
                    "retries": 0,
                    "retryInterval": 60000,
                    "timeout": 3600000,
                    "manually": false,
                    "scheduleDelayMilli": 0,
                    "pauseOnFailure": false,
                    "properties": {
                        "instanceId": {
                            "Ref": "instanceId"
                        },
                        "instances": [
                            {
                                "instanceId": "i-******kK"
                            }
                        ]
                    },
                    "initContext": {}
                }
            ],
            "properties": []
        },
        "createdTimestamp": 1713941313268,
        "updatedTimestamp": 1713941326534,
        "finishedTimestamp": 1713941326534,
        "state": "SUCCESS",
        "properties": {},
        "tasks": [
            {
                "id": "t-*****************dMGNa",
                "revision": 79917077,
                "createdTimestamp": 1713941313269,
                "updatedTimestamp": 1713941326532,
                "finishedTimestamp": 1713941326532,
                "state": "SUCCESS",
                "operator": {
                    "name": "stop_bcc",
                    "operator": "BCE::BCC::StopInstance",
                    "retries": 0,
                    "retryInterval": 60000,
                    "timeout": 3600000,
                    "manually": false,
                    "scheduleDelayMilli": 0,
                    "pauseOnFailure": false,
                    "properties": {},
                    "initContext": {
                        "instanceId": {
                            "Ref": "instanceId"
                        },
                        "instances": [
                            {
                                "instanceId": "i-******kK"
                            }
                        ]
                    }
                },
                "initContext": {
                    "instanceId": {
                        "Ref": "instanceId"
                    },
                    "instances": [
                        {
                            "instanceId": "i-******kK"
                        }
                    ]
                },
                "context": {},
                "outputContext": {
                    "instances": [
                        {
                            "instanceId": "i-******kK"
                        }
                    ]
                },
                "tries": 0,
                "children": []
            }
        ],
        "tags": [],
        "trigger": "MANUAL"
    }
}
 
上一篇
运维模板(Template)接口