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

feat: Turbo编译加速对接权限中心RBAC #316 #319

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/backend/turbo/api-turbo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ dependencies {
api(project(":common-turbo:common-turbo-util"))
compileOnly("org.springframework.boot:spring-boot-starter-web")
compileOnly("org.springframework.cloud:spring-cloud-openfeign-core")
api("com.tencent.bk.devops.ci.common:common-api:${Versions.ciVersion}") {
api("com.tencent.bk.devops.ci.common:common-api") {
isTransitive = false
}
api("com.tencent.bk.sdk:iam-java-sdk")
}

plugins {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tencent.devops.turbo.api

import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO
import com.tencent.devops.api.pojo.Response
import com.tencent.devops.common.util.constants.AUTH_HEADER_DEVOPS_PROJECT_ID
import io.swagger.annotations.Api
Expand All @@ -9,6 +10,7 @@ import org.springframework.cloud.openfeign.FeignClient
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping

Expand All @@ -33,4 +35,11 @@ interface IServiceTurboPlanController {
@PathVariable("pipelineElementId")
pipelineElementId: String
): Response<String?>

@ApiOperation("特定资源列表,注册存量加速方案")
@PostMapping("/instances/list")
fun resourceList(
@ApiParam(value = "回调信息", required = true)
callBackInfo: CallbackRequestDTO
): Response<String>
}
11 changes: 1 addition & 10 deletions src/backend/turbo/biz-turbo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ dependencies {
api("com.google.guava:guava")
api("io.jsonwebtoken:jjwt")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core")
api("com.tencent.bk.devops.ci.project:api-project:${Versions.ciVersion}"){
isTransitive = false
}
api("com.tencent.bk.devops.ci.common:common-api:${Versions.ciVersion}"){
isTransitive = false
}
api("com.tencent.bk.devops.ci.auth:api-auth:${Versions.ciVersion}"){
isTransitive = false
}
api("com.tencent.bk.devops.ci.common:common-auth-api:${Versions.ciVersion}"){
api("com.tencent.bk.devops.ci.project:api-project") {
isTransitive = false
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.tencent.devops.turbo.controller

import com.tencent.bk.sdk.iam.dto.callback.request.CallbackRequestDTO
import com.tencent.devops.api.pojo.Response
import com.tencent.devops.turbo.api.IServiceTurboPlanController
import com.tencent.devops.turbo.service.TurboPlanService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RestController

@Suppress("MaxLineLength")
@RestController
class ServiceTurboPlanController @Autowired constructor(
private val turboPlanService: TurboPlanService
) : IServiceTurboPlanController {

override fun findTurboPlanIdByProjectIdAndPipelineInfo(projectId: String, pipelineId: String, pipelineElementId: String): Response<String?> {
return Response.success(turboPlanService.findMigratedTurboPlanByPipelineInfo(projectId, pipelineId, pipelineElementId)?.taskId)
override fun findTurboPlanIdByProjectIdAndPipelineInfo(
projectId: String,
pipelineId: String,
pipelineElementId: String
): Response<String?> {
return Response.success(
turboPlanService.findMigratedTurboPlanByPipelineInfo(
projectId,
pipelineId,
pipelineElementId
)?.taskId
)
}

override fun resourceList(callBackInfo: CallbackRequestDTO): Response<String> {
return Response.success(turboPlanService.getInstanceByResource(callBackInfo))
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.tencent.devops.turbo.controller

import com.tencent.devops.api.pojo.Response
import com.tencent.devops.common.api.exception.TurboException
import com.tencent.devops.common.api.exception.code.IS_NOT_ADMIN_MEMBER
import com.tencent.devops.common.util.constants.NO_ADMIN_MEMBER_MESSAGE
import com.tencent.devops.common.api.annotation.RequiresAuth
import com.tencent.devops.common.util.enums.ResourceActionType
import com.tencent.devops.common.util.enums.ResourceType
import com.tencent.devops.turbo.api.IUserTurboDaySummaryController
import com.tencent.devops.turbo.service.TurboAuthService
import com.tencent.devops.turbo.service.TurboSummaryService
import com.tencent.devops.turbo.vo.TurboOverviewStatRowVO
import com.tencent.devops.turbo.vo.TurboOverviewTrendVO
Expand All @@ -14,47 +13,37 @@ import org.springframework.web.bind.annotation.RestController

@RestController
class UserTurboDaySummaryController @Autowired constructor(
private val turboSummaryService: TurboSummaryService,
private val turboAuthService: TurboAuthService
private val turboSummaryService: TurboSummaryService
) : IUserTurboDaySummaryController {
/**
* 获取总览页面统计栏数据
*/
@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.OVERVIEW)
override fun getOverviewStatRowData(projectId: String, user: String): Response<TurboOverviewStatRowVO> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
return Response.success(turboSummaryService.getOverviewStatRowData(projectId))
}

/**
* 获取总览页面耗时分布趋势图数据
*/
@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.OVERVIEW)
override fun getTimeConsumingTrendData(
dateType: String,
projectId: String,
user: String
): Response<List<TurboOverviewTrendVO>> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
return Response.success(turboSummaryService.getTimeConsumingTrendData(dateType, projectId))
}

/**
* 获取总览页面编译次数趋势图数据
*/
@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.OVERVIEW)
override fun getCompileNumberTrendData(
dateType: String,
projectId: String,
user: String
): Response<List<TurboOverviewTrendVO>> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
return Response.success(turboSummaryService.getCompileNumberTrendData(dateType, projectId))
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.tencent.devops.turbo.controller

import com.tencent.devops.api.pojo.Response
import com.tencent.devops.common.api.annotation.RequiresAuth
import com.tencent.devops.common.api.exception.TurboException
import com.tencent.devops.common.api.exception.code.IS_NOT_ADMIN_MEMBER
import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.util.constants.NO_ADMIN_MEMBER_MESSAGE
import com.tencent.devops.common.util.enums.ResourceActionType
import com.tencent.devops.common.util.enums.ResourceType
import com.tencent.devops.turbo.api.IUserTurboPlanController
import com.tencent.devops.turbo.pojo.TurboPlanModel
import com.tencent.devops.turbo.service.TurboAuthService
Expand All @@ -16,63 +19,82 @@ import com.tencent.devops.turbo.vo.TurboPlanStatusBatchUpdateReqVO
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RestController

@Suppress("MaxLineLength")
@RestController
class UserTurboPlanController @Autowired constructor(
private val turboPlanService: TurboPlanService,
private val turboAuthService: TurboAuthService
) : IUserTurboPlanController {

@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.CREATE)
override fun addNewTurboPlan(turboPlanModel: TurboPlanModel, projectId: String, user: String): Response<String?> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
return Response.success(turboPlanService.addNewTurboPlan(turboPlanModel, user))
}

override fun getTurboPlanStatRowData(projectId: String, pageNum: Int?, pageSize: Int?, user: String): Response<TurboPlanPageVO> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.LIST)
override fun getTurboPlanStatRowData(
projectId: String,
pageNum: Int?,
pageSize: Int?,
user: String
): Response<TurboPlanPageVO> {
return Response.success(turboPlanService.getTurboPlanStatRowData(projectId, pageNum, pageSize))
}

override fun getTurboPlanDetailByPlanId(planId: String, projectId: String, user: String): Response<TurboPlanDetailVO> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
@RequiresAuth
override fun getTurboPlanDetailByPlanId(
planId: String,
projectId: String,
user: String
): Response<TurboPlanDetailVO> {
return Response.success(turboPlanService.getTurboPlanDetailByPlanId(planId))
}

override fun putTurboPlanDetailNameAndOpenStatus(turboPlanModel: TurboPlanModel, planId: String, user: String, projectId: String): Response<Boolean> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
@RequiresAuth(permission = ResourceActionType.EDIT)
override fun putTurboPlanDetailNameAndOpenStatus(
turboPlanModel: TurboPlanModel,
planId: String,
user: String,
projectId: String
): Response<Boolean> {
return Response.success(turboPlanService.putTurboPlanDetailNameAndOpenStatus(turboPlanModel, planId, user))
}

override fun putTurboPlanConfigParam(turboPlanModel: TurboPlanModel, planId: String, user: String, projectId: String): Response<Boolean> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}
@RequiresAuth(permission = ResourceActionType.EDIT)
override fun putTurboPlanConfigParam(
turboPlanModel: TurboPlanModel,
planId: String,
user: String,
projectId: String
): Response<Boolean> {
return Response.success(turboPlanService.putTurboPlanConfigParam(turboPlanModel, planId, user))
}

