Skip to content

Commit

Permalink
Merge pull request #2515 from wangyu096/issue_2318
Browse files Browse the repository at this point in the history
feat: 脚本开放管理类API #2318
  • Loading branch information
wangyu096 authored Oct 13, 2023
2 parents b1f4a6b + b17add3 commit f47c055
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.tencent.bk.job.common.annotation.InternalAPI;
import com.tencent.bk.job.common.model.InternalResponse;
import com.tencent.bk.job.manage.model.inner.ServiceScriptDTO;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateReq;
import com.tentent.bk.job.common.api.feign.annotation.SmartFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand Down Expand Up @@ -66,7 +66,7 @@ InternalResponse<Pair<String, Long>> createScriptWithVersionId(
@ApiParam("脚本状态") @RequestHeader(value = "X-Script-Status", required = false) Integer scriptStatus,
@ApiParam(value = "业务ID", required = true, example = "2") @PathVariable("appId") Long appId,
@ApiParam(value = "新增/更新的脚本对象", name = "scriptCreateUpdateReq",
required = true) @RequestBody ScriptCreateUpdateReq scriptCreateUpdateReq);
required = true) @RequestBody ScriptCreateReq scriptCreateReq);

@ApiOperation(value = "获取脚本基本信息", produces = "application/json")
@GetMapping("/service/script/{scriptId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import com.tencent.bk.job.common.annotation.WebAPI;
import com.tencent.bk.job.common.model.PageData;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq;
import com.tencent.bk.job.common.validation.Create;
import com.tencent.bk.job.common.validation.Update;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptInfoUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptSyncReq;
import com.tencent.bk.job.manage.model.web.request.ScriptTagBatchPatchReq;
import com.tencent.bk.job.manage.model.web.request.ScriptVersionCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.vo.BasicScriptVO;
import com.tencent.bk.job.manage.model.web.vo.ScriptVO;
import com.tencent.bk.job.manage.model.web.vo.TagCountVO;
Expand All @@ -41,6 +44,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -193,7 +197,8 @@ Response<ScriptVO> saveScript(
String username,
@ApiParam(value = "新增/更新的脚本对象", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
@Validated
ScriptCreateReq request
);

@ApiOperation(value = "新增脚本版本", produces = "application/json")
Expand All @@ -206,7 +211,8 @@ Response<ScriptVO> saveScriptVersion(
String scriptId,
@ApiParam(value = "新增脚本版本请求", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
@Validated(Create.class)
ScriptVersionCreateUpdateReq request
);

@ApiOperation(value = "更新脚本版本", produces = "application/json")
Expand All @@ -221,7 +227,8 @@ Response<ScriptVO> updateScriptVersion(
Long scriptVersionId,
@ApiParam(value = "更新脚本版本请求", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
@Validated(Update.class)
ScriptVersionCreateUpdateReq request
);

@ApiOperation(value = "上线脚本", produces = "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import com.tencent.bk.job.common.model.PageData;
import com.tencent.bk.job.common.model.Response;
import com.tencent.bk.job.common.model.dto.AppResourceScope;
import com.tencent.bk.job.common.validation.Create;
import com.tencent.bk.job.common.validation.Update;
import com.tencent.bk.job.manage.model.web.request.ScriptCheckReq;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptInfoUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptSyncReq;
import com.tencent.bk.job.manage.model.web.request.ScriptTagBatchPatchReq;
import com.tencent.bk.job.manage.model.web.request.ScriptVersionCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.vo.BasicScriptVO;
import com.tencent.bk.job.manage.model.web.vo.ScriptCheckResultItemVO;
import com.tencent.bk.job.manage.model.web.vo.ScriptVO;
Expand All @@ -44,6 +47,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -285,7 +289,7 @@ Response<ScriptVO> saveScript(
String scopeId,
@ApiParam(value = "新增/更新的脚本对象", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
ScriptCreateReq request
);

@ApiOperation(value = "新增脚本版本", produces = "application/json")
Expand All @@ -307,7 +311,8 @@ Response<ScriptVO> saveScriptVersion(
String scriptId,
@ApiParam(value = "新增脚本版本请求", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
@Validated(Create.class)
ScriptVersionCreateUpdateReq request
);

@ApiOperation(value = "更新脚本版本", produces = "application/json")
Expand All @@ -331,7 +336,8 @@ Response<ScriptVO> updateScriptVersion(
Long scriptVersionId,
@ApiParam(value = "更新脚本版本请求", name = "request", required = true)
@RequestBody
ScriptCreateUpdateReq request
@Validated(Update.class)
ScriptVersionCreateUpdateReq request
);

@ApiOperation(value = "上线脚本", produces = "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,60 @@

package com.tencent.bk.job.manage.model.web.request;

import com.tencent.bk.job.common.validation.CheckEnum;
import com.tencent.bk.job.manage.common.consts.script.ScriptTypeEnum;
import com.tencent.bk.job.manage.model.web.vo.TagVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
* 脚本新增、更新请求
* 脚本新增请求
*/
@Data
@ApiModel("脚本新增、更新请求报文")
public class ScriptCreateUpdateReq {
/**
* 脚本版本ID,对应某个版本的脚本的ID
*/
@Deprecated
@ApiModelProperty(value = "脚本版本ID,对应某个版本的脚本的ID", hidden = true)
private Long scriptVersionId;
/**
* 脚本ID
*/
@Deprecated
@ApiModelProperty(value = "脚本ID", hidden = true)
private String id;
@ApiModel("脚本新增请求")
public class ScriptCreateReq {

/**
* 脚本名称
*/
@ApiModelProperty(value = "脚本名称", required = true, example = "scriptName")
@NotEmpty(message = "{validation.constraints.ScriptName_empty.message}")
@Length(max = 60, message = "{validation.constraints.ScriptName_outOfLength.message}")
@Pattern(regexp = "^[^\\\\|/:*<>\"?]+$", message = "{validation.constraints.ScriptName_illegal.message}")
private String name;

/**
* 脚本类型
*/
@ApiModelProperty(value = "脚本类型,新增脚本/脚本版本时需要传入")
@ApiModelProperty(value = "脚本类型,创建脚本时需要传入")
@NotNull(message = "{validation.constraints.ScriptType_empty.message}")
@CheckEnum(enumClass = ScriptTypeEnum.class, enumMethod = "isValid",
message = "{validation.constraints.ScriptType_illegal.message}")
private Integer type;

/**
* 脚本内容
*/
@ApiModelProperty(value = "脚本内容,新增脚本/脚本版本时需要传入,BASE64编码")
@ApiModelProperty(value = "脚本内容,创建脚本时需要传入,BASE64编码")
@NotEmpty(message = "{validation.constraints.ScriptContent_empty.message}")
private String content;

/**
* 创建者
*/
@ApiModelProperty(value = "创建者,新增脚本/脚本版本时需要传入")
private String creator;

/**
* 脚本的版本号
*/
@ApiModelProperty(value = "版本号,新增脚本/脚本版本时需要传入")
@ApiModelProperty(value = "版本号,新增脚本时需要传入")
@NotEmpty(message = "{validation.constraints.ScriptVersion_empty.message}")
@Length(max = 60, message = "{validation.constraints.ScriptVersion_outOfLength.message}")
@Pattern(regexp = "^[A-Za-z0-9_\\-#@.]+$", message = "{validation.constraints.ScriptVersion_illegal.message}")
private String version;

/**
* 脚本标签
*/
Expand All @@ -88,13 +90,6 @@ public class ScriptCreateUpdateReq {
@ApiModelProperty(value = "脚本描述")
private String description;

/**
* 脚本版本描述
*/
@ApiModelProperty(value = "脚本版本描述")
private String versionDesc;


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.manage.model.web.request;

import com.tencent.bk.job.common.validation.Create;
import com.tencent.bk.job.common.validation.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;

/**
* 脚本版本新增、更新请求
*/
@Data
@ApiModel("脚本版本新增、更新请求报文")
public class ScriptVersionCreateUpdateReq {

/**
* 脚本内容
*/
@ApiModelProperty(value = "脚本内容,新增脚本/脚本版本时需要传入,BASE64编码")
@NotEmpty(message = "{validation.constraints.ScriptContent_empty.message}", groups = {Create.class, Update.class})
private String content;

/**
* 脚本的版本号
*/
@ApiModelProperty(value = "版本号,新增脚本版本时需要传入")
@NotEmpty(message = "{validation.constraints.ScriptVersion_empty.message}", groups = Create.class)
@Length(max = 60, message = "{validation.constraints.ScriptVersion_outOfLength.message}", groups = Create.class)
@Pattern(regexp = "^[A-Za-z0-9_\\-#@.]+$", message = "{validation.constraints.ScriptVersion_illegal.message}",
groups = Create.class)
private String version;

/**
* 脚本版本描述
*/
@ApiModelProperty(value = "脚本版本描述")
private String versionDesc;

}


Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import com.tencent.bk.job.manage.model.esb.v3.request.EsbCreateScriptVersionV3Req;
import com.tencent.bk.job.manage.model.esb.v3.request.EsbUpdatePublicScriptVersionV3Req;
import com.tencent.bk.job.manage.model.esb.v3.request.EsbUpdateScriptVersionV3Req;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptVersionCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.vo.TagVO;
import org.springframework.stereotype.Service;

Expand All @@ -45,10 +46,14 @@
@Service
public class ScriptDTOBuilder {

public ScriptDTO buildFromCreateUpdateReq(ScriptCreateUpdateReq req) {
/**
* ScriptCreateReq -> ScriptDTO 转换
*
* @param req 请求
* @return 转换后的脚本
*/
public ScriptDTO buildFromScriptCreateReq(ScriptCreateReq req) {
ScriptDTO scriptDTO = new ScriptDTO();
scriptDTO.setId(req.getId());
scriptDTO.setScriptVersionId(req.getScriptVersionId());
scriptDTO.setName(req.getName());
scriptDTO.setType(req.getType());
if (req.getType() != null) {
Expand All @@ -71,6 +76,19 @@ public ScriptDTO buildFromCreateUpdateReq(ScriptCreateUpdateReq req) {
}
scriptDTO.setVersion(req.getVersion());
scriptDTO.setDescription(req.getDescription());
return scriptDTO;
}

/**
* ScriptVersionCreateUpdateReq -> ScriptDTO 转换
*
* @param req 请求
* @return 转换后的脚本
*/
public ScriptDTO buildFromScriptVersionCreateUpdateReq(ScriptVersionCreateUpdateReq req) {
ScriptDTO scriptDTO = new ScriptDTO();
scriptDTO.setContent(Base64Util.decodeContentToStr(req.getContent()));
scriptDTO.setVersion(req.getVersion());
scriptDTO.setVersionDesc(req.getVersionDesc());
return scriptDTO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.tencent.bk.job.manage.model.dto.ScriptDTO;
import com.tencent.bk.job.manage.model.dto.converter.ScriptConverter;
import com.tencent.bk.job.manage.model.inner.ServiceScriptDTO;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateUpdateReq;
import com.tencent.bk.job.manage.model.web.request.ScriptCreateReq;
import com.tencent.bk.job.manage.service.ScriptManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -103,12 +103,12 @@ public InternalResponse<ServiceScriptDTO> getScriptByScriptVersionId(Long script
public InternalResponse<Pair<String, Long>> createScriptWithVersionId(String username, Long createTime,
Long lastModifyTime, String lastModifyUser,
Integer scriptStatus, Long appId,
ScriptCreateUpdateReq scriptCreateUpdateReq) {
ScriptCreateReq scriptCreateReq) {
if (log.isDebugEnabled()) {
log.debug("createScriptWithVersionId,operator={},appId={},script={},status={}", username, appId,
scriptCreateUpdateReq, scriptStatus);
scriptCreateReq, scriptStatus);
}
ScriptDTO script = scriptDTOBuilder.buildFromCreateUpdateReq(scriptCreateUpdateReq);
ScriptDTO script = scriptDTOBuilder.buildFromScriptCreateReq(scriptCreateReq);
script.setAppId(appId);
script.setCreator(username);
if (StringUtils.isNotBlank(lastModifyUser)) {
Expand Down
Loading

0 comments on commit f47c055

Please sign in to comment.