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:构建资源类型为第三方构建集群时支持指定Job并发数 #9810 #9872

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7fd1b04
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 20, 2023
e787bc1
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 25, 2023
232e6ed
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Dec 26, 2023
cc72406
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
f8158d3
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
d9d7d94
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
995f1af
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
cfc91b7
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
6495541
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 26, 2023
40881fa
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
a573583
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
7caa324
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
b160d4d
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
3d8377b
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
72e6fa1
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Dec 27, 2023
cc15f74
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Dec 27, 2023
10c5a60
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Jan 5, 2024
d23f6a2
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Apr 10, 2024
9210270
Merge branch 'issue_10082' of https://github.com/tangruotian/bk-ci in…
tangruotian Apr 10, 2024
bf7c00e
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Apr 11, 2024
7de444f
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Apr 11, 2024
3539a1b
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian Apr 11, 2024
1283b3f
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Apr 12, 2024
f301456
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
tangruotian Apr 28, 2024
f0c6416
feat:构建资源类型为第三方构建集群时支持指定Job并发数 #9810
tangruotian May 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ data class JobControlOption(
@get:Schema(title = "containerId与jobId映射,depend on运行时使用的是containerId", required = false)
var dependOnContainerId2JobIds: Map<String, String>? = null, // containerId与jobId映射,depend on运行时使用的是containerId
@get:Schema(title = "是否失败继续", required = false)
val continueWhenFailed: Boolean? = false // 失败继续
val continueWhenFailed: Boolean? = false, // 失败继续
@get:Schema(title = "第三方构建机集群-单节点并发限制")
val singleNodeConcurrency: Int? = null,
@get:Schema(title = "第三方构建机集群-所有节点并发限制")
val allNodeConcurrency: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ const val BK_ENV_WORKER_ERROR_IGNORE = "bkEnvWorkerErrorIgnore" // 构建机环
const val AGENT_REUSE_MUTEX_REDISPATCH = "agentReuseMuteXRedispatch" // 构建机复用互斥,节点 {0} 已被 {1} 构建使用,重新调度
// 构建机复用互斥,等待被依赖的节点 {0} 调度到具体节点后再进行复用调度
const val AGENT_REUSE_MUTEX_WAIT_REUSED_ENV = "agentReuseMuteXWaitReusedEnv"
const val BK_THIRD_JOB_ENV_CURR = "bkThirdJobEnvCurr" // 当前环境下所有构建机并发{0}已经超过配置的{1},排队{2}分钟
const val BK_THIRD_JOB_NODE_CURR = "bkThirdJobNodeCurr" // 当前环境下所有节点运行任务都超过了配置的{0},排队{1}分钟
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ class DockerVMListener @Autowired constructor(
containerHashId = containerHashId,
customBuildEnv = customBuildEnv,
dockerRoutingType = dockerRoutingType.name,
jobId = null
jobId = null,
singleNodeConcurrency = null,
allNodeConcurrency = null
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.tencent.devops.model.dispatch.tables.records.TDispatchThirdpartyAgent
import org.jooq.DSLContext
import org.jooq.JSON
import org.jooq.Result
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.time.LocalDateTime

Expand Down Expand Up @@ -77,7 +78,8 @@ class ThirdPartyAgentBuildDao {
executeCount: Int?,
containerHashId: String?,
envId: Long?,
ignoreEnvAgentIds: Set<String>?
ignoreEnvAgentIds: Set<String>?,
jobId: String?
): Int {
with(TDispatchThirdpartyAgentBuild.T_DISPATCH_THIRDPARTY_AGENT_BUILD) {
val now = LocalDateTime.now()
Expand Down Expand Up @@ -112,6 +114,7 @@ class ThirdPartyAgentBuildDao {
.set(CONTAINER_HASH_ID, containerHashId)
.set(ENV_ID, envId)
.set(IGNORE_ENV_AGENT_IDS, ignoreEnvAgentIdsJson)
.set(JOB_ID, jobId)
.where(ID.eq(preRecord.id)).execute()
}
return dslContext.insertInto(
Expand All @@ -134,7 +137,8 @@ class ThirdPartyAgentBuildDao {
EXECUTE_COUNT,
CONTAINER_HASH_ID,
ENV_ID,
IGNORE_ENV_AGENT_IDS
IGNORE_ENV_AGENT_IDS,
JOB_ID
).values(
projectId,
agentId,
Expand All @@ -158,7 +162,8 @@ class ThirdPartyAgentBuildDao {
executeCount,
containerHashId,
envId,
ignoreEnvAgentIdsJson
ignoreEnvAgentIdsJson,
jobId
).execute()
}
}
Expand Down Expand Up @@ -335,4 +340,47 @@ class ThirdPartyAgentBuildDao {
.fetchAny()
}
}

fun countProjectJobRunningAndQueueAll(
dslContext: DSLContext,
pipelineId: String,
envId: Long,
jobId: String,
projectId: String
): Long {
with(TDispatchThirdpartyAgentBuild.T_DISPATCH_THIRDPARTY_AGENT_BUILD) {
return dslContext.selectCount().from(this)
.where(PROJECT_ID.eq(projectId))
.and(PIPELINE_ID.eq(pipelineId))
.and(JOB_ID.eq(jobId))
.and(ENV_ID.eq(envId))
.and(STATUS.`in`(PipelineTaskStatus.RUNNING.status, PipelineTaskStatus.QUEUE.status))
.fetchOne(0, Long::class.java)!!
}
}

fun countAgentsJobRunningAndQueueAll(
dslContext: DSLContext,
projectId: String,
pipelineId: String,
envId: Long,
jobId: String,
agentIds: Set<String>
): Map<String, Int> {
with(TDispatchThirdpartyAgentBuild.T_DISPATCH_THIRDPARTY_AGENT_BUILD) {
return dslContext.select(
AGENT_ID, DSL.count().`as`("COUNT")
).from(this.forceIndex("IDX_AGENTID_STATUS_UPDATE"))
.where(AGENT_ID.`in`(agentIds))
.and(STATUS.`in`(PipelineTaskStatus.RUNNING.status, PipelineTaskStatus.QUEUE.status))
.and(PROJECT_ID.eq(projectId))
.and(PIPELINE_ID.eq(pipelineId))
.and(JOB_ID.eq(jobId))
.and(ENV_ID.eq(envId))
.groupBy(AGENT_ID)
.fetch().map {
it[AGENT_ID] to (it["COUNT"] as Int)
}.toMap()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ enum class ErrorCodeEnum(
ErrorType.USER,
2103022,
"构建机复用互斥,未找到Job: {0}对应的构建节点"
),
GET_BUILD_RESOURCE_ERROR(
ErrorType.USER,
2103023,
"获取构建资源超时"
);

fun getErrorMessage(params: Array<String>? = null, language: String? = null): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class ThirdPartyAgentService @Autowired constructor(
retryCount: Int = 0,
dockerInfo: ThirdPartyAgentDockerInfoDispatch?,
envId: Long?,
ignoreEnvAgentIds: Set<String>?
ignoreEnvAgentIds: Set<String>?,
jobId: String?
) {
with(dispatchMessage.event) {
try {
Expand All @@ -120,7 +121,8 @@ class ThirdPartyAgentService @Autowired constructor(
executeCount = executeCount,
containerHashId = containerHashId,
envId = envId,
ignoreEnvAgentIds = ignoreEnvAgentIds
ignoreEnvAgentIds = ignoreEnvAgentIds,
jobId = jobId
)
} catch (e: DeadlockLoserDataAccessException) {
logger.warn("Fail to add the third party agent build of ($buildId|$vmSeqId|${agent.agentId}")
Expand All @@ -132,7 +134,8 @@ class ThirdPartyAgentService @Autowired constructor(
retryCount = retryCount + 1,
dockerInfo = dockerInfo,
envId = envId,
ignoreEnvAgentIds = ignoreEnvAgentIds
ignoreEnvAgentIds = ignoreEnvAgentIds,
jobId = jobId
)
} else {
throw OperationException("Fail to add the third party agent build")
Expand Down Expand Up @@ -706,6 +709,38 @@ class ThirdPartyAgentService @Autowired constructor(
}
}

fun countProjectJobRunningAndQueueAll(
pipelineId: String,
envId: Long,
jobId: String,
projectId: String
): Long {
return thirdPartyAgentBuildDao.countProjectJobRunningAndQueueAll(
dslContext = dslContext,
pipelineId = pipelineId,
envId = envId,
jobId = jobId,
projectId = projectId
)
}

fun countAgentsJobRunningAndQueueAll(
projectId: String,
pipelineId: String,
envId: Long,
jobId: String,
agentIds: Set<String>
): Map<String, Int> {
return thirdPartyAgentBuildDao.countAgentsJobRunningAndQueueAll(
dslContext = dslContext,
pipelineId = pipelineId,
envId = envId,
jobId = jobId,
agentIds = agentIds,
projectId = projectId
)
}

companion object {
private val logger = LoggerFactory.getLogger(ThirdPartyAgentService::class.java)

Expand Down
Loading
Loading