Skip to content

Commit

Permalink
【PAC】feat:支持从代码库维度查看对应的代码库事件 #8122
Browse files Browse the repository at this point in the history
  • Loading branch information
hejieehe committed Nov 14, 2023
1 parent dfe84b7 commit e86157c
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.tencent.devops.process.pojo.BuildManualStartupInfo
import com.tencent.devops.process.pojo.BuildTaskPauseInfo
import com.tencent.devops.process.pojo.pipeline.ModelDetail
import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent
import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired

Expand Down Expand Up @@ -137,23 +138,24 @@ class ApigwBuildResourceV3Impl @Autowired constructor(
buildNo: Int?
): Result<BuildId> {
logger.info("OPENAPI_BUILD_V3|$userId|start|$projectId|$pipelineId|$values|$buildNo")
val buildId = client.get(ServiceBuildResource::class).manualStartupNew(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values ?: emptyMap(),
buildNo = buildNo,
channelCode = apiGatewayUtil.getChannelCode(),
startType = StartType.SERVICE
)
saveTriggerEvent(
val buildId = saveTriggerEvent(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values,
buildId = buildId.data
action = {
client.get(ServiceBuildResource::class).manualStartupNew(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values ?: emptyMap(),
buildNo = buildNo,
channelCode = apiGatewayUtil.getChannelCode(),
startType = StartType.SERVICE
).data
}
)
return buildId
return Result(buildId)
}

override fun stop(
Expand Down Expand Up @@ -297,23 +299,40 @@ class ApigwBuildResourceV3Impl @Autowired constructor(
projectId: String,
pipelineId: String,
values: Map<String, String>?,
buildId: BuildId?
) {
action: () -> BuildId?
): BuildId {
var buildId: BuildId? = null
var status = PipelineTriggerStatus.SUCCEED.name
var failReason = ""
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.SERVICE.name,
buildInfo = buildId
)
)
buildId = action.invoke()
} catch (ignored: Exception) {
logger.warn("OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored)
status = PipelineTriggerStatus.FAILED.name
failReason = ignored.message.toString()
throw ignored
} finally {
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.SERVICE.name,
buildInfo = buildId,
failReason = failReason,
status = status
)
)
} catch (ignored: Exception) {
logger.warn(
"OPENAPI_BUILD_V3|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId",
ignored
)
}
}
return buildId!!
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.tencent.devops.process.pojo.BuildTaskPauseInfo
import com.tencent.devops.process.pojo.ReviewParam
import com.tencent.devops.process.pojo.pipeline.ModelRecord
import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent
import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired

