Skip to content

Commit

Permalink
feat: Package提取到common-metadata TencentBlueKing#2680
Browse files Browse the repository at this point in the history
* feat: Package提取到common-metadata TencentBlueKing#2680

* feat: Package提取到common-metadata TencentBlueKing#2680
  • Loading branch information
yaoxuwan authored Oct 28, 2024
1 parent 0dc8afd commit e57be3e
Show file tree
Hide file tree
Showing 110 changed files with 633 additions and 531 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@

package com.tencent.bkrepo.analyst.event.listener

import com.tencent.bkrepo.analyst.event.SubtaskStatusChangedEvent
import com.tencent.bkrepo.analyst.model.SubScanTaskDefinition
import com.tencent.bkrepo.analyst.model.TPlanArtifactLatestSubScanTask
import com.tencent.bkrepo.analyst.pojo.request.ArtifactPlanRelationRequest
import com.tencent.bkrepo.analyst.service.ScanPlanService
import com.tencent.bkrepo.common.analysis.pojo.scanner.SubScanTaskStatus
import com.tencent.bkrepo.common.api.util.toJsonString
import com.tencent.bkrepo.common.artifact.constant.FORBID_STATUS
import com.tencent.bkrepo.common.artifact.constant.FORBID_TYPE
import com.tencent.bkrepo.common.artifact.constant.SCAN_STATUS
import com.tencent.bkrepo.common.artifact.pojo.RepositoryType
import com.tencent.bkrepo.common.analysis.pojo.scanner.SubScanTaskStatus
import com.tencent.bkrepo.repository.api.PackageMetadataClient
import com.tencent.bkrepo.common.metadata.service.metadata.MetadataService
import com.tencent.bkrepo.common.metadata.service.metadata.PackageMetadataService
import com.tencent.bkrepo.repository.pojo.metadata.ForbidType
import com.tencent.bkrepo.repository.pojo.metadata.MetadataModel
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
import com.tencent.bkrepo.repository.pojo.metadata.packages.PackageMetadataSaveRequest
import com.tencent.bkrepo.analyst.event.SubtaskStatusChangedEvent
import com.tencent.bkrepo.analyst.model.SubScanTaskDefinition
import com.tencent.bkrepo.analyst.model.TPlanArtifactLatestSubScanTask
import com.tencent.bkrepo.analyst.pojo.request.ArtifactPlanRelationRequest
import com.tencent.bkrepo.analyst.service.ScanPlanService
import com.tencent.bkrepo.common.metadata.service.metadata.MetadataService
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener
import org.springframework.scheduling.annotation.Async
Expand All @@ -52,7 +52,7 @@ import org.springframework.stereotype.Component
@Component
class SubtaskStatusChangedEventListener(
private val metadataService: MetadataService,
private val packageMetadataClient: PackageMetadataClient,
private val packageMetadataService: PackageMetadataService,
private val scanPlanService: ScanPlanService
) {
@Async
Expand Down Expand Up @@ -158,7 +158,7 @@ class SubtaskStatusChangedEventListener(
version = version!!,
versionMetadata = metadata
)
packageMetadataClient.saveMetadata(request)
packageMetadataService.saveMetadata(request)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@
package com.tencent.bkrepo.analyst.service.impl

import com.tencent.bkrepo.common.api.pojo.Page
import com.tencent.bkrepo.common.metadata.service.project.ProjectUsageStatisticsService
import com.tencent.bkrepo.common.metadata.pojo.project.ProjectUsageStatistics
import com.tencent.bkrepo.common.metadata.pojo.project.ProjectUsageStatisticsListOption
import com.tencent.bkrepo.repository.api.ProjectUsageStatisticsClient
import org.springframework.beans.factory.ObjectProvider
import com.tencent.bkrepo.common.metadata.service.project.ProjectUsageStatisticsService
import org.springframework.scheduling.annotation.Async

open class ProjectUsageStatisticsServiceImpl(
private val projectUsageStatisticsClient: ObjectProvider<ProjectUsageStatisticsClient>
private val projectUsageStatisticsService: ProjectUsageStatisticsService
) : ProjectUsageStatisticsService {

@Async
override fun inc(projectId: String, reqCount: Long, receivedBytes: Long, responseBytes: Long) {
projectUsageStatisticsClient.ifAvailable?.inc(projectId, reqCount, receivedBytes, responseBytes)
projectUsageStatisticsService.inc(projectId, reqCount, receivedBytes, responseBytes)
}

override fun page(options: ProjectUsageStatisticsListOption): Page<ProjectUsageStatistics> {
Expand Down
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 @@ -10,8 +10,6 @@ import com.tencent.bkrepo.common.api.constant.StringPool
import com.tencent.bkrepo.common.api.exception.ErrorCodeException
import com.tencent.bkrepo.common.storage.StorageAutoConfiguration
import com.tencent.bkrepo.common.storage.core.StorageService
import com.tencent.bkrepo.repository.api.FileReferenceClient
import com.tencent.bkrepo.repository.api.RepositoryClient
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand All @@ -34,12 +32,6 @@ class CompressServiceTest @Autowired constructor(
@MockBean
lateinit var storageService: StorageService

@MockBean
lateinit var fileReferenceClient: FileReferenceClient

@MockBean
lateinit var repositoryClient: RepositoryClient

@BeforeEach
fun beforeEach() {
compressFileRepository.deleteAll()
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,8 @@ 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.PackageDownloadsService
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,8 +66,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
import org.springframework.beans.factory.annotation.Autowired
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 All @@ -106,7 +106,7 @@ abstract class AbstractArtifactRepository : ArtifactRepository {
lateinit var publisher: ApplicationEventPublisher

@Autowired
lateinit var packageDownloadsClient: PackageDownloadsClient
lateinit var packageDownloadsService: PackageDownloadsService

@Autowired
lateinit var artifactResourceWriter: ArtifactResourceWriter
Expand Down Expand Up @@ -237,7 +237,7 @@ abstract class AbstractArtifactRepository : ArtifactRepository {
) {
if (artifactResource.channel == ArtifactChannel.LOCAL) {
buildDownloadRecord(context, artifactResource)?.let {
taskAsyncExecutor.execute { packageDownloadsClient.record(it) }
taskAsyncExecutor.execute { packageDownloadsService.record(it) }
publishPackageDownloadEvent(context, it)
}
}
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>()
Loading

0 comments on commit e57be3e

Please sign in to comment.