@RequiresAuth(permission = ResourceActionType.EDIT)
override fun putTurboPlanTopStatus(planId: String, topStatus: String, user: String): Response<Boolean> {
return Response.success(turboPlanService.putTurboPlanTopStatus(planId, topStatus, user))
}

override fun getAvailableTurboPlanList(projectId: String, pageNum: Int?, pageSize: Int?): Response<Page<TurboPlanDetailVO>> {
@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.LIST)
override fun getAvailableTurboPlanList(
projectId: String,
pageNum: Int?,
pageSize: Int?
): Response<Page<TurboPlanDetailVO>> {
return Response.success(turboPlanService.getAvailableProjectIdList(projectId, pageNum, pageSize))
}

override fun findTurboPlanIdByProjectIdAndPipelineInfo(projectId: String, pipelineId: String, pipelineElementId: String): Response<TurboMigratedPlanVO?> {
return Response.success(turboPlanService.findMigratedTurboPlanByPipelineInfo(projectId, pipelineId, pipelineElementId))
override fun findTurboPlanIdByProjectIdAndPipelineInfo(
projectId: String,
pipelineId: String,
pipelineElementId: String
): Response<TurboMigratedPlanVO?> {
return Response.success(
turboPlanService.findMigratedTurboPlanByPipelineInfo(
projectId,
pipelineId,
pipelineElementId
)
)
}

override fun manualRefreshStatus(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.tencent.devops.turbo.controller

import com.tencent.devops.api.pojo.Response
import com.tencent.devops.common.api.annotation.RequiresAuth
import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.util.enums.ResourceActionType
import com.tencent.devops.common.util.enums.ResourceType
import com.tencent.devops.turbo.api.IUserTurboPlanInstanceController
import com.tencent.devops.turbo.service.TurboPlanInstanceService
import com.tencent.devops.turbo.vo.TurboPlanInstanceVO
Expand All @@ -14,13 +17,22 @@ class UserTurboPlanInstanceController @Autowired constructor(
private val turboPlanInstanceService: TurboPlanInstanceService
) : IUserTurboPlanInstanceController {

@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.LIST_TASK)
override fun getTurboPlanInstanceList(
turboPlanId: String,
pageNum: Int?,
pageSize: Int?,
sortField: String?,
sortType: String?
): Response<Page<TurboPlanInstanceVO>> {
return Response.success(turboPlanInstanceService.getTurboPlanInstanceList(turboPlanId, pageNum, pageSize, sortField, sortType))
return Response.success(
turboPlanInstanceService.getTurboPlanInstanceList(
turboPlanId,
pageNum,
pageSize,
sortField,
sortType
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.tencent.devops.turbo.controller

import com.tencent.devops.api.pojo.Response
import com.tencent.devops.common.api.annotation.RequiresAuth
import com.tencent.devops.common.api.exception.TurboException
import com.tencent.devops.common.api.exception.code.IS_NOT_ADMIN_MEMBER
import com.tencent.devops.common.api.exception.code.TURBO_PARAM_INVALID
import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.util.constants.NO_ADMIN_MEMBER_MESSAGE
import com.tencent.devops.common.util.enums.ResourceActionType
import com.tencent.devops.common.util.enums.ResourceType
import com.tencent.devops.turbo.api.IUserTurboRecordController
import com.tencent.devops.turbo.enums.EnumDistccTaskStatus
import com.tencent.devops.turbo.pojo.TurboRecordModel
Expand Down Expand Up @@ -33,6 +36,7 @@ class UserTurboRecordController @Autowired constructor(
private val logger = LoggerFactory.getLogger(UserTurboRecordController::class.java)
}

@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.LIST_TASK)
override fun getTurboRecordHistoryList(
pageNum: Int?,
pageSize: Int?,
Expand Down Expand Up @@ -67,12 +71,12 @@ class UserTurboRecordController @Autowired constructor(
)
}

override fun getTurboDisplayInfoById(turboRecordId: String, projectId: String, user: String): Response<TurboRecordDisplayVO> {
// 判断是否是管理员
if (!turboAuthService.getAuthResult(projectId, user)) {
throw TurboException(errorCode = IS_NOT_ADMIN_MEMBER, errorMessage = NO_ADMIN_MEMBER_MESSAGE)
}

@RequiresAuth(resourceType = ResourceType.PROJECT, permission = ResourceActionType.VIEW_TASK)
override fun getTurboDisplayInfoById(
turboRecordId: String,
projectId: String,
user: String
): Response<TurboRecordDisplayVO> {
val turboRecordEntity = turboRecordService.findByRecordId(turboRecordId)
if (null == turboRecordEntity || turboRecordEntity.turboPlanId.isNullOrBlank()) {
logger.info("no turbo record found with id: $turboRecordId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ class TurboPlanDao @Autowired constructor(
/**
* 根据项目id和创建时间获取加速方案列表
*/
fun getTurboPlanByProjectIdAndCreatedDate(projectId: String, startTime: LocalDate?, endTime: LocalDate?, pageable: Pageable): Page<TTurboPlanEntity> {
fun getTurboPlanByProjectIdAndCreatedDate(
projectId: String,
startTime: LocalDate?,
endTime: LocalDate?,
pageable: Pageable
): Page<TTurboPlanEntity> {
val query = turboPlanParameter(projectId, startTime, endTime)
//先算总数
val totalCount = mongoTemplate.count(query, TTurboPlanEntity::class.java)
Expand Down
Loading
Loading