From 497c199157145ed2dfbadeae099b170f9cfa80f2 Mon Sep 17 00:00:00 2001 From: sawyersong2 Date: Fri, 15 Oct 2021 12:25:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=81=E6=B0=B4=E7=BA=BFJob=E9=85=8D?= =?UTF-8?q?=E9=A2=9D=E7=AE=A1=E7=90=86=20#5154?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dispatch.sdk/listener/BuildListener.kt | 8 +++- .../dispatch.sdk/service/JobQuotaService.kt | 9 ++++- .../api/BuildJobQuotaBusinessResource.kt | 39 ++++++++++++------- .../api/ServiceJobQuotaBusinessResource.kt | 5 ++- .../BuildJobQuotaBusinessResourceImpl.kt | 6 ++- .../ServiceJobQuotaBusinessResourceImpl.kt | 3 +- .../devops/dispatch/pojo/JobQuotaHistory.kt | 1 + .../service/JobQuotaBusinessService.kt | 9 ++++- 8 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/listener/BuildListener.kt b/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/listener/BuildListener.kt index d4cde8a4f89..185e2e860b0 100644 --- a/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/listener/BuildListener.kt +++ b/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/listener/BuildListener.kt @@ -110,7 +110,13 @@ interface BuildListener { logger.warn("Fail to handle the shutdown message - ($event)", t) } finally { val jobQuotaService = getJobQuotaService() - jobQuotaService.removeRunningJob(event.projectId, event.buildId, event.vmSeqId, event.executeCount) + jobQuotaService.removeRunningJob( + projectId = event.projectId, + pipelineId = event.pipelineId, + buildId = event.buildId, + vmSeqId = event.vmSeqId, + executeCount = event.executeCount + ) } } diff --git a/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/service/JobQuotaService.kt b/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/service/JobQuotaService.kt index e7e633f4d70..d1b338c7f9b 100644 --- a/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/service/JobQuotaService.kt +++ b/src/backend/ci/core/common/common-dispatch-sdk/src/main/kotlin/com/tencent/devops/common/dispatch.sdk/service/JobQuotaService.kt @@ -142,12 +142,19 @@ class JobQuotaService constructor( } } - fun removeRunningJob(projectId: String, buildId: String, vmSeqId: String?, executeCount: Int?) { + fun removeRunningJob( + projectId: String, + pipelineId: String, + buildId: String, + vmSeqId: String?, + executeCount: Int? + ) { if (jobQuotaEnable) { logger.info("Remove running job to dispatch:[$projectId|$buildId|$vmSeqId]") try { client.get(ServiceJobQuotaBusinessResource::class).removeRunningJob( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, vmSeqId = vmSeqId ?: "1", executeCount = executeCount ?: 1 diff --git a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/BuildJobQuotaBusinessResource.kt b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/BuildJobQuotaBusinessResource.kt index fc824e2cc88..f05ddd2cc25 100644 --- a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/BuildJobQuotaBusinessResource.kt +++ b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/BuildJobQuotaBusinessResource.kt @@ -27,12 +27,17 @@ package com.tencent.devops.dispatch.api +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BUILD_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PIPELINE_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID +import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_VM_SEQ_ID import com.tencent.devops.common.api.pojo.Result import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam import javax.ws.rs.Consumes import javax.ws.rs.DELETE +import javax.ws.rs.HeaderParam import javax.ws.rs.POST import javax.ws.rs.Path import javax.ws.rs.PathParam @@ -48,16 +53,19 @@ interface BuildJobQuotaBusinessResource { @ApiOperation("上报一个Agent启动") @POST - @Path("/agent/projects/{projectId}/builds/{buildId}/vmSeqs/{vmSeqId}") + @Path("/agent/start") fun addRunningAgent( - @ApiParam(value = "projectId", required = true) - @PathParam("projectId") + @ApiParam("项目ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectId: String, - @ApiParam(value = "buildId", required = true) - @PathParam("buildId") + @ApiParam(value = "流水线ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID) + pipelineId: String, + @ApiParam(value = "构建ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_BUILD_ID) buildId: String, - @ApiParam(value = "vmSeqId", required = true) - @PathParam("vmSeqId") + @ApiParam(value = "构建job序号", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_VM_SEQ_ID) vmSeqId: String, @ApiParam(value = "executeCount", required = true) @QueryParam("executeCount") @@ -66,16 +74,19 @@ interface BuildJobQuotaBusinessResource { @ApiOperation("上报一个Agent结束") @DELETE - @Path("/agent/projects/{projectId}/builds/{buildId}/vmSeqs/{vmSeqId}") + @Path("/agent/shutdown") fun removeRunningAgent( - @ApiParam(value = "projectId", required = true) - @PathParam("projectId") + @ApiParam("项目ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_PROJECT_ID) projectId: String, - @ApiParam(value = "buildId", required = true) - @PathParam("buildId") + @ApiParam(value = "流水线ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_PIPELINE_ID) + pipelineId: String, + @ApiParam(value = "构建ID", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_BUILD_ID) buildId: String, - @ApiParam(value = "vmSeqId", required = true) - @PathParam("vmSeqId") + @ApiParam(value = "构建job序号", required = true) + @HeaderParam(AUTH_HEADER_DEVOPS_VM_SEQ_ID) vmSeqId: String, @ApiParam(value = "executeCount", required = true) @QueryParam("executeCount") diff --git a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/ServiceJobQuotaBusinessResource.kt b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/ServiceJobQuotaBusinessResource.kt index af06a90ad82..a3737952ed8 100644 --- a/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/ServiceJobQuotaBusinessResource.kt +++ b/src/backend/ci/core/dispatch/api-dispatch/src/main/kotlin/com/tencent/devops/dispatch/api/ServiceJobQuotaBusinessResource.kt @@ -76,11 +76,14 @@ interface ServiceJobQuotaBusinessResource { @ApiOperation("上报一个JOB结束") @DELETE - @Path("/job/projects/{projectId}/builds/{buildId}/vmSeqs/{vmSeqId}") + @Path("/job/projects/{projectId}/pipelines/{pipelineId}/builds/{buildId}/vmSeqs/{vmSeqId}") fun removeRunningJob( @ApiParam(value = "projectId", required = true) @PathParam("projectId") projectId: String, + @ApiParam(value = "pipelineId", required = true) + @PathParam("pipelineId") + pipelineId: String, @ApiParam(value = "buildId", required = true) @PathParam("buildId") buildId: String, diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/BuildJobQuotaBusinessResourceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/BuildJobQuotaBusinessResourceImpl.kt index b41220500f2..89a03a5448b 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/BuildJobQuotaBusinessResourceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/BuildJobQuotaBusinessResourceImpl.kt @@ -40,21 +40,23 @@ class BuildJobQuotaBusinessResourceImpl @Autowired constructor( override fun addRunningAgent( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int ): Result { - jobQuotaBusinessService.updateAgentStartTime(projectId, buildId, vmSeqId, executeCount) + jobQuotaBusinessService.updateAgentStartTime(projectId, pipelineId, buildId, vmSeqId, executeCount) return Result(true) } override fun removeRunningAgent( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int ): Result { - jobQuotaBusinessService.updateRunningTime(projectId, buildId, vmSeqId, executeCount) + jobQuotaBusinessService.updateRunningTime(projectId, pipelineId, buildId, vmSeqId, executeCount) return Result(true) } } diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/ServiceJobQuotaBusinessResourceImpl.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/ServiceJobQuotaBusinessResourceImpl.kt index 42daf097657..0c370b16804 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/ServiceJobQuotaBusinessResourceImpl.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/controller/ServiceJobQuotaBusinessResourceImpl.kt @@ -61,11 +61,12 @@ class ServiceJobQuotaBusinessResourceImpl @Autowired constructor( override fun removeRunningJob( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int ): Result { - jobQuotaBusinessService.deleteRunningJob(projectId, buildId, vmSeqId, executeCount) + jobQuotaBusinessService.deleteRunningJob(projectId, pipelineId, buildId, vmSeqId, executeCount) return Result(true) } } diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/pojo/JobQuotaHistory.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/pojo/JobQuotaHistory.kt index 8a9598bef63..6fe5ae4f3d2 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/pojo/JobQuotaHistory.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/pojo/JobQuotaHistory.kt @@ -29,6 +29,7 @@ package com.tencent.devops.dispatch.pojo data class JobQuotaHistory( val projectId: String, + val pipelineId: String, val buildId: String, val vmSeqId: String, val executeCount: Int, diff --git a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/JobQuotaBusinessService.kt b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/JobQuotaBusinessService.kt index 21e48261c1e..f3b8ce4091c 100644 --- a/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/JobQuotaBusinessService.kt +++ b/src/backend/ci/core/dispatch/biz-dispatch/src/main/kotlin/com/tencent/devops/dispatch/service/JobQuotaBusinessService.kt @@ -101,12 +101,13 @@ class JobQuotaBusinessService @Autowired constructor( */ fun deleteRunningJob( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int ) { LOG.info("$projectId|$buildId|$vmSeqId|$executeCount >>> update agent startTime.") - jobAgentFinish(projectId, buildId, vmSeqId, executeCount) + jobAgentFinish(projectId, pipelineId, buildId, vmSeqId, executeCount) } /** @@ -114,6 +115,7 @@ class JobQuotaBusinessService @Autowired constructor( */ fun updateAgentStartTime( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int @@ -127,12 +129,13 @@ class JobQuotaBusinessService @Autowired constructor( */ fun updateRunningTime( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int ) { LOG.info("$projectId|$buildId|$vmSeqId|$executeCount >>> update agent running time.") - jobAgentFinish(projectId, buildId, vmSeqId, executeCount) + jobAgentFinish(projectId, pipelineId, buildId, vmSeqId, executeCount) } private fun getProjectRunningJobStatus(projectId: String, vmType: JobQuotaVmType): JobQuotaStatus { @@ -264,6 +267,7 @@ class JobQuotaBusinessService @Autowired constructor( private fun jobAgentFinish( projectId: String, + pipelineId: String, buildId: String, vmSeqId: String, executeCount: Int @@ -293,6 +297,7 @@ class JobQuotaBusinessService @Autowired constructor( jobQuotaInterface.saveJobQuotaHistory( JobQuotaHistory( projectId = projectId, + pipelineId = pipelineId, buildId = buildId, vmSeqId = vmSeqId, executeCount = executeCount,