Skip to content

Commit

Permalink
feat: 流水线新增构建矩阵 TencentBlueKing#4518
Browse files Browse the repository at this point in the history
  • Loading branch information
royalhuang committed Nov 20, 2021
1 parent 3da6e62 commit 9033559
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class BuildingHeartBeatUtils @Autowired constructor(
}

fun dispatchHeartbeatEvent(buildInfo: BuildInfo, containerId: String) {
val ctr = pipelineContainerService.getContainer(buildInfo.buildId, stageId = null, containerId = containerId)
?: return
val ctr = pipelineContainerService.getContainer(
buildId = buildInfo.buildId,
stageId = null,
containerSeqId = containerId
) ?: return
pipelineEventDispatcher.dispatch(
PipelineContainerAgentHeartBeatEvent(
source = "buildVMStarted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,39 @@ class PipelineBuildContainerDao {
.set(PIPELINE_ID, it.pipelineId)
.set(MATRIX_GROUP_ID, it.matrixGroupId)
.set(CONTAINER_TYPE, it.containerType)
.set(SEQ, it.seq)
.set(CONTAINER_ID, it.containerId)
.set(STATUS, it.status)
.set(START_TIME, it.startTime)
.set(END_TIME, it.endTime)
.set(COST, it.cost)
.set(EXECUTE_COUNT, it.executeCount)
.set(CONDITIONS, it.conditions)
.where(BUILD_ID.eq(it.buildId)
.and(STAGE_ID.eq(it.stageId)).and(CONTAINER_ID.eq(it.containerId)))
.and(STAGE_ID.eq(it.stageId)).and(SEQ.eq(it.seq)))
)
}
}
dslContext.batch(records).execute()
}

fun get(
fun getBySeqId(
dslContext: DSLContext,
buildId: String,
stageId: String?,
containerSeqId: Int
): TPipelineBuildContainerRecord? {

return with(T_PIPELINE_BUILD_CONTAINER) {
val query = dslContext.selectFrom(this).where(BUILD_ID.eq(buildId))
if (stageId.isNullOrBlank()) {
query.and(SEQ.eq(containerSeqId)).fetchAny()
} else {
query.and(STAGE_ID.eq(stageId)).and(SEQ.eq(containerSeqId)).fetchAny()
}
}
}

fun getByContainerId(
dslContext: DSLContext,
buildId: String,
stageId: String?,
Expand All @@ -169,7 +186,7 @@ class PipelineBuildContainerDao {
dslContext: DSLContext,
buildId: String,
stageId: String,
containerId: String,
containerSeqId: Int,
startTime: LocalDateTime?,
endTime: LocalDateTime?,
buildStatus: BuildStatus
Expand All @@ -195,7 +212,7 @@ class PipelineBuildContainerDao {
}

update.where(BUILD_ID.eq(buildId)).and(STAGE_ID.eq(stageId))
.and(CONTAINER_ID.eq(containerId)).execute()
.and(SEQ.eq(containerSeqId)).execute()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ class PipelineBuildTaskDao {
fun listByStatus(
dslContext: DSLContext,
buildId: String,
containerId: String?,
containerSeqId: String?,
statusSet: Collection<BuildStatus>?
): List<TPipelineBuildTaskRecord> {
return with(T_PIPELINE_BUILD_TASK) {
val where = dslContext.selectFrom(this)
.where(BUILD_ID.eq(buildId))
if (!containerId.isNullOrBlank()) {
where.and(CONTAINER_ID.eq(containerId))
// #4518 T_PIPELINE_BUILD_TASK表中的CONTAINER_ID为Container的seq id
if (!containerSeqId.isNullOrBlank()) {
where.and(CONTAINER_ID.eq(containerSeqId))
}
if (statusSet != null && statusSet.isNotEmpty()) {
val statusIntSet = mutableSetOf<Int>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class PipelineBuildContainerEvent(
override val userId: String,
val buildId: String,
val stageId: String,
val containerId: String,
val containerId: String, // model中的container.id,CONTAINER表中的seq id,TASK表中的containerId
val containerType: String,
val previousStageStatus: BuildStatus? = null, // 此仅在Stage下发处才会赋值,Job内/Task回调 等都会为null
override var actionType: ActionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ class PipelineContainerService @Autowired constructor(
private val logger = LoggerFactory.getLogger(PipelineContainerService::class.java)
}

fun getContainer(buildId: String, stageId: String?, containerId: String): PipelineBuildContainer? {
val result = pipelineBuildContainerDao.get(dslContext, buildId, stageId, containerId)
fun getContainer(buildId: String, stageId: String?, containerSeqId: String): PipelineBuildContainer? {
// #4518 防止出错暂时保留两个字段的兼容查询
val result = try {
pipelineBuildContainerDao.getBySeqId(dslContext, buildId, stageId, containerSeqId.toInt())
} catch (ignore: Throwable) {
pipelineBuildContainerDao.getByContainerId(dslContext, buildId, stageId, containerSeqId)
}
if (result != null) {
return pipelineBuildContainerDao.convert(result)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ class PipelineRepositoryService constructor(

var taskSeq = 0
c.id = containerSeqId.incrementAndGet().toString()
// #4518 Model中的containerId 和T_PIPELINE_BUILD_CONTAINER表的containerId保持一致
if (c.containerId.isNullOrBlank()) {
c.containerId = UUIDUtil.generate()
c.containerId = modelContainerIdGenerator.getNextId()
}
c.elements.forEach { e ->
if (e.id.isNullOrBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class PipelineVMBuildService @Autowired(required = false) constructor(
pipelineContainerService.updateContainerStatus(
buildId = buildId,
stageId = startUpVMTask.stageId,
containerId = startUpVMTask.containerId,
containerSeqId = startUpVMTask.containerId,
startTime = LocalDateTime.now(),
endTime = null,
buildStatus = BuildStatus.RUNNING
Expand Down
Loading

0 comments on commit 9033559

Please sign in to comment.