From f347cedce3f92efdce66360910aede855ca1214f Mon Sep 17 00:00:00 2001 From: zeaslity Date: Mon, 6 Feb 2023 15:35:18 +0800 Subject: [PATCH] [ server ] [ scheduler ]- script scheduler add function --- .../scheduler/beans/ScriptSchedulerVO.java | 10 ++++++++- .../script/AgentApplyScheduledScript.java | 9 +++++++- .../source/shell/function/load50cpu_2_hour.sh | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 source/src/main/java/io/wdd/source/shell/function/load50cpu_2_hour.sh diff --git a/server/src/main/java/io/wdd/rpc/scheduler/beans/ScriptSchedulerVO.java b/server/src/main/java/io/wdd/rpc/scheduler/beans/ScriptSchedulerVO.java index f02cca4..5c424d0 100644 --- a/server/src/main/java/io/wdd/rpc/scheduler/beans/ScriptSchedulerVO.java +++ b/server/src/main/java/io/wdd/rpc/scheduler/beans/ScriptSchedulerVO.java @@ -10,6 +10,7 @@ import lombok.experimental.SuperBuilder; import javax.annotation.Nullable; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; import java.time.LocalDateTime; @Data @@ -53,9 +54,16 @@ public class ScriptSchedulerVO { * 脚本任务的内容 */ @TableField(value = "script_content") - @NotNull + @Nullable private String scriptContent; + /** + * 脚本任务的类型 + */ + @TableField(value = "script_type") + @Nullable + private String scriptType; + /** * 执行目标机器agent_topic_name列表,使用, 分隔 */ diff --git a/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java b/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java index be068cd..7beda9e 100644 --- a/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java +++ b/server/src/main/java/io/wdd/rpc/scheduler/service/script/AgentApplyScheduledScript.java @@ -5,6 +5,7 @@ import io.wdd.rpc.execute.service.CoreExecutionService; import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO; import io.wdd.rpc.scheduler.config.QuartzSchedulerUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -31,9 +32,15 @@ public class AgentApplyScheduledScript { HashMap futureResultKeyMap = scriptSchedulerDTO.getAgentTopicNameToFutureResultKeyMap(); + // 新增-定时调用Nacos中预编辑脚本的内容 + String scriptType = scriptSchedulerDTO.getScriptType(); + if (StringUtils.isEmpty(scriptType)) { + scriptType = "Scheduled Script"; + } + List resultKeyList = coreExecutionService.SendCommandToAgentComplete( targetMachineList, - "Scheduled Script", + scriptType, completeCommandList, futureResultKeyMap ); diff --git a/source/src/main/java/io/wdd/source/shell/function/load50cpu_2_hour.sh b/source/src/main/java/io/wdd/source/shell/function/load50cpu_2_hour.sh new file mode 100644 index 0000000..29a1ddb --- /dev/null +++ b/source/src/main/java/io/wdd/source/shell/function/load50cpu_2_hour.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +. /octopus-agent/shell/lib/wdd-lib-log.sh + +start_time=$(date +%s) +current_time=$(date +%s) +elapsed_time=$((current_time - start_time)) + +log "开始执行CPU占用任务,占用时间为 2小时!" +while [ $elapsed_time -lt 7200 ] +do + # Busy wait + for i in {1..1000000} + do + : + done + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) +done + +log "CPU占用任务完成!"