Skip to content

Commit

Permalink
Merge pull request #9539 from yjieliang/feat-4780
Browse files Browse the repository at this point in the history
feat:希望支持分支进行上架测试 #4780
  • Loading branch information
bkci-bot authored Nov 24, 2023
2 parents 2d14f2a + b5d5094 commit 247ddeb
Show file tree
Hide file tree
Showing 44 changed files with 880 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const val OR = "or" // 或
const val TIMETOSELECT = "timetoSelect" // 时必选
const val MASTER = "master" // 主干
const val SYSTEM = "system" // 系统
const val IN_READY_TEST = "IN_READY_TEST" // 正在测试中
const val BUILD_RUNNING = "buildRunning" // 运行中
const val BUILD_QUEUE = "buildQueue" // 构建排队中
const val BUILD_REVIEWING = "buildReviewing" // 构建待审核
Expand Down Expand Up @@ -154,6 +155,7 @@ const val KEY_UPDATED_TIME = "updatedTime"
const val KEY_DEFAULT_LOCALE_LANGUAGE = "defaultLocaleLanguage"
const val KEY_PROJECT_ID = "projectId"
const val KEY_PIPELINE_NUM = "pipelineNum"
const val KEY_BRANCH_TEST_FLAG = "branchTestFlag"

const val BK_BUILD_ENV_START_FAILED = "bkBuildEnvStartFailed" // 构建环境启动失败
const val BK_START_PULL_IMAGE = "bkStartPullImage" // 开始拉取镜像,镜像名称:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
package com.tencent.devops.log.api.print

import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID_DEFAULT_VALUE
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.log.pojo.QueryLogs
import com.tencent.devops.common.log.pojo.TaskBuildLogProperty
import com.tencent.devops.common.log.pojo.enums.LogType
import com.tencent.devops.common.log.pojo.message.LogMessage
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.HeaderParam
import javax.ws.rs.POST
import javax.ws.rs.PUT
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.MediaType
Expand Down Expand Up @@ -162,4 +168,79 @@ interface BuildLogPrintResource {
@ApiParam("所有插件的日志存储结果", required = true)
propertyList: List<TaskBuildLogProperty>
): Result<Boolean>

