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

perf: 详情页的旧数据兼容下架 #9522 #11008

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data class PipelineBuildContainer(
val stageId: String,
val containerId: String, // 与seq id同值
val containerHashId: String?, // 与model中的container.containerHashId同值
val containPostTaskFlag: Boolean?,
val jobId: String?,
val matrixGroupFlag: Boolean?,
val matrixGroupId: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ data class BuildRecordContainer(
containerId = container.id!!,
containerType = container.getClassType(),
executeCount = context.executeCount,
containPostTaskFlag = container.containPostTaskFlag,
matrixGroupFlag = container.matrixGroupFlag,
status = buildStatus?.name,
containerVar = containerVar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import com.tencent.devops.process.pojo.KEY_EXECUTE_COUNT
import com.tencent.devops.process.pojo.pipeline.record.BuildRecordContainer
import org.jooq.Condition
import org.jooq.DSLContext
import org.jooq.Record15
import org.jooq.Record16
import org.jooq.RecordMapper
import org.jooq.impl.DSL
import org.jooq.util.mysql.MySQLDSL
Expand All @@ -63,6 +63,7 @@ class BuildRecordContainerDao {
EXECUTE_COUNT,
CONTAINER_VAR,
CONTAINER_TYPE,
CONTAIN_POST_TASK,
MATRIX_GROUP_FLAG,
MATRIX_GROUP_ID,
STATUS,
Expand All @@ -81,6 +82,7 @@ class BuildRecordContainerDao {
record.executeCount,
JsonUtil.toJson(record.containerVar, false),
record.containerType,
record.containPostTaskFlag,
record.matrixGroupFlag,
record.matrixGroupId,
record.status,
Expand Down Expand Up @@ -240,7 +242,7 @@ class BuildRecordContainerDao {
).from(this).where(conditions).groupBy(CONTAINER_ID)
val result = dslContext.select(
BUILD_ID, PROJECT_ID, PIPELINE_ID, RESOURCE_VERSION, STAGE_ID, CONTAINER_ID,
CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, MATRIX_GROUP_FLAG,
CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, CONTAIN_POST_TASK, MATRIX_GROUP_FLAG,
MATRIX_GROUP_ID, START_TIME, END_TIME, TIMESTAMPS
).from(this).join(max).on(
CONTAINER_ID.eq(max.field(KEY_CONTAINER_ID, String::class.java))
Expand Down Expand Up @@ -273,7 +275,7 @@ class BuildRecordContainerDao {
).from(this).where(conditions).groupBy(CONTAINER_ID)
val result = dslContext.select(
BUILD_ID, PROJECT_ID, PIPELINE_ID, RESOURCE_VERSION, STAGE_ID, CONTAINER_ID,
CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, MATRIX_GROUP_FLAG,
CONTAINER_VAR, EXECUTE_COUNT, CONTAINER_TYPE, STATUS, CONTAIN_POST_TASK, MATRIX_GROUP_FLAG,
MATRIX_GROUP_ID, START_TIME, END_TIME, TIMESTAMPS
).from(this).join(max).on(
CONTAINER_ID.eq(max.field(KEY_CONTAINER_ID, String::class.java))
Expand All @@ -287,8 +289,8 @@ class BuildRecordContainerDao {
}

private fun TPipelineBuildRecordContainer.generateBuildRecordContainer(
record: Record15<String, String, String, Int,
String, String, String, Int, String, String, Boolean, String, LocalDateTime, LocalDateTime, String>
record: Record16<String, String, String, Int,
String, String, String, Int, String, String, Boolean, Boolean, String, LocalDateTime, LocalDateTime, String>
) =
BuildRecordContainer(
buildId = record[BUILD_ID],
Expand All @@ -303,6 +305,7 @@ class BuildRecordContainerDao {
record[CONTAINER_VAR], object : TypeReference<MutableMap<String, Any>>() {}
),
containerType = record[CONTAINER_TYPE],
containPostTaskFlag = record[CONTAIN_POST_TASK],
matrixGroupFlag = record[MATRIX_GROUP_FLAG],
matrixGroupId = record[MATRIX_GROUP_ID],
startTime = record[START_TIME],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class BuildRecordTaskDao {
executeCount: Int,
buildStatus: BuildStatus,
stageId: String? = null,
containerId: String? = null
containerId: String? = null,
taskIds: Set<String>? = null
) {
with(TPipelineBuildRecordTask.T_PIPELINE_BUILD_RECORD_TASK) {
val update = dslContext.update(this)
Expand All @@ -158,6 +159,7 @@ class BuildRecordTaskDao {
)
stageId?.let { update.and(STAGE_ID.eq(stageId)) }
containerId?.let { update.and(CONTAINER_ID.eq(containerId)) }
taskIds?.let { update.and(TASK_ID.`in`(taskIds)) }
update.execute()
}
}
Expand All @@ -169,7 +171,8 @@ class BuildRecordTaskDao {
buildId: String,
executeCount: Int,
containerId: String? = null,
buildStatusSet: Set<BuildStatus>? = null
buildStatusSet: Set<BuildStatus>? = null,
queryPostTaskFlag: Boolean? = null
): List<BuildRecordTask> {
with(TPipelineBuildRecordTask.T_PIPELINE_BUILD_RECORD_TASK) {
val conditions = mutableListOf<Condition>()
Expand All @@ -179,8 +182,12 @@ class BuildRecordTaskDao {
conditions.add(EXECUTE_COUNT.eq(executeCount))
containerId?.let { conditions.add(CONTAINER_ID.eq(containerId)) }
buildStatusSet?.let { conditions.add(STATUS.`in`(it.map { status -> status.name })) }
return dslContext.selectFrom(this)
.where(conditions).orderBy(TASK_SEQ.asc()).fetch(mapper)
if (queryPostTaskFlag == true) {
conditions.add(POST_INFO.isNotNull)
} else if (queryPostTaskFlag == false) {
conditions.add(POST_INFO.isNull)
}
return dslContext.selectFrom(this).where(conditions).orderBy(TASK_SEQ.asc()).fetch(mapper)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ class PipelineBuildContainerDao {
containerType = containerType,
containerId = containerId,
containerHashId = containerHashId,
containPostTaskFlag = controlOption.containPostTaskFlag,
jobId = jobId,
matrixGroupFlag = matrixGroupFlag,
matrixGroupId = matrixGroupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ class PipelineBuildTaskDao {
projectId: String,
buildId: String,
containerId: String?,
statusSet: Collection<BuildStatus>?
statusSet: Collection<BuildStatus>?,
startTaskSeq: Int? = null,
endTaskSeq: Int? = null
): List<PipelineBuildTask> {
return with(T_PIPELINE_BUILD_TASK) {
val where = dslContext.selectFrom(this)
Expand All @@ -292,6 +294,8 @@ class PipelineBuildTaskDao {
if (!statusSet.isNullOrEmpty()) {
where.and(STATUS.`in`(statusSet.map { it.ordinal }))
}
startTaskSeq?.let { where.and(TASK_SEQ.ge(startTaskSeq)) }
endTaskSeq?.let { where.and(TASK_SEQ.le(endTaskSeq)) }
where.orderBy(TASK_SEQ.asc()).fetch(mapper)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.process.engine.service

import com.tencent.devops.common.api.constant.CommonMessageCode
import com.tencent.devops.common.api.enums.BuildReviewType
import com.tencent.devops.common.api.exception.ErrorCodeException
import com.tencent.devops.common.api.exception.TaskExecuteException
Expand Down Expand Up @@ -76,10 +77,10 @@ import com.tencent.devops.process.utils.PIPELINE_BUILD_NUM
import com.tencent.devops.quality.api.v2.ServiceQualityRuleResource
import com.tencent.devops.quality.api.v2.pojo.ControlPointPosition
import com.tencent.devops.quality.api.v2.pojo.request.BuildCheckParams
import java.time.LocalDateTime
import javax.ws.rs.core.Response
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import javax.ws.rs.core.Response

@Suppress(
"LongParameterList",
Expand All @@ -95,7 +96,6 @@ class PipelineBuildQualityService(
private val client: Client,
private val pipelineEventDispatcher: PipelineEventDispatcher,
private val pipelineRepositoryService: PipelineRepositoryService,
private val buildDetailService: PipelineBuildDetailService,
private val taskBuildRecordService: TaskBuildRecordService,
private val pipelineRuntimeService: PipelineRuntimeService,
private val buildVariableService: BuildVariableService
Expand Down Expand Up @@ -135,61 +135,39 @@ class PipelineBuildQualityService(
)
}

val model = buildDetailService.getBuildModel(projectId, buildId)
val buildInfo = pipelineRuntimeService.getBuildInfo(projectId, pipelineId, buildId)
?: throw ErrorCodeException(
statusCode = Response.Status.NOT_FOUND.statusCode,
errorCode = ProcessMessageCode.ERROR_NO_BUILD_EXISTS_BY_ID,
params = arrayOf(buildId)
)

var find = false
var taskType = ""
model.stages.forEachIndexed nextStage@{ index, s ->
if (index == 0) {
return@nextStage
}
s.containers.forEach nextContainer@{ c ->
c.elements.forEach nextElement@{ element ->
if (element.id != elementId) return@nextElement
logger.info("${element.id}, ${element.name}")
when (element) {
is QualityGateInElement -> {
find = true
taskType = element.interceptTask!!
}
is QualityGateOutElement -> {
find = true
taskType = element.interceptTask!!
}
}
return@nextStage
}
c.fetchGroupContainers()?.forEach {
it.elements.forEach nextElement@{ element ->
if (element.id != elementId || element !is MatrixStatusElement) return@nextElement
logger.info("${element.id}, ${element.name}")
if (element.originClassType == QualityGateInElement.classType ||
element.originClassType == QualityGateOutElement.classType
) {
find = true
taskType = element.interceptTask!!
}
return@nextStage
}
}
}
}

if (!find) {
val buildRecordTask = taskBuildRecordService.getTaskBuildRecord(
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
taskId = elementId,
executeCount = buildInfo.executeCount ?: 1
)
val atomCode = buildRecordTask?.atomCode
if (atomCode.isNullOrBlank() || atomCode !in listOf(
QualityGateInElement.classType,
QualityGateOutElement.classType
)
) {
throw ErrorCodeException(
statusCode = Response.Status.FORBIDDEN.statusCode,
errorCode = ProcessMessageCode.ERROR_QUALITY_TASK_NOT_FOUND,
params = arrayOf(elementId)
)
}
val interceptTaskKey = QualityGateInElement::interceptTask.name
val interceptTask = buildRecordTask.taskVar[interceptTaskKey]?.toString() ?: throw ErrorCodeException(
errorCode = CommonMessageCode.PARAMETER_IS_NULL,
params = arrayOf(interceptTaskKey)
)

// 校验审核权限
val auditUserSet = getAuditUserList(projectId, pipelineId, buildId, taskType)
val auditUserSet = getAuditUserList(projectId, pipelineId, buildId, interceptTask)
if (!auditUserSet.contains(userId)) {
throw ErrorCodeException(
statusCode = Response.Status.NOT_FOUND.statusCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class PipelineContainerService @Autowired constructor(
containPostTaskFlag = container.containPostTaskFlag,
agentReuseMutex = agentReuseMutex
),
containPostTaskFlag = container.containPostTaskFlag,
matrixGroupFlag = false,
matrixGroupId = matrixGroupId
)
Expand Down Expand Up @@ -680,6 +681,7 @@ class PipelineContainerService @Autowired constructor(
seq = context.containerSeq,
status = BuildStatus.QUEUE,
controlOption = controlOption,
containPostTaskFlag = container.containPostTaskFlag,
matrixGroupFlag = container.matrixGroupFlag,
matrixGroupId = null
),
Expand All @@ -695,9 +697,9 @@ class PipelineContainerService @Autowired constructor(
projectId = context.projectId, pipelineId = context.pipelineId, buildId = context.buildId,
resourceVersion = context.resourceVersion, stageId = stage.id!!,
containerId = container.id!!, containerType = container.getClassType(),
executeCount = context.executeCount, matrixGroupFlag = container.matrixGroupFlag,
matrixGroupId = null, status = BuildStatus.SKIP.name, containerVar = mutableMapOf(),
startTime = null, endTime = null, timestamps = mapOf()
executeCount = context.executeCount, containPostTaskFlag = container.containPostTaskFlag,
matrixGroupFlag = container.matrixGroupFlag, matrixGroupId = null, status = BuildStatus.SKIP.name,
containerVar = mutableMapOf(), startTime = null, endTime = null, timestamps = mapOf()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.tencent.devops.common.pipeline.enums.BuildStatus
import com.tencent.devops.common.pipeline.pojo.JobHeartbeatRequest
import com.tencent.devops.process.constant.ProcessMessageCode
import com.tencent.devops.process.dao.record.BuildRecordTaskDao
import com.tencent.devops.process.engine.dao.PipelineBuildDao
import com.tencent.devops.process.engine.service.record.ContainerBuildRecordService
import com.tencent.devops.process.engine.service.record.TaskBuildRecordService
import com.tencent.devops.process.pojo.BuildStageProgressInfo
Expand All @@ -22,6 +23,7 @@ class PipelineProgressRateService constructor(
private val pipelineRuntimeService: PipelineRuntimeService,
private val buildRecordService: ContainerBuildRecordService,
private val buildRecordTaskDao: BuildRecordTaskDao,
private val pipelineBuildDao: PipelineBuildDao,
private val dslContext: DSLContext
) {
fun reportProgressRate(
Expand All @@ -33,7 +35,9 @@ class PipelineProgressRateService constructor(
logger.info("report progress rate:$projectId|$buildId|$executeCount|$jobHeartbeatRequest")
val task2ProgressRate = jobHeartbeatRequest?.task2ProgressRate ?: return
if (task2ProgressRate.isEmpty()) return
val pipelineId = pipelineRuntimeService.getBuildInfo(projectId, buildId)?.pipelineId ?: return
val pipelineId = pipelineBuildDao.getBuildInfo(
dslContext = dslContext, projectId = projectId, buildId = buildId
)?.pipelineId ?: return
task2ProgressRate.forEach { (taskId, progressRate) ->
taskBuildRecordService.updateTaskRecord(
projectId = projectId,
Expand Down
Loading
Loading