Skip to content

Commit

Permalink
Merge pull request #3418 from jsonwan/github_feat/win_interpreter
Browse files Browse the repository at this point in the history
feature: 支持指定脚本解释器运行脚本 #3321
  • Loading branch information
jsonwan authored Feb 13, 2025
2 parents 89b51c3 + fb0b5b9 commit 634e9f4
Show file tree
Hide file tree
Showing 39 changed files with 388 additions and 57 deletions.
34 changes: 18 additions & 16 deletions docs/apidoc/bk-api-gateway/v3/zh/bkci_plugin_fast_execute_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@

#### Body参数

| 字段 | 类型 | 必选 | 描述 |
|---------------|------------|--------|------------|
| bk_scope_type | string || 资源范围类型。可选值: biz - 业务,biz_set - 业务集 |
| bk_scope_id | string || 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| script_version_id | long || 脚本版本ID。当script_version_id不为空的时候,使用script_version_id对应的脚本版本 |
| script_id | string || 脚本ID。当传入script_id,且script_version_id为空的时候,使用脚本的上线版本 |
| script_content | string || 脚本内容Base64。如果不存在script_version_id和script_id,那么使用script_content。优先级:script_version_id>script_id>script_content |
| task_name | string || 自定义作业名称 |
| 字段 | 类型 | 必选 | 描述 |
|---------------|------------|--------|--------------------------------------------------------------------------------------------------------------------------------------|
| bk_scope_type | string || 资源范围类型。可选值: biz - 业务,biz_set - 业务集 |
| bk_scope_id | string || 资源范围ID, 与bk_scope_type对应, 表示业务ID或者业务集ID |
| script_version_id | long || 脚本版本ID。当script_version_id不为空的时候,使用script_version_id对应的脚本版本 |
| script_id | string || 脚本ID。当传入script_id,且script_version_id为空的时候,使用脚本的上线版本 |
| script_content | string || 脚本内容Base64。如果不存在script_version_id和script_id,那么使用script_content。优先级:script_version_id>script_id>script_content |
| task_name | string || 自定义作业名称 |
| script_param | string || 脚本参数Base64。脚本参数长度不得超过 5000 个字符。注意:如果有多个参数,比如"param1 param2"这种,需要对"param1 param2"整体进行base64编码,而不是对每个参数进行base64编码再拼接起来 |
| timeout | long || 脚本执行超时时间,秒。默认7200,取值范围1-86400 |
| account_alias | string || 执行账号别名。与account_id必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
| account_id | long || 执行账号ID。与account_alias必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
| is_param_sensitive | boolean || 敏感参数将会在执行详情页面上隐藏。默认为 false|
| script_language | int || 脚本语言:1 - shell, 2 - bat, 3 - perl, 4 - python, 5 - powershell。当使用script_content传入自定义脚本的时候,需要指定script_language |
| execute_target | object || 执行目标,定义见 execute_target |
| callback | object | 否 | 回调配置。当任务执行完成后,JOB会调用该URL告知任务执行结果。回调协议参考callback_protocol组件文档 |
| rolling_config | object || 滚动配置,见rolling_config定义 |
| windows_interpreter | string || 自定义Windows解释器路径,当该值不为空时,在windows中优先使用该解释器运行脚本,只对Windows机器生效 |
| timeout | long || 脚本执行超时时间,秒。默认7200,取值范围1-86400 |
| account_alias | string || 执行账号别名。与account_id必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
| account_id | long || 执行账号ID。与account_alias必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
| is_param_sensitive | boolean || 敏感参数将会在执行详情页面上隐藏。默认为 false |
| script_language | int || 脚本语言:1 - shell, 2 - bat, 3 - perl, 4 - python, 5 - powershell。当使用script_content传入自定义脚本的时候,需要指定script_language |
| execute_target | object || 执行目标,定义见 execute_target |
| callback | object | 否 | 回调配置。当任务执行完成后,JOB会调用该URL告知任务执行结果。回调协议参考callback_protocol组件文档 |
| rolling_config | object || 滚动配置,见rolling_config定义 |

##### execute_target