@ApiOperation("根据构建ID获取初始化所有日志")
@GET
@Path("/{projectId}/{pipelineId}/{buildId}/")
fun getInitLogs(
@ApiParam("用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@ApiParam("项目ID", required = true)
@PathParam("projectId")
projectId: String,
@ApiParam("流水线ID", required = true)
@PathParam("pipelineId")
pipelineId: String,
@ApiParam("构建ID", required = true)
@PathParam("buildId")
buildId: String,
@ApiParam("是否包含调试日志", required = false)
@QueryParam("debug")
debug: Boolean? = false,
@ApiParam("过滤日志级别", required = false)
@QueryParam("logType")
logType: LogType? = null,
@ApiParam("对应elementId", required = false)
@QueryParam("tag")
tag: String?,
@ApiParam("指定subTag", required = false)
@QueryParam("subTag")
subTag: String?,
@ApiParam("对应jobId", required = false)
@QueryParam("jobId")
jobId: String?,
@ApiParam("执行次数", required = false)
@QueryParam("executeCount")
executeCount: Int?
): Result<QueryLogs>

@ApiOperation("获取某行后的日志")
@GET
@Path("/{projectId}/{pipelineId}/{buildId}/after")
fun getAfterLogs(
@ApiParam("用户ID", required = true, defaultValue = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@ApiParam("项目ID", required = true)
@PathParam("projectId")
projectId: String,
@ApiParam("流水线ID", required = true)
@PathParam("pipelineId")
pipelineId: String,
@ApiParam("构建ID", required = true)
@PathParam("buildId")
buildId: String,
@ApiParam("起始行号", required = true)
@QueryParam("start")
start: Long,
@ApiParam("是否包含调试日志", required = false)
@QueryParam("debug")
debug: Boolean? = false,
@ApiParam("过滤日志级别", required = false)
@QueryParam("logType")
logType: LogType? = null,
@ApiParam("对应elementId", required = false)
@QueryParam("tag")
tag: String?,
@ApiParam("指定subTag", required = false)
@QueryParam("subTag")
subTag: String?,
@ApiParam("对应jobId", required = false)
@QueryParam("jobId")
jobId: String?,
@ApiParam("执行次数", required = false)
@QueryParam("executeCount")
executeCount: Int?
): Result<QueryLogs>
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
package com.tencent.devops.log.resources

import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.log.pojo.QueryLogs
import com.tencent.devops.common.log.pojo.TaskBuildLogProperty
import com.tencent.devops.common.log.pojo.enums.LogStorageMode
import com.tencent.devops.common.log.pojo.enums.LogType
import com.tencent.devops.common.log.pojo.message.LogMessage
import com.tencent.devops.common.web.RestResource
import com.tencent.devops.log.api.print.BuildLogPrintResource
import com.tencent.devops.log.event.LogOriginEvent
import com.tencent.devops.log.event.LogStatusEvent
import com.tencent.devops.log.meta.Ansi
import com.tencent.devops.log.service.BuildLogPrintService
import com.tencent.devops.log.service.BuildLogQueryService
import com.tencent.devops.log.service.IndexService
import com.tencent.devops.log.service.LogStatusService
import io.micrometer.core.annotation.Timed
Expand All @@ -55,7 +58,8 @@ class BuildLogPrintResourceImpl @Autowired constructor(
private val buildLogPrintService: BuildLogPrintService,
private val logStatusService: LogStatusService,
private val indexService: IndexService,
private val meterRegistry: MeterRegistry
private val meterRegistry: MeterRegistry,
private val buildLogQueryService: BuildLogQueryService
) : BuildLogPrintResource {

@Value("\${spring.application.name:#{null}}")
Expand Down Expand Up @@ -190,6 +194,65 @@ class BuildLogPrintResourceImpl @Autowired constructor(
return Result(true)
}

override fun getInitLogs(
userId: String,
projectId: String,
pipelineId: String,
buildId: String,
debug: Boolean?,
logType: LogType?,
tag: String?,
subTag: String?,
jobId: String?,
executeCount: Int?
): Result<QueryLogs> {
val initLogs = buildLogQueryService.getInitLogs(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
debug = debug,
logType = logType,
tag = tag,
subTag = subTag,
jobId = jobId,
executeCount = executeCount
)
recordMultiLogCount(initLogs.data?.logs?.size ?: 0)
return initLogs
}

override fun getAfterLogs(
userId: String,
projectId: String,
pipelineId: String,
buildId: String,
start: Long,
debug: Boolean?,
logType: LogType?,
tag: String?,
subTag: String?,
jobId: String?,
executeCount: Int?
): Result<QueryLogs> {
val afterLogs = buildLogQueryService.getAfterLogs(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
start = start,
debug = debug,
logType = logType,
tag = tag,
subTag = subTag,
jobId = jobId,
executeCount = executeCount
)
recordMultiLogCount(afterLogs.data?.logs?.size ?: 0)

return afterLogs
}

/**
* 记录日志列表函数
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.quality.api.v2

import com.tencent.devops.common.api.constant.IN_READY_TEST
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.quality.api.v2.pojo.QualityControlPoint
import io.swagger.annotations.Api
Expand All @@ -52,6 +53,8 @@ interface ServiceQualityControlPointMarketResource {
fun setTestControlPoint(
@QueryParam("userId")
userId: String,
@QueryParam("tag")
tag: String = IN_READY_TEST,
controlPoint: QualityControlPoint
): Result<Long>

Expand All @@ -68,6 +71,8 @@ interface ServiceQualityControlPointMarketResource {
@DELETE
fun deleteTestControlPoint(
@QueryParam("elementType")
elementType: String
elementType: String,
@QueryParam("tag")
tag: String = IN_READY_TEST
): Result<Int>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.quality.api.v2

import com.tencent.devops.common.api.constant.IN_READY_TEST
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.quality.api.v2.pojo.op.IndicatorUpdate
import io.swagger.annotations.Api
Expand Down Expand Up @@ -54,6 +55,8 @@ interface ServiceQualityIndicatorMarketResource {
userId: String,
@QueryParam("atomCode")
atomCode: String,
@QueryParam("tag")
tag: String = IN_READY_TEST,
indicatorUpdateList: Collection<IndicatorUpdate>
): Result<Int>

Expand All @@ -71,6 +74,8 @@ interface ServiceQualityIndicatorMarketResource {
@DELETE
fun deleteTestIndicator(
@QueryParam("elementType")
elementType: String
elementType: String,
@QueryParam("extra")
extra: String = IN_READY_TEST
): Result<Int>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.quality.api.v2

import com.tencent.devops.common.api.constant.IN_READY_TEST
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.quality.api.v2.pojo.op.QualityMetaData
import io.swagger.annotations.Api
Expand All @@ -46,14 +47,16 @@ import javax.ws.rs.core.MediaType
@Consumes(MediaType.APPLICATION_JSON)
interface ServiceQualityMetadataMarketResource {

@ApiOperation("注册插件指标的元数据")
@ApiOperation("注册插件指标的测试元数据")
@Path("/setMetadata")
@POST
fun setTestMetadata(
@QueryParam("userId")
userId: String,
@QueryParam("atomCode")
atomCode: String,
@QueryParam("extra")
extra: String = IN_READY_TEST,
metadataList: List<QualityMetaData>
): Result<Map<String/* dataId */, Long/* metadataId */>>

Expand All @@ -70,6 +73,8 @@ interface ServiceQualityMetadataMarketResource {
@DELETE
fun deleteTestMetadata(
@QueryParam("elementType")
elementType: String
elementType: String,
@QueryParam("extra")
extra: String = IN_READY_TEST
): Result<Int>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.quality.dao.v2

import com.tencent.devops.common.api.constant.IN_READY_TEST
import com.tencent.devops.common.api.util.HashUtil
import com.tencent.devops.common.api.util.PageUtil
import com.tencent.devops.model.quality.tables.TQualityControlPoint
Expand Down Expand Up @@ -63,7 +64,7 @@ class QualityControlPointDao {
val sqlLimit = PageUtil.convertPageSizeToSQLLimit(page, pageSize)
with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
return dslContext.selectFrom(this)
.where((TAG.isNull).or(TAG.ne("IN_READY_TEST")))
.where((TAG.isNull).or(TAG.notContains(IN_READY_TEST)))
.orderBy(CREATE_TIME.desc())
.limit(sqlLimit.offset, sqlLimit.limit)
.fetch()
Expand All @@ -82,7 +83,7 @@ class QualityControlPointDao {
fun count(dslContext: DSLContext): Long {
with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
return dslContext.selectCount().from(this)
.where((TAG.isNull).or(TAG.ne("IN_READY_TEST")))
.where((TAG.isNull).or(TAG.notContains(IN_READY_TEST)))
.fetchOne(0, Long::class.java)!!
}
}
Expand Down Expand Up @@ -110,7 +111,7 @@ class QualityControlPointDao {
fun getStages(dslContext: DSLContext): Result<Record1<String>> {
return with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
dslContext.select(STAGE).from(this)
.where(STAGE.isNotNull.and(TAG.ne("IN_READY_TEST")))
.where(STAGE.isNotNull.and(TAG.notContains(IN_READY_TEST)))
.groupBy(STAGE)
.fetch()
}
Expand All @@ -123,17 +124,22 @@ class QualityControlPointDao {
fun getElementNames(dslContext: DSLContext): Result<Record2<String, String>> {
return with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
dslContext.select(ELEMENT_TYPE, NAME).from(this)
.where(NAME.isNotNull.and(TAG.ne("IN_READY_TEST")))
.where(NAME.isNotNull.and(TAG.notContains(IN_READY_TEST)))
.groupBy(ELEMENT_TYPE, NAME)
.fetch()
}
}

fun setTestControlPoint(dslContext: DSLContext, userId: String, controlPoint: QualityControlPoint): Long {
fun setTestControlPoint(
dslContext: DSLContext,
userId: String,
tag: String,
controlPoint: QualityControlPoint
): Long {
var pointId = 0L
with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
val testControlPoint = dslContext.selectFrom(this)
.where(ELEMENT_TYPE.eq(controlPoint.type).and(TAG.eq("IN_READY_TEST")))
.where(ELEMENT_TYPE.eq(controlPoint.type).and(TAG.eq(tag)))
.fetchOne()
if (testControlPoint != null) {
dslContext.update(this)
Expand Down Expand Up @@ -177,7 +183,7 @@ class QualityControlPointDao {
LocalDateTime.now(),
controlPoint.atomVersion,
controlPoint.testProject,
"IN_READY_TEST"
tag
).returning(ID).fetchOne()!!.id
val hashId = HashUtil.encodeLongId(pointId)
dslContext.update(this)
Expand All @@ -197,8 +203,8 @@ class QualityControlPointDao {
.where(ELEMENT_TYPE.eq(elementType))
.fetch()

val testControlPoint = controlPoints.firstOrNull { it.tag == "IN_READY_TEST" }
val prodControlPoint = controlPoints.firstOrNull { it.tag != "IN_READY_TEST" }
val testControlPoint = controlPoints.firstOrNull { it.tag == IN_READY_TEST }
val prodControlPoint = controlPoints.firstOrNull { it.tag != IN_READY_TEST }

// 测试为空,代表quality.json被删了,直接把生产的也删了
if (testControlPoint == null) {
Expand Down Expand Up @@ -227,10 +233,10 @@ class QualityControlPointDao {
return 0
}

fun deleteTestControlPoint(dslContext: DSLContext, elementType: String): Int {
fun deleteTestControlPoint(dslContext: DSLContext, elementType: String, tag: String): Int {
return with(TQualityControlPoint.T_QUALITY_CONTROL_POINT) {
dslContext.deleteFrom(this)
.where(ELEMENT_TYPE.eq(elementType).and(TAG.eq("IN_READY_TEST")))
.where(ELEMENT_TYPE.eq(elementType).and(TAG.eq(tag)))
.execute()
}
}
Expand Down
Loading

0 comments on commit 247ddeb

Please sign in to comment.