Skip to content

Commit

Permalink
feature: Job 支持容器执行 - 脚本任务 TencentBlueKing#2631
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Dec 28, 2023
1 parent 4bfea68 commit 37ac6e0
Show file tree
Hide file tree
Showing 23 changed files with 1,034 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.tencent.bk.job.common.annotation.PersistenceObject;
import com.tencent.bk.job.common.model.vo.ContainerVO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -124,4 +125,14 @@ public String toString() {
.add("podLabels=" + podLabels)
.toString();
}

public ContainerVO toContainerVO() {
ContainerVO vo = new ContainerVO();
vo.setId(id);
vo.setUid(containerId);
vo.setNodeHostId(hostId);
vo.setPodName(podName);
vo.setPodLabels(podLabels);
return vo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ContainerVO {
private Map<String, String> podLabels;

@ApiModelProperty("所属 Node hostId")
private String nodeHostId;
private Long nodeHostId;

@ApiModelProperty("所属 Node Ip")
private String nodeIp;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
* 作业执行日志API-前端调用
*/
@Api(tags = {"job-execute:web:Task_Execution_Log"})
@RequestMapping("/web/execution")
@RequestMapping("/web/scope/{scopeType}/{scopeId}")
@RestController
@WebAPI
public interface WebTaskLogResource {

@ApiOperation(value = "请求下载执行日志文件", produces = "application/json")
@GetMapping("/scope/{scopeType}/{scopeId}/step-execution-result/{stepInstanceId}/log-file")
@GetMapping("/taskInstance/{taskInstanceId}/stepInstance/{stepInstanceId}/requestDownloadLogFile")
Response<LogExportJobInfoVO> requestDownloadLogFile(
@ApiParam("用户名,网关自动传入")
@RequestHeader("username")
Expand All @@ -68,6 +68,9 @@ Response<LogExportJobInfoVO> requestDownloadLogFile(
@ApiParam(value = "资源范围ID", required = true)
@PathVariable(value = "scopeId")
String scopeId,
@ApiParam(value = "作业实例 ID", name = "taskInstanceId", required = true)
@PathVariable("taskInstanceId")
Long taskInstanceId,
@ApiParam(value = "步骤实例 ID", name = "stepInstanceId", required = true)
@PathVariable("stepInstanceId")
Long stepInstanceId,
Expand All @@ -83,7 +86,7 @@ Response<LogExportJobInfoVO> requestDownloadLogFile(
);

@ApiOperation(value = "下载执行日志文件", produces = "application/json")
@GetMapping("/scope/{scopeType}/{scopeId}/step-execution-result/{stepInstanceId}/log-file/download")
@GetMapping("/taskInstance/{taskInstanceId}/stepInstance/{stepInstanceId}/downloadLogFile")
ResponseEntity<StreamingResponseBody> downloadLogFile(
HttpServletResponse response,
@ApiParam("用户名,网关自动传入")
Expand All @@ -98,6 +101,9 @@ ResponseEntity<StreamingResponseBody> downloadLogFile(
@ApiParam(value = "资源范围ID", required = true)
@PathVariable(value = "scopeId")
String scopeId,
@ApiParam(value = "作业实例 ID", name = "taskInstanceId", required = true)
@PathVariable("taskInstanceId")
Long taskInstanceId,
@ApiParam(value = "步骤实例 ID", name = "stepInstanceId", required = true)
@PathVariable("stepInstanceId")
Long stepInstanceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ public class AgentTaskExecutionVO {
@ApiModelProperty("Agent对应的主机ID")
private Long hostId;

@ApiModelProperty("云区域+ipv4,废弃字段,ipv6版本发布后删除")
@Deprecated
private String ip;
@ApiModelProperty("Agent ID")
private String agentId;

@ApiModelProperty("Agent ipv4")
private String ipv4;

@ApiModelProperty("Agent ipv6")
private String ipv6;

@ApiModelProperty("执行对象任务执行状态")
@ApiModelProperty("Agent任务执行状态")
private Integer status;

@ApiModelProperty("执行对象任务执行状态描述")
@ApiModelProperty("Agent任务执行状态描述")
private String statusDesc;

@ApiModelProperty("开始时间")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.web.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@ApiModel("文件任务-执行对象执行日志")
@Data
public class ExecuteObjectFileLogVO {
@ApiModelProperty(name = "isIncludingLogContent", value = "是否包含日志内容")
private boolean includingLogContent;
@ApiModelProperty("文件分发执行详情")
private List<FileDistributionDetailV2VO> fileDistributionDetails;
@ApiModelProperty(name = "finished", value = "日志是否拉取完成")
private boolean finished;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("文件任务执行日志")
@ApiModel("脚本任务-执行对象执行日志")
@Data
public class FileLogContentVO {
@ApiModelProperty("ip")
private String displayIp;
@ApiModelProperty("文件名称")
private String fileName;
public class ExecuteObjectScriptLogVO {
@ApiModelProperty("执行对象")
ExecuteObjectVO executeObject;
@ApiModelProperty("日志内容")
private String logContent;
@ApiModelProperty(name = "finished", value = "日志是否拉取完成")
private boolean finished;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.web.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("文件分发执行详情")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FileDistributionDetailV2VO implements Comparable<FileDistributionDetailV2VO> {
@ApiModelProperty(name = "taskId", value = "文件任务ID,用于检索单个文件分发的结果")
private String taskId;
@ApiModelProperty(name = "srcExecuteObject", value = "文件源执行对象")
private ExecuteObjectVO srcExecuteObject;
@ApiModelProperty(name = "destExecuteObject", value = "目标执行对象")
private ExecuteObjectVO destExecuteObject;
@ApiModelProperty("文件名称")
private String fileName;
@ApiModelProperty("文件大小")
private String fileSize;
@ApiModelProperty("状态,0-Pulling,1-Waiting,2-Uploading,3-Downloading,4-Finished,5-Failed")
private Integer status;
@ApiModelProperty("状态描述")
private String statusDesc;
@ApiModelProperty("速率")
private String speed;
@ApiModelProperty("进度")
private String progress;
@ApiModelProperty("文件任务上传下载标识,0-上传,1-下载")
private Integer mode;
@ApiModelProperty("日志内容")
private String logContent;

@Override
public int compareTo(FileDistributionDetailV2VO other) {
if (other == null) {
return 1;
}
// 从文件源拉取文件的详情日志放在最前面
if (this.status == 0 && other.status > 0) {
return -1;
}
int compareFileNameResult = compareString(this.fileName, other.getFileName());
if (compareFileNameResult != 0) {
return compareFileNameResult;
}
return this.srcExecuteObject.getExecuteObjectResourceId()
.compareTo(other.getSrcExecuteObject().getExecuteObjectResourceId());
}


private int compareString(String a, String b) {
if (a == null && b == null) {
return 0;
} else if (a != null && b == null) {
return 1;
} else if (a == null) {
return -1;
} else {
return a.compareTo(b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
package com.tencent.bk.job.execute.model.web.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.tencent.bk.job.common.annotation.CompatibleImplementation;
import com.tencent.bk.job.common.constant.CompatibleType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("文件分发执行详情")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@Deprecated
@CompatibleImplementation(name = "execute_object", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY,
explain = "使用 FileDistributionDetailV2VO 替换。发布完成后可以删除")
public class FileDistributionDetailVO implements Comparable<FileDistributionDetailVO> {
@ApiModelProperty(name = "taskId", value = "文件任务ID,用于检索单个文件分发的结果")
private String taskId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package com.tencent.bk.job.execute.model.web.vo;

import com.tencent.bk.job.common.annotation.CompatibleImplementation;
import com.tencent.bk.job.common.constant.CompatibleType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
Expand All @@ -32,6 +34,9 @@

@ApiModel("文件任务Agent执行日志")
@Data
@Deprecated
@CompatibleImplementation(name = "execute_object", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY,
explain = "使用 ExecuteObjectFileLogVO 替换。发布完成后可以删除")
public class IpFileLogContentVO {
@ApiModelProperty(name = "isIncludingLogContent", value = "是否包含日志内容")
private boolean includingLogContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@

package com.tencent.bk.job.execute.model.web.vo;

import com.tencent.bk.job.common.annotation.CompatibleImplementation;
import com.tencent.bk.job.common.constant.CompatibleType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("Agent作业执行日志")
@Data
@Deprecated
@CompatibleImplementation(name = "execute_object", deprecatedVersion = "3.9.x", type = CompatibleType.DEPLOY,
explain = "使用 ExecuteObjectScriptLogVO 参数替换。发布完成后可以删除")
public class IpScriptLogContentVO {
@ApiModelProperty("ip")
private String displayIp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public EsbResp<EsbStepInstanceStatusV3DTO> getStepInstanceStatus(String username
.tag(tag)
.logKeyword(keyword)
.searchIp(searchIp)
.maxAgentTasksForResultGroup(maxHostNumPerGroup)
.maxTasksForResultGroup(maxHostNumPerGroup)
.fetchAllGroupData(status == null)
.build();

Expand Down
Loading

0 comments on commit 37ac6e0

Please sign in to comment.