diff --git a/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/api/IUserTurboPlanController.kt b/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/api/IUserTurboPlanController.kt index 9911e5fb..588ea577 100644 --- a/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/api/IUserTurboPlanController.kt +++ b/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/api/IUserTurboPlanController.kt @@ -9,6 +9,7 @@ import com.tencent.devops.turbo.validate.TurboPlanGroup import com.tencent.devops.turbo.vo.TurboMigratedPlanVO import com.tencent.devops.turbo.vo.TurboPlanDetailVO import com.tencent.devops.turbo.vo.TurboPlanPageVO +import com.tencent.devops.turbo.vo.TurboPlanStatusBatchUpdateReqVO import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -179,4 +180,21 @@ interface IUserTurboPlanController { @PathVariable("pipelineElementId") pipelineElementId: String ): Response + + @ApiOperation("加速方案-刷新状态") + @PutMapping( + "/status/manualRefresh", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + fun manualRefreshStatus( + @ApiParam(value = "新增加速方案请求数据信息", required = true) + @RequestBody + reqVO: TurboPlanStatusBatchUpdateReqVO, + @ApiParam(value = "用户信息", required = true) + @RequestHeader(AUTH_HEADER_DEVOPS_USER_ID) + user: String, + @ApiParam(value = "蓝盾项目id", required = true) + @RequestHeader(AUTH_HEADER_DEVOPS_PROJECT_ID) + projectId: String + ): Response } diff --git a/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/vo/TurboPlanStatusBatchUpdateReqVO.kt b/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/vo/TurboPlanStatusBatchUpdateReqVO.kt new file mode 100644 index 00000000..ed79d4c2 --- /dev/null +++ b/src/backend/turbo/api-turbo/src/main/kotlin/com/tencent/devops/turbo/vo/TurboPlanStatusBatchUpdateReqVO.kt @@ -0,0 +1,6 @@ +package com.tencent.devops.turbo.vo + +data class TurboPlanStatusBatchUpdateReqVO( + val status: Boolean, + val projectIdList: List +) diff --git a/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/controller/UserTurboPlanController.kt b/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/controller/UserTurboPlanController.kt index 9f15beb9..ff1f937b 100644 --- a/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/controller/UserTurboPlanController.kt +++ b/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/controller/UserTurboPlanController.kt @@ -12,6 +12,7 @@ import com.tencent.devops.turbo.service.TurboPlanService import com.tencent.devops.turbo.vo.TurboMigratedPlanVO import com.tencent.devops.turbo.vo.TurboPlanDetailVO import com.tencent.devops.turbo.vo.TurboPlanPageVO +import com.tencent.devops.turbo.vo.TurboPlanStatusBatchUpdateReqVO import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.RestController @@ -73,4 +74,16 @@ class UserTurboPlanController @Autowired constructor( override fun findTurboPlanIdByProjectIdAndPipelineInfo(projectId: String, pipelineId: String, pipelineElementId: String): Response { return Response.success(turboPlanService.findMigratedTurboPlanByPipelineInfo(projectId, pipelineId, pipelineElementId)) } + + override fun manualRefreshStatus( + reqVO: TurboPlanStatusBatchUpdateReqVO, + user: String, + projectId: String + ): Response { + // 判断是否是管理员 + if (!turboAuthService.getAuthResult(projectId, user)) { + throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE) + } + return Response.success(turboPlanService.manualRefreshStatus(reqVO)) + } } diff --git a/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/service/TurboPlanService.kt b/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/service/TurboPlanService.kt index 257c8a7f..ce18bd52 100644 --- a/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/service/TurboPlanService.kt +++ b/src/backend/turbo/biz-turbo/src/main/kotlin/com/tencent/devops/turbo/service/TurboPlanService.kt @@ -5,6 +5,7 @@ import com.tencent.devops.common.api.exception.code.TURBO_NO_DATA_FOUND import com.tencent.devops.common.api.exception.code.TURBO_PARAM_INVALID import com.tencent.devops.common.api.exception.code.TURBO_THIRDPARTY_SYSTEM_FAIL import com.tencent.devops.common.api.pojo.Page +import com.tencent.devops.common.api.util.OkhttpUtil import com.tencent.devops.common.client.Client import com.tencent.devops.common.db.PageUtils import com.tencent.devops.common.service.prometheus.BkTimed @@ -27,6 +28,7 @@ import com.tencent.devops.turbo.vo.TurboMigratedPlanVO import com.tencent.devops.turbo.vo.TurboPlanDetailVO import com.tencent.devops.turbo.vo.TurboPlanPageVO import com.tencent.devops.turbo.vo.TurboPlanStatRowVO +import com.tencent.devops.turbo.vo.TurboPlanStatusBatchUpdateReqVO import org.slf4j.LoggerFactory import org.springframework.beans.BeanUtils import org.springframework.beans.factory.annotation.Autowired @@ -662,7 +664,7 @@ class TurboPlanService @Autowired constructor( fun updatePlanStatusByBkProjectStatus(userId: String, projectId: String, enabled: Boolean) { logger.info("ProjectStatusUpdate event: $userId, $projectId, $enabled") // true表示启用项目,false表示停用项目 - // 启用项目时注意,只回复系统自动停用的方案,用户停用的方案保持停用 + // 启用项目时注意,只启用系统自动停用的方案,用户停用的方案保持停用 val updatedBy = if (enabled) SYSTEM_ADMIN else null // 获取到待启用/待停用的加速方案清单 @@ -700,4 +702,27 @@ class TurboPlanService @Autowired constructor( logger.info("Sync turbo info to TBS backend successful") } } + + /** + * 更新存量停用项目的加速方案状态 + */ + fun manualRefreshStatus(reqVO: TurboPlanStatusBatchUpdateReqVO): String { + val projectIdList = reqVO.projectIdList + logger.info("manualRefreshStatus: ${reqVO.status}, project id:${projectIdList.joinToString()}") + + val failedProjectIds = projectIdList.filter { projectId -> + try { + this.updatePlanStatusByBkProjectStatus(SYSTEM_ADMIN, projectId, reqVO.status) + OkhttpUtil.needSleep(200) + false + } catch (e: TurboException) { + true + } + } + return if (failedProjectIds.isNotEmpty()) { + "update failed project id: ${failedProjectIds.joinToString()}" + } else { + "all project id turbo plan status updated successfully!" + } + } } diff --git a/src/backend/turbo/common-turbo/common-turbo-api/src/main/kotlin/com/tencent/devops/common/api/util/OkhttpUtil.kt b/src/backend/turbo/common-turbo/common-turbo-api/src/main/kotlin/com/tencent/devops/common/api/util/OkhttpUtil.kt index 9f3a459c..fe5b2943 100644 --- a/src/backend/turbo/common-turbo/common-turbo-api/src/main/kotlin/com/tencent/devops/common/api/util/OkhttpUtil.kt +++ b/src/backend/turbo/common-turbo/common-turbo-api/src/main/kotlin/com/tencent/devops/common/api/util/OkhttpUtil.kt @@ -51,7 +51,7 @@ object OkhttpUtil { return body.toRequestBody(mediaType) } - private fun needSleep(sleepMillis: Long) { + fun needSleep(sleepMillis: Long) { try { Thread.sleep(sleepMillis) } catch (e: Exception) {