Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#10169 from sawyersong2/issue10162_…
Browse files Browse the repository at this point in the history
…github_branch

feat:Docker构建机支持拓展资源调度 TencentBlueKing#10162
  • Loading branch information
bkci-bot authored Apr 16, 2024
2 parents 9d0fb1b + 6282aa2 commit b22c87f
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ interface OpJobQuotaProjectResource {
jobQuota: JobQuotaProject
): Result<Boolean>

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])
Expand All @@ -64,6 +63,6 @@ class DispatchDockerBeanConfiguration @Autowired constructor(
fun extDebugService() = ExtDebugServiceImpl()

@Bean
@ConditionalOnMissingBean(ExtDockerResourceOptionsService::class)
fun extDockerResourceOptionsService() = ExtDockerResourceOptionsServiceImpl()
@ConditionalOnMissingBean(ExtDockerResourceService::class)
fun extDockerResourceService() = ExtDockerResourceServiceImpl()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -174,7 +174,7 @@ class DockerResourceOptionsService constructor(
getDockerResourceOptions(projectId)
}
else -> {
extDockerResourceOptionsService.getDockerResourceConfigList(
extDockerResourceService.getDockerResourceConfigList(
userId, projectId, buildType ?: BuildType.DOCKER.name
) ?: UserDockerResourceOptionsVO(
default = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,4 +41,13 @@ class ExtDockerResourceOptionsServiceImpl : ExtDockerResourceOptionsService {
): UserDockerResourceOptionsVO? {
return null
}

override fun startExtDocker(
event: PipelineAgentStartupEvent,
containerPool: Pool,
dockerRoutingType: DockerRoutingType,
demoteFlag: Boolean
) {
return
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit b22c87f

Please sign in to comment.