Skip to content

Commit

Permalink
feat: Package提取到common-metadata #2680
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Oct 25, 2024
1 parent 8173632 commit 9eb222b
Show file tree
Hide file tree
Showing 99 changed files with 576 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import com.tencent.bkrepo.analyst.pojo.response.ScanLicensePlanInfo
import com.tencent.bkrepo.analyst.pojo.response.ScanPlanInfo
import com.tencent.bkrepo.analyst.service.ScanPlanService
import com.tencent.bkrepo.analyst.service.ScannerService
import com.tencent.bkrepo.analyst.utils.Request
import com.tencent.bkrepo.analyst.utils.RuleConverter
import com.tencent.bkrepo.analyst.utils.RuleUtil
import com.tencent.bkrepo.analyst.utils.ScanLicenseConverter
Expand All @@ -59,18 +58,18 @@ import com.tencent.bkrepo.common.api.message.CommonMessageCode
import com.tencent.bkrepo.common.api.pojo.Page
import com.tencent.bkrepo.common.api.util.toJsonString
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType
import com.tencent.bkrepo.common.metadata.service.packages.PackageService
import com.tencent.bkrepo.common.query.model.PageLimit
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.common.security.permission.PrincipalType
import com.tencent.bkrepo.common.security.util.SecurityUtils
import com.tencent.bkrepo.repository.api.PackageClient
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import java.time.LocalDateTime