Expand Down Expand Up @@ -174,23 +175,24 @@ class ApigwBuildResourceV4Impl @Autowired constructor(
buildNo: Int?
): Result<BuildId> {
logger.info("OPENAPI_BUILD_V4|$userId|start|$projectId|$pipelineId|$values|$buildNo")
val buildId = client.get(ServiceBuildResource::class).manualStartupNew(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values ?: emptyMap(),
buildNo = buildNo,
channelCode = apiGatewayUtil.getChannelCode(),
startType = StartType.SERVICE
)
saveTriggerEvent(
val buildId = saveTriggerEvent(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values,
buildId = buildId.data
action = {
client.get(ServiceBuildResource::class).manualStartupNew(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values ?: emptyMap(),
buildNo = buildNo,
channelCode = apiGatewayUtil.getChannelCode(),
startType = StartType.SERVICE
).data
}
)
return buildId
return Result(buildId)
}

override fun stop(
Expand Down Expand Up @@ -443,23 +445,40 @@ class ApigwBuildResourceV4Impl @Autowired constructor(
projectId: String,
pipelineId: String,
values: Map<String, String>?,
buildId: BuildId?
) {
action: () -> BuildId?
): BuildId {
var buildId: BuildId? = null
var status = PipelineTriggerStatus.SUCCEED.name
var failReason = ""
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.SERVICE.name,
buildInfo = buildId
)
)
buildId = action.invoke()
} catch (ignored: Exception) {
logger.warn("OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored)
status = PipelineTriggerStatus.FAILED.name
failReason = ignored.message.toString()
throw ignored
} finally {
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.SERVICE.name,
buildInfo = buildId,
failReason = failReason,
status = status
)
)
} catch (ignored: Exception) {
logger.warn(
"OPENAPI_BUILD_V4|fail to save trigger event|$projectId|$pipelineId|$userId|$buildId",
ignored
)
}
}
return buildId!!
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ data class PipelineSpecificEvent(
@ApiModelProperty("触发类型")
val triggerType: String = PipelineTriggerType.MANUAL.name,
@ApiModelProperty("构建信息")
val buildInfo: BuildId?
val buildInfo: BuildId?,
@ApiModelProperty("构建状态")
val status: String,
@ApiModelProperty("失败信息")
val failReason: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ data class PipelineTriggerEvent(
val replayRequestId: String? = null,
@ApiModelProperty("事件请求参数, 记录手动/openapi/定时/远程触发启动参数")
val requestParams: Map<String, String>? = null,
@ApiModelProperty("触发事件")
@ApiModelProperty("触发时间")
val createTime: LocalDateTime
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class ServiceTriggerEventResourceImpl @Autowired constructor(
eventSource = eventSource,
eventDesc = eventDesc,
triggerType = PipelineTriggerType.PIPELINE.name,
buildInfo = buildInfo
buildInfo = buildInfo,
status = status,
failReason = failReason
)
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import com.tencent.devops.process.pojo.ReviewParam
import com.tencent.devops.process.pojo.pipeline.ModelDetail
import com.tencent.devops.process.pojo.pipeline.ModelRecord
import com.tencent.devops.process.pojo.trigger.PipelineSpecificEvent
import com.tencent.devops.process.pojo.trigger.PipelineTriggerStatus
import com.tencent.devops.process.service.PipelineRecentUseService
import com.tencent.devops.process.service.builds.PipelineBuildFacadeService
import com.tencent.devops.process.service.builds.PipelineBuildMaintainFacadeService
Expand Down Expand Up @@ -99,24 +100,25 @@ class UserBuildResourceImpl @Autowired constructor(
triggerReviewers: List<String>?
): Result<BuildId> {
checkParam(userId, projectId, pipelineId)
val manualStartup = pipelineBuildFacadeService.buildManualStartup(
val manualStartup = saveTriggerEvent(
userId = userId,
startType = StartType.MANUAL,
projectId = projectId,
pipelineId = pipelineId,
values = values,
channelCode = ChannelCode.BS,
buildNo = buildNo,
triggerReviewers = triggerReviewers
action = {
pipelineBuildFacadeService.buildManualStartup(
userId = userId,
startType = StartType.MANUAL,
projectId = projectId,
pipelineId = pipelineId,
values = values,
channelCode = ChannelCode.BS,
buildNo = buildNo,
triggerReviewers = triggerReviewers
)
}
)
pipelineRecentUseService.record(userId, projectId, pipelineId)
saveTriggerEvent(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
values = values,
buildId = manualStartup
)
return Result(manualStartup)
}

Expand Down Expand Up @@ -553,23 +555,37 @@ class UserBuildResourceImpl @Autowired constructor(
projectId: String,
pipelineId: String,
values: Map<String, String>?,
buildId: BuildId?
) {
action: () -> BuildId?
): BuildId {
var buildId: BuildId? = null
var status = PipelineTriggerStatus.SUCCEED.name
var failReason = ""
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.MANUAL.name,
buildInfo = buildId
)
)
buildId = action.invoke()
} catch (ignored: Exception) {
logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored)
status = PipelineTriggerStatus.FAILED.name
failReason = ignored.message.toString()
throw ignored
} finally {
try {
client.get(ServiceTriggerEventResource::class).saveSpecificEvent(
specificEvent = PipelineSpecificEvent(
projectId = projectId,
pipelineId = pipelineId,
requestParams = values,
userId = userId,
eventSource = userId,
triggerType = StartType.MANUAL.name,
buildInfo = buildId,
failReason = failReason,
status = status
)
)
} catch (ignored: Exception) {
logger.warn("fail to save trigger event|$projectId|$pipelineId|$userId|$buildId", ignored)
}
}
return buildId!!
}

companion object{
Expand Down
Loading

0 comments on commit e86157c

Please sign in to comment.