From 4bec56cdc3d5c7d0c02a6033fb11d0e8e2a183f8 Mon Sep 17 00:00:00 2001 From: liuliaozhong Date: Wed, 17 Jan 2024 18:18:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feature:=20=E6=B7=BB=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9A=84ESB/APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apidocs/en/delete_cron_job.md | 53 +++++++++++++++++++ .../apidocs/zh_hans/delete_cron_job.md | 53 +++++++++++++++++++ docs/apidoc/esb/jobv3-confapis/job.yaml | 10 ++++ .../i18n/exception/message.properties | 1 + .../i18n/exception/message_en.properties | 1 + .../i18n/exception/message_en_US.properties | 1 + .../i18n/exception/message_zh.properties | 1 + .../i18n/exception/message_zh_CN.properties | 1 + .../bk/job/common/constant/ErrorCode.java | 1 + .../api/esb/v3/EsbCronJobV3Resource.java | 13 +++++ .../v3/request/EsbDeleteCronV3Request.java | 46 ++++++++++++++++ .../esb/v3/impl/EsbCronJobV3ResourceImpl.java | 13 +++++ .../tencent/bk/job/api/util/Operations.java | 10 ++++ .../bk/job/api/v3/constants/APIV3Urls.java | 2 + .../model/request/EsbDeleteCronV3Request.java | 39 ++++++++++++++ .../api/v3/testcase/CronResourceAPITest.java | 34 +++++++++++- 16 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md create mode 100644 docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron_job.md create mode 100644 src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java create mode 100644 tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbDeleteCronV3Request.java diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md b/docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md new file mode 100644 index 0000000000..257057bb37 --- /dev/null +++ b/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 diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron_job.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron_job.md new file mode 100644 index 0000000000..aa4ef8c67a --- /dev/null +++ b/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 + +无 diff --git a/docs/apidoc/esb/jobv3-confapis/job.yaml b/docs/apidoc/esb/jobv3-confapis/job.yaml index 552a4e1858..161a2b81f6 100644 --- a/docs/apidoc/esb/jobv3-confapis/job.yaml +++ b/docs/apidoc/esb/jobv3-confapis/job.yaml @@ -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: 新建凭据 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties index 4e4ebc7734..02f100c9a5 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message.properties @@ -181,6 +181,7 @@ 1244029=步骤 [{0}] 的源文件主机为空 ## 业务错误-定时任务(job-crontab) +1245008=删除定时任务失败 1245006=定时任务执行时间已失效 1245007=定时任务结束时间或通知时间已失效 1245005=更新定时任务获取锁失败 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties index ce7cf7bfb3..8173562ffe 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en.properties @@ -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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties index ce7cf7bfb3..8173562ffe 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_en_US.properties @@ -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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties index 4e4ebc7734..02f100c9a5 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh.properties @@ -181,6 +181,7 @@ 1244029=步骤 [{0}] 的源文件主机为空 ## 业务错误-定时任务(job-crontab) +1245008=删除定时任务失败 1245006=定时任务执行时间已失效 1245007=定时任务结束时间或通知时间已失效 1245005=更新定时任务获取锁失败 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties index b058a7153e..bac5184c7c 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/exception/message_zh_CN.properties @@ -182,6 +182,7 @@ 1244029=步骤 [{0}] 的源文件主机为空 ## 业务错误-定时任务(job-crontab) +1245008=删除定时任务失败 1245006=定时任务执行时间已失效 1245007=定时任务结束时间或通知时间已失效 1245005=更新定时任务获取锁失败 diff --git a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java index d4ce0f7006..4218ec4f6e 100644 --- a/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java +++ b/src/backend/commons/common/src/main/java/com/tencent/bk/job/common/constant/ErrorCode.java @@ -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 // 日志服务 diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java index 1bff0ed6fc..2ba2a13d5a 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/EsbCronJobV3Resource.java @@ -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; @@ -136,4 +137,16 @@ EsbResp 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 + ); } diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java new file mode 100644 index 0000000000..87222790f6 --- /dev/null +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java @@ -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; +} diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java index c95669b750..92098be27c 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/api/esb/v3/impl/EsbCronJobV3ResourceImpl.java @@ -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; @@ -334,6 +335,18 @@ public EsbResp 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())) { diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java index 4606b48476..483fdc36a9 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/util/Operations.java @@ -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; @@ -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)); diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java index 4b2ebcd41b..42426a2ff6 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/constants/APIV3Urls.java @@ -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"; } diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbDeleteCronV3Request.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbDeleteCronV3Request.java new file mode 100644 index 0000000000..b7824a8124 --- /dev/null +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/model/request/EsbDeleteCronV3Request.java @@ -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; +} diff --git a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java index ed0721fcd1..6c33063754 100644 --- a/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java +++ b/tests/openapi/src/test/java/com/tencent/bk/job/api/v3/testcase/CronResourceAPITest.java @@ -11,11 +11,13 @@ import com.tencent.bk.job.api.util.TestValueGenerator; import com.tencent.bk.job.api.v3.constants.APIV3Urls; import com.tencent.bk.job.api.v3.model.EsbCronInfoV3DTO; +import com.tencent.bk.job.api.v3.model.request.EsbDeleteCronV3Request; import com.tencent.bk.job.api.v3.model.request.EsbGetCronDetailV3Request; import com.tencent.bk.job.api.v3.model.request.EsbGetCronListV3Request; import com.tencent.bk.job.api.v3.model.request.EsbSaveCronV3Request; import com.tencent.bk.job.api.v3.model.request.EsbUpdateCronStatusV3Request; import io.restassured.common.mapper.TypeRef; +import org.apache.commons.collections4.CollectionUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -39,7 +41,17 @@ class CronResourceAPITest extends BaseTest { @AfterAll static void tearDown() { - // cron没有清理接口,暂时忽略 + // 清理测试数据 + if (CollectionUtils.isNotEmpty(createdCronList)) { + createdCronList.forEach(cron -> { + // 清理定时任务 + EsbDeleteCronV3Request req = new EsbDeleteCronV3Request(); + req.setScopeId(cron.getScopeId()); + req.setScopeType(cron.getScopeType()); + req.setId(cron.getId()); + Operations.deleteCron(req); + }); + } } @Nested @@ -253,4 +265,24 @@ void testUpdateCron() { .body("data.bk_scope_id", equalTo(req.getScopeId())); } } + + @Nested + class CronDeleteTest { + @Test + @DisplayName("测试定时任务删除") + void testDeleteCron() { + EsbCronInfoV3DTO createdScript = Operations.createCron(); + EsbDeleteCronV3Request req = new EsbDeleteCronV3Request(); + req.setScopeId(createdScript.getScopeId()); + req.setScopeType(createdScript.getScopeType()); + req.setId(createdScript.getId()); + + given() + .spec(ApiUtil.requestSpec(TestProps.DEFAULT_TEST_USER)) + .body(JsonUtil.toJson(req)) + .post(APIV3Urls.DELETE_CRON) + .then() + .spec(ApiUtil.successResponseSpec()); + } + } } From 41beb92c6fa3b40535ebf4761ea7605e14405f40 Mon Sep 17 00:00:00 2001 From: liuliaozhong Date: Fri, 26 Jan 2024 18:28:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feature:=20=E6=B7=BB=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9A=84ESB/APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bk-api-gateway/v3/zh/delete_cron.md | 62 +++++++++++++++++++ .../en/{delete_cron_job.md => delete_cron.md} | 0 .../{delete_cron_job.md => delete_cron.md} | 0 .../validation/ValidationMessages.properties | 1 + .../ValidationMessages_en.properties | 1 + .../ValidationMessages_en_US.properties | 1 + .../ValidationMessages_zh.properties | 1 + .../ValidationMessages_zh_CN.properties | 1 + .../v3/request/EsbDeleteCronV3Request.java | 4 +- 9 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 docs/apidoc/bk-api-gateway/v3/zh/delete_cron.md rename docs/apidoc/esb/jobv3-confapis/apidocs/en/{delete_cron_job.md => delete_cron.md} (100%) rename docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/{delete_cron_job.md => delete_cron.md} (100%) diff --git a/docs/apidoc/bk-api-gateway/v3/zh/delete_cron.md b/docs/apidoc/bk-api-gateway/v3/zh/delete_cron.md new file mode 100644 index 0000000000..676f7cf123 --- /dev/null +++ b/docs/apidoc/bk-api-gateway/v3/zh/delete_cron.md @@ -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 + +无 diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md b/docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron.md similarity index 100% rename from docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron_job.md rename to docs/apidoc/esb/jobv3-confapis/apidocs/en/delete_cron.md diff --git a/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron_job.md b/docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron.md similarity index 100% rename from docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron_job.md rename to docs/apidoc/esb/jobv3-confapis/apidocs/zh_hans/delete_cron.md diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties index 55e374504e..235f15e4a0 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties @@ -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_empty.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties index c908964129..d0930d2c8f 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties @@ -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_empty.message=Cron id cannot be empty 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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties index c908964129..d0930d2c8f 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties @@ -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_empty.message=Cron id cannot be empty 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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties index 3340848b6b..d859bc43fe 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties @@ -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_empty.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties index e62ef5c1c1..29fff1cc07 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties @@ -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_empty.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java index 87222790f6..e519dbe6ec 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java @@ -30,7 +30,7 @@ import lombok.EqualsAndHashCode; import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; @Data @EqualsAndHashCode(callSuper = true) @@ -40,7 +40,7 @@ public class EsbDeleteCronV3Request extends EsbAppScopeReq { /** * 定时作业 ID */ - @NotEmpty(message = "{validation.constraints.CronId_empty.message}") + @NotNull(message = "{validation.constraints.CronId_empty.message}") @Min(value = 1L, message = "{validation.constraints.InvalidCronId.message}") private Long id; } From 9dc7a121fe4bbbe82396fcb3974523e47d05e511 Mon Sep 17 00:00:00 2001 From: liuliaozhong Date: Mon, 29 Jan 2024 14:18:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feature:=20=E6=B7=BB=E5=8A=A0=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9A=84ESB/APIGW?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20#2733?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/i18n/validation/ValidationMessages.properties | 2 +- .../resources/i18n/validation/ValidationMessages_en.properties | 2 +- .../i18n/validation/ValidationMessages_en_US.properties | 2 +- .../resources/i18n/validation/ValidationMessages_zh.properties | 2 +- .../i18n/validation/ValidationMessages_zh_CN.properties | 2 +- .../crontab/model/esb/v3/request/EsbDeleteCronV3Request.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties index 235f15e4a0..75fee5f361 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages.properties @@ -47,7 +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_empty.message=定时任务ID不能为空 +validation.constraints.CronId_null.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties index d0930d2c8f..82421144c9 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en.properties @@ -47,7 +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_empty.message=Cron id cannot be empty +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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties index d0930d2c8f..82421144c9 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_en_US.properties @@ -47,7 +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_empty.message=Cron id cannot be empty +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 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties index d859bc43fe..66837b4997 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh.properties @@ -47,7 +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_empty.message=定时任务ID不能为空 +validation.constraints.CronId_null.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业 ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties index 29fff1cc07..f20e6ede3c 100644 --- a/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties +++ b/src/backend/commons/common-i18n/src/main/resources/i18n/validation/ValidationMessages_zh_CN.properties @@ -47,7 +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_empty.message=定时任务ID不能为空 +validation.constraints.CronId_null.message=定时任务ID不能为空 validation.constraints.InvalidCronJobPlanId.message=非法的作业ID validation.constraints.InvalidCronJobName_empty.message=定时作业名称不能为空 validation.constraints.InvalidCronJobName_outOfLength.message=定时作业名称不能超过{max}个字符 diff --git a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java index e519dbe6ec..aa603d6b8f 100644 --- a/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java +++ b/src/backend/job-crontab/api-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/esb/v3/request/EsbDeleteCronV3Request.java @@ -40,7 +40,7 @@ public class EsbDeleteCronV3Request extends EsbAppScopeReq { /** * 定时作业 ID */ - @NotNull(message = "{validation.constraints.CronId_empty.message}") + @NotNull(message = "{validation.constraints.CronId_null.message}") @Min(value = 1L, message = "{validation.constraints.InvalidCronId.message}") private Long id; }