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 Jan 2, 2024
1 parent c0ab0fd commit cf79956
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,7 @@ Response<IpFileLogContentVO> getFileLogContentByHost(
@ApiParam(value = "执行次数,首次传0", name = "executeCount", required = true)
@PathVariable("executeCount")
Integer executeCount,
@ApiParam(value = "主机ip(云区域ID:ip),兼容历史版本数据,后续会删除;建议使用hostId", name = "ip")
@PathVariable(value = "ip", required = false) String ip,
@ApiParam(value = "主机ID,优先级比ip参数高", name = "hostId")
@ApiParam(value = "主机ID", name = "hostId")
@PathVariable(value = "hostId", required = false) Long hostId,
@ApiParam(value = "文件任务上传下载标识,upload-上传,download-下载", name = "mode", required = true)
@RequestParam(value = "mode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ public Response<IpFileLogContentVO> getFileLogContentByHost(String username,
String scopeId,
Long stepInstanceId,
Integer executeCount,
String ip,
Long hostId,
String mode,
Integer batch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public List<ResultGroupDTO> listAndGroupTasks(StepInstanceBaseDTO stepInstance,
int executeCount,
Integer batch) {
List<ResultGroupDTO> resultGroups = new ArrayList<>();
List<ExecuteObjectTask> executeObjectTasks = listTasks(stepInstance, executeCount, batch);
List<ExecuteObjectTask> executeObjectTasks = listTasks(stepInstance, executeCount,
batch, FileTaskModeEnum.DOWNLOAD);
if (CollectionUtils.isEmpty(executeObjectTasks)) {
return resultGroups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,12 @@ private boolean isSupportExecuteObjectFeature(TaskInstanceDTO taskInstance) {
.addContextParam(ToggleStrategyContextParams.CTX_PARAM_RESOURCE_SCOPE,
appScopeMappingService.getScopeByAppId(taskInstance.getAppId()));

return FeatureToggle.checkFeature(
boolean featureEnabled = FeatureToggle.checkFeature(
FeatureIdConstants.FEATURE_EXECUTE_OBJECT,
featureExecutionContext
);
log.info("Check feature: {}, result: {}", FeatureIdConstants.FEATURE_EXECUTE_OBJECT, featureEnabled);
return featureEnabled;
}

private void saveTaskInstance(StopWatch watch,
Expand Down Expand Up @@ -849,7 +851,7 @@ private void fillTaskInstanceContainerDetail(TaskInstanceExecuteObjects taskInst
taskInstanceExecuteObjects.setNotExistContainerIds(notExistContainerIds);

for (StepInstanceDTO stepInstance : stepInstanceList) {
if (!isStepContainsExecuteObject(stepInstance)) {
if (isStepDoNotContainsExecuteObject(stepInstance)) {
continue;
}
if (CollectionUtils.isNotEmpty(stepInstance.getTargetExecuteObjects().getStaticContainerList())) {
Expand Down Expand Up @@ -1042,7 +1044,7 @@ private void checkExecuteObjectAccessible(List<StepInstanceDTO> stepInstanceList
// 非法的主机
Set<HostDTO> invalidHosts = new HashSet<>();
for (StepInstanceDTO stepInstance : stepInstanceList) {
if (!isStepContainsExecuteObject(stepInstance)) {
if (isStepDoNotContainsExecuteObject(stepInstance)) {
continue;
}
TaskStepTypeEnum stepType = stepInstance.getStepType();
Expand Down Expand Up @@ -1185,7 +1187,7 @@ private void setHostsForTopoNode(ExecuteObjectsDTO servers,
}

private void checkStepInstanceHostNonEmpty(StepInstanceDTO stepInstance) {
if (!isStepContainsExecuteObject(stepInstance)) {
if (isStepDoNotContainsExecuteObject(stepInstance)) {
return;
}
ExecuteObjectsDTO targetExecuteObjects = stepInstance.getTargetExecuteObjects();
Expand All @@ -1211,9 +1213,9 @@ private void checkStepInstanceHostNonEmpty(StepInstanceDTO stepInstance) {
}
}

private boolean isStepContainsExecuteObject(StepInstanceBaseDTO stepInstance) {
private boolean isStepDoNotContainsExecuteObject(StepInstanceBaseDTO stepInstance) {
// 判断步骤是否包含执行对象
return stepInstance.isScriptStep() || stepInstance.isFileStep();
return !stepInstance.isScriptStep() && !stepInstance.isFileStep();
}

private void fillTaskInstanceHostDetail(TaskInstanceDTO taskInstance,
Expand All @@ -1238,7 +1240,7 @@ private void fillTaskInstanceHostDetail(TaskInstanceDTO taskInstance,
}

for (StepInstanceDTO stepInstance : stepInstanceList) {
if (!isStepContainsExecuteObject(stepInstance)) {
if (isStepDoNotContainsExecuteObject(stepInstance)) {
continue;
}
// 目标主机设置主机详情
Expand Down Expand Up @@ -1341,7 +1343,7 @@ private Set<HostDTO> extractHosts(List<StepInstanceDTO> stepInstanceList,
Collection<TaskVariableDTO> variables) {
Set<HostDTO> hosts = new HashSet<>();
for (StepInstanceDTO stepInstance : stepInstanceList) {
if (!isStepContainsExecuteObject(stepInstance)) {
if (isStepDoNotContainsExecuteObject(stepInstance)) {
continue;
}
if (stepInstance.getTargetExecuteObjects() != null) {
Expand Down Expand Up @@ -1426,7 +1428,7 @@ private void checkStepInstanceAtomicTasksLimit(TaskInstanceDTO taskInstance,
int sourceServerSize = 1;
Integer fileType = fileSource.getFileType();
if (fileType == TaskFileTypeEnum.SERVER.getType() && fileSource.getServers() != null) {
sourceServerSize = CollectionUtils.size(fileSource.getServers().getIpList());
sourceServerSize = CollectionUtils.size(fileSource.getServers().getExecuteObjectsCompatibly());
}
int sourceFileSize = CollectionUtils.size(fileSource.getFiles());
totalSourceFileSize += sourceServerSize * sourceFileSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ private StepExecutionDetailDTO filterAndSortExecutionResultInDB(StopWatch watch,
queryExecuteCount, query.getBatch());
watch.stop();

watch.start("setAgentTasks");
watch.start("setExecuteObjectTasks");
List<ResultGroupDTO> resultGroups = baseResultGroups.stream()
.map(ResultGroupDTO::new)
.collect(Collectors.toList());
Expand Down

0 comments on commit cf79956

Please sign in to comment.