Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:环境-节点管理列表支持按照状态等字段搜索 #11445 #11450

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ const val REPORT_TYPE = "reportType" // 报告类型
const val DATA = "data" // 数据
const val STRING = "string" // 字符串
const val LATEST_MODIFIER = "latestModifier" // 最近修改人
const val IMPORTER = "importer" // 导入人
const val USAGE = "usage" // 用途
const val ALIAS = "alias" // 别名
const val LATEST_UPDATE_TIME = "latestUpdateTime" // 最近修改时间
const val LATEST_EXECUTOR = "latestExecutor" // 最近执行人
const val LATEST_EXECUTE_TIME = "latestExecuteTime" // 最近执行时间
const val LATEST_EXECUTE_PIPELINE = "latestExecutePipeline" // 最近执行流水线
const val DANG = "dang" // 当
const val AND = "and" // 和
const val OR = "or" // 或
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.devops.dispatch.api

import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.dispatch.pojo.thirdpartyagent.AgentBuildInfo
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
Expand All @@ -39,7 +40,6 @@ import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.MediaType
import com.tencent.devops.common.api.pojo.Result

@Tag(name = "SERVICE_AGENT", description = "服务-Agent")
@Path("/service/agents")
Expand Down Expand Up @@ -68,6 +68,15 @@ interface ServiceAgentResource {
pageSize: Int?
): Page<AgentBuildInfo>

@Operation(summary = "批量获取构建机最近执行记录")
@GET
@Path("listLatestBuildPipelines")
fun listLatestBuildPipelines(
@Parameter(description = "agent Hash ID", required = true)
@QueryParam("agentIds")
agentIds: List<String>
): List<AgentBuildInfo>

@Operation(summary = "获取agent登录调试url")
@GET
@Path("/docker/debug/url")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class ServiceAgentResourceImpl @Autowired constructor(
)
}

override fun listLatestBuildPipelines(agentIds: List<String>): List<AgentBuildInfo> {
return thirdPartyAgentService.listLatestBuildPipelines(
agentIds = agentIds
)
}
override fun getDockerDebugUrl(
userId: String,
projectId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@
package com.tencent.devops.dispatch.dao

import com.tencent.devops.common.api.util.JsonUtil
import com.tencent.devops.common.api.util.timestamp
import com.tencent.devops.common.pipeline.type.agent.ThirdPartyAgentDockerInfoDispatch
import com.tencent.devops.dispatch.pojo.enums.PipelineTaskStatus
import com.tencent.devops.dispatch.pojo.thirdpartyagent.AgentBuildInfo
import com.tencent.devops.dispatch.pojo.thirdpartyagent.BuildJobType
import com.tencent.devops.model.dispatch.tables.TDispatchThirdpartyAgentBuild
import com.tencent.devops.model.dispatch.tables.records.TDispatchThirdpartyAgentBuildRecord
import java.time.LocalDateTime
import org.jooq.DSLContext
import org.jooq.JSON
import org.jooq.Result
import org.jooq.impl.DSL
import org.springframework.stereotype.Repository
import java.time.LocalDateTime

@Repository
@Suppress("ALL")
Expand Down Expand Up @@ -289,6 +291,48 @@ class ThirdPartyAgentBuildDao {
}
}

fun listLatestBuildPipelines(
dslContext: DSLContext,
agentIds: List<String>
): List<AgentBuildInfo> {
with(TDispatchThirdpartyAgentBuild.T_DISPATCH_THIRDPARTY_AGENT_BUILD) {
val sub = dslContext.select(DSL.max(ID).`as`("max_id"))
.from(this).groupBy(AGENT_ID).asTable("sub")
return dslContext.select(
PROJECT_ID,
AGENT_ID,
PIPELINE_ID,
PIPELINE_NAME,
BUILD_ID,
BUILD_NUM,
VM_SEQ_ID,
TASK_NAME,
STATUS,
CREATED_TIME,
UPDATED_TIME,
WORKSPACE
).from(this)
.join(sub).on(ID.eq(sub.field("max_id", Long::class.java)))
.orderBy(CREATED_TIME.desc())
.fetch().map {
AgentBuildInfo(
projectId = it.value1(),
agentId = it.value2(),
pipelineId = it.value3(),
pipelineName = it.value4(),
buildId = it.value5(),
buildNum = it.value6(),
vmSeqId = it.value7(),
taskName = it.value8(),
status = PipelineTaskStatus.toStatus(it.value9()).name,
createdTime = it.value10().timestamp(),
updatedTime = it.value11().timestamp(),
workspace = it.value12() ?: ""
)
}
}
}

