Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: ESB V3接口update_cron_status支持返回定时任务详细信息 #1431 #2750

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion docs/apidoc/esb/jobv3-confapis/apidocs/en/update_cron_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Update Cron job status, such as started or paused
| bk_scope_id | string | yes | Resource scope ID. Corresponds to bk_scope_type, which means business ID or business set ID |
| id | long | yes |Cron job ID|
| status | int | yes |State, 1. Start, 2. Paused|
| return_cron_detail | boolean | no | Whether to return cron details.The default value is false. |

### Example of request

Expand Down Expand Up @@ -56,4 +57,42 @@ Update Cron job status, such as started or paused

| Fields | Type | Description |
|-----------|-----------|-----------|
| data | long | Cron Job ID |
| job_plan_id | long | Job Plan ID |
| id | long | Cron job ID |
| name | string | Cron job name |
| status | int | Cron job status: 1. Started, 2. Paused |
| expression | string | Timing rules for Cron Job crontab, required when creating, optional when modifying. The meaning of each field is: minute hour day month week, for example: 0/5 * * * * ? means execute every 5 minutes |
| global_var_list | array | Global variable information|
| creator | string | Cron job creator|
| create_time | long | Creation time, Unix timestamp|
| last_modify_user | string | Cron job modifier|
| last_modify_time | long | Last modified time, Unix timestamp|

#### global_var

| Fields | Type | Description |
|-----------|-----------|------------|
| id | long | Global variable id, unique identification. If the id is empty, then name is used as the unique identification|
| name | string | Global variable name|
| value | string | Character, password, value of global variable of array type|
| server | object | Host type global variable value|

#### server
| Fields | Type | Description |
|-----------------------|-------|------------|
| ip_list | array |Static IP list|
| dynamic_group_list | array |Dynamic grouping list|
| topo_node_list | array |Dynamic topo node list|

#### ip

| Fields | Type | Description |
|-------------|---------|---------|
| bk_cloud_id | int | BK-Net ID |
| ip | string | IP Address |

#### topo_node
| Fields | Type | Description |
|------------------|--------|------------|
| id | long | Dynamic topo node ID, corresponding to bk_inst_id in CMDB API|
| node_type | string |Dynamic topo node type, corresponding to bk_obj_id in CMDB API, such as "module" and "set"|
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| bk_scope_id | string | 是 | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| id | long | 是 | 定时作业 ID |
| status | int | 是 | 定时状态,1.启动、2.暂停 |
| return_cron_detail | boolean | 否 | 是否返回定时任务详情,默认值为false |

### 请求参数示例

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.tencent.bk.job.crontab.model.esb.v3.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.constant.ErrorCode;
import com.tencent.bk.job.common.esb.model.EsbAppScopeReq;
import com.tencent.bk.job.common.exception.InvalidParamException;
Expand All @@ -49,6 +50,12 @@ public class EsbUpdateCronStatusV3Request extends EsbAppScopeReq {
*/
private Integer status;

/**
* 是否返回定时任务详情
*/
@JsonProperty("return_cron_detail")
private Boolean returnCronDetail = false;

public boolean validate() {
if (id == null || id <= 0) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public EsbResp<EsbCronInfoV3DTO> updateCronStatus(String username,
if (updateResult) {
EsbCronInfoV3DTO esbCronInfoV3DTO = new EsbCronInfoV3DTO();
esbCronInfoV3DTO.setId(request.getId());
if (request.getReturnCronDetail()) {
CronJobInfoDTO cronJobInfoById = cronJobService.getCronJobInfoById(request.getAppId(),
request.getId());
esbCronInfoV3DTO = CronJobInfoDTO.toEsbCronInfoV3(cronJobInfoById);
}
return EsbResp.buildSuccessResp(esbCronInfoV3DTO);
}
throw new InternalException(ErrorCode.UPDATE_CRON_JOB_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.tencent.bk.job.api.v3.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.api.model.EsbAppScopeReq;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -46,4 +47,11 @@ public class EsbUpdateCronStatusV3Request extends EsbAppScopeReq {
* 1.启动、2.暂停
*/
private Integer status;

/**
* 是否返回定时任务详情
*/
@JsonProperty("return_cron_detail")
private Boolean returnCronDetail = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ void testUpdateCronStatus() {
.spec(ApiUtil.successResponseSpec())
.body("data", notNullValue())
.body("data.id", equalTo(req.getId().intValue()));

// 返回定时任务详情
req.setReturnCronDetail(true);
given().spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.UPDATE_CRON_STATUS)
.then()
.spec(ApiUtil.successResponseSpec())
.body("data", notNullValue())
.body("data.id", equalTo(req.getId().intValue()))
.body("data.name", notNullValue())
.body("data.status", notNullValue())
.body("data.bk_scope_type", equalTo(req.getScopeType()))
.body("data.bk_scope_id", equalTo(req.getScopeId()))
.body("data.expression", notNullValue())
.body("data.creator", equalTo(TestProps.DEFAULT_TEST_USER))
.body("data.create_time", greaterThan(0))
.body("data.last_modify_user", equalTo(TestProps.DEFAULT_TEST_USER))
.body("data.last_modify_time", greaterThan(0));
}

// 更新定时任务
Expand Down
Loading