Skip to content

Commit

Permalink
feat: blockNode抽取至公共模块 TencentBlueKing#2413
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Aug 9, 2024
1 parent 3687776 commit 822c4d9
Show file tree
Hide file tree
Showing 50 changed files with 418 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.common.mongo.reactive.dao
package com.tencent.bkrepo.common.api.mongo

/**
* 分表Document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.common.mongo.dao.sharding
package com.tencent.bkrepo.common.api.mongo

/**
* 分表字段
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
api(project(":common:common-operate:operate-service"))
api(project(":common:common-stream"))
api(project(":common:common-metrics-push"))
api(project(":common:common-metadata:metadata-service"))

api("org.springframework.boot:spring-boot-starter-aop")
api("io.micrometer:micrometer-registry-prometheus")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import com.tencent.bkrepo.common.artifact.manager.resource.LocalNodeResource
import com.tencent.bkrepo.common.artifact.manager.resource.NodeResource
import com.tencent.bkrepo.common.artifact.manager.resource.RemoteNodeResource
import com.tencent.bkrepo.common.artifact.stream.Range
import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService
import com.tencent.bkrepo.common.service.cluster.ClusterInfo
import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties
import com.tencent.bkrepo.common.storage.core.StorageService
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.fs.server.api.FsNodeClient
import com.tencent.bkrepo.fs.server.constant.FS_ATTR_KEY
import com.tencent.bkrepo.replication.api.ClusterNodeClient
import com.tencent.bkrepo.replication.exception.ReplicationMessageCode
Expand All @@ -51,7 +51,7 @@ class NodeResourceFactoryImpl(
private val clusterProperties: ClusterProperties,
private val storageService: StorageService,
private val storageCredentialsClient: StorageCredentialsClient,
private val fsNodeClient: FsNodeClient,
private val blockNodeService: BlockNodeService,
private val clusterNodeClient: ClusterNodeClient,
private val archiveClient: ArchiveClient,
) : NodeResourceFactory {
Expand All @@ -71,7 +71,7 @@ class NodeResourceFactoryImpl(
): NodeResource {
val digest = nodeInfo.sha256.orEmpty()
if (isFsFile(nodeInfo)) {
return FsNodeResource(nodeInfo, fsNodeClient, range, storageService, storageCredentials)
return FsNodeResource(nodeInfo, blockNodeService, range, storageService, storageCredentials)
}
if (clusterProperties.role == ClusterNodeType.EDGE &&
clusterProperties.architecture != ClusterArchitecture.COMMIT_EDGE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,28 @@ package com.tencent.bkrepo.common.artifact.manager.resource

import com.tencent.bkrepo.common.artifact.stream.ArtifactInputStream
import com.tencent.bkrepo.common.artifact.stream.Range
import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService
import com.tencent.bkrepo.common.storage.core.StorageService
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.fs.server.api.FsNodeClient
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.node.NodeInfo

/**
* 文件节点
* */
class FsNodeResource(
private val node: NodeInfo,
private val fsNodeClient: FsNodeClient,
private val blockNodeService: BlockNodeService,
private val range: Range,
private val storageService: StorageService,
private val storageCredentials: StorageCredentials?
) : AbstractNodeResource() {
override fun getArtifactInputStream(): ArtifactInputStream? {
with(node) {
val blocks = fsNodeClient.listBlockResources(
projectId = projectId,
repoName = repoName,
path = fullPath,
startPos = range.start,
endPos = range.end
).data ?: emptyList()
val blocks = blockNodeService.info(
nodeDetail = NodeDetail(this),
range = range
)
return storageService.load(blocks, range, storageCredentials)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ package com.tencent.bkrepo.common.metadata.constant

const val SHARDING_COUNT = 256
const val ID = "_id"

const val FAKE_SHA256 = "0000000000000000000000000000000000000000000000000000000000000000"
const val FAKE_MD5 = "00000000000000000000000000000000"
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@

package com.tencent.bkrepo.common.metadata

import com.tencent.bkrepo.common.metadata.dao.MetadataDaoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import

@Configuration
@ConditionalOnWebApplication
@Import(
MetadataDaoConfiguration::class
)
@ComponentScan(basePackages = ["com.tencent.bkrepo.common.metadata"])
class MetadataAutoConfiguration
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.common.metadata.condition

import org.springframework.context.annotation.Condition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.common.metadata.condition

import org.springframework.context.annotation.Condition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

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

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

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

import com.tencent.bkrepo.common.api.mongo.ShardingDocument
import com.tencent.bkrepo.common.metadata.constant.SHARDING_COUNT
import com.tencent.bkrepo.common.metadata.model.TBlockNode.Companion.BLOCK_IDX
import com.tencent.bkrepo.common.metadata.model.TBlockNode.Companion.BLOCK_IDX_DEF
import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingDocument
import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingKey
import com.tencent.bkrepo.common.api.mongo.ShardingKey
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ package com.tencent.bkrepo.common.metadata.service.blocknode
import com.tencent.bkrepo.common.artifact.stream.Range
import com.tencent.bkrepo.common.metadata.model.TBlockNode
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.common.storage.pojo.RegionResource
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import java.time.LocalDateTime

interface BlockNodeService {
Expand Down Expand Up @@ -86,4 +88,12 @@ interface BlockNodeService {
nodeCreateDate: LocalDateTime,
nodeDeleteDate: LocalDateTime
)

/**
* 查询节点对应范围的分块资源
*/
fun info(
nodeDetail: NodeDetail,
range: Range
): List<RegionResource>
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

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

import com.tencent.bkrepo.common.artifact.stream.Range
import com.tencent.bkrepo.common.metadata.model.TBlockNode
import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.common.storage.pojo.RegionResource
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import java.time.LocalDateTime

interface RBlockNodeService {
Expand Down Expand Up @@ -58,4 +87,12 @@ interface RBlockNodeService {
nodeCreateDate: LocalDateTime,
nodeDeleteDate: LocalDateTime
)

/**
* 查询节点对应范围的分块资源
*/
suspend fun info(
nodeDetail: NodeDetail,
range: Range
): List<RegionResource>
}
Loading

0 comments on commit 822c4d9

Please sign in to comment.