fun countAgentBuilds(
dslContext: DSLContext,
agentId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ class ThirdPartyAgentService @Autowired constructor(
return Page(pageNotNull, pageSizeNotNull, agentBuildCount, agentBuilds)
}

fun listLatestBuildPipelines(agentIds: List<String>): List<AgentBuildInfo> {
return thirdPartyAgentBuildDao.listLatestBuildPipelines(
dslContext = dslContext,
agentIds = agentIds
)
}

private fun finishBuild(record: TDispatchThirdpartyAgentBuildRecord, success: Boolean) {
logger.info(
"Finish the third party agent(${record.agentId}) build(${record.buildId}) " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ import com.tencent.devops.common.api.pojo.Page
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.environment.pojo.DisplayName
import com.tencent.devops.environment.pojo.NodeWithPermission
import com.tencent.devops.environment.pojo.enums.NodeStatus
import com.tencent.devops.environment.pojo.enums.NodeType
import io.swagger.v3.oas.annotations.tags.Tag
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import javax.servlet.http.HttpServletResponse
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.HeaderParam
Expand All @@ -45,6 +47,7 @@ import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.QueryParam
import javax.ws.rs.core.Context
import javax.ws.rs.core.MediaType

@Tag(name = "USER_NODE", description = "用户-节点")
Expand Down Expand Up @@ -122,11 +125,91 @@ interface UserNodeResource {
@Parameter(description = "关键字", required = false)
@QueryParam("keywords")
keywords: String?,
@Parameter(description = "节点类型", required = false)
@Parameter(description = "节点类型|用途 (构建: THIRDPARTY;部署: CMDB)", required = false)
@QueryParam("nodeType")
nodeType: NodeType?
nodeType: NodeType?,
@Parameter(description = "Agent 状态", required = false)
@QueryParam("nodeStatus")
nodeStatus: NodeStatus?,
@Parameter(description = "Agent 版本", required = false)
@QueryParam("agentVersion")
agentVersion: String?,
@Parameter(description = "操作系统", required = false)
@QueryParam("osName")
osName: String?,
@Parameter(description = "最近执行流水线", required = false)
@QueryParam("latestBuildPipelineId")
latestBuildPipelineId: String?,
@Parameter(description = "最近构建执行时间 (开始)", required = false)
@QueryParam("latestBuildTimeStart")
latestBuildTimeStart: Long?,
@Parameter(description = "最近构建执行时间 (结束)", required = false)
@QueryParam("latestBuildTimeEnd")
latestBuildTimeEnd: Long?,
@Parameter(description = "排序字段", required = false)
@QueryParam("sortType")
sortType: String?,
@Parameter(description = "正序ASC/倒序DESC (默认倒序)", required = false)
@QueryParam("collation")
collation: String?
): Result<Page<NodeWithPermission>>

@Operation(summary = "导出节点管理列表相关信息csv文件")
@POST
@Path("/{projectId}/listNew_export")
fun listNewExport(
@Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "项目ID", required = true)
@PathParam("projectId")
projectId: String,
@Parameter(description = "IP", required = false)
@QueryParam("nodeIp")
nodeIp: String?,
@Parameter(description = "别名", required = false)
@QueryParam("displayName")
displayName: String?,
@Parameter(description = "创建人", required = false)
@QueryParam("createdUser")
createdUser: String?,
@Parameter(description = "最后修改人", required = false)
@QueryParam("lastModifiedUser")
lastModifiedUser: String?,
@Parameter(description = "关键字", required = false)
@QueryParam("keywords")
keywords: String?,
@Parameter(description = "节点类型|用途 (构建: THIRDPARTY;部署: CMDB)", required = false)
@QueryParam("nodeType")
nodeType: NodeType?,
@Parameter(description = "Agent 状态", required = false)
@QueryParam("nodeStatus")
nodeStatus: NodeStatus?,
@Parameter(description = "Agent 版本", required = false)
@QueryParam("agentVersion")
agentVersion: String?,
@Parameter(description = "操作系统", required = false)
@QueryParam("osName")
osName: String?,
@Parameter(description = "最近执行流水线", required = false)
@QueryParam("latestBuildPipelineId")
latestBuildPipelineId: String?,
@Parameter(description = "最近构建执行时间 (开始)", required = false)
@QueryParam("latestBuildTimeStart")
latestBuildTimeStart: Long?,
@Parameter(description = "最近构建执行时间 (结束)", required = false)
@QueryParam("latestBuildTimeEnd")
latestBuildTimeEnd: Long?,
@Parameter(description = "排序字段", required = false)
@QueryParam("sortType")
sortType: String?,
@Parameter(description = "正序ASC/倒序DESC (默认倒序)", required = false)
@QueryParam("collation")
collation: String?,
@Context
response: HttpServletResponse
)

@Operation(summary = "获取用户有权限使用的服务器列表")
@GET
@Path("/{projectId}/listUsableServerNodes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,24 @@ interface UserThirdPartyAgentResource {
pageSize: Int?
): Result<Page<AgentBuildDetail>>

@Operation(summary = "获取构建机最近执行记录")
@GET
@Path("/projects/{projectId}/listLatestBuildPipelines")
fun listLatestBuildPipelines(
@Parameter(description = "用户ID", required = true, example = AUTH_HEADER_USER_ID_DEFAULT_VALUE)
@HeaderParam(AUTH_HEADER_USER_ID)
userId: String,
@Parameter(description = "项目ID", required = true)
@PathParam("projectId")
projectId: String,
@Parameter(description = "第几页", required = false)
@QueryParam("page")
page: Int?,
@Parameter(description = "每页条数", required = false)
@QueryParam("pageSize")
pageSize: Int?
): Result<Page<AgentBuildDetail>>

@Operation(summary = "获取第三方构建机活动")
@GET
@Path("/projects/{projectId}/nodes/{nodeHashId}/listAgentActions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,9 @@ object EnvironmentMessageCode {
const val BK_SOLID_STATE_DISK = "bkSolidStateDisk" // {0}GB 固态硬盘
const val BK_ESTIMATED_DELIVERY_TIME = "bkEstimatedDeliveryTime" // 预计交付周期:{0}分钟
const val BK_HIGH_END_VERSION = "bkHighEndVersion" // 32核64G(高配版)
const val AGENT_VERSION = "agentVersion" // Agent版本
const val AGENT_STATUS = "agentStatus" // Agent版本
const val OS_TYPE = "osType" // 操作系统
const val NODE_USAGE_BUILD = "nodeUsageBuild" // 构建
const val NODE_USAGE_DEPLOYMENT = "nodeUsageDeployment" // 部署
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.tencent.devops.environment.pojo

import com.tencent.devops.environment.pojo.thirdpartyagent.AgentBuildDetail
import io.swagger.v3.oas.annotations.media.Schema

@Schema(title = "NodeWithPermission-节点信息(权限)")
Expand Down Expand Up @@ -94,5 +95,7 @@ data class NodeWithPermission(
@get:Schema(title = "机型")
val size: String? = null,
@get:Schema(title = "该节点所属环境名")
val envNames: List<String>? = null
val envNames: List<String>? = null,
@get:Schema(title = "最近构建信息")
var latestBuildDetail: AgentBuildDetail? = null
)
Loading
Loading