forked from TencentBlueKing/bk-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blockNode抽取至公共模块 TencentBlueKing#2413
- Loading branch information
Showing
18 changed files
with
311 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...service/src/main/kotlin/com/tencent/bkrepo/common/metadata/condition/ReactiveCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.tencent.bkrepo.common.metadata.condition | ||
|
||
import org.springframework.context.annotation.Condition | ||
import org.springframework.context.annotation.ConditionContext | ||
import org.springframework.core.type.AnnotatedTypeMetadata | ||
|
||
class ReactiveCondition : Condition { | ||
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean { | ||
try { | ||
context.classLoader?.loadClass("com.mongodb.reactivestreams.client.MongoClient") | ||
return true | ||
} catch (e: ClassNotFoundException) { | ||
return false | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/condition/SyncCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.tencent.bkrepo.common.metadata.condition | ||
|
||
import org.springframework.context.annotation.Condition | ||
import org.springframework.context.annotation.ConditionContext | ||
import org.springframework.core.type.AnnotatedTypeMetadata | ||
|
||
class SyncCondition : Condition { | ||
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean { | ||
try { | ||
context.classLoader?.loadClass("com.mongodb.client.MongoClient") | ||
return true | ||
} catch (e: ClassNotFoundException) { | ||
return false | ||
} | ||
} | ||
} |
34 changes: 5 additions & 29 deletions
34
...a/metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/BlockNodeDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,11 @@ | ||
/* | ||
* 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.condition.SyncCondition | ||
import com.tencent.bkrepo.common.metadata.model.TBlockNode | ||
import com.tencent.bkrepo.common.mongo.dao.sharding.HashShardingMongoDao | ||
import org.springframework.context.annotation.Conditional | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class BlockNodeDao : ShardingMongoReactiveDao<TBlockNode>() | ||
@Conditional(SyncCondition::class) | ||
class BlockNodeDao : HashShardingMongoDao<TBlockNode>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../metadata-service/src/main/kotlin/com/tencent/bkrepo/common/metadata/dao/RBlockNodeDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
package com.tencent.bkrepo.common.metadata.dao | ||
|
||
import com.tencent.bkrepo.common.metadata.condition.ReactiveCondition | ||
import com.tencent.bkrepo.common.metadata.model.TBlockNode | ||
import com.tencent.bkrepo.common.mongo.reactive.dao.ShardingMongoReactiveDao | ||
import org.springframework.context.annotation.Conditional | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
@Conditional(ReactiveCondition::class) | ||
class RBlockNodeDao : ShardingMongoReactiveDao<TBlockNode>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...src/main/kotlin/com/tencent/bkrepo/common/metadata/service/blocknode/RBlockNodeService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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 java.time.LocalDateTime | ||
|
||
interface RBlockNodeService { | ||
/** | ||
* 查询出范围内的分块 | ||
* */ | ||
suspend fun listBlocks( | ||
range: Range, | ||
projectId: String, | ||
repoName: String, | ||
fullPath: String, | ||
createdDate: String | ||
): List<TBlockNode> | ||
|
||
/** | ||
* 创建分块 | ||
* */ | ||
suspend fun createBlock( | ||
blockNode: TBlockNode, | ||
storageCredentials: StorageCredentials? | ||
): TBlockNode | ||
|
||
/** | ||
* 删除旧分块,即删除非指定的nodeCurrentSha256的分块。 | ||
* 如果未指定nodeCurrentSha256,则删除节点所有分块 | ||
* @param projectId 项目id | ||
* @param repoName 仓库名 | ||
* @param fullPath 文件路径 | ||
* */ | ||
suspend fun deleteBlocks( | ||
projectId: String, | ||
repoName: String, | ||
fullPath: String | ||
) | ||
|
||
/** | ||
* 移动文件对应分块 | ||
*/ | ||
suspend fun moveBlocks( | ||
projectId: String, | ||
repoName: String, | ||
fullPath: String, | ||
dstFullPath: String | ||
) | ||
|
||
/** | ||
* 恢复文件对应分块 | ||
*/ | ||
suspend fun restoreBlocks( | ||
projectId: String, | ||
repoName: String, | ||
fullPath: String, | ||
nodeCreateDate: LocalDateTime, | ||
nodeDeleteDate: LocalDateTime | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.