Skip to content

Commit

Permalink
feature: 添加删除定时任务的ESB/APIGW接口 TencentBlueKing#2733
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliaozhong committed Jan 17, 2024
1 parent a7d0c9d commit 4bec56c
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 1 deletion.
53 changes: 53 additions & 0 deletions docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md
@@ -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_job.md
@@ -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
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
Expand Up @@ -181,6 +181,7 @@
1244029=步骤 [{0}] 的源文件主机为空

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Expand Up @@ -181,6 +181,7 @@
1244029=Step [{0}] source host is empty

## 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
Expand Up @@ -181,6 +181,7 @@
1244029=Step [{0}] source host is empty

## 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
Expand Up @@ -181,6 +181,7 @@
1244029=步骤 [{0}] 的源文件主机为空

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Expand Up @@ -182,6 +182,7 @@
1244029=步骤 [{0}] 的源文件主机为空

## 业务错误-定时任务(job-crontab)
1245008=删除定时任务失败
1245006=定时任务执行时间已失效
1245007=定时任务结束时间或通知时间已失效
1245005=更新定时任务获取锁失败
Expand Down
Expand Up @@ -348,6 +348,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
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
);
}
@@ -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.NotEmpty;

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

/**
* 定时作业 ID
*/
@NotEmpty(message = "{validation.constraints.CronId_empty.message}")
@Min(value = 1L, message = "{validation.constraints.InvalidCronId.message}")
private Long id;
}
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
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
Expand Up @@ -69,6 +69,8 @@ public interface APIV3Urls {
String GET_CRON_LIST = "/api/job/v3/job-crontab/get_cron_list";
String UPDATE_CRON_STATUS = "/api/job/v3/job-crontab/update_cron_status";
String GET_CRON_DETAIL = "/api/job/v3/job-crontab/get_cron_detail";
String DELETE_CRON = "/api/job/v3/job-crontab/delete_cron";


String GET_JOB_PLAN_LIST = "/api/job/v3/job-manage/get_job_plan_list";
}
@@ -0,0 +1,39 @@
/*
* 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.api.v3.model.request;

import com.tencent.bk.job.api.model.EsbAppScopeReq;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class EsbDeleteCronV3Request extends EsbAppScopeReq {

/**
* 定时作业 ID
*/
private Long id;
}

0 comments on commit 4bec56c

Please sign in to comment.