Skip to content

Commit

Permalink
feat: 共享的环境名称使用project@poolName格式,以区分跨项目还是本项目的环境 TencentBlueKing#4934
Browse files Browse the repository at this point in the history
  • Loading branch information
huangjiao-heart committed Aug 13, 2021
1 parent 01802da commit 4582c5d
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,21 +659,23 @@ class ThirdPartyAgentMgrService @Autowired(required = false) constructor(
}).plus(sharedThridPartyAgentList)
}

private fun getSharedThirdPartyAgentList(projectId: String, envName: String): List<ThirdPartyAgent> {
val sharedProjEnv = envName.split("@") // sharedProjId@poolName
private fun getSharedThirdPartyAgentList(projectId: String, projectEnvName: String): List<ThirdPartyAgent> {
val sharedProjEnv = projectEnvName.split("@") // sharedProjId@poolName
if (sharedProjEnv.size != 2 || sharedProjEnv[0].isNullOrBlank() || sharedProjEnv[1].isNullOrBlank()) {
return emptyList()
}
val sharedEnvRecord = envShareProjectDao.get(dslContext, sharedProjEnv[1], projectId, sharedProjEnv[0])
val sharedProjectId = sharedProjEnv[0]
val sharedEnvName = sharedProjEnv[1]
val sharedEnvRecord = envShareProjectDao.get(dslContext, sharedEnvName, projectId, sharedProjectId)
if (sharedEnvRecord.isEmpty()) {
logger.info("env name not exists, envName: ${sharedProjEnv[1]}, projectId:$projectId, " +
"mainProjectId: ${sharedProjEnv[0]}")
logger.info("env name not exists, envName: $sharedEnvName, projectId:$projectId, " +
"mainProjectId: $sharedProjectId")
return emptyList()
}
logger.info("sharedEnvRecord size: ${sharedEnvRecord.size}")
val sharedThirdPartyAgents = mutableListOf<ThirdPartyAgent>()
sharedEnvRecord.forEach {
val envRecord = envDao.getByEnvName(dslContext, it.mainProjectId, envName) ?: return@forEach
val envRecord = envDao.getByEnvName(dslContext, it.mainProjectId, sharedEnvName) ?: return@forEach
sharedThirdPartyAgents.addAll(getAgentByEnvId(it.mainProjectId, HashUtil.encodeLongId(envRecord.envId)))
}
logger.info("sharedThirdPartyAgents size: ${sharedThirdPartyAgents.size}")
Expand Down

0 comments on commit 4582c5d

Please sign in to comment.