@Service
class ScanPlanServiceImpl(
private val packageClient: PackageClient,
private val packageService: PackageService,
private val scanPlanDao: ScanPlanDao,
private val scanTaskDao: ScanTaskDao,
private val scannerDao: ScannerDao,
Expand Down Expand Up @@ -284,10 +283,7 @@ class ScanPlanServiceImpl(
fullPath = fullPath
)
if (fullPath == null) {
val packageVersion = Request.request {
packageClient.findVersionByName(projectId, repoName, packageKey!!, version!!)
}

val packageVersion = packageService.findVersionByName(projectId, repoName, packageKey!!, version!!)
fullPath = packageVersion?.contentPath ?: packageVersion?.manifestPath
fullPath ?: throw NotFoundException(CommonMessageCode.RESOURCE_NOT_FOUND, packageKey!!, version!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import com.tencent.bkrepo.analyst.utils.RuleUtil
import com.tencent.bkrepo.common.analysis.pojo.scanner.Scanner
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType
import com.tencent.bkrepo.common.metadata.service.node.NodeSearchService
import com.tencent.bkrepo.common.metadata.service.packages.PackageService
import com.tencent.bkrepo.common.metadata.service.repo.RepositoryService
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.repository.api.PackageClient
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.node.NodeInfo
import com.tencent.bkrepo.repository.pojo.packages.PackageSummary
Expand All @@ -51,7 +51,7 @@ import org.springframework.stereotype.Component
class IteratorManager(
private val nodeSearchService: NodeSearchService,
private val repositoryService: RepositoryService,
private val packageClient: PackageClient
private val packageService: PackageService
) {
/**
* 创建待扫描文件迭代器
Expand All @@ -75,7 +75,7 @@ class IteratorManager(

val isPackageScanPlanType = scanTask.scanPlan != null && scanTask.scanPlan!!.type != RepositoryType.GENERIC.name
return if (isPackageScanPlanType || packageRule(rule)) {
PackageIterator(packageClient, nodeSearchService, PackageIterator.PackageIteratePosition(rule))
PackageIterator(packageService, nodeSearchService, PackageIterator.PackageIteratePosition(rule))
} else {
NodeIterator(projectIdIterator, nodeSearchService, NodeIterator.NodeIteratePosition(rule))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import com.tencent.bkrepo.analyst.utils.Request
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_NUMBER
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_SIZE
import com.tencent.bkrepo.common.metadata.service.node.NodeSearchService
import com.tencent.bkrepo.common.metadata.service.packages.PackageService
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.matcher.RuleMatcher
import com.tencent.bkrepo.common.query.model.PageLimit
import com.tencent.bkrepo.common.query.model.QueryModel
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.repository.api.PackageClient
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.packages.PackageSummary
import org.slf4j.LoggerFactory
Expand All @@ -49,7 +49,7 @@ import kotlin.math.min
* 依赖包迭代器
*/
class PackageIterator(
private val packageClient: PackageClient,
private val packageService: PackageService,
private val nodeSearchService: NodeSearchService,
override val position: PackageIteratePosition
) : PageableIterator<Node>() {
Expand Down Expand Up @@ -101,7 +101,7 @@ class PackageIterator(
rule = packageSummaryRule(position.rule)
)

val records = Request.request { packageClient.searchPackage(packageQueryModel) }!!.records
val records = packageService.searchPackage(packageQueryModel).records
return if (records.isEmpty()) {
emptyList()
} else {
Expand Down Expand Up @@ -218,9 +218,7 @@ class PackageIterator(
if (logger.isDebugEnabled) {
logger.debug("populating package[$pkg]")
}
val packageVersion = Request.request {
packageClient.findVersionByName(projectId, repoName, packageKey, packageVersion!!)
}
val packageVersion = packageService.findVersionByName(projectId, repoName, packageKey, packageVersion!!)
pkg.fullPath = packageVersion?.contentPath ?: packageVersion?.manifestPath
pkg.size = packageVersion?.size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ package com.tencent.bkrepo.common.artifact.manager

import com.tencent.bkrepo.common.api.exception.NotFoundException
import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode
import com.tencent.bkrepo.repository.api.PackageClient
import com.tencent.bkrepo.common.metadata.service.packages.PackageService
import com.tencent.bkrepo.repository.pojo.packages.PackageSummary
import com.tencent.bkrepo.repository.pojo.packages.PackageVersion

/**
* 包版本相关Manager
*/
class PackageManager(
private val packageClient: PackageClient
private val packageService: PackageService
) {

fun findPackageByKey(projectId: String, repoName: String, packageKey: String): PackageSummary {
return packageClient.findPackageByKey(projectId, repoName, packageKey).data
return packageService.findPackageByKey(projectId, repoName, packageKey)
?: throw NotFoundException(ArtifactMessageCode.PACKAGE_NOT_FOUND, packageKey)
}

Expand All @@ -55,7 +55,7 @@ class PackageManager(
packageKey: String,
version: String
): PackageVersion {
return packageClient.findVersionByName(projectId, repoName, packageKey, version).data
return packageService.findVersionByName(projectId, repoName, packageKey, version)
?: throw NotFoundException(ArtifactMessageCode.VERSION_NOT_FOUND, version)
}

Expand All @@ -65,7 +65,7 @@ class PackageManager(
packageKey: String,
tag: String
): String {
return packageClient.findVersionNameByTag(projectId, repoName, packageKey, tag).data
return packageService.findVersionNameByTag(projectId, repoName, packageKey, tag)
?: throw NotFoundException(ArtifactMessageCode.VERSION_NOT_FOUND, tag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.tencent.bkrepo.common.artifact.resolve.response.ArtifactResourceWrite
import com.tencent.bkrepo.common.artifact.util.PackageKeys
import com.tencent.bkrepo.common.metadata.service.node.NodeSearchService
import com.tencent.bkrepo.common.metadata.service.node.NodeService
import com.tencent.bkrepo.common.metadata.service.packages.PackageService
import com.tencent.bkrepo.common.metadata.service.repo.RepositoryService
import com.tencent.bkrepo.common.security.util.SecurityUtils
import com.tencent.bkrepo.common.service.util.HeaderUtils
Expand All @@ -64,7 +65,6 @@ import com.tencent.bkrepo.common.service.util.LocaleMessageUtils
import com.tencent.bkrepo.common.storage.core.StorageService
import com.tencent.bkrepo.common.storage.monitor.Throughput
import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier
import com.tencent.bkrepo.repository.api.PackageClient
import com.tencent.bkrepo.repository.api.PackageDownloadsClient
import com.tencent.bkrepo.repository.pojo.download.PackageDownloadRecord
import org.slf4j.LoggerFactory
Expand All @@ -91,7 +91,7 @@ abstract class AbstractArtifactRepository : ArtifactRepository {
lateinit var repositoryService: RepositoryService

@Autowired
lateinit var packageClient: PackageClient
lateinit var packageService: PackageService

@Autowired
lateinit var storageService: StorageService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class LocalRepository : AbstractArtifactRepository() {
val packageKey = nodeDetail.packageName()?.let { PackageKeys.ofName(repo.type, it) }
val version = nodeDetail.packageVersion()
if (packageKey != null && version != null) {
packageClient.findVersionByName(projectId, repoName, packageKey, version).data?.let { packageVersion ->
packageService.findVersionByName(projectId, repoName, packageKey, version)?.let { packageVersion ->
downloadIntercept(context, packageVersion)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.tencent.bkrepo.common.artifact.util.version

import com.tencent.bkrepo.common.metadata.util.version.SemVersion
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.dao
package com.tencent.bkrepo.common.metadata.dao.packages

import com.mongodb.client.result.UpdateResult
import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.mongo.dao.simple.SimpleMongoDao
import com.tencent.bkrepo.repository.model.TPackage
import com.tencent.bkrepo.repository.util.PackageQueryHelper
import com.tencent.bkrepo.common.metadata.model.TPackage
import com.tencent.bkrepo.common.metadata.util.PackageQueryHelper
import org.springframework.context.annotation.Conditional
import org.springframework.data.mongodb.core.FindAndModifyOptions
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
Expand All @@ -46,6 +48,7 @@ import org.springframework.stereotype.Repository
* 包数据访问层
*/
@Repository
@Conditional(SyncCondition::class)
class PackageDao : SimpleMongoDao<TPackage>() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.dao
package com.tencent.bkrepo.common.metadata.dao.packages

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.mongo.dao.simple.SimpleMongoDao
import com.tencent.bkrepo.repository.model.TPackageDependents
import com.tencent.bkrepo.repository.util.PackageQueryHelper
import com.tencent.bkrepo.common.metadata.model.TPackageDependents
import com.tencent.bkrepo.common.metadata.util.PackageQueryHelper
import org.springframework.context.annotation.Conditional
import org.springframework.data.mongodb.core.query.Update
import org.springframework.stereotype.Repository

/**
* 包依赖关系数据访问层
*/
@Repository
@Conditional(SyncCondition::class)
class PackageDependentsDao : SimpleMongoDao<TPackageDependents>() {

fun findByPackageKey(projectId: String, repoName: String, key: String): TPackageDependents? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.dao
package com.tencent.bkrepo.common.metadata.dao.packages

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.mongo.dao.simple.SimpleMongoDao
import com.tencent.bkrepo.repository.model.TPackageDownloads
import com.tencent.bkrepo.common.metadata.model.TPackageDownloads
import org.springframework.context.annotation.Conditional
import org.springframework.stereotype.Repository

/**
* 包下载统计数据访问层
*/
@Repository
@Conditional(SyncCondition::class)
class PackageDownloadsDao : SimpleMongoDao<TPackageDownloads>()
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.dao
package com.tencent.bkrepo.common.metadata.dao.packages

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.mongo.dao.simple.SimpleMongoDao
import com.tencent.bkrepo.repository.model.TPackageVersion
import com.tencent.bkrepo.repository.util.PackageQueryHelper
import com.tencent.bkrepo.common.metadata.model.TPackageVersion
import com.tencent.bkrepo.common.metadata.util.PackageQueryHelper
import org.springframework.context.annotation.Conditional
import org.springframework.data.mongodb.core.FindAndModifyOptions
import org.springframework.data.mongodb.core.query.Update
import org.springframework.stereotype.Repository
Expand All @@ -42,6 +44,7 @@ import org.springframework.stereotype.Repository
* 包版本 DAO
*/
@Repository
@Conditional(SyncCondition::class)
class PackageVersionDao : SimpleMongoDao<TPackageVersion>() {

fun listByPackageId(packageId: String): List<TPackageVersion> {
Expand Down
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.bkrepo.repository.model
package com.tencent.bkrepo.common.metadata.model

/**
* 集群资源
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.model
package com.tencent.bkrepo.common.metadata.model

import com.tencent.bkrepo.repository.model.TPackage.Companion.PACKAGE_KEY_IDX
import com.tencent.bkrepo.repository.model.TPackage.Companion.PACKAGE_KEY_IDX_DEF
import com.tencent.bkrepo.repository.model.TPackage.Companion.PACKAGE_NAME_IDX
import com.tencent.bkrepo.repository.model.TPackage.Companion.PACKAGE_NAME_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TPackage.Companion.PACKAGE_KEY_IDX
import com.tencent.bkrepo.common.metadata.model.TPackage.Companion.PACKAGE_KEY_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TPackage.Companion.PACKAGE_NAME_IDX
import com.tencent.bkrepo.common.metadata.model.TPackage.Companion.PACKAGE_NAME_IDX_DEF
import com.tencent.bkrepo.repository.pojo.packages.PackageType
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.model
package com.tencent.bkrepo.common.metadata.model

import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.model
package com.tencent.bkrepo.common.metadata.model

import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.model
package com.tencent.bkrepo.common.metadata.model

import com.tencent.bkrepo.common.metadata.model.TMetadata
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_METADATA_IDX
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_METADATA_IDX_DEF
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_NAME_IDX
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_NAME_IDX_DEF
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_TAGS_IDX
import com.tencent.bkrepo.repository.model.TPackageVersion.Companion.VERSION_TAGS_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_METADATA_IDX
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_METADATA_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_NAME_IDX
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_NAME_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_TAGS_IDX
import com.tencent.bkrepo.common.metadata.model.TPackageVersion.Companion.VERSION_TAGS_IDX_DEF
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
import org.springframework.data.mongodb.core.mapping.Document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.search.packages
package com.tencent.bkrepo.common.metadata.search.packages

import com.tencent.bkrepo.common.query.builder.MongoQueryInterpreter
import com.tencent.bkrepo.common.query.model.QueryModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.search.packages
package com.tencent.bkrepo.common.metadata.search.packages

import com.tencent.bkrepo.common.query.interceptor.QueryContext
import com.tencent.bkrepo.common.query.model.QueryModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.service.metadata
package com.tencent.bkrepo.common.metadata.service.metadata

import com.tencent.bkrepo.repository.pojo.metadata.packages.PackageMetadataSaveRequest

Expand Down
Loading

0 comments on commit 9eb222b

Please sign in to comment.