Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Enhancement】编译加速刷存量已停用项目的加速方案为停用 #260 #261

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -179,4 +180,21 @@ interface IUserTurboPlanController {
@PathVariable("pipelineElementId")
pipelineElementId: String
): Response<TurboMigratedPlanVO?>

@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<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.tencent.devops.turbo.vo

data class TurboPlanStatusBatchUpdateReqVO(
val status: Boolean,
val projectIdList: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -73,4 +74,16 @@ class UserTurboPlanController @Autowired constructor(
override fun findTurboPlanIdByProjectIdAndPipelineInfo(projectId: String, pipelineId: String, pipelineElementId: String): Response<TurboMigratedPlanVO?> {
return Response.success(turboPlanService.findMigratedTurboPlanByPipelineInfo(projectId, pipelineId, pipelineElementId))
}

override fun manualRefreshStatus(
reqVO: TurboPlanStatusBatchUpdateReqVO,
user: String,
projectId: String
): Response<String> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
return Response.success(turboPlanService.manualRefreshStatus(reqVO))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

// 获取到待启用/待停用的加速方案清单
Expand Down Expand Up @@ -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!"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading