From b03dffccb3c90cd4e79decb5d473a0b750b1ace1 Mon Sep 17 00:00:00 2001 From: ruotiantang Date: Mon, 12 Aug 2024 19:24:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bugfix:=20Agent=E5=A4=8D=E7=94=A8=E5=90=8C?= =?UTF-8?q?=E7=BA=A7=E8=8A=82=E7=82=B9=E6=97=B6=E8=B7=B3=E8=BF=87=E4=BA=86?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E9=94=81=20#10795?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ThirdPartyDispatchService.kt | 17 ++------ .../container/impl/AgentReuseMutexCmd.kt | 43 ++++++++----------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/ThirdPartyDispatchService.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/ThirdPartyDispatchService.kt index 8659b8aeb66..5fa689af8ee 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/ThirdPartyDispatchService.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/ThirdPartyDispatchService.kt @@ -74,7 +74,6 @@ import com.tencent.devops.environment.pojo.thirdpartyagent.EnvNodeAgent import com.tencent.devops.environment.pojo.thirdpartyagent.ThirdPartyAgent import com.tencent.devops.process.api.service.ServiceBuildResource import com.tencent.devops.process.api.service.ServiceVarResource -import com.tencent.devops.process.constant.ProcessMessageCode import com.tencent.devops.process.engine.common.VMUtils import com.tencent.devops.process.pojo.SetContextVarData import com.tencent.devops.process.pojo.VmInfo @@ -435,22 +434,12 @@ class ThirdPartyDispatchService @Autowired constructor( ) }/console/pipeline/${dispatchMessage.event.projectId}/$pipelineId/detail/$lockedBuildId" if (lockedBuildId != dispatchMessage.event.buildId) { - I18nUtil.getCodeLanMessage( - messageCode = ProcessMessageCode.BK_LOCKED, - language = I18nUtil.getDefaultLocaleLanguage() - ) + ": $linkTip" + - I18nUtil.getCodeLanMessage( - messageCode = ProcessMessageCode.BK_CLICK, - language = I18nUtil.getDefaultLocaleLanguage() - ) + "" + "$linkTip$lockedBuildId" } else { - I18nUtil.getCodeLanMessage( - messageCode = ProcessMessageCode.BK_CURRENT, - language = I18nUtil.getDefaultLocaleLanguage() - ) + ": $linkTip" + linkTip } } ?: "" - log( + logWarn( dispatchMessage.event, I18nUtil.getCodeLanMessage( messageCode = AGENT_REUSE_MUTEX_REDISPATCH, diff --git a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/AgentReuseMutexCmd.kt b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/AgentReuseMutexCmd.kt index 0e17f453635..5722b45fccd 100644 --- a/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/AgentReuseMutexCmd.kt +++ b/src/backend/ci/core/process/biz-engine/src/main/kotlin/com/tencent/devops/process/engine/control/command/container/impl/AgentReuseMutexCmd.kt @@ -44,8 +44,8 @@ class AgentReuseMutexCmd @Autowired constructor( ) : ContainerCmd { override fun canExecute(commandContext: ContainerContext): Boolean { return commandContext.cmdFlowState == CmdFlowState.CONTINUE && - !commandContext.buildStatus.isFinish() && - commandContext.container.controlOption.agentReuseMutex != null + !commandContext.buildStatus.isFinish() && + commandContext.container.controlOption.agentReuseMutex != null } override fun execute(commandContext: ContainerContext) { @@ -59,22 +59,15 @@ class AgentReuseMutexCmd @Autowired constructor( * 互斥情况存在三种 * 1、依赖某个AgentId,直接往下执行即可 * 2、Root节点,即没有复用节点的节点,根据类型先拿取锁 - * 3、Reuse节点,但没有复用节点,可能是因为和复用节点同级,或存在和复用节点先后顺序不明确的, - * 这种先拿取复用的JobId看有没有,没有就按root节点的逻辑走 + * 3、Reuse节点,但没有复用节点,可能是因为和复用节点同级,或存在和复用节点先后顺序不明确的,就按root节点的逻辑走 */ private fun doExecute(commandContext: ContainerContext) { var mutex = commandContext.container.controlOption.agentReuseMutex!! + // 复用的不用参与锁逻辑 if (!mutex.type.needEngineLock()) { commandContext.cmdFlowState = CmdFlowState.CONTINUE return } - // 如果有依赖Job且不是依赖类型的可以先拿一下上下文看看有没有已经写入了,如果写入了可以直接跳过 - if (mutex.reUseJobId != null && - commandContext.variables.containsKey(AgentReuseMutex.genAgentContextKey(mutex.reUseJobId!!)) - ) { - commandContext.cmdFlowState = CmdFlowState.CONTINUE - return - } // 极端情况上下文没有写入,且agentId还是空,理论上不会有,逻辑上出现了就失败 if (mutex.agentOrEnvId.isNullOrBlank()) { return agentIdNullError(commandContext, mutex, null) @@ -85,7 +78,7 @@ class AgentReuseMutexCmd @Autowired constructor( AgentReuseMutexType.AGENT_ID, AgentReuseMutexType.AGENT_NAME -> { acquireMutex(commandContext, mutex) } - + // 环境的因为无法确定节点不参与锁 else -> { commandContext.cmdFlowState = CmdFlowState.CONTINUE } @@ -165,8 +158,10 @@ class AgentReuseMutexCmd @Autowired constructor( commandContext.cmdFlowState = CmdFlowState.LOOP } - else -> { // 正常运行 - commandContext.cmdFlowState = CmdFlowState.CONTINUE // 检查通过,继续向下执行 + // 正常运行 + else -> { + // 检查通过,继续向下执行 + commandContext.cmdFlowState = CmdFlowState.CONTINUE } } } else if (commandContext.container.status.isFinish()) { // 对于存在重放的结束消息做闭环 @@ -174,7 +169,7 @@ class AgentReuseMutexCmd @Autowired constructor( LOG.info( "AGENT_REUSE|ENGINE|${event.buildId}|${event.source}|status=${commandContext.container.status}" + - "|concurrent_container_event" + "|concurrent_container_event" ) releaseContainerMutex( @@ -310,7 +305,7 @@ class AgentReuseMutexCmd @Autowired constructor( containerVar = emptyMap(), buildStatus = null, timestamps = mapOf( BuildTimestampType.JOB_AGENT_REUSE_MUTEX_QUEUE to - BuildRecordTimeStamp(null, LocalDateTime.now().timestampmilli()) + BuildRecordTimeStamp(null, LocalDateTime.now().timestampmilli()) ) ) } @@ -347,9 +342,9 @@ class AgentReuseMutexCmd @Autowired constructor( // 排队等待时间为0的时候,立即超时, 退出队列,并失败, 没有就继续在队列中,timeOut时间为分钟 if (mutex.timeout == 0 || timeDiff > TimeUnit.MINUTES.toSeconds(mutex.timeout.toLong())) { val desc = "${ - if (mutex.timeoutVar.isNullOrBlank()) { - "[${mutex.timeout} minutes]" - } else " timeoutVar[${mutex.timeoutVar}] setup to [${mutex.timeout} minutes]" + if (mutex.timeoutVar.isNullOrBlank()) { + "[${mutex.timeout} minutes]" + } else " timeoutVar[${mutex.timeoutVar}] setup to [${mutex.timeout} minutes]" } " logAgentMutex( container, mutex, lockedBuildId, @@ -443,7 +438,7 @@ class AgentReuseMutexCmd @Autowired constructor( containerVar = emptyMap(), buildStatus = null, timestamps = mapOf( BuildTimestampType.JOB_MUTEX_QUEUE to - BuildRecordTimeStamp(LocalDateTime.now().timestampmilli(), null) + BuildRecordTimeStamp(LocalDateTime.now().timestampmilli(), null) ) ) } @@ -514,10 +509,10 @@ class AgentReuseMutexCmd @Autowired constructor( messageCode = ProcessMessageCode.BK_LOCKED, language = I18nUtil.getDefaultLocaleLanguage() ) + ": $linkTip" + - I18nUtil.getCodeLanMessage( - messageCode = ProcessMessageCode.BK_CLICK, - language = I18nUtil.getDefaultLocaleLanguage() - ) + " | $msg" + I18nUtil.getCodeLanMessage( + messageCode = ProcessMessageCode.BK_CLICK, + language = I18nUtil.getDefaultLocaleLanguage() + ) + " | $msg" } else { I18nUtil.getCodeLanMessage( messageCode = ProcessMessageCode.BK_CURRENT, From 072389a3e67e78c53b8aeab1597122df3d010853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?yongyiduan=28=E6=AE=B5=E6=B0=B8=E5=84=84=29?= Date: Mon, 12 Aug 2024 19:58:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat=EF=BC=9A=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=AE=A1=E7=90=86=E6=9C=BA=E5=88=B6=20#8161?= =?UTF-8?q?=20=E5=B8=A6=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/schema/V3_0/ci.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/ci/core/common/common-pipeline-yaml/src/main/resources/schema/V3_0/ci.json b/src/backend/ci/core/common/common-pipeline-yaml/src/main/resources/schema/V3_0/ci.json index cac3c239d04..e38f1675aac 100644 --- a/src/backend/ci/core/common/common-pipeline-yaml/src/main/resources/schema/V3_0/ci.json +++ b/src/backend/ci/core/common/common-pipeline-yaml/src/main/resources/schema/V3_0/ci.json @@ -255,6 +255,9 @@ "type" : "string" } } + }, + "skip-wip" : { + "type" : "boolean" } } } ] @@ -943,6 +946,9 @@ "type" : "string" } } + }, + "skip-wip" : { + "type" : "boolean" } } } ] @@ -2226,6 +2232,12 @@ "type" : "string" } }, + "chat-id" : { + "type" : "array", + "items" : { + "type" : "string" + } + }, "notify-groups" : { "type" : "array", "items" : {