diff --git a/src/backend/boot-assembly/src/main/kotlin/com/tencent/bkrepo/config/FsNodeDefaultImpl.kt b/src/backend/boot-assembly/src/main/kotlin/com/tencent/bkrepo/config/FsNodeDefaultImpl.kt index b7f145c119..b405a2c13e 100644 --- a/src/backend/boot-assembly/src/main/kotlin/com/tencent/bkrepo/config/FsNodeDefaultImpl.kt +++ b/src/backend/boot-assembly/src/main/kotlin/com/tencent/bkrepo/config/FsNodeDefaultImpl.kt @@ -48,18 +48,4 @@ class FsNodeDefaultImpl : FsNodeClient { ): Response> { throw MethodNotAllowedException() } - - override fun restoreBlockResources( - projectId: String, - repoName: String, - fullPath: String, - nodeCreateDate: String, - nodeDeleteDate: String - ): Response { - throw MethodNotAllowedException() - } - - override fun deleteBlockResources(projectId: String, repoName: String, fullPath: String) { - throw MethodNotAllowedException() - } } diff --git a/src/backend/common/common-metadata/build.gradle.kts b/src/backend/common/common-metadata/build.gradle.kts new file mode 100644 index 0000000000..6971910f79 --- /dev/null +++ b/src/backend/common/common-metadata/build.gradle.kts @@ -0,0 +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. + */ diff --git a/src/backend/common/common-metadata/metadata-api/build.gradle.kts b/src/backend/common/common-metadata/metadata-api/build.gradle.kts new file mode 100644 index 0000000000..6971910f79 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-api/build.gradle.kts @@ -0,0 +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. + */ diff --git a/src/backend/common/common-metadata/metadata-api/src/main/kotlin/com/tencent/bkrepo/common/metadata/constant/Constant.kt b/src/backend/common/common-metadata/metadata-api/src/main/kotlin/com/tencent/bkrepo/common/metadata/constant/Constant.kt new file mode 100644 index 0000000000..bc1aa7340c --- /dev/null +++ b/src/backend/common/common-metadata/metadata-api/src/main/kotlin/com/tencent/bkrepo/common/metadata/constant/Constant.kt @@ -0,0 +1,31 @@ +/* + * 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.constant + +const val SHARDING_COUNT = 256 +const val ID = "_id" diff --git a/src/backend/common/common-metadata/metadata-service/build.gradle.kts b/src/backend/common/common-metadata/metadata-service/build.gradle.kts new file mode 100644 index 0000000000..5bc96239fb --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/build.gradle.kts @@ -0,0 +1,38 @@ +/* + * 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. + */ + +dependencies { + api(project(":common:common-artifact:artifact-api")) + api(project(":common:common-metadata:metadata-api")) + api(project(":common:common-mongo-reactive")) + api(project(":common:common-storage:storage-api")) + api(project(":repository:api-repository")) +} diff --git a/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/MetadataAutoConfiguration.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/MetadataAutoConfiguration.kt new file mode 100644 index 0000000000..49ad3b2a54 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/MetadataAutoConfiguration.kt @@ -0,0 +1,40 @@ +/* + * 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 + +import com.tencent.bkrepo.common.metadata.dao.MetadataDaoConfiguration +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import + +@Configuration +@ConditionalOnWebApplication +@Import( + MetadataDaoConfiguration::class +) +class MetadataAutoConfiguration diff --git a/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/BlockNodeDao.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/BlockNodeDao.kt new file mode 100644 index 0000000000..2e09ca3001 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/BlockNodeDao.kt @@ -0,0 +1,35 @@ +/* + * 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.mongo.reactive.dao.ShardingMongoReactiveDao +import com.tencent.bkrepo.common.metadata.model.TBlockNode +import org.springframework.stereotype.Repository + +@Repository +class BlockNodeDao : ShardingMongoReactiveDao() diff --git a/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/MetadataDaoConfiguration.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/MetadataDaoConfiguration.kt new file mode 100644 index 0000000000..3b5c430747 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/MetadataDaoConfiguration.kt @@ -0,0 +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.dao + +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import + +@Configuration +@Import( + BlockNodeDao::class +) +class MetadataDaoConfiguration diff --git a/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/model/TBlockNode.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/model/TBlockNode.kt new file mode 100644 index 0000000000..a6d47edac1 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/model/TBlockNode.kt @@ -0,0 +1,64 @@ +/* + * 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.model + +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 org.springframework.data.mongodb.core.index.CompoundIndex +import org.springframework.data.mongodb.core.index.CompoundIndexes +import java.time.LocalDateTime + +/** + * 块节点 + * */ +@ShardingDocument("block_node") +@CompoundIndexes( + CompoundIndex(name = BLOCK_IDX, def = BLOCK_IDX_DEF) +) +data class TBlockNode( + var id: String? = null, + var createdBy: String, + var createdDate: LocalDateTime, + val nodeFullPath: String, + val startPos: Long, + var sha256: String, + val projectId: String, + @ShardingKey(count = SHARDING_COUNT) + val repoName: String, + val size: Long, + val endPos: Long = startPos + size - 1, + var deleted: LocalDateTime? = null +) { + companion object { + const val BLOCK_IDX = "start_pos_idx" + const val BLOCK_IDX_DEF = "{'projectId': 1, 'repoName': 1,'nodeFullPath':1, 'startPos': 1, 'isDeleted': 1}" + } +} diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeService.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/BlockNodeService.kt similarity index 52% rename from src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeService.kt rename to src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/BlockNodeService.kt index aba1d01b58..faf875679c 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeService.kt +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/BlockNodeService.kt @@ -1,40 +1,37 @@ /* * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. * - * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * 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. + * 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: + * 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 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. + * 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.fs.server.service +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.fs.server.model.TBlockNode import java.time.LocalDateTime -/** - * 块服务 - * */ interface BlockNodeService { /** * 查询出范围内的分块 diff --git a/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/impl/AbstractBlockNodeService.kt b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/impl/AbstractBlockNodeService.kt new file mode 100644 index 0000000000..6e67b1c68c --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/impl/AbstractBlockNodeService.kt @@ -0,0 +1,150 @@ +/* + * 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.impl + +import com.tencent.bkrepo.common.api.util.EscapeUtils +import com.tencent.bkrepo.common.artifact.stream.Range +import com.tencent.bkrepo.common.metadata.constant.ID +import com.tencent.bkrepo.common.metadata.dao.BlockNodeDao +import com.tencent.bkrepo.common.metadata.model.TBlockNode +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService +import com.tencent.bkrepo.common.storage.credentials.StorageCredentials +import com.tencent.bkrepo.repository.pojo.node.NodeDetail +import org.slf4j.LoggerFactory +import org.springframework.data.domain.Sort +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.Update +import org.springframework.data.mongodb.core.query.and +import org.springframework.data.mongodb.core.query.gt +import org.springframework.data.mongodb.core.query.isEqualTo +import org.springframework.data.mongodb.core.query.lt +import org.springframework.data.mongodb.core.query.where +import java.time.LocalDateTime + +abstract class AbstractBlockNodeService( + private val blockNodeDao: BlockNodeDao +) : BlockNodeService { + + override suspend fun createBlock( + blockNode: TBlockNode, + storageCredentials: StorageCredentials? + ): TBlockNode { + with(blockNode) { + val bn = blockNodeDao.save(blockNode) + incFileRef(bn.sha256, storageCredentials?.key) + logger.info("Create block node[$projectId/$repoName$nodeFullPath-$startPos] ,sha256[$sha256] success.") + return bn + } + } + + override suspend fun listBlocks( + range: Range, + projectId: String, + repoName: String, + fullPath: String, + createdDate: String + ): List { + val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) + .and(TBlockNode::projectId.name).isEqualTo(projectId) + .and(TBlockNode::repoName.name).isEqualTo(repoName) + .and(TBlockNode::deleted).isEqualTo(null) + .and(TBlockNode::createdDate).gt(LocalDateTime.parse(createdDate)) + .norOperator( + TBlockNode::startPos.gt(range.end), + TBlockNode::endPos.lt(range.start) + ) + val query = Query(criteria).with(Sort.by(TBlockNode::createdDate.name)) + return blockNodeDao.find(query) + } + + override suspend fun deleteBlocks( + projectId: String, + repoName: String, + fullPath: String + ) { + val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) + .and(TBlockNode::projectId.name).isEqualTo(projectId) + .and(TBlockNode::repoName.name).isEqualTo(repoName) + .and(TBlockNode::deleted).isEqualTo(null) + val update = Update().set(TBlockNode::deleted.name, LocalDateTime.now()) + blockNodeDao.updateMulti(Query(criteria), update) + logger.info("Delete node blocks[$projectId/$repoName$fullPath] success.") + } + + override suspend fun moveBlocks(projectId: String, repoName: String, fullPath: String, dstFullPath: String) { + val nodeDetail = getNodeDetail(projectId, repoName, dstFullPath) + if (nodeDetail.folder) { + val criteria = where(TBlockNode::nodeFullPath).regex("^${EscapeUtils.escapeRegex(fullPath)}/") + .and(TBlockNode::projectId.name).isEqualTo(projectId) + .and(TBlockNode::repoName.name).isEqualTo(repoName) + .and(TBlockNode::deleted).isEqualTo(null) + val blocks = blockNodeDao.find(Query(criteria)) + blocks.forEach { + val update = Update().set(TBlockNode::nodeFullPath.name, it.nodeFullPath.replace(fullPath, dstFullPath)) + val query = Query(Criteria.where(ID).isEqualTo(it.id).and(TBlockNode::repoName).isEqualTo(repoName)) + blockNodeDao.updateMulti(query, update) + } + } else { + val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) + .and(TBlockNode::projectId.name).isEqualTo(projectId) + .and(TBlockNode::repoName.name).isEqualTo(repoName) + .and(TBlockNode::deleted).isEqualTo(null) + val update = Update().set(TBlockNode::nodeFullPath.name, dstFullPath) + blockNodeDao.updateMulti(Query(criteria), update) + } + logger.info("Move node[$projectId/$repoName$fullPath] to node[$projectId/$repoName$dstFullPath] success.") + } + + + + override suspend fun restoreBlocks( + projectId: String, + repoName: String, + fullPath: String, + nodeCreateDate: LocalDateTime, + nodeDeleteDate: LocalDateTime + ) { + val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) + .and(TBlockNode::projectId.name).isEqualTo(projectId) + .and(TBlockNode::repoName.name).isEqualTo(repoName) + .and(TBlockNode::createdDate).gt(nodeCreateDate).lt(nodeDeleteDate) + val update = Update().set(TBlockNode::deleted.name, null) + val result = blockNodeDao.updateMulti(Query(criteria), update) + logger.info("Restore ${result.modifiedCount} blocks node[$projectId/$repoName$fullPath] " + + "between $nodeCreateDate and $nodeDeleteDate success.") + } + + abstract suspend fun incFileRef(sha256: String, credentialsKey: String?) + + abstract suspend fun getNodeDetail(projectId: String, repoName: String, dstFullPath: String): NodeDetail + + companion object { + private val logger = LoggerFactory.getLogger(AbstractBlockNodeService::class.java) + } +} diff --git a/src/backend/common/common-metadata/metadata-service/src/main/resources/META-INF/spring.factories b/src/backend/common/common-metadata/metadata-service/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..4a292034f6 --- /dev/null +++ b/src/backend/common/common-metadata/metadata-service/src/main/resources/META-INF/spring.factories @@ -0,0 +1,29 @@ +# +# 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. +# + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +com.tencent.bkrepo.common.metadata.MetadataAutoConfiguration diff --git a/src/backend/fs/api-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/FsNodeClient.kt b/src/backend/fs/api-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/FsNodeClient.kt index 9853d201bf..7b69ea50ea 100644 --- a/src/backend/fs/api-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/FsNodeClient.kt +++ b/src/backend/fs/api-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/FsNodeClient.kt @@ -50,20 +50,4 @@ interface FsNodeClient { @RequestParam startPos: Long, @RequestParam endPos: Long ): Response> - - @PostMapping("/restore/{projectId}/{repoName}") - fun restoreBlockResources( - @PathVariable projectId: String, - @PathVariable repoName: String, - @RequestParam fullPath: String, - @RequestParam nodeCreateDate: String, - @RequestParam nodeDeleteDate: String, - ): Response - - @DeleteMapping("/delete/{projectId}/{repoName}") - fun deleteBlockResources( - @PathVariable projectId: String, - @PathVariable repoName: String, - @RequestParam fullPath: String - ) } diff --git a/src/backend/fs/boot-fs-server/build.gradle.kts b/src/backend/fs/boot-fs-server/build.gradle.kts index a064ed1d00..1c9fd46dd3 100644 --- a/src/backend/fs/boot-fs-server/build.gradle.kts +++ b/src/backend/fs/boot-fs-server/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { api(project(":common:common-stream")) api(project(":fs:api-fs-server")) implementation("com.github.ben-manes.caffeine:caffeine:2.9.3") + implementation(project(":common:common-metadata:metadata-service")) testImplementation("org.mockito.kotlin:mockito-kotlin") testImplementation("de.flapdoodle.embed:de.flapdoodle.embed.mongo") diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/service/FsNodeHandler.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/service/FsNodeHandler.kt index 829a5fc5f3..42e1deb5c0 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/service/FsNodeHandler.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/service/FsNodeHandler.kt @@ -28,11 +28,11 @@ package com.tencent.bkrepo.fs.server.handler.service import com.tencent.bkrepo.common.artifact.stream.Range +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.fs.server.api.RRepositoryClient import com.tencent.bkrepo.fs.server.request.service.DeleteBlocksRequest import com.tencent.bkrepo.fs.server.request.service.ListBlocksRequest import com.tencent.bkrepo.fs.server.request.service.RestoreBlocksRequest -import com.tencent.bkrepo.fs.server.service.BlockNodeService import com.tencent.bkrepo.fs.server.service.FileNodeService import com.tencent.bkrepo.fs.server.utils.ReactiveResponseBuilder import kotlinx.coroutines.reactor.awaitSingle diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/model/TBlockNode.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/model/TBlockNode.kt deleted file mode 100644 index bafc4b9284..0000000000 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/model/TBlockNode.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.fs.server.model - -import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingDocument -import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingKey -import com.tencent.bkrepo.fs.server.model.TBlockNode.Companion.BLOCK_IDX -import com.tencent.bkrepo.fs.server.model.TBlockNode.Companion.BLOCK_IDX_DEF -import com.tencent.bkrepo.repository.constant.SHARDING_COUNT -import org.springframework.data.mongodb.core.index.CompoundIndex -import org.springframework.data.mongodb.core.index.CompoundIndexes -import java.time.LocalDateTime - -/** - * 块节点 - * */ -@ShardingDocument("block_node") -@CompoundIndexes( - CompoundIndex(name = BLOCK_IDX, def = BLOCK_IDX_DEF) -) -data class TBlockNode( - var id: String? = null, - var createdBy: String, - var createdDate: LocalDateTime, - val nodeFullPath: String, - val startPos: Long, - var sha256: String, - val projectId: String, - @ShardingKey(count = SHARDING_COUNT) - val repoName: String, - val size: Long, - val endPos: Long = startPos + size - 1, - var deleted: LocalDateTime? = null -) { - companion object { - const val BLOCK_IDX = "start_pos_idx" - const val BLOCK_IDX_DEF = "{'projectId': 1, 'repoName': 1,'nodeFullPath':1, 'startPos': 1, 'isDeleted': 1}" - } -} diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/repository/BlockNodeRepository.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/repository/BlockNodeRepository.kt deleted file mode 100644 index 2e6d607082..0000000000 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/repository/BlockNodeRepository.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2019 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.fs.server.repository - -import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingMongoReactiveDao -import com.tencent.bkrepo.fs.server.model.TBlockNode -import org.springframework.stereotype.Repository - -@Repository -class BlockNodeRepository : ShardingMongoReactiveDao() diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeServiceImpl.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeServiceImpl.kt index 51fd09ee1b..fe24eb906a 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeServiceImpl.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/BlockNodeServiceImpl.kt @@ -27,124 +27,27 @@ package com.tencent.bkrepo.fs.server.service -import com.tencent.bkrepo.common.api.util.EscapeUtils import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException -import com.tencent.bkrepo.common.artifact.stream.Range -import com.tencent.bkrepo.common.storage.credentials.StorageCredentials +import com.tencent.bkrepo.common.metadata.dao.BlockNodeDao +import com.tencent.bkrepo.common.metadata.service.blocknode.impl.AbstractBlockNodeService import com.tencent.bkrepo.fs.server.api.RRepositoryClient -import com.tencent.bkrepo.fs.server.constant.ID -import com.tencent.bkrepo.fs.server.model.TBlockNode -import com.tencent.bkrepo.fs.server.repository.BlockNodeRepository +import com.tencent.bkrepo.repository.pojo.node.NodeDetail import kotlinx.coroutines.reactor.awaitSingle -import org.slf4j.LoggerFactory -import org.springframework.data.domain.Sort -import org.springframework.data.mongodb.core.query.Criteria -import org.springframework.data.mongodb.core.query.Query -import org.springframework.data.mongodb.core.query.Update -import org.springframework.data.mongodb.core.query.and -import org.springframework.data.mongodb.core.query.gt -import org.springframework.data.mongodb.core.query.isEqualTo -import org.springframework.data.mongodb.core.query.lt -import org.springframework.data.mongodb.core.query.where -import java.time.LocalDateTime /** * 文件块服务 * */ class BlockNodeServiceImpl( - private val blockNodeRepository: BlockNodeRepository, + blockNodeDao: BlockNodeDao, private val rRepositoryClient: RRepositoryClient -) : BlockNodeService { +) : AbstractBlockNodeService(blockNodeDao) { - override suspend fun createBlock( - blockNode: TBlockNode, - storageCredentials: StorageCredentials? - ): TBlockNode { - with(blockNode) { - val bn = blockNodeRepository.save(blockNode) - rRepositoryClient.increment(blockNode.sha256, storageCredentials?.key).awaitSingle() - logger.info("Create block node[$projectId/$repoName$nodeFullPath-$startPos] ,sha256[$sha256] success.") - return bn - } + override suspend fun incFileRef(sha256: String, credentialsKey: String?) { + rRepositoryClient.increment(sha256, credentialsKey).awaitSingle() } - override suspend fun listBlocks( - range: Range, - projectId: String, - repoName: String, - fullPath: String, - createdDate: String - ): List { - val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) - .and(TBlockNode::projectId.name).isEqualTo(projectId) - .and(TBlockNode::repoName.name).isEqualTo(repoName) - .and(TBlockNode::deleted).isEqualTo(null) - .and(TBlockNode::createdDate).gt(LocalDateTime.parse(createdDate)) - .norOperator( - TBlockNode::startPos.gt(range.end), - TBlockNode::endPos.lt(range.start) - ) - val query = Query(criteria).with(Sort.by(TBlockNode::createdDate.name)) - return blockNodeRepository.find(query) - } - - override suspend fun deleteBlocks( - projectId: String, - repoName: String, - fullPath: String - ) { - val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) - .and(TBlockNode::projectId.name).isEqualTo(projectId) - .and(TBlockNode::repoName.name).isEqualTo(repoName) - .and(TBlockNode::deleted).isEqualTo(null) - val update = Update().set(TBlockNode::deleted.name, LocalDateTime.now()) - blockNodeRepository.updateMulti(Query(criteria), update) - logger.info("Delete node blocks[$projectId/$repoName$fullPath] success.") - } - - override suspend fun moveBlocks(projectId: String, repoName: String, fullPath: String, dstFullPath: String) { - val nodeDetail = rRepositoryClient.getNodeDetail(projectId, repoName, dstFullPath).awaitSingle().data + override suspend fun getNodeDetail(projectId: String, repoName: String, dstFullPath: String): NodeDetail { + return rRepositoryClient.getNodeDetail(projectId, repoName, dstFullPath).awaitSingle().data ?: throw NodeNotFoundException(dstFullPath) - if (nodeDetail.folder) { - val criteria = where(TBlockNode::nodeFullPath).regex("^${EscapeUtils.escapeRegex(fullPath)}/") - .and(TBlockNode::projectId.name).isEqualTo(projectId) - .and(TBlockNode::repoName.name).isEqualTo(repoName) - .and(TBlockNode::deleted).isEqualTo(null) - val blocks = blockNodeRepository.find(Query(criteria)) - blocks.forEach { - val update = Update().set(TBlockNode::nodeFullPath.name, it.nodeFullPath.replace(fullPath, dstFullPath)) - val query = Query(Criteria.where(ID).isEqualTo(it.id).and(TBlockNode::repoName).isEqualTo(repoName)) - blockNodeRepository.updateMulti(query, update) - } - } else { - val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) - .and(TBlockNode::projectId.name).isEqualTo(projectId) - .and(TBlockNode::repoName.name).isEqualTo(repoName) - .and(TBlockNode::deleted).isEqualTo(null) - val update = Update().set(TBlockNode::nodeFullPath.name, dstFullPath) - blockNodeRepository.updateMulti(Query(criteria), update) - } - logger.info("Move node[$projectId/$repoName$fullPath] to node[$projectId/$repoName$dstFullPath] success.") - } - - override suspend fun restoreBlocks( - projectId: String, - repoName: String, - fullPath: String, - nodeCreateDate: LocalDateTime, - nodeDeleteDate: LocalDateTime - ) { - val criteria = where(TBlockNode::nodeFullPath).isEqualTo(fullPath) - .and(TBlockNode::projectId.name).isEqualTo(projectId) - .and(TBlockNode::repoName.name).isEqualTo(repoName) - .and(TBlockNode::createdDate).gt(nodeCreateDate).lt(nodeDeleteDate) - val update = Update().set(TBlockNode::deleted.name, null) - val result = blockNodeRepository.updateMulti(Query(criteria), update) - logger.info("Restore ${result.modifiedCount} blocks node[$projectId/$repoName$fullPath] " + - "between $nodeCreateDate and $nodeDeleteDate success.") - } - - companion object { - private val logger = LoggerFactory.getLogger(BlockNodeServiceImpl::class.java) } } diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileNodeService.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileNodeService.kt index bbe381c47c..121139edd3 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileNodeService.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileNodeService.kt @@ -30,6 +30,7 @@ package com.tencent.bkrepo.fs.server.service 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.credentials.StorageCredentials import com.tencent.bkrepo.common.storage.pojo.RegionResource import com.tencent.bkrepo.fs.server.constant.FAKE_SHA256 diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileOperationService.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileOperationService.kt index 83bbcf5470..75b1e48e21 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileOperationService.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/FileOperationService.kt @@ -33,7 +33,7 @@ import com.tencent.bkrepo.fs.server.api.RRepositoryClient import com.tencent.bkrepo.fs.server.constant.FS_ATTR_KEY import com.tencent.bkrepo.fs.server.context.ReactiveArtifactContextHolder import com.tencent.bkrepo.fs.server.model.NodeAttribute -import com.tencent.bkrepo.fs.server.model.TBlockNode +import com.tencent.bkrepo.common.metadata.model.TBlockNode import com.tencent.bkrepo.fs.server.request.BlockRequest import com.tencent.bkrepo.fs.server.request.FlushRequest import com.tencent.bkrepo.fs.server.storage.CoStorageManager diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/storage/CoStorageManager.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/storage/CoStorageManager.kt index 8fe79860e7..e0ceb4abdb 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/storage/CoStorageManager.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/storage/CoStorageManager.kt @@ -30,12 +30,12 @@ package com.tencent.bkrepo.fs.server.storage import com.tencent.bkrepo.common.artifact.api.ArtifactFile import com.tencent.bkrepo.common.artifact.stream.ArtifactInputStream import com.tencent.bkrepo.common.artifact.stream.Range +import com.tencent.bkrepo.common.metadata.model.TBlockNode +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.common.storage.pojo.RegionResource import com.tencent.bkrepo.fs.server.RepositoryCache -import com.tencent.bkrepo.fs.server.model.TBlockNode -import com.tencent.bkrepo.fs.server.service.BlockNodeService import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/src/backend/fs/boot-fs-server/src/test/kotlin/com/tencent/com/bkrepo/fs/service/BlockNodeServiceTest.kt b/src/backend/fs/boot-fs-server/src/test/kotlin/com/tencent/com/bkrepo/fs/service/BlockNodeServiceTest.kt index 8ff6833fdf..e27bdcfec3 100644 --- a/src/backend/fs/boot-fs-server/src/test/kotlin/com/tencent/com/bkrepo/fs/service/BlockNodeServiceTest.kt +++ b/src/backend/fs/boot-fs-server/src/test/kotlin/com/tencent/com/bkrepo/fs/service/BlockNodeServiceTest.kt @@ -6,9 +6,9 @@ import com.tencent.bkrepo.common.api.pojo.Response import com.tencent.bkrepo.common.artifact.stream.Range import com.tencent.bkrepo.common.storage.credentials.FileSystemCredentials import com.tencent.bkrepo.fs.server.api.RRepositoryClient -import com.tencent.bkrepo.fs.server.model.TBlockNode -import com.tencent.bkrepo.fs.server.repository.BlockNodeRepository -import com.tencent.bkrepo.fs.server.service.BlockNodeService +import com.tencent.bkrepo.common.metadata.model.TBlockNode +import com.tencent.bkrepo.common.metadata.dao.BlockNodeDao +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.repository.pojo.node.NodeDetail import com.tencent.bkrepo.repository.pojo.node.NodeInfo import com.tencent.com.bkrepo.fs.UT_PROJECT_ID @@ -36,7 +36,7 @@ import reactor.core.publisher.Mono import java.time.LocalDateTime @DataMongoTest -@Import(BlockNodeRepository::class) +@Import(BlockNodeDao::class) @SpringBootConfiguration @EnableAutoConfiguration @TestPropertySource(locations = ["classpath:bootstrap-ut.properties"]) @@ -49,13 +49,13 @@ class BlockNodeServiceTest { lateinit var blockNodeService: BlockNodeService @Autowired - lateinit var blockNodeRepository: BlockNodeRepository + lateinit var blockNodeDao: BlockNodeDao private val storageCredentials = FileSystemCredentials() @BeforeEach fun beforeEach() { val criteria = where(TBlockNode::repoName).isEqualTo(UT_REPO_NAME) - runBlocking { blockNodeRepository.remove(Query(criteria)) } + runBlocking { blockNodeDao.remove(Query(criteria)) } } @DisplayName("测试创建块") diff --git a/src/backend/repository/biz-repository/build.gradle.kts b/src/backend/repository/biz-repository/build.gradle.kts index c3ac8bd752..e992c620ab 100644 --- a/src/backend/repository/biz-repository/build.gradle.kts +++ b/src/backend/repository/biz-repository/build.gradle.kts @@ -42,4 +42,5 @@ dependencies { testImplementation("org.mockito.kotlin:mockito-kotlin") testImplementation("io.mockk:mockk") implementation("com.tencent.bk.sdk:bk-notice-java-sdk:${Versions.Notice}") + implementation(project(":common:common-metadata:metadata-service")) } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/blocknode/BlockNodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/blocknode/BlockNodeServiceImpl.kt new file mode 100644 index 0000000000..2ebaf6fc90 --- /dev/null +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/blocknode/BlockNodeServiceImpl.kt @@ -0,0 +1,60 @@ +/* + * 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.repository.service.blocknode + +import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException +import com.tencent.bkrepo.common.metadata.dao.BlockNodeDao +import com.tencent.bkrepo.common.metadata.service.blocknode.impl.AbstractBlockNodeService +import com.tencent.bkrepo.repository.dao.NodeDao +import com.tencent.bkrepo.repository.pojo.node.NodeDetail +import com.tencent.bkrepo.repository.service.file.FileReferenceService +import com.tencent.bkrepo.repository.service.node.impl.NodeBaseService +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import org.springframework.stereotype.Service + +@Service +class BlockNodeServiceImpl( + blockNodeDao: BlockNodeDao, + private val fileReferenceService: FileReferenceService, + private val nodeDao: NodeDao +) : AbstractBlockNodeService(blockNodeDao) { + + override suspend fun incFileRef(sha256: String, credentialsKey: String?) { + withContext(Dispatchers.IO) { + fileReferenceService.increment(sha256, credentialsKey) + } + } + + override suspend fun getNodeDetail(projectId: String, repoName: String, dstFullPath: String): NodeDetail { + return withContext(Dispatchers.IO) { + val node = nodeDao.findNode(projectId, repoName, dstFullPath) ?: throw NodeNotFoundException(dstFullPath) + NodeBaseService.convertToDetail(node)!! + } + } +} diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt index ce53f37a32..0774709404 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt @@ -42,6 +42,7 @@ import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.common.artifact.pojo.RepositoryType import com.tencent.bkrepo.common.artifact.router.RouterControllerProperties +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.mongo.dao.util.Pages import com.tencent.bkrepo.common.query.model.Sort import com.tencent.bkrepo.common.security.manager.PermissionManager @@ -51,7 +52,6 @@ import com.tencent.bkrepo.common.service.util.SpringContextUtils.Companion.publi import com.tencent.bkrepo.common.storage.core.StorageService import com.tencent.bkrepo.common.stream.constant.BinderType import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.fs.server.constant.FAKE_MD5 import com.tencent.bkrepo.fs.server.constant.FAKE_SHA256 import com.tencent.bkrepo.repository.config.RepositoryProperties @@ -105,7 +105,7 @@ abstract class NodeBaseService( open val servicePermissionClient: ServicePermissionClient, open val routerControllerClient: RouterControllerClient, open val routerControllerProperties: RouterControllerProperties, - open val fsNodeClient: FsNodeClient + open val blockNodeService: BlockNodeService ) : NodeService { @Autowired diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt index 1ff2302842..1694091b3d 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt @@ -35,8 +35,8 @@ import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.artifact.api.ArtifactInfo import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode import com.tencent.bkrepo.common.artifact.path.PathUtils.isRoot +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.security.util.SecurityUtils -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.fs.server.constant.FAKE_SHA256 import com.tencent.bkrepo.fs.server.constant.FS_ATTR_KEY import com.tencent.bkrepo.repository.dao.NodeDao @@ -58,6 +58,7 @@ import com.tencent.bkrepo.repository.util.NodeQueryHelper.nodeDeletedPointQuery import com.tencent.bkrepo.repository.util.NodeQueryHelper.nodeListQuery import com.tencent.bkrepo.repository.util.NodeQueryHelper.nodeQuery import com.tencent.bkrepo.repository.util.NodeQueryHelper.nodeRestoreUpdate +import kotlinx.coroutines.runBlocking import org.slf4j.LoggerFactory import org.springframework.dao.DuplicateKeyException import org.springframework.data.mongodb.core.FindAndModifyOptions @@ -73,7 +74,7 @@ open class NodeRestoreSupport( ) : NodeRestoreOperation { val nodeDao: NodeDao = nodeBaseService.nodeDao - val fsNodeClient: FsNodeClient = nodeBaseService.fsNodeClient + val blockNodeService: BlockNodeService = nodeBaseService.blockNodeService override fun getDeletedNodeDetail(artifact: ArtifactInfo): List { with(artifact) { @@ -178,13 +179,15 @@ open class NodeRestoreSupport( val deletedNode = nodeDao.findAndModify(query, nodeRestoreUpdate(), option, TNode::class.java) if (deletedNode?.sha256 == FAKE_SHA256 || deletedNode?.metadata?.find { it.key == FS_ATTR_KEY } != null) { try { - fsNodeClient.restoreBlockResources( - projectId = projectId, - repoName = repoName, - fullPath = fullPath, - nodeCreateDate = deletedNode.createdDate.toString(), - nodeDeleteDate = deletedNode.deleted!!.toString() - ) + runBlocking { + blockNodeService.restoreBlocks( + projectId = projectId, + repoName = repoName, + fullPath = fullPath, + nodeCreateDate = deletedNode.createdDate, + nodeDeleteDate = deletedNode.deleted!! + ) + } } catch (e: Exception) { logger.error("restore block resources failed: $projectId/$repoName/$fullPath", e) nodeDao.save(deletedNode) @@ -202,7 +205,7 @@ open class NodeRestoreSupport( with(node) { val query = nodeQuery(projectId, repoName, fullPath) if (node.sha256 == FAKE_SHA256 || node.metadata?.find { it.key == FS_ATTR_KEY } != null) { - fsNodeClient.deleteBlockResources(projectId, repoName, fullPath) + runBlocking { blockNodeService.deleteBlocks(projectId, repoName, fullPath) } } nodeDao.updateFirst(query, NodeQueryHelper.nodeDeleteUpdate(userId)) } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt index 23882d5646..0b566a0f28 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt @@ -31,10 +31,10 @@ import com.tencent.bkrepo.archive.api.ArchiveClient import com.tencent.bkrepo.auth.api.ServicePermissionClient import com.tencent.bkrepo.common.artifact.api.ArtifactInfo import com.tencent.bkrepo.common.artifact.router.RouterControllerProperties +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.service.cluster.condition.DefaultCondition import com.tencent.bkrepo.common.storage.core.StorageService import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.repository.config.RepositoryProperties import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.dao.RepositoryDao @@ -76,7 +76,7 @@ class NodeServiceImpl( override val servicePermissionClient: ServicePermissionClient, override val routerControllerClient: RouterControllerClient, override val routerControllerProperties: RouterControllerProperties, - override val fsNodeClient: FsNodeClient, + override val blockNodeService: BlockNodeService, private val archiveClient: ArchiveClient, ) : NodeBaseService( nodeDao, @@ -90,7 +90,7 @@ class NodeServiceImpl( servicePermissionClient, routerControllerClient, routerControllerProperties, - fsNodeClient + blockNodeService ) { override fun computeSize( diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt index f8731311af..95922cbb06 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt @@ -35,12 +35,12 @@ import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.common.artifact.router.RouterControllerProperties import com.tencent.bkrepo.common.artifact.util.ClusterUtils +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.security.util.SecurityUtils -import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties import com.tencent.bkrepo.common.service.cluster.condition.CommitEdgeCenterCondition +import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties import com.tencent.bkrepo.common.storage.core.StorageService import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.repository.config.RepositoryProperties import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.dao.RepositoryDao @@ -84,7 +84,7 @@ class CommitEdgeCenterNodeServiceImpl( override val servicePermissionClient: ServicePermissionClient, override val routerControllerClient: RouterControllerClient, override val routerControllerProperties: RouterControllerProperties, - override val fsNodeClient: FsNodeClient, + override val blockNodeService: BlockNodeService, val clusterProperties: ClusterProperties, val archiveClient: ArchiveClient, ) : NodeServiceImpl( @@ -99,7 +99,7 @@ class CommitEdgeCenterNodeServiceImpl( servicePermissionClient, routerControllerClient, routerControllerProperties, - fsNodeClient, + blockNodeService, archiveClient ) { diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeBaseService.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeBaseService.kt index 0f7084ed58..bcc9388a07 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeBaseService.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeBaseService.kt @@ -30,11 +30,11 @@ package com.tencent.bkrepo.repository.service.node.impl.edge import com.tencent.bkrepo.auth.api.ServicePermissionClient import com.tencent.bkrepo.common.artifact.router.RouterControllerProperties import com.tencent.bkrepo.common.artifact.util.ClusterUtils.reportMetadataToCenter +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties import com.tencent.bkrepo.common.service.feign.FeignClientFactory import com.tencent.bkrepo.common.storage.core.StorageService import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.repository.api.cluster.ClusterNodeClient import com.tencent.bkrepo.repository.config.RepositoryProperties import com.tencent.bkrepo.repository.dao.NodeDao @@ -62,7 +62,7 @@ abstract class EdgeNodeBaseService( override val routerControllerClient: RouterControllerClient, override val servicePermissionClient: ServicePermissionClient, override val routerControllerProperties: RouterControllerProperties, - override val fsNodeClient: FsNodeClient, + override val blockNodeService: BlockNodeService, open val clusterProperties: ClusterProperties ) : NodeBaseService( nodeDao, @@ -76,7 +76,7 @@ abstract class EdgeNodeBaseService( servicePermissionClient, routerControllerClient, routerControllerProperties, - fsNodeClient + blockNodeService ) { val centerNodeClient: ClusterNodeClient by lazy { diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt index 5272514e8e..f8e5356784 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt @@ -34,11 +34,11 @@ import com.tencent.bkrepo.common.artifact.router.RouterControllerProperties import com.tencent.bkrepo.common.artifact.util.ClusterUtils.ignoreException import com.tencent.bkrepo.common.artifact.util.ClusterUtils.nodeLevelNotFoundError import com.tencent.bkrepo.common.artifact.util.ClusterUtils.repoLevelNotFoundError +import com.tencent.bkrepo.common.metadata.service.blocknode.BlockNodeService import com.tencent.bkrepo.common.service.cluster.condition.CommitEdgeEdgeCondition import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties import com.tencent.bkrepo.common.storage.core.StorageService import com.tencent.bkrepo.common.stream.event.supplier.MessageSupplier -import com.tencent.bkrepo.fs.server.api.FsNodeClient import com.tencent.bkrepo.repository.config.RepositoryProperties import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.dao.RepositoryDao @@ -89,7 +89,7 @@ class EdgeNodeServiceImpl( override val clusterProperties: ClusterProperties, override val routerControllerClient: RouterControllerClient, override val routerControllerProperties: RouterControllerProperties, - override val fsNodeClient: FsNodeClient, + override val blockNodeService: BlockNodeService, val archiveClient: ArchiveClient, ) : EdgeNodeBaseService( nodeDao, @@ -103,7 +103,7 @@ class EdgeNodeServiceImpl( routerControllerClient, servicePermissionClient, routerControllerProperties, - fsNodeClient, + blockNodeService, clusterProperties, ) { override fun computeSize( diff --git a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt index 614c400906..d7022a6902 100644 --- a/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt +++ b/src/backend/repository/biz-repository/src/test/kotlin/com/tencent/bkrepo/repository/service/ServiceBaseTest.kt @@ -177,8 +177,6 @@ open class ServiceBaseTest { whenever(messageSupplier.delegateToSupplier(any(), anyOrNull(), anyString(), anyOrNull(), any())) .then {} whenever(resourcePermissionListener.handle(any())).then {} - whenever(fsNodeClient.restoreBlockResources(anyString(), anyString(), anyString(), anyString(), anyString())) - .then {} } fun initRepoForUnitTest( diff --git a/src/backend/settings.gradle.kts b/src/backend/settings.gradle.kts index 25925627e1..4d0fae6d4f 100644 --- a/src/backend/settings.gradle.kts +++ b/src/backend/settings.gradle.kts @@ -91,3 +91,4 @@ includeAll(":archive") includeAll(":s3") includeAll(":router-controller") includeAll(":media") +includeAll(":common:common-metadata")