From 79d42c19ea4f452057b14df3c186e0b2482bfc37 Mon Sep 17 00:00:00 2001 From: sawyersong Date: Thu, 28 Mar 2024 15:24:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat=EF=BC=9ADocker=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=9C=BA=E6=94=AF=E6=8C=81=E6=8B=93=E5=B1=95=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=20#10162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...uration.kt => BuildLessMQConfiguration.kt} | 46 +++++----- .../config/DispatchDockerBeanConfiguration.kt | 11 ++- ...ntLessListener.kt => BuildLessListener.kt} | 4 +- .../service/DockerResourceOptionsService.kt | 4 +- ...Service.kt => ExtDockerResourceService.kt} | 18 +++- ...mpl.kt => ExtDockerResourceServiceImpl.kt} | 14 ++- .../docker/service/StoreImageService.kt | 89 ------------------- .../{ => debug/impl}/ExtDebugServiceImpl.kt | 2 +- 8 files changed, 62 insertions(+), 126 deletions(-) rename src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/{AgentLessMQConfiguration.kt => BuildLessMQConfiguration.kt} (75%) rename src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/{AgentLessListener.kt => BuildLessListener.kt} (98%) rename src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/{ExtDockerResourceOptionsService.kt => ExtDockerResourceService.kt} (73%) rename src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/{ExtDockerResourceOptionsServiceImpl.kt => ExtDockerResourceServiceImpl.kt} (79%) delete mode 100644 src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/StoreImageService.kt rename src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/{ => debug/impl}/ExtDebugServiceImpl.kt (97%) diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/AgentLessMQConfiguration.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/BuildLessMQConfiguration.kt similarity index 75% rename from src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/AgentLessMQConfiguration.kt rename to src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/BuildLessMQConfiguration.kt index dfcf159a247..b54ff47f169 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/AgentLessMQConfiguration.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/BuildLessMQConfiguration.kt @@ -30,7 +30,7 @@ package com.tencent.devops.dispatch.docker.config import com.fasterxml.jackson.databind.ObjectMapper import com.tencent.devops.common.event.dispatcher.pipeline.mq.MQ import com.tencent.devops.common.event.dispatcher.pipeline.mq.Tools -import com.tencent.devops.dispatch.docker.listener.AgentLessListener +import com.tencent.devops.dispatch.docker.listener.BuildLessListener import org.springframework.amqp.core.Binding import org.springframework.amqp.core.BindingBuilder import org.springframework.amqp.core.DirectExchange @@ -45,7 +45,7 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration -class AgentLessMQConfiguration @Autowired constructor() { +class BuildLessMQConfiguration @Autowired constructor() { @Bean fun rabbitAdmin(connectionFactory: ConnectionFactory): RabbitAdmin { @@ -59,37 +59,37 @@ class AgentLessMQConfiguration @Autowired constructor() { * 构建无编译构建机启动交换机 */ @Bean - fun agentLessDispatchExchange(): DirectExchange { + fun buildLessDispatchExchange(): DirectExchange { val directExchange = DirectExchange(MQ.EXCHANGE_BUILD_LESS_AGENT_LISTENER_DIRECT, true, false) directExchange.isDelayed = true return directExchange } @Bean - fun agentLessDispatchStartQueue() = Queue(MQ.QUEUE_BUILD_LESS_AGENT_STARTUP_DISPATCH) + fun buildLessDispatchStartQueue() = Queue(MQ.QUEUE_BUILD_LESS_AGENT_STARTUP_DISPATCH) @Bean - fun agentLessDispatchStartQueueBind( - @Autowired agentLessDispatchStartQueue: Queue, - @Autowired agentLessDispatchExchange: DirectExchange + fun buildLessDispatchStartQueueBind( + @Autowired buildLessDispatchStartQueue: Queue, + @Autowired buildLessDispatchExchange: DirectExchange ): Binding { - return BindingBuilder.bind(agentLessDispatchStartQueue).to(agentLessDispatchExchange) + return BindingBuilder.bind(buildLessDispatchStartQueue).to(buildLessDispatchExchange) .with(MQ.ROUTE_BUILD_LESS_AGENT_STARTUP_DISPATCH) } @Bean - fun agentLessDispatchStartListenerContainer( + fun buildLessDispatchStartListenerContainer( @Autowired connectionFactory: ConnectionFactory, - @Autowired agentLessDispatchStartQueue: Queue, + @Autowired buildLessDispatchStartQueue: Queue, @Autowired rabbitAdmin: RabbitAdmin, - @Autowired agentLessListener: AgentLessListener, + @Autowired buildLessListener: BuildLessListener, @Autowired messageConverter: Jackson2JsonMessageConverter ): SimpleMessageListenerContainer { - val adapter = MessageListenerAdapter(agentLessListener, agentLessListener::listenAgentStartUpEvent.name) + val adapter = MessageListenerAdapter(buildLessListener, buildLessListener::listenAgentStartUpEvent.name) adapter.setMessageConverter(messageConverter) return Tools.createSimpleMessageListenerContainerByAdapter( connectionFactory = connectionFactory, - queue = agentLessDispatchStartQueue, + queue = buildLessDispatchStartQueue, rabbitAdmin = rabbitAdmin, startConsumerMinInterval = 10000, consecutiveActiveTrigger = 5, @@ -101,30 +101,30 @@ class AgentLessMQConfiguration @Autowired constructor() { } @Bean - fun agentLessDispatchShutdownQueue() = Queue(MQ.QUEUE_BUILD_LESS_AGENT_SHUTDOWN_DISPATCH) + fun buildLessDispatchShutdownQueue() = Queue(MQ.QUEUE_BUILD_LESS_AGENT_SHUTDOWN_DISPATCH) @Bean - fun agentLessDispatchShutdownQueueBind( - @Autowired agentLessDispatchShutdownQueue: Queue, - @Autowired agentLessDispatchExchange: DirectExchange + fun buildLessDispatchShutdownQueueBind( + @Autowired buildLessDispatchShutdownQueue: Queue, + @Autowired buildLessDispatchExchange: DirectExchange ): Binding { - return BindingBuilder.bind(agentLessDispatchShutdownQueue).to(agentLessDispatchExchange) + return BindingBuilder.bind(buildLessDispatchShutdownQueue).to(buildLessDispatchExchange) .with(MQ.ROUTE_BUILD_LESS_AGENT_SHUTDOWN_DISPATCH) } @Bean - fun agentLessDispatchShutdownListenerContainer( + fun buildLessDispatchShutdownListenerContainer( @Autowired connectionFactory: ConnectionFactory, - @Autowired agentLessDispatchShutdownQueue: Queue, + @Autowired buildLessDispatchShutdownQueue: Queue, @Autowired rabbitAdmin: RabbitAdmin, - @Autowired agentLessListener: AgentLessListener, + @Autowired buildLessListener: BuildLessListener, @Autowired messageConverter: Jackson2JsonMessageConverter ): SimpleMessageListenerContainer { - val adapter = MessageListenerAdapter(agentLessListener, agentLessListener::listenAgentShutdownEvent.name) + val adapter = MessageListenerAdapter(buildLessListener, buildLessListener::listenAgentShutdownEvent.name) adapter.setMessageConverter(messageConverter) return Tools.createSimpleMessageListenerContainerByAdapter( connectionFactory = connectionFactory, - queue = agentLessDispatchShutdownQueue, + queue = buildLessDispatchShutdownQueue, rabbitAdmin = rabbitAdmin, startConsumerMinInterval = 10000, consecutiveActiveTrigger = 5, diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/DispatchDockerBeanConfiguration.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/DispatchDockerBeanConfiguration.kt index 48e236c22ab..f2ea523356b 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/DispatchDockerBeanConfiguration.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/config/DispatchDockerBeanConfiguration.kt @@ -30,9 +30,9 @@ package com.tencent.devops.dispatch.docker.config import com.tencent.devops.dispatch.docker.dao.PipelineDockerIPInfoDao import com.tencent.devops.dispatch.docker.service.DockerHostProxyService import com.tencent.devops.dispatch.docker.service.DockerHostProxyServiceImpl -import com.tencent.devops.dispatch.docker.service.ExtDebugServiceImpl -import com.tencent.devops.dispatch.docker.service.ExtDockerResourceOptionsService -import com.tencent.devops.dispatch.docker.service.ExtDockerResourceOptionsServiceImpl +import com.tencent.devops.dispatch.docker.service.debug.impl.ExtDebugServiceImpl +import com.tencent.devops.dispatch.docker.service.ExtDockerResourceService +import com.tencent.devops.dispatch.docker.service.ExtDockerResourceServiceImpl import com.tencent.devops.dispatch.docker.service.debug.ExtDebugService import org.jooq.DSLContext import org.springframework.beans.factory.annotation.Autowired @@ -44,7 +44,6 @@ import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.DependsOn import org.springframework.core.Ordered -@Suppress("ALL") @Configuration @ConditionalOnWebApplication @DependsOn(value = ["jooqConfiguration"]) @@ -64,6 +63,6 @@ class DispatchDockerBeanConfiguration @Autowired constructor( fun extDebugService() = ExtDebugServiceImpl() @Bean - @ConditionalOnMissingBean(ExtDockerResourceOptionsService::class) - fun extDockerResourceOptionsService() = ExtDockerResourceOptionsServiceImpl() + @ConditionalOnMissingBean(ExtDockerResourceService::class) + fun extDockerResourceService() = ExtDockerResourceServiceImpl() } diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/AgentLessListener.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/BuildLessListener.kt similarity index 98% rename from src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/AgentLessListener.kt rename to src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/BuildLessListener.kt index 69fe42eabf5..efe1ceeeb33 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/AgentLessListener.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/BuildLessListener.kt @@ -51,7 +51,7 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component @Component -class AgentLessListener @Autowired constructor( +class BuildLessListener @Autowired constructor( private val client: Client, private val buildLogPrinter: BuildLogPrinter, private val jobQuotaService: JobQuotaService, @@ -173,6 +173,6 @@ class AgentLessListener @Autowired constructor( } companion object { - private val logger = LoggerFactory.getLogger(AgentLessListener::class.java) + private val logger = LoggerFactory.getLogger(BuildLessListener::class.java) } } diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/DockerResourceOptionsService.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/DockerResourceOptionsService.kt index 6bcef822ae9..042b1ecf16e 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/DockerResourceOptionsService.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/DockerResourceOptionsService.kt @@ -48,7 +48,7 @@ class DockerResourceOptionsService constructor( private val dockerResourceOptionsDao: DockerResourceOptionsDao, private val pipelineDockerTaskSimpleDao: PipelineDockerTaskSimpleDao, private val dockerResourceWhitelistService: DockerResourceWhitelistService, - private val extDockerResourceOptionsService: ExtDockerResourceOptionsService + private val extDockerResourceService: ExtDockerResourceService ) { private val logger = LoggerFactory.getLogger(DockerResourceOptionsService::class.java) @@ -174,7 +174,7 @@ class DockerResourceOptionsService constructor( getDockerResourceOptions(projectId) } else -> { - extDockerResourceOptionsService.getDockerResourceConfigList( + extDockerResourceService.getDockerResourceConfigList( userId, projectId, buildType ?: BuildType.DOCKER.name ) ?: UserDockerResourceOptionsVO( default = "", diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsService.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceService.kt similarity index 73% rename from src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsService.kt rename to src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceService.kt index 97e6f585f48..5302e4774ce 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsService.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceService.kt @@ -27,8 +27,22 @@ package com.tencent.devops.dispatch.docker.service +import com.tencent.devops.common.dispatch.sdk.pojo.docker.DockerRoutingType +import com.tencent.devops.dispatch.docker.pojo.Pool import com.tencent.devops.dispatch.docker.pojo.resource.UserDockerResourceOptionsVO +import com.tencent.devops.process.pojo.mq.PipelineAgentStartupEvent -interface ExtDockerResourceOptionsService { - fun getDockerResourceConfigList(userId: String, projectId: String, buildType: String): UserDockerResourceOptionsVO? +interface ExtDockerResourceService { + fun getDockerResourceConfigList( + userId: String, + projectId: String, + buildType: String + ): UserDockerResourceOptionsVO? + + fun startExtDocker( + event: PipelineAgentStartupEvent, + containerPool: Pool, + dockerRoutingType: DockerRoutingType = DockerRoutingType.VM, + demoteFlag: Boolean = false + ) } diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsServiceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceServiceImpl.kt similarity index 79% rename from src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsServiceImpl.kt rename to src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceServiceImpl.kt index 2aff9c2612a..b9855fd4a2a 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceOptionsServiceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDockerResourceServiceImpl.kt @@ -27,9 +27,12 @@ package com.tencent.devops.dispatch.docker.service +import com.tencent.devops.common.dispatch.sdk.pojo.docker.DockerRoutingType +import com.tencent.devops.dispatch.docker.pojo.Pool import com.tencent.devops.dispatch.docker.pojo.resource.UserDockerResourceOptionsVO +import com.tencent.devops.process.pojo.mq.PipelineAgentStartupEvent -class ExtDockerResourceOptionsServiceImpl : ExtDockerResourceOptionsService { +class ExtDockerResourceServiceImpl : ExtDockerResourceService { override fun getDockerResourceConfigList( userId: String, @@ -38,4 +41,13 @@ class ExtDockerResourceOptionsServiceImpl : ExtDockerResourceOptionsService { ): UserDockerResourceOptionsVO? { return null } + + override fun startExtDocker( + event: PipelineAgentStartupEvent, + containerPool: Pool, + dockerRoutingType: DockerRoutingType, + demoteFlag: Boolean + ) { + return + } } diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/StoreImageService.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/StoreImageService.kt deleted file mode 100644 index 35f6353be1b..00000000000 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/StoreImageService.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. - * - * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. - * - * A copy of the MIT License is included in this file. - * - * - * Terms of the MIT License: - * --------------------------------------------------- - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of - * the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT - * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package com.tencent.devops.dispatch.docker.service - -import com.tencent.devops.common.api.exception.InvalidParamException -import com.tencent.devops.common.client.Client -import com.tencent.devops.dispatch.docker.common.ErrorCodeEnum -import com.tencent.devops.store.api.image.ServiceStoreImageResource -import com.tencent.devops.store.pojo.image.exception.ImageNotInstalledException -import com.tencent.devops.store.pojo.image.response.ImageRepoInfo -import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Service - -/** - * @Description - * @Date 2019/10/17 - * @Version 1.0 - */ - -@Service -class StoreImageService @Autowired constructor( - private val client: Client -) { - - companion object { - private val logger = LoggerFactory.getLogger(StoreImageService::class.java) - } - - // 从镜像商店获取完整的镜像名称 - fun getImageRepoInfo( - userId: String, - projectId: String, - pipelineId: String?, - buildId: String?, - imageCode: String?, - imageVersion: String?, - defaultPrefix: String? - ): ImageRepoInfo { - logger.info("getImageRepoInfo:Input($userId,$projectId,$imageCode,$imageVersion)") - // 鉴权:安装了才有权限使用 - if (null == imageCode) { - throw InvalidParamException("Input:($userId,$projectId,$imageCode),imageCode is null") - } - val permissionResult = client.get(ServiceStoreImageResource::class).isInstalled(userId, projectId, imageCode) - if (permissionResult.isNotOk() || (!permissionResult.data!!)) { - throw ImageNotInstalledException( - "Input:($userId,$projectId,$imageCode)", - "${ErrorCodeEnum.USER_IMAGE_NOT_INSTALLED.errorCode}" - ) - } - // 调商店接口获取镜像信息 - val result = client.get(ServiceStoreImageResource::class) - .getImageRepoInfoByCodeAndVersion( - userId = userId, - projectCode = projectId, - imageCode = imageCode, - imageVersion = imageVersion, - pipelineId = pipelineId, - buildId = buildId - ) - return result.data!! - } -} diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDebugServiceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/debug/impl/ExtDebugServiceImpl.kt similarity index 97% rename from src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDebugServiceImpl.kt rename to src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/debug/impl/ExtDebugServiceImpl.kt index 3442e08b8d9..9a2fab37edc 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/ExtDebugServiceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/service/debug/impl/ExtDebugServiceImpl.kt @@ -25,7 +25,7 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.tencent.devops.dispatch.docker.service +package com.tencent.devops.dispatch.docker.service.debug.impl import com.tencent.devops.dispatch.docker.service.debug.ExtDebugService From 6df514161f766d7771faa633a68b0187b2d0e144 Mon Sep 17 00:00:00 2001 From: sawyersong Date: Thu, 28 Mar 2024 16:46:11 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat=EF=BC=9ADocker=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=9C=BA=E6=94=AF=E6=8C=81=E6=8B=93=E5=B1=95=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=20#10162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docker/listener/DockerVMListener.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/DockerVMListener.kt b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/DockerVMListener.kt index 7dc7c6213f9..36673882bd9 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/DockerVMListener.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch-docker/src/main/kotlin/com/tencent/devops/dispatch/docker/listener/DockerVMListener.kt @@ -52,6 +52,7 @@ import com.tencent.devops.dispatch.docker.exception.DockerServiceException import com.tencent.devops.dispatch.docker.pojo.Credential import com.tencent.devops.dispatch.docker.pojo.Pool import com.tencent.devops.dispatch.docker.service.DockerHostBuildService +import com.tencent.devops.dispatch.docker.service.ExtDockerResourceService import com.tencent.devops.dispatch.docker.utils.DispatchDockerCommonUtils import com.tencent.devops.dispatch.docker.utils.DockerHostUtils import com.tencent.devops.dispatch.pojo.enums.JobQuotaVmType @@ -79,6 +80,7 @@ class DockerVMListener @Autowired constructor( private val pipelineDockerHostDao: PipelineDockerHostDao, private val pipelineDockerBuildDao: PipelineDockerBuildDao, private val dockerRoutingSdkService: DockerRoutingSdkService, + private val extDockerResourceService: ExtDockerResourceService, private val pipelineEventDispatcher: PipelineEventDispatcher ) : BuildListener { @@ -176,11 +178,16 @@ class DockerVMListener @Autowired constructor( imageType = dispatchType.imageType?.type ) - val dockerRoutingType = dockerRoutingSdkService.getDockerRoutingType(event.projectId) - if (dockerRoutingType == DockerRoutingType.VM) { - startup(dispatchMessage, containerPool) - } else { - startKubernetesDocker(dispatchMessage, containerPool, dockerRoutingType, demoteFlag) + when (val dockerRoutingType = dockerRoutingSdkService.getDockerRoutingType(event.projectId)) { + DockerRoutingType.VM -> { + startup(dispatchMessage, containerPool) + } + DockerRoutingType.DEVCLOUD -> { + extDockerResourceService.startExtDocker(dispatchMessage.event, containerPool, dockerRoutingType, demoteFlag) + } + else -> { + startKubernetesDocker(dispatchMessage, containerPool, dockerRoutingType, demoteFlag) + } } } From 65f29acc821905fa8f6c095c59e85a6055e1e84e Mon Sep 17 00:00:00 2001 From: sawyersong Date: Wed, 10 Apr 2024 17:36:02 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat=EF=BC=9ADocker=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=9C=BA=E6=94=AF=E6=8C=81=E6=8B=93=E5=B1=95=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=20#10162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devops/dispatch/api/OpJobQuotaProjectResource.kt | 7 +++++-- .../dispatch/controller/OpJobQuotaProjectResourceImpl.kt | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/OpJobQuotaProjectResource.kt b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/OpJobQuotaProjectResource.kt index 7eccc0a71a8..2345445252f 100644 --- a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/OpJobQuotaProjectResource.kt +++ b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/OpJobQuotaProjectResource.kt @@ -115,16 +115,19 @@ interface OpJobQuotaProjectResource { jobQuota: JobQuotaProject ): Result - @Operation(summary = "清零项目的当月已运行时间") + @Operation(summary = "清零异常的构建配额记录") @POST @Path("/project/{projectId}/vm/{vmType}") - fun restore( + fun restoreProjectRunningJobs( @Parameter(description = "项目ID", required = true) @PathParam("projectId") projectId: String, @Parameter(description = "构建机类型", required = true) @PathParam("vmType") vmType: JobQuotaVmType, + @Parameter(description = "构建时间", required = true) + @QueryParam("createTime") + createTime: String, @Parameter(description = "构建来源", required = false) @QueryParam("channelCode") channelCode: String = ChannelCode.BS.name diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt index 5aa28b517cd..0b0ca4dbbb3 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt @@ -65,7 +65,12 @@ class OpJobQuotaProjectResourceImpl @Autowired constructor( return Result(jobQuotaManagerService.updateProjectQuota(projectId, vmType, jobQuota)) } - override fun restore(projectId: String, vmType: JobQuotaVmType, channelCode: String): Result { + override fun restoreProjectRunningJobs( + projectId: String, + vmType: JobQuotaVmType, + createTime: String, + channelCode: String + ): Result { jobQuotaRedisUtils.restoreProjectJobTime(projectId, vmType, channelCode) return Result(true) } From 6282aa253237c23d6df4767dadbed374b42e0fe5 Mon Sep 17 00:00:00 2001 From: sawyersong Date: Tue, 16 Apr 2024 15:24:32 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat=EF=BC=9ADocker=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=9C=BA=E6=94=AF=E6=8C=81=E6=8B=93=E5=B1=95=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=20#10162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpJobQuotaProjectResourceImpl.kt | 2 +- .../devops/dispatch/dao/RunningJobsDao.kt | 17 +++++++++++++ .../jobquota/JobQuotaManagerService.kt | 25 +++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt index 0b0ca4dbbb3..3504ff83b90 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/OpJobQuotaProjectResourceImpl.kt @@ -71,7 +71,7 @@ class OpJobQuotaProjectResourceImpl @Autowired constructor( createTime: String, channelCode: String ): Result { - jobQuotaRedisUtils.restoreProjectJobTime(projectId, vmType, channelCode) + jobQuotaManagerService.clearRunningJobs(projectId, vmType, createTime, channelCode) return Result(true) } } diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/dao/RunningJobsDao.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/dao/RunningJobsDao.kt index ce184abc3da..790d5ff5450 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/dao/RunningJobsDao.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/dao/RunningJobsDao.kt @@ -211,6 +211,23 @@ class RunningJobsDao { } } + fun clearRunningJobs( + dslContext: DSLContext, + projectId: String, + vmType: JobQuotaVmType, + channelCode: String, + createTime: LocalDateTime + ) { + with(TDispatchRunningJobs.T_DISPATCH_RUNNING_JOBS) { + dslContext.deleteFrom(this) + .where(PROJECT_ID.eq(projectId)) + .and(VM_TYPE.eq(vmType.name)) + .and(CHANNEL_CODE.eq(channelCode)) + .and(CREATED_TIME.lessOrEqual(createTime)) + .execute() + } + } + fun getProject(dslContext: DSLContext): Result>? { with(TDispatchRunningJobs.T_DISPATCH_RUNNING_JOBS) { return dslContext.selectDistinct(PROJECT_ID).from(this).fetch() diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/jobquota/JobQuotaManagerService.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/jobquota/JobQuotaManagerService.kt index feceb210774..64f6f936bfe 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/jobquota/JobQuotaManagerService.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/jobquota/JobQuotaManagerService.kt @@ -31,6 +31,7 @@ import com.tencent.devops.common.api.util.timestamp import com.tencent.devops.common.pipeline.enums.ChannelCode import com.tencent.devops.dispatch.dao.JobQuotaProjectDao import com.tencent.devops.dispatch.dao.JobQuotaSystemDao +import com.tencent.devops.dispatch.dao.RunningJobsDao import com.tencent.devops.dispatch.pojo.JobQuotaProject import com.tencent.devops.dispatch.pojo.JobQuotaSystem import com.tencent.devops.dispatch.pojo.enums.JobQuotaVmType @@ -38,12 +39,14 @@ import org.jooq.DSLContext import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import java.time.LocalDateTime +import java.time.format.DateTimeFormatter @Service@Suppress("ALL") class JobQuotaManagerService @Autowired constructor( - private val jobQuotaProjectDao: JobQuotaProjectDao, + private val dslContext: DSLContext, + private val runningJobsDao: RunningJobsDao, private val jobQuotaSystemDao: JobQuotaSystemDao, - private val dslContext: DSLContext + private val jobQuotaProjectDao: JobQuotaProjectDao ) { fun listProjectQuota(projectId: String?): List { val record = jobQuotaProjectDao.list(dslContext, projectId) @@ -219,4 +222,22 @@ class JobQuotaManagerService @Autowired constructor( fun updateSystemQuota(jobQuotaVmType: JobQuotaVmType, jobQuota: JobQuotaSystem): Boolean { return jobQuotaSystemDao.update(dslContext, jobQuota.channelCode, jobQuotaVmType, jobQuota) } + + /** + * 清理指定项目时间点的配额记录 + */ + fun clearRunningJobs( + projectId: String, + vmType: JobQuotaVmType, + createTime: String, + channelCode: String = ChannelCode.BS.name + ) { + runningJobsDao.clearRunningJobs( + dslContext = dslContext, + projectId = projectId, + vmType = vmType, + channelCode = channelCode, + createTime = LocalDateTime.parse(createTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME) + ) + } }