From 23e4931ca75fe9b5d73225887deaaa0f4bc0f9b0 Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 23 Oct 2023 21:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90PAC=E3=80=91feat=EF=BC=9A=E5=BC=80?= =?UTF-8?q?=E5=90=AFPAC=E6=A8=A1=E5=BC=8F=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=BA=93=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=BA=93YAML=E5=8F=98=E6=9B=B4=E5=88=B0?= =?UTF-8?q?=E8=93=9D=E7=9B=BE=20#8130?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trigger/CodeGitWebHookTriggerElement.kt | 3 --- .../trigger/CodeGithubWebHookTriggerElement.kt | 3 --- .../trigger/CodeGitlabWebHookTriggerElement.kt | 3 --- .../trigger/CodeP4WebHookTriggerElement.kt | 3 --- .../trigger/CodeSVNWebHookTriggerElement.kt | 3 --- .../trigger/CodeTGitWebHookTriggerElement.kt | 3 --- .../engine/service/PipelineWebhookService.kt | 15 +++++++-------- 7 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt index 9b9e53e1ab4..fd31ed72a56 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitWebHookTriggerElement.kt @@ -103,13 +103,10 @@ data class CodeGitWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeGitWebHookTrigger" - const val taskAtom = "codeGitWebhookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom(): String = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt index bf648a0ba60..3eb1827f1a0 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGithubWebHookTriggerElement.kt @@ -58,13 +58,10 @@ data class CodeGithubWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeGithubWebHookTrigger" - const val taskAtom = "codeGithubWebHookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom() = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt index 642eaceabe4..22e323e58aa 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeGitlabWebHookTriggerElement.kt @@ -81,13 +81,10 @@ data class CodeGitlabWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeGitlabWebHookTrigger" - const val taskAtom = "codeGitlabWebHookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom() = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt index 3c247a3917a..fe96c9dad04 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeP4WebHookTriggerElement.kt @@ -46,13 +46,10 @@ data class CodeP4WebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeP4WebHookTrigger" - const val taskAtom = "codeP4WebHookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom() = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt index 8206107b4c1..aeecec816f6 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeSVNWebHookTriggerElement.kt @@ -60,13 +60,10 @@ data class CodeSVNWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeSVNWebHookTrigger" - const val taskAtom = "codeSvnWebHookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom() = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt index c72220db6c1..28390e432a4 100644 --- a/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt +++ b/src/backend/ci/core/common/common-pipeline/src/main/kotlin/com/tencent/devops/common/pipeline/pojo/element/trigger/CodeTGitWebHookTriggerElement.kt @@ -47,13 +47,10 @@ data class CodeTGitWebHookTriggerElement( ) : WebHookTriggerElement(name, id, status) { companion object { const val classType = "codeTGitWebHookTrigger" - const val taskAtom = "codeTGitWebhookTriggerTaskAtom" } override fun getClassType() = classType - override fun getTaskAtom() = taskAtom - override fun findFirstTaskIdByStartType(startType: StartType): String { return if (startType.name == StartType.WEB_HOOK.name) { this.id!! diff --git a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt index 8114629f579..b7d0928f0b5 100644 --- a/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt +++ b/src/backend/ci/core/process/biz-process/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineWebhookService.kt @@ -28,7 +28,6 @@ package com.tencent.devops.process.engine.service import com.fasterxml.jackson.databind.ObjectMapper -import com.google.common.cache.CacheBuilder import com.tencent.devops.common.api.enums.RepositoryConfig import com.tencent.devops.common.api.enums.RepositoryType import com.tencent.devops.common.api.enums.ScmType @@ -79,6 +78,7 @@ import org.jooq.DSLContext import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.util.Optional import java.util.concurrent.Executors /** @@ -668,9 +668,7 @@ class PipelineWebhookService @Autowired constructor( private fun updateWebhookEventInfoTask() { var offset = 0 val limit = 1000 - val repoCache = CacheBuilder.newBuilder() - .maximumSize(1000) - .build() + val repoCache = mutableMapOf>() // 上一个更新的项目ID var preProjectId: String? = null do { @@ -682,7 +680,7 @@ class PipelineWebhookService @Autowired constructor( pipelines.forEach { (projectId, pipelineId) -> // 更改项目,清空代码库缓存 if (preProjectId != null && preProjectId != projectId) { - repoCache.cleanUp() + repoCache.clear() } preProjectId = projectId val model = getModel(projectId, pipelineId) @@ -718,8 +716,8 @@ class PipelineWebhookService @Autowired constructor( ) return@webhook } - val repository = - repoCache.get("${projectId}_${elementRepositoryConfig.getRepositoryId()}") { + val repository = repoCache.putIfAbsent( + "${projectId}_${elementRepositoryConfig.getRepositoryId()}", Optional.ofNullable( try { scmProxyService.getRepo( projectId = projectId, @@ -729,7 +727,8 @@ class PipelineWebhookService @Autowired constructor( logger.warn("fail to get repository info", ignored) null } - } + ) + )?.get() if (repository != null && webhook.projectName != repository.projectName) { logger.info( "webhook projectName different from repo projectName|" +