diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3Resource.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3Resource.java new file mode 100644 index 0000000000..4efc22063a --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3Resource.java @@ -0,0 +1,63 @@ +/* + * 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.execute.api.esb.v3; + +import com.tencent.bk.job.common.annotation.EsbAPI; +import com.tencent.bk.job.common.constant.JobCommonHeaders; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.execute.model.esb.v3.EsbTaskLinkV3DTO; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RequestMapping("/esb/api/v3") +@RestController +@EsbAPI +public interface EsbQueryToolsV3Resource { + + @GetMapping("/query_gse_task") + EsbResp> queryGSETaskByStep( + @RequestHeader(value = JobCommonHeaders.USERNAME) + String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) + String appCode, + @RequestParam(value = "step_instance_id") + Long stepInstanceId + ); + + @GetMapping("/query_job_instance") + EsbResp queryJobInstanceByGseTask( + @RequestHeader(value = JobCommonHeaders.USERNAME) + String username, + @RequestHeader(value = JobCommonHeaders.APP_CODE) + String appCode, + @RequestParam(value = "gse_task_id") + String gseTaskId + ); +} diff --git a/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskLinkV3DTO.java b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskLinkV3DTO.java new file mode 100644 index 0000000000..87b2c20ecc --- /dev/null +++ b/src/backend/job-execute/api-job-execute/src/main/java/com/tencent/bk/job/execute/model/esb/v3/EsbTaskLinkV3DTO.java @@ -0,0 +1,71 @@ +/* + * 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.execute.model.esb.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tencent.bk.job.common.esb.model.EsbAppScopeDTO; +import lombok.Data; + +import java.util.List; + +@Data +public class EsbTaskLinkV3DTO extends EsbAppScopeDTO { + + /** + * 任务ID + */ + @JsonProperty("job_instance_id") + private Long jobInstanceId; + + /** + * 步骤ID + */ + @JsonProperty("step_instance_id") + private Long stepInstanceId; + + /** + * 执行次数 + */ + @JsonProperty("retry_count") + private Integer retryCount; + + /** + * 批次 + */ + @JsonProperty("batch") + private Integer batch; + + /** + * gse任务ID + */ + @JsonProperty("gse_task_id") + private String gseTaskId; + + /** + * web访问链接 + */ + @JsonProperty("link") + private List link; +} diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3ResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3ResourceImpl.java new file mode 100644 index 0000000000..4515140831 --- /dev/null +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/esb/v3/EsbQueryToolsV3ResourceImpl.java @@ -0,0 +1,231 @@ +/* + * 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.execute.api.esb.v3; + +import com.tencent.bk.job.common.constant.ErrorCode; +import com.tencent.bk.job.common.esb.model.EsbResp; +import com.tencent.bk.job.common.esb.util.EsbDTOAppScopeMappingHelper; +import com.tencent.bk.job.common.iam.constant.ActionId; +import com.tencent.bk.job.common.iam.exception.PermissionDeniedException; +import com.tencent.bk.job.common.iam.model.AuthResult; +import com.tencent.bk.job.common.iam.service.AppAuthService; +import com.tencent.bk.job.common.model.dto.AppResourceScope; +import com.tencent.bk.job.common.model.dto.ResourceScope; +import com.tencent.bk.job.common.service.AppScopeMappingService; +import com.tencent.bk.job.execute.model.GseTaskSimpleDTO; +import com.tencent.bk.job.execute.model.StepInstanceBaseDTO; +import com.tencent.bk.job.execute.model.StepInstanceRollingTaskDTO; +import com.tencent.bk.job.execute.model.esb.v3.EsbTaskLinkV3DTO; +import com.tencent.bk.job.execute.service.GseTaskService; +import com.tencent.bk.job.execute.service.StepInstanceRollingTaskService; +import com.tencent.bk.job.execute.service.StepInstanceService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +public class EsbQueryToolsV3ResourceImpl implements EsbQueryToolsV3Resource { + private final StepInstanceService stepInstanceService; + private final GseTaskService gseTaskService; + private final AppAuthService appAuthService; + private final AppScopeMappingService appScopeMappingService; + private final StepInstanceRollingTaskService stepInstanceRollingTaskService; + + @Value("${job.web.url:}") + private String jobWebUrl; + + /** + * 快速执行链接地址 + */ + private static final String FAST_LINK = "%s/api_execute/%s?stepInstanceId=%s&retryCount=%s&batch=%s"; + + /** + * 作业执行链接地址 + */ + private static final String TASK_LINK = "%s/api_execute_step/%s/%s?retryCount=%s&batch=%s"; + + @Autowired + public EsbQueryToolsV3ResourceImpl(StepInstanceService stepInstanceService, + GseTaskService gseTaskService, + AppAuthService appAuthService, + AppScopeMappingService appScopeMappingService, + StepInstanceRollingTaskService stepInstanceRollingTaskService) { + this.stepInstanceService = stepInstanceService; + this.gseTaskService = gseTaskService; + this.appAuthService = appAuthService; + this.appScopeMappingService = appScopeMappingService; + this.stepInstanceRollingTaskService = stepInstanceRollingTaskService; + } + + @Override + public EsbResp> queryGSETaskByStep(String username, String appCode, Long stepInstanceId) { + StepInstanceBaseDTO stepInstance = stepInstanceService.getBaseStepInstanceById(stepInstanceId); + if (stepInstance == null) { + String reason = String.format("step not found by id: %s", stepInstanceId); + return EsbResp.buildCommonFailResp( + ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON, + new String[]{String.valueOf(stepInstanceId), reason}, + null + ); + } + + Long appId = stepInstance.getAppId(); + ResourceScope resourceScope = appScopeMappingService.getAppResourceScope(appId); + AppResourceScope appResourceScope = new AppResourceScope(appId, resourceScope); + // 鉴权 + auth(username, appResourceScope); + + List gseTaskResult = new ArrayList<>(); + List stepInstanceRollingTaskDTOS = + stepInstanceRollingTaskService.listRollingTasksByStep(stepInstance.getTaskInstanceId(), stepInstanceId); + + if (CollectionUtils.isNotEmpty(stepInstanceRollingTaskDTOS)) { + // 步骤为滚动执行 + for (StepInstanceRollingTaskDTO stepInstanceRollingTaskDTO : stepInstanceRollingTaskDTOS) { + List gseTaskSimpleDTOS = gseTaskService.listGseTaskSimpleInfo( + stepInstanceId, + stepInstanceRollingTaskDTO.getExecuteCount(), + stepInstanceRollingTaskDTO.getBatch() + ); + gseTaskResult.addAll(gseTaskSimpleDTOS); + } + } else { + // 步骤不是滚动执行 + gseTaskResult.addAll(gseTaskService.listGseTaskSimpleInfo( + stepInstanceId, + null, + null + )); + } + + List taskLinks = new ArrayList<>(); + for (GseTaskSimpleDTO gseTaskSimpleDTO : gseTaskResult) { + taskLinks.add(buildEsbTaskLinkV3DTO( + appId, + stepInstance, + gseTaskSimpleDTO.getExecuteCount(), + gseTaskSimpleDTO.getBatch(), + gseTaskSimpleDTO.getGseTaskId() + )); + } + return EsbResp.buildSuccessResp(taskLinks); + } + + @Override + public EsbResp queryJobInstanceByGseTask(String username, String appCode, String gseTaskId) { + GseTaskSimpleDTO gseTask = gseTaskService.getGseTaskSimpleInfo(gseTaskId); + if (gseTask == null) { + String reason = String.format("gseTask not found by id: %s", gseTaskId); + return EsbResp.buildCommonFailResp( + ErrorCode.ILLEGAL_PARAM_WITH_PARAM_NAME_AND_REASON, + new String[]{gseTaskId, reason}, + null + ); + } + + StepInstanceBaseDTO stepInstanceBaseDTO = stepInstanceService.getBaseStepInstance( + gseTask.getTaskInstanceId(), + gseTask.getStepInstanceId() + ); + Long appId = stepInstanceBaseDTO.getAppId(); + ResourceScope resourceScope = appScopeMappingService.getScopeByAppId(appId); + AppResourceScope appResourceScope = new AppResourceScope(appId, resourceScope); + auth(username, appResourceScope); + + return EsbResp.buildSuccessResp(buildEsbTaskLinkV3DTO( + appId, + stepInstanceBaseDTO, + gseTask.getExecuteCount(), + gseTask.getBatch(), + gseTaskId + )); + } + + private void auth(String username, AppResourceScope appResourceScope) { + AuthResult authResult = appAuthService.auth( + username, + ActionId.ACCESS_BUSINESS, + appResourceScope + ); + if (!authResult.isPass()) { + throw new PermissionDeniedException(authResult); + } + + authResult = appAuthService.auth( + username, + ActionId.VIEW_HISTORY, + appResourceScope + ); + if (!authResult.isPass()) { + throw new PermissionDeniedException(authResult); + } + } + + private EsbTaskLinkV3DTO buildEsbTaskLinkV3DTO( + Long appId, + StepInstanceBaseDTO stepInstanceBase, + int retryCount, + int batch, + String gseTaskId + ) { + + EsbTaskLinkV3DTO esbTaskLinkV3DTO = new EsbTaskLinkV3DTO(); + esbTaskLinkV3DTO.setJobInstanceId(stepInstanceBase.getTaskInstanceId()); + esbTaskLinkV3DTO.setStepInstanceId(stepInstanceBase.getId()); + EsbDTOAppScopeMappingHelper.fillEsbAppScopeDTOByAppId(appId, esbTaskLinkV3DTO); + esbTaskLinkV3DTO.setRetryCount(retryCount); + esbTaskLinkV3DTO.setBatch(batch); + esbTaskLinkV3DTO.setGseTaskId(gseTaskId); + esbTaskLinkV3DTO.setLink(buildLink(esbTaskLinkV3DTO, stepInstanceBase)); + return esbTaskLinkV3DTO; + } + + private List buildLink(EsbTaskLinkV3DTO esbTaskLinkV3DTO, StepInstanceBaseDTO stepInstanceBase) { + List links = new ArrayList<>(); + String linkTemplate = FAST_LINK; + // 是作业执行 + if (stepInstanceBase.getStepId() != -1L) { + linkTemplate = TASK_LINK; + } + + String[] urls = jobWebUrl.split(","); + for (String url : urls) { + String link = String.format( + linkTemplate, + url, + esbTaskLinkV3DTO.getJobInstanceId(), + esbTaskLinkV3DTO.getStepInstanceId(), + esbTaskLinkV3DTO.getRetryCount(), + esbTaskLinkV3DTO.getBatch() + ); + links.add(link); + } + return links; + } +} diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebSearchToolsResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebSearchToolsResourceImpl.java index 7407d465fe..32b4c742ff 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebSearchToolsResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/web/impl/WebSearchToolsResourceImpl.java @@ -111,7 +111,7 @@ public Response> getTaskLinkByStepId(String username, // 是否滚动执行 if (CollectionUtils.isNotEmpty(stepInstanceRollingTaskDTOS)) { for (StepInstanceRollingTaskDTO stepInstanceRollingTaskDTO : stepInstanceRollingTaskDTOS) { - List gseTaskSimpleDTOList = gseTaskService.ListGseTaskSimpleInfo(stepInstanceId, + List gseTaskSimpleDTOList = gseTaskService.listGseTaskSimpleInfo(stepInstanceId, stepInstanceRollingTaskDTO.getExecuteCount(), stepInstanceRollingTaskDTO.getBatch()); if (CollectionUtils.isNotEmpty(gseTaskSimpleDTOList)) { @@ -119,7 +119,7 @@ public Response> getTaskLinkByStepId(String username, } } } else { - List gseTaskSimpleDTOList = gseTaskService.ListGseTaskSimpleInfo(stepInstanceId, + List gseTaskSimpleDTOList = gseTaskService.listGseTaskSimpleInfo(stepInstanceId, null, null); if (CollectionUtils.isNotEmpty(gseTaskSimpleDTOList)) { diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/GseTaskService.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/GseTaskService.java index fe53160c1f..189892cd46 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/GseTaskService.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/GseTaskService.java @@ -85,7 +85,7 @@ public interface GseTaskService { * @param batch 批次 * @return GSE 任务列表 */ - List ListGseTaskSimpleInfo(Long stepInstanceId, + List listGseTaskSimpleInfo(Long stepInstanceId, Integer executeCount, Integer batch); } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/GseTaskServiceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/GseTaskServiceImpl.java index cdff344f3a..0cc88ed6ab 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/GseTaskServiceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/service/impl/GseTaskServiceImpl.java @@ -75,7 +75,7 @@ public GseTaskSimpleDTO getGseTaskSimpleInfo(String gseTaskId) { } @Override - public List ListGseTaskSimpleInfo(Long stepInstanceId, + public List listGseTaskSimpleInfo(Long stepInstanceId, Integer executeCount, Integer batch) { return gseTaskDAO.ListGseTaskSimpleInfo(stepInstanceId, executeCount, batch); diff --git a/support-files/bk-api-gateway/v3/apidocs/en/system_query_gse_task.md.j2 b/support-files/bk-api-gateway/v3/apidocs/en/system_query_gse_task.md.j2 new file mode 100644 index 0000000000..e7c17fb95e --- /dev/null +++ b/support-files/bk-api-gateway/v3/apidocs/en/system_query_gse_task.md.j2 @@ -0,0 +1,81 @@ +### Function Description + +query gse task id by step instance id + +### Request Parameters + +#### Interface parameters + +| Fields | Type | Required | Description | +|------------------|------|----------|------------------| +| step_instance_id | Int | 是 | step instance id | + +### Example of request + +- GET + +```json +/api/v3/system/query_gse_task?step_instance_id=1000001 +``` + +### Example of response + +```json +{ + "result": true, + "code": 0, + "message": "success", + "data": [ + { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 1, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + }, + { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 2, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + } + ] +} +``` + +### Response Description + +#### response + +| Fields | Type | Description | +|------------|-------------------|------------------------------------------------------------------------------------------| +| result | bool | Whether the request was successful or not. True: request succeeded;False: request failed | +| code | int | Error code. 0 indicates success, >0 indicates failure | +| message | string | Error message | +| data | List | Data returned by request | +| permission | object | Permission information | +| request_id | string | Request chain id | + +##### TaskLinkDTO + +| Fields | Type | Description | +|------------------|----------|---------------------------------------------------------------------------------------------| +| bk_scope_type | string | Resource scope type. Optional values: biz - Business,biz_set - Business Set | +| bk_scope_id | string | Resource scope ID. Corresponds to bk_scope_type, which means business ID or business set ID | +| job_instance_id | long | Job instance ID | +| step_instance_id | long | Step instance ID | +| retry_count | int | Step retry count | +| batch | int | Batch No. Not set to 0 when rolling | +| gse_task_id | string | Gse task id | +| link | string[] | Gse task id corresponding job links | diff --git a/support-files/bk-api-gateway/v3/apidocs/en/system_query_job_instance.md.j2 b/support-files/bk-api-gateway/v3/apidocs/en/system_query_job_instance.md.j2 new file mode 100644 index 0000000000..dab212266d --- /dev/null +++ b/support-files/bk-api-gateway/v3/apidocs/en/system_query_job_instance.md.j2 @@ -0,0 +1,58 @@ +### Function Description + +query job link by gse task id + +### Request Parameters + +#### Interface parameters + +| Fields | Type | Required | Description | +|-------------|------|----------|-------------| +| gse_task_id | Int | yes | gse task id | + +### Example of request + +- GET + +```json +/api/v3/system/query_job_instance?gse_task_id=a:aa:aa:a +``` + +### Example of response + +```json +{ + "result": true, + "code": 0, + "message": "success", + "data": { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 1, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + } +} +``` + +### Response Description + +{% include '_generic_response.md.j2' %} + +##### data + +| Fields | Type | Description | +|------------------|----------|---------------------------------------------------------------------------------------------| +| bk_scope_type | string | Resource scope type. Optional values: biz - Business,biz_set - Business Set | +| bk_scope_id | string | Resource scope ID. Corresponds to bk_scope_type, which means business ID or business set ID | +| job_instance_id | long | Job instance ID | +| step_instance_id | long | Step instance ID | +| retry_count | int | Step retry count | +| batch | int | Batch No. Not set to 0 when rolling | +| gse_task_id | string | Gse task id | +| link | string[] | Gse task id corresponding job links | diff --git a/support-files/bk-api-gateway/v3/apidocs/zh/system_query_gse_task.md.j2 b/support-files/bk-api-gateway/v3/apidocs/zh/system_query_gse_task.md.j2 new file mode 100644 index 0000000000..a4d6540cf2 --- /dev/null +++ b/support-files/bk-api-gateway/v3/apidocs/zh/system_query_gse_task.md.j2 @@ -0,0 +1,81 @@ +### 功能描述 + +根据步骤实例id查询gse task id + +### 请求参数 + +#### Query参数 + +| 字段 | 类型 | 必选 | 描述 | +|------------------|-----|----|------------------| +| step_instance_id | Int | 是 | step instance id | + +### 请求参数示例 + +- GET + +```json +/api/v3/system/query_gse_task?step_instance_id=1000001 +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "success", + "data": [ + { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 1, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + }, + { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 2, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + } + ] +} +``` + +### 返回结果说明 + +#### response + +| 字段 | 类型 | 描述 | +|------------|-------------------|----------------------------| +| result | bool | 请求成功与否。true:请求成功;false请求失败 | +| code | int | 错误编码。 0表示success,>0表示失败错误 | +| message | string | 请求失败返回的错误信息 | +| data | List | 请求返回的数据 | +| request_id | string | 请求ID | +| permission | object | 权限信息 | + +##### TaskLinkDTO + +| 字段 | 类型 | 描述 | +|------------------|----------|-----------------------------------------| +| bk_scope_type | string | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| job_instance_id | long | 作业实例ID | +| step_instance_id | long | 脚本实例ID | +| retry_count | int | 重试次数 | +| batch | int | 批次,滚动执行时不为0 | +| gse_task_id | string | gse task id | +| link | string[] | gse task id 对应的job网址 | diff --git a/support-files/bk-api-gateway/v3/apidocs/zh/system_query_job_instance.md.j2 b/support-files/bk-api-gateway/v3/apidocs/zh/system_query_job_instance.md.j2 new file mode 100644 index 0000000000..9c24f69180 --- /dev/null +++ b/support-files/bk-api-gateway/v3/apidocs/zh/system_query_job_instance.md.j2 @@ -0,0 +1,58 @@ +### 功能描述 + +根据gse_task_id查询job链接 + +### 请求参数 + +#### Query参数 + +| 字段 | 类型 | 必选 | 描述 | +|-------------|-----|----|-------------| +| gse_task_id | Int | 是 | gse task id | + +### 请求参数示例 + +- GET + +```json +/api/v3/system/query_job_instance?gse_task_id=a:aa:aa:a +``` + +### 返回结果示例 + +```json +{ + "result": true, + "code": 0, + "message": "success", + "data": { + "bk_scope_type": "biz", + "bk_scope_id": "1", + "job_instance_id": 1000000, + "step_instance_id": 10000001, + "retry_count": 0, + "batch": 1, + "gse_task_id": "aa:aa:aa:aa", + "link": [ + "https://xxx.com" + ] + } +} +``` + +### 返回结果说明 + +{% include '_generic_response.md.j2' %} + +##### data + +| 字段 | 类型 | 描述 | +|------------------|----------|-----------------------------------------| +| bk_scope_type | string | 资源范围类型。可选值: biz - 业务,biz_set - 业务集 | +| bk_scope_id | string | 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID | +| job_instance_id | long | 作业实例ID | +| step_instance_id | long | 脚本实例ID | +| retry_count | int | 重试次数 | +| batch | int | 批次,滚动执行时不为0 | +| gse_task_id | string | gse task id | +| link | string[] | gse task id 对应的job网址 | diff --git a/support-files/bk-api-gateway/v3/resources.yaml b/support-files/bk-api-gateway/v3/resources.yaml index 2eca6a265c..8845e0d99f 100644 --- a/support-files/bk-api-gateway/v3/resources.yaml +++ b/support-files/bk-api-gateway/v3/resources.yaml @@ -3311,3 +3311,55 @@ paths: userVerifiedRequired: false resourcePermissionRequired: false descriptionEn: Callback protocol + /api/v3/system/query_gse_task: + get: + operationId: system_query_gse_task + description: 根据step_instance_id查询gse task id + tags: ['system'] + responses: + default: + description: '' + x-bk-apigateway-resource: + isPublic: false + allowApplyPermission: false + matchSubpath: false + backend: + # name: default 支持设置 backend, 默认不配置为 default,和 stage 的 backends 配置的后端服务 name 一致 + type: HTTP + method: get + path: /api/job/v3/job-execute/query_gse_task + matchSubpath: false + timeout: 0 + upstreams: {} + transformHeaders: {} + authConfig: + appVerifiedRequired: true + userVerifiedRequired: false + resourcePermissionRequired: true + descriptionEn: Query GSE task id by step instance id + /api/v3/system/query_job_instance: + get: + operationId: system_query_job_instance + description: 根据gse_task_id查询job任务 + tags: ['system'] + responses: + default: + description: '' + x-bk-apigateway-resource: + isPublic: false + allowApplyPermission: false + matchSubpath: false + backend: + # name: default 支持设置 backend, 默认不配置为 default,和 stage 的 backends 配置的后端服务 name 一致 + type: HTTP + method: get + path: /api/job/v3/job-execute/query_job_instance + matchSubpath: false + timeout: 0 + upstreams: {} + transformHeaders: {} + authConfig: + appVerifiedRequired: true + userVerifiedRequired: false + resourcePermissionRequired: true + descriptionEn: Query job instance by GSE task id