Expand Down Expand Up @@ -141,6 +142,7 @@
"script_version_id": 1,
"script_content": "ZWNobyAkMQ==",
"script_param": "aGVsbG8=",
"windows_interpreter": "D:\\Software\\python3\\python.exe",
"timeout": 1000,
"account_id": 1000,
"is_param_sensitive": 0,
Expand Down
4 changes: 3 additions & 1 deletion docs/apidoc/bk-api-gateway/v3/zh/fast_execute_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
| script_content | string || 脚本内容Base64。如果不存在script_version_id和script_id,那么使用script_content。优先级:script_version_id>script_id>script_content |
| task_name | string || 自定义作业名称 |
| script_param | string || 脚本参数Base64。注意:如果有多个参数,比如"param1 param2"这种,需要对"param1 param2"整体进行base64编码,而不是对每个参数进行base64编码再拼接起来 |
| windows_interpreter | string || 自定义Windows解释器路径,当该值不为空时,在windows中优先使用该解释器运行脚本,只对Windows机器生效 |
| timeout | long || 脚本执行超时时间,秒。默认7200,取值范围1-86400 |
| account_alias | string || 执行账号别名。与account_id必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
| account_id | long || 执行账号ID。与account_alias必须存在一个。当同时存在account_alias和account_id时,account_id优先。 |
Expand Down Expand Up @@ -80,6 +81,7 @@
"script_version_id": 1,
"script_content": "ZWNobyAkMQ==",
"script_param": "aGVsbG8=",
"windows_interpreter": "D:\\Software\\python3\\python.exe",
"timeout": 1000,
"account_id": 1000,
"is_param_sensitive": 0,
Expand Down Expand Up @@ -135,4 +137,4 @@
|-----------|-----------|-----------|
| job_instance_id | long | 作业实例ID |
| job_instance_name | long | 作业实例名称 |
| step_instance_id | long | 步骤实例ID |
| step_instance_id | long | 步骤实例ID |
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ validation.constraints.InvalidWhiteIpScope.message=目标业务不可为空
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.queryExecuteObjects_outOfRange.message=单次查询执行对象数量范围必须在 {min}-{max} 之间

## 快速执行脚本
validation.constraints.WindowsInterpreterExceedMaxLength.message=Windows解释器路径长度不可超过260字符

## AI对话
validation.constraints.AIGeneralChat_contentEmpty.message=对话输入内容不能为空
Expand All @@ -124,6 +126,8 @@ validation.constraints.AIAnalyzeError_executeObjectResourceIdEmpty.message=执
validation.constraints.AICheckScript_contentExceedMaxLength.message=检查的脚本内容长度不可超过5MB
validation.constraints.AIGeneralChat_contentExceedMaxLength.message=对话输入内容长度不可超过5MB
validation.constraints.ExceedMaxLength.message=字段超出最大长度
validation.constraints.MustEndWithSuffix.message=必须以指定后缀结尾
validation.constraints.WinInterpreterInvalidSuffix.message=解释器路径不合法,需以 .exe 结尾


## MySQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ validation.constraints.InvalidWhiteIpScope.message=ScopeList cannot be empty
validation.constraints.queryAgentInfoHostIds_tooMany.message=HostIds size can not be over 5000
validation.constraints.queryExecuteObjects_outOfRange.message=Query execute objects size must be between {min} and {max}

## Fast Execute Script
validation.constraints.WindowsInterpreterExceedMaxLength.message=Windows interpreter path length cannot exceed 260 chars

## AI Chat
validation.constraints.AIGeneralChat_contentEmpty.message=Chat message cannot be empty
validation.constraints.AIAnalyzeError_contentEmpty.message=Error content cannot be empty
Expand All @@ -123,6 +126,8 @@ validation.constraints.AIAnalyzeError_executeObjectResourceIdEmpty.message=Execu
validation.constraints.AICheckScript_contentExceedMaxLength.message=Script content cannot exceed 5MB
validation.constraints.AIGeneralChat_contentExceedMaxLength.message=Chat content cannot exceed 5MB
validation.constraints.ExceedMaxLength.message=String field exceed max length
validation.constraints.MustEndWithSuffix.message=must end with suffix
validation.constraints.WinInterpreterInvalidSuffix.message=Interpreter path is invalid. Must end with .exe


## MySQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ validation.constraints.InvalidWhiteIpScope.message=ScopeList cannot be empty
validation.constraints.queryAgentInfoHostIds_tooMany.message=HostIds size can not be over 5000
validation.constraints.queryExecuteObjects_outOfRange.message=Query execute objects size must be between {min} and {max}

## Fast Execute Script
validation.constraints.WindowsInterpreterExceedMaxLength.message=Windows interpreter path length cannot exceed 260 chars

## AI Chat
validation.constraints.AIGeneralChat_contentEmpty.message=Chat message cannot be empty
validation.constraints.AIAnalyzeError_contentEmpty.message=Error content cannot be empty
Expand All @@ -123,6 +126,8 @@ validation.constraints.AIAnalyzeError_executeObjectResourceIdEmpty.message=Execu
validation.constraints.AICheckScript_contentExceedMaxLength.message=Script content cannot exceed 5MB
validation.constraints.AIGeneralChat_contentExceedMaxLength.message=Chat content cannot exceed 5MB
validation.constraints.ExceedMaxLength.message=String field exceed max length
validation.constraints.MustEndWithSuffix.message=must end with suffix
validation.constraints.WinInterpreterInvalidSuffix.message=Interpreter path is invalid. Must end with .exe


## MySQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ validation.constraints.InvalidWhiteIpScope.message=目标业务不可为空
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.queryExecuteObjects_outOfRange.message=单次查询执行对象数量范围必须在 {min}-{max} 之间

## 快速执行脚本
validation.constraints.WindowsInterpreterExceedMaxLength.message=Windows解释器路径长度不可超过260字符


## AI对话
validation.constraints.AIGeneralChat_contentEmpty.message=对话输入内容不能为空
Expand All @@ -124,6 +127,8 @@ validation.constraints.AIAnalyzeError_executeObjectResourceIdEmpty.message=执
validation.constraints.AICheckScript_contentExceedMaxLength.message=检查的脚本内容长度不可超过5MB
validation.constraints.AIGeneralChat_contentExceedMaxLength.message=对话输入内容长度不可超过5MB
validation.constraints.ExceedMaxLength.message=字段超出最大长度
validation.constraints.MustEndWithSuffix.message=必须以指定后缀结尾
validation.constraints.WinInterpreterInvalidSuffix.message=解释器路径不合法,需以 .exe 结尾


## MySQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ validation.constraints.InvalidWhiteIpScope.message=目标业务不可为空
validation.constraints.queryAgentInfoHostIds_tooMany.message=单次查询主机数量不可超过5000
validation.constraints.queryExecuteObjects_outOfRange.message=单次查询执行对象数量范围必须在 {min}-{max} 之间

## 快速执行脚本
validation.constraints.WindowsInterpreterExceedMaxLength.message=Windows解释器路径长度不可超过260字符


## AI对话
validation.constraints.AIGeneralChat_contentEmpty.message=对话输入内容不能为空
Expand All @@ -124,6 +127,8 @@ validation.constraints.AIAnalyzeError_executeObjectResourceIdEmpty.message=执
validation.constraints.AICheckScript_contentExceedMaxLength.message=检查的脚本内容长度不可超过5MB
validation.constraints.AIGeneralChat_contentExceedMaxLength.message=对话输入内容长度不可超过5MB
validation.constraints.ExceedMaxLength.message=字段超出最大长度
validation.constraints.MustEndWithSuffix.message=必须以指定后缀结尾
validation.constraints.WinInterpreterInvalidSuffix.message=解释器路径不合法,需以 .exe 结尾


## MySQL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.common.validation;

import org.apache.commons.lang3.StringUtils;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = EndWith.Validator.class)
@Documented
public @interface EndWith {
String fieldName();

String value();

String message() default "{fieldName} {validation.constraints.MustEndWithSuffix.message}: {value}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

class Validator implements ConstraintValidator<EndWith, String> {
private String suffix;

@Override
public void initialize(EndWith endWithAnnotation) {
this.suffix = endWithAnnotation.value();
}

@Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
if (StringUtils.isBlank(value)) {
return true;
}
return value.trim().endsWith(suffix);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.analysis.model.web.req.validation;
package com.tencent.bk.job.common.validation;

import javax.validation.Constraint;
import javax.validation.Payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* IN THE SOFTWARE.
*/

package com.tencent.bk.job.analysis.model.web.req.validation;
package com.tencent.bk.job.common.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class EsbScriptStepV3DTO {
@JsonPropertyDescription("Script params")
private String scriptParam;

@JsonProperty("windows_interpreter")
@JsonPropertyDescription("Windows interpreter")
private String windowsInterpreter;

@JsonProperty("script_timeout")
@JsonPropertyDescription("Timeout")
private Long scriptTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public ScriptRequestBuilder addScriptTask(List<Agent> agents, String storeDir, S
return this;
}

/**
* 设置Windows执行脚本的命令行解释器
*
* @param windowsInterpreter Windows执行脚本的命令行解释器
*/
public void setWindowsInterpreter(String windowsInterpreter) {
request.setWindowsInterpreter(windowsInterpreter);
}

public ExecuteScriptRequest build() {
return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class ExecuteScriptRequest extends GseReq {
@JsonProperty("atomic_tasks_relations")
private List<AtomicScriptTaskRelation> atomicScriptTaskRelations = new ArrayList<>();

/**
* 当该值不为空时,在windows中优先使用该解释器运行脚本
*/
@JsonProperty("windows_interpreter")
private String windowsInterpreter;

public void addScript(GseScript script) {
scripts.add(script);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.tencent.bk.job.analysis.model.web.req;

import com.tencent.bk.job.analysis.model.web.req.validation.MaxLength;
import com.tencent.bk.job.common.validation.MaxLength;
import com.tencent.bk.job.common.validation.CheckEnum;
import com.tencent.bk.job.manage.api.common.constants.script.ScriptTypeEnum;
import io.swagger.annotations.ApiModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package com.tencent.bk.job.analysis.model.web.req;

import com.tencent.bk.job.analysis.model.web.req.validation.MaxLength;
import com.tencent.bk.job.common.validation.MaxLength;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
Expand Down
Loading

0 comments on commit 634e9f4

Please sign in to comment.