Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/bk-job into issue…
Browse files Browse the repository at this point in the history
…_2631
  • Loading branch information
wangyu096 committed Feb 1, 2024
2 parents 6ab5dca + a7e1878 commit 49148ac
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 1 deletion.
62 changes: 62 additions & 0 deletions docs/apidoc/bk-api-gateway/v3/zh/delete_cron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
### 功能描述

删除定时任务

### 请求参数

{{ bkapi_authorization_description }}

#### Header参数

| 字段 | 类型 | 必选 | 描述 |
|---------------------------|------------|---------|------------|
| X-Bkapi-Authorization | string || 认证信息。详情参考[调用网关 API](https://github.com/TencentBlueKing/BKDocs/blob/master/ZH/7.0/APIGateway/apigateway/use-api/use-apigw-api.md) |
| Accept | string || 固定值。application/json|
| Content-Type | string || 固定值。application/json|

#### Body参数

| 字段 | 类型 | 必选 | 描述 |
|---------------|------------|--------|------------|
| bk_scope_type | string || 资源范围类型。可选值: biz - 业务,biz_set - 业务集 |
| bk_scope_id | string || 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| id | long || 定时任务ID |

### 请求参数示例

- POST
```json
{
"bk_app_code": "esb_test",
"bk_app_secret": "xxx",
"bk_token": "xxx",
"bk_scope_type":"biz",
"bk_scope_id":"2",
"id": 1000045
}
```

### 返回结果示例

```json
{
"code": 0,
"result": true
}
```

### 返回结果参数说明

#### response
| 字段 | 类型 | 描述 |
|--------------|-----------|-----------|
| result | bool | 请求成功与否。true:请求成功;false请求失败 |
| code | int | 错误编码。 0表示success,>0表示失败错误 |
| message | string | 请求失败返回的错误信息|
| data | object | 请求返回的数据|
| permission | object | 权限信息|


#### data

53 changes: 53 additions & 0 deletions docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Function Description

Delete cron job

### Request Parameters

{{ common_args_desc }}

#### Interface parameters

| Fields | Type | Required | Description |
| ------------- | ------ | -------- | ------------------------------------------------------------ |
| bk_scope_type | string | yes | Resource scope type. Optional values: biz - Business,biz_set - Business Set |
| 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 |

### Example of request

```json
{
"bk_app_code": "esb_test",
"bk_app_secret": "xxx",
"bk_token": "xxx",
"bk_scope_type":"biz",
"bk_scope_id":"2",
"id": 1000045
}
```

### Example of responses

```json
{
"code": 0,
"result": true
}
```

### Response Description

#### response

| Fields | Type | Description |
| ---------- | ------ | ------------------------------------------------------------ |
| result | bool | Whether the request succeeded or not. True: request succeeded;False: request failed |
| code | int | Error code. 0 indicates success, >0 indicates failure |
| message | string | Error message |
| data | object | Data returned by request |
| permission | object | Permission information |

#### data

null
53 changes: 53 additions & 0 deletions docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### 功能描述

删除定时任务

### 请求参数

{{ common_args_desc }}

#### 接口参数

| 字段 | 类型 | 必选 | 描述 |
| ------------- | ------ | ---- | ------------------------------------------------------- |
| bk_scope_type | string || 资源范围类型。可选值: biz - 业务,biz_set - 业务集 |
| bk_scope_id | string || 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| id | long || 定时任务ID |

### 请求参数示例

```json
{
"bk_app_code": "esb_test",
"bk_app_secret": "xxx",
"bk_token": "xxx",
"bk_scope_type":"biz",
"bk_scope_id":"2",
"id": 1000045
}
```

### 返回结果示例

```json
{
"code": 0,
"result": true
}
```

### 返回结果参数说明

#### response

| 字段 | 类型 | 描述 |
| ---------- | ------ | ------------------------------------------ |
| result | bool | 请求成功与否。true:请求成功;false请求失败 |
| code | int | 错误编码。 0表示success,>0表示失败错误 |
| message | string | 请求失败返回的错误信息 |
| data | object | 请求返回的数据 |
| permission | object | 权限信息 |

#### data

10 changes: 10 additions & 0 deletions docs/apidoc/esb/jobv3-confapis/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@
dest_path: /api/job/v3/job-crontab/update_cron_status/
dest_http_method: POST

- path: /v2/jobv3/delete_cron/
name: delete_cron
label: 删除定时任务
label_en: Delete cron
suggest_method: POST
api_type: operate
comp_codename: generic.v2.jobv3.job_component
dest_path: /api/job/v3/job-crontab/delete_cron/
dest_http_method: POST

- path: /v2/jobv3/create_credential/
name: create_credential
label: 新建凭据
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
1244030=作业引用的执行对象不存在。不存在的执行对象个数:{0},执行对象列表[{1}]

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
1244030=Execute object referenced by the job does not exist. Number of non-existent execution objects: {0}, execution object list: [{1}]

## Business error - job-crontab
1245008=Failed to delete cron
1245006=Cron job execution time already passed
1245007=Cron job end time or notify time already passed
1245005=Acquire lock failed while update cron job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
1244030=Execute object referenced by the job does not exist. Number of non-existent execution objects: {0}, execution object list: [{1}]

## Business error - job-crontab
1245008=Failed to delete cron
1245006=Cron job execution time already passed
1245007=Cron job end time or notify time already passed
1245005=Acquire lock failed while update cron job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
1244030=作业引用的执行对象不存在。不存在的执行对象个数:{0},执行对象列表[{1}]

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
1244030=作业引用的执行对象不存在。不存在的执行对象个数:{0},执行对象列表[{1}]

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ validation.constraints.InvalidHighRiskRegularStatus.message=非法的规则启
validation.constraints.InvalidHighRiskRegularDescription_outOfLength.message=规则说明不能超过{max}个字符
validation.constraints.InvalidBkBizId.message=非法的业务 ID
validation.constraints.InvalidCronId.message=非法的定时任务 ID
validation.constraints.CronId_null.message=定时任务ID不能为空
validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID
validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空
validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ validation.constraints.InvalidHighRiskRegularStatus.message=Invalid High-risk ex
validation.constraints.InvalidHighRiskRegularDescription_outOfLength.message=High-risk explanation description can not exceed {max} characters
validation.constraints.InvalidBkBizId.message=Invalid bk_biz_id
validation.constraints.InvalidCronId.message=Invalid id
validation.constraints.CronId_null.message=Cron id cannot be null
validation.constraints.InvalidCronJobPlanId.message=Invalid job_plan_id
validation.constraints.InvalidCronJobName_empty.message=Cron name cannot be empty
validation.constraints.InvalidCronJobName_outOfLength.message=Cron name can not exceed {max} characters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ validation.constraints.InvalidHighRiskRegularStatus.message=Invalid High-risk ex
validation.constraints.InvalidHighRiskRegularDescription_outOfLength.message=High-risk explanation description can not exceed {max} characters
validation.constraints.InvalidBkBizId.message=Invalid bk_biz_id
validation.constraints.InvalidCronId.message=Invalid id
validation.constraints.CronId_null.message=Cron id cannot be null
validation.constraints.InvalidCronJobPlanId.message=Invalid job_plan_id
validation.constraints.InvalidCronJobName_empty.message=Cron name cannot be empty
validation.constraints.InvalidCronJobName_outOfLength.message=Cron name can not exceed {max} characters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ validation.constraints.InvalidHighRiskRegularStatus.message=非法的规则启
validation.constraints.InvalidHighRiskRegularDescription_outOfLength.message=规则说明不能超过{max}个字符
validation.constraints.InvalidBkBizId.message=非法的业务 ID
validation.constraints.InvalidCronId.message=非法的定时任务 ID
validation.constraints.CronId_null.message=定时任务ID不能为空
validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID
validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空
validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ validation.constraints.InvalidHighRiskRegularStatus.message=非法的规则启
validation.constraints.InvalidHighRiskRegularDescription_outOfLength.message=规则说明不能超过{max}个字符
validation.constraints.InvalidBkBizId.message=非法的业务ID
validation.constraints.InvalidCronId.message=非法的定时任务ID
validation.constraints.CronId_null.message=定时任务ID不能为空
validation.constraints.InvalidCronJobPlanId.message=非法的作业ID
validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空
validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public class ErrorCode {
public static final int ACQUIRE_CRON_JOB_LOCK_FAILED = 1245005;
public static final int CRON_JOB_TIME_PASSED = 1245006;
public static final int END_TIME_OR_NOTIFY_TIME_ALREADY_PASSED = 1245007;
public static final int DELETE_CRON_FAILED = 1245008;
// 定时作业 end

// 日志服务
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.tencent.bk.job.common.constant.JobCommonHeaders;
import com.tencent.bk.job.common.esb.model.EsbResp;
import com.tencent.bk.job.common.esb.model.job.v3.EsbPageDataV3;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbDeleteCronV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbGetCronDetailV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbGetCronListV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbSaveCronV3Request;
Expand Down Expand Up @@ -136,4 +137,16 @@ EsbResp<EsbCronInfoV3DTO> saveCron(
@Validated
EsbSaveCronV3Request request
);

/**
* 删除定时任务
*/
@PostMapping(value = "/delete_cron")
EsbResp deleteCron(
@RequestHeader(value = JobCommonHeaders.USERNAME) String username,
@RequestHeader(value = JobCommonHeaders.APP_CODE) String appCode,
@RequestBody
@Validated
EsbDeleteCronV3Request request
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
*
* License for BK-JOB蓝鲸智云作业平台:
* --------------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

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

import com.tencent.bk.job.common.esb.model.EsbAppScopeReq;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("删除定时任务请求报文")
public class EsbDeleteCronV3Request extends EsbAppScopeReq {

/**
* 定时作业 ID
*/
@NotNull(message = "{validation.constraints.CronId_null.message}")
@Min(value = 1L, message = "{validation.constraints.InvalidCronId.message}")
private Long id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.tencent.bk.job.crontab.exception.TaskExecuteAuthFailedException;
import com.tencent.bk.job.crontab.model.dto.CronJobInfoDTO;
import com.tencent.bk.job.crontab.model.dto.CronJobVariableDTO;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbDeleteCronV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbGetCronDetailV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbGetCronListV3Request;
import com.tencent.bk.job.crontab.model.esb.v3.request.EsbSaveCronV3Request;
Expand Down Expand Up @@ -334,6 +335,18 @@ public EsbResp<EsbCronInfoV3DTO> saveCron(String username,
}
}

@Override
@EsbApiTimed(value = CommonMetricNames.ESB_API, extraTags = {"api_name", "v3_delete_cron"})
@AuditEntry
public EsbResp deleteCron(String username,
String appCode,
@AuditRequestBody EsbDeleteCronV3Request request) {
if (cronJobService.deleteCronJobInfo(username, request.getAppId(), request.getId())) {
return EsbResp.buildSuccessResp(null);
}
return EsbResp.buildCommonFailResp(ErrorCode.DELETE_CRON_FAILED);
}

private void checkRequest(EsbSaveCronV3Request request) {
// 定时任务表达式有效性校验
if (StringUtils.isNotBlank(request.getCronExpression())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.tencent.bk.job.api.v3.model.request.EsbCreateDangerousRuleV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbCreatePublicScriptV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbCreateScriptV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbDeleteCronV3Request;
import com.tencent.bk.job.api.v3.model.request.EsbDeletePublicScriptV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbDeletePublicScriptVersionV3Req;
import com.tencent.bk.job.api.v3.model.request.EsbDeleteScriptV3Req;
Expand Down Expand Up @@ -331,6 +332,15 @@ public static EsbCronInfoV3DTO createCron() {
.getData();
}

public static void deleteCron(EsbDeleteCronV3Request req) {
given()
.spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER))
.body(JsonUtil.toJson(req))
.post(APIV3Urls.DELETE_CRON)
.then()
.statusCode(200);
}

public static Long getTaskPlanId() {
EsbGetPlanListV3Request req = new EsbGetPlanListV3Request();
req.setScopeId(String.valueOf(TestProps.DEFAULT_BIZ));
Expand Down
Loading

0 comments on commit 49148ac

Please sign in to comment.