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 5, 2024
1 parent fe9b542 commit 282ea12
Show file tree
Hide file tree
Showing 22 changed files with 289 additions and 186 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.reactive.dao
package com.tencent.bkrepo.common.api.mongo

/**
* 分表字段
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.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
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
@@ -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.service.blocknode

import com.tencent.bkrepo.common.artifact.stream.Range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,20 @@

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.metadata.util.BlockNodeQueryHelper
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(
Expand All @@ -67,16 +63,7 @@ abstract class AbstractBlockNodeService(
fullPath: String,
createdDate: String
): List<TBlockNode> {
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))
val query = BlockNodeQueryHelper.listQuery(projectId, repoName, fullPath, createdDate, range)
return blockNodeDao.find(query)
}

Expand All @@ -85,34 +72,25 @@ abstract class AbstractBlockNodeService(
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())
val criteria = BlockNodeQueryHelper.fullPathCriteria(projectId, repoName, fullPath, false)
val update = BlockNodeQueryHelper.deleteUpdate()
blockNodeDao.updateMulti(Query(criteria), update)
logger.info("Delete node blocks[$projectId/$repoName$fullPath] success.")
}

override 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 criteria = BlockNodeQueryHelper.fullPathCriteria(projectId, repoName, fullPath, true)
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)
val criteria = BlockNodeQueryHelper.fullPathCriteria(projectId, repoName, fullPath, false)
val update = BlockNodeQueryHelper.moveUpdate(dstFullPath)
blockNodeDao.updateMulti(Query(criteria), update)
}
logger.info("Move node[$projectId/$repoName$fullPath] to node[$projectId/$repoName$dstFullPath] success.")
Expand All @@ -127,11 +105,9 @@ abstract class AbstractBlockNodeService(
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 criteria =
BlockNodeQueryHelper.deletedCriteria(projectId, repoName, fullPath, nodeCreateDate, nodeDeleteDate)
val update = BlockNodeQueryHelper.restoreUpdate()
val result = blockNodeDao.updateMulti(Query(criteria), update)
logger.info("Restore ${result.modifiedCount} blocks node[$projectId/$repoName$fullPath] " +
"between $nodeCreateDate and $nodeDeleteDate success.")
Expand Down
Loading

0 comments on commit 282ea12

Please sign in to comment.