Skip to content

Commit

Permalink
feat: NodeMetadata提取到common-metadata TencentBlueKing#2576
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Sep 26, 2024
1 parent b79129f commit 5584b5a
Show file tree
Hide file tree
Showing 75 changed files with 201 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.job.base
package com.tencent.bkrepo.common.metadata.config

/**
* 仓库后台任务配置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.config
package com.tencent.bkrepo.common.metadata.config

import com.tencent.bkrepo.common.artifact.pojo.RepositoryType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.config
package com.tencent.bkrepo.common.metadata.config

import com.tencent.bkrepo.repository.job.base.RepoJobProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.NestedConfigurationProperty
import org.springframework.context.annotation.Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
* SOFTWARE.
*/

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

import com.tencent.bkrepo.common.api.constant.StringPool
import com.tencent.bkrepo.common.artifact.path.PathUtils
import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.mongo.dao.sharding.HashShardingMongoDao
import com.tencent.bkrepo.common.mongo.dao.util.Pages
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.common.metadata.model.TNode
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import com.tencent.bkrepo.repository.util.NodeQueryHelper
import com.tencent.bkrepo.common.metadata.util.NodeQueryHelper
import org.springframework.context.annotation.Conditional
import org.springframework.data.domain.Page
import org.springframework.data.mongodb.core.FindAndModifyOptions
import org.springframework.data.mongodb.core.query.Query
Expand All @@ -53,6 +55,7 @@ import java.time.LocalDateTime
* 节点 Dao
*/
@Repository
@Conditional(SyncCondition::class)
class NodeDao : HashShardingMongoDao<TNode>() {
/**
* 查询节点
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

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

/**
* 元数据模型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@
* SOFTWARE.
*/

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

import com.tencent.bkrepo.common.api.mongo.ShardingDocument
import com.tencent.bkrepo.common.api.mongo.ShardingKey
import com.tencent.bkrepo.repository.constant.SHARDING_COUNT
import com.tencent.bkrepo.repository.model.TNode.Companion.ARCHIVED_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.ARCHIVED_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.CLUSTER_NAMES_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.CLUSTER_NAMES_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.COMPRESSED_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.COMPRESSED_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.COPY_FROM_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.COPY_FROM_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.FOLDER_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.FOLDER_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.FULL_PATH_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.FULL_PATH_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.METADATA_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.METADATA_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.PATH_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.PATH_IDX_DEF
import com.tencent.bkrepo.repository.model.TNode.Companion.SHA256_IDX
import com.tencent.bkrepo.repository.model.TNode.Companion.SHA256_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.ARCHIVED_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.ARCHIVED_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.CLUSTER_NAMES_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.CLUSTER_NAMES_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.COMPRESSED_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.COMPRESSED_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.COPY_FROM_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.COPY_FROM_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.FOLDER_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.FOLDER_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.FULL_PATH_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.FULL_PATH_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.METADATA_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.METADATA_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.PATH_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.PATH_IDX_DEF
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.SHA256_IDX
import com.tencent.bkrepo.common.metadata.model.TNode.Companion.SHA256_IDX_DEF
import org.springframework.data.mongodb.core.index.CompoundIndex
import org.springframework.data.mongodb.core.index.CompoundIndexes
import java.time.LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

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

import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.repository.service.metadata.impl.center
package com.tencent.bkrepo.common.metadata.service.metadata.impl

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.metadata.util.ClusterUtils
import com.tencent.bkrepo.common.security.manager.ci.CIPermissionManager
import com.tencent.bkrepo.common.service.cluster.condition.CommitEdgeCenterCondition
import com.tencent.bkrepo.repository.config.RepositoryProperties
import com.tencent.bkrepo.repository.dao.NodeDao
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.repository.service.metadata.impl.MetadataServiceImpl
import com.tencent.bkrepo.common.metadata.config.RepositoryProperties
import com.tencent.bkrepo.common.metadata.dao.node.NodeDao
import com.tencent.bkrepo.common.metadata.model.TNode
import org.springframework.context.annotation.Conditional
import org.springframework.stereotype.Service

@Service
@Conditional(CommitEdgeCenterCondition::class)
class CommitEdgeCenterMetadataServiceImpl(
@Conditional(SyncCondition::class, CommitEdgeCenterCondition::class)
class CenterMetadataServiceImpl(
nodeDao: NodeDao,
repositoryProperties: RepositoryProperties,
ciPermissionManager: CIPermissionManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.repository.service.metadata.impl.edge
package com.tencent.bkrepo.common.metadata.service.metadata.impl

import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.metadata.util.ClusterUtils.ignoreException
import com.tencent.bkrepo.common.metadata.util.ClusterUtils.nodeLevelNotFoundError
import com.tencent.bkrepo.common.security.manager.ci.CIPermissionManager
import com.tencent.bkrepo.common.service.cluster.condition.CommitEdgeEdgeCondition
import com.tencent.bkrepo.common.service.cluster.properties.ClusterProperties
import com.tencent.bkrepo.common.service.feign.FeignClientFactory
import com.tencent.bkrepo.repository.api.cluster.ClusterMetadataClient
import com.tencent.bkrepo.repository.config.RepositoryProperties
import com.tencent.bkrepo.repository.dao.NodeDao
import com.tencent.bkrepo.common.metadata.config.RepositoryProperties
import com.tencent.bkrepo.common.metadata.dao.node.NodeDao
import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
import com.tencent.bkrepo.repository.service.metadata.impl.MetadataServiceImpl
import org.springframework.context.annotation.Conditional
import org.springframework.stereotype.Service

@Service
@Conditional(CommitEdgeEdgeCondition::class)
@Conditional(SyncCondition::class, CommitEdgeEdgeCondition::class)
class EdgeMetadataServiceImpl(
nodeDao: NodeDao,
repositoryProperties: RepositoryProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.service.metadata.impl
package com.tencent.bkrepo.common.metadata.service.metadata.impl

import com.tencent.bkrepo.common.api.constant.StringPool
import com.tencent.bkrepo.common.api.exception.ErrorCodeException
Expand All @@ -39,23 +39,24 @@ import com.tencent.bkrepo.common.artifact.constant.PIPELINE
import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException
import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode
import com.tencent.bkrepo.common.artifact.path.PathUtils.normalizeFullPath
import com.tencent.bkrepo.common.metadata.condition.SyncCondition
import com.tencent.bkrepo.common.metadata.util.ClusterUtils
import com.tencent.bkrepo.common.security.exception.PermissionException
import com.tencent.bkrepo.common.security.manager.ci.CIPermissionManager
import com.tencent.bkrepo.common.service.cluster.condition.DefaultCondition
import com.tencent.bkrepo.common.service.util.SpringContextUtils.Companion.publishEvent
import com.tencent.bkrepo.repository.config.RepositoryProperties
import com.tencent.bkrepo.repository.dao.NodeDao
import com.tencent.bkrepo.common.metadata.config.RepositoryProperties
import com.tencent.bkrepo.common.metadata.dao.node.NodeDao
import com.tencent.bkrepo.repository.message.RepositoryMessageCode
import com.tencent.bkrepo.repository.model.TMetadata
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.common.metadata.model.TMetadata
import com.tencent.bkrepo.common.metadata.model.TNode
import com.tencent.bkrepo.common.metadata.service.metadata.MetadataService
import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
import com.tencent.bkrepo.repository.service.metadata.MetadataService
import com.tencent.bkrepo.repository.util.MetadataUtils
import com.tencent.bkrepo.repository.util.NodeEventFactory.buildMetadataDeletedEvent
import com.tencent.bkrepo.repository.util.NodeEventFactory.buildMetadataSavedEvent
import com.tencent.bkrepo.repository.util.NodeQueryHelper
import com.tencent.bkrepo.common.metadata.util.MetadataUtils
import com.tencent.bkrepo.common.metadata.util.NodeEventFactory.buildMetadataDeletedEvent
import com.tencent.bkrepo.common.metadata.util.NodeEventFactory.buildMetadataSavedEvent
import com.tencent.bkrepo.common.metadata.util.NodeQueryHelper
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Conditional
import org.springframework.data.mongodb.core.query.Query
Expand All @@ -69,7 +70,7 @@ import org.springframework.transaction.annotation.Transactional
* 元数据服务实现类
*/
@Service
@Conditional(DefaultCondition::class)
@Conditional(SyncCondition::class, DefaultCondition::class)
class MetadataServiceImpl(
private val nodeDao: NodeDao,
private val repositoryProperties: RepositoryProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* SOFTWARE.
*/

package com.tencent.bkrepo.repository.util
package com.tencent.bkrepo.common.metadata.util

import com.tencent.bkrepo.common.api.exception.ErrorCodeException
import com.tencent.bkrepo.common.artifact.constant.FORBID_STATUS
Expand All @@ -41,7 +41,7 @@ import com.tencent.bkrepo.common.artifact.constant.METADATA_KEY_LINK_REPO
import com.tencent.bkrepo.common.artifact.constant.SCAN_STATUS
import com.tencent.bkrepo.common.security.util.SecurityUtils
import com.tencent.bkrepo.repository.message.RepositoryMessageCode
import com.tencent.bkrepo.repository.model.TMetadata
import com.tencent.bkrepo.common.metadata.model.TMetadata
import com.tencent.bkrepo.repository.pojo.metadata.ForbidType
import com.tencent.bkrepo.repository.pojo.metadata.MetadataModel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.repository.util
package com.tencent.bkrepo.common.metadata.util

import com.tencent.bkrepo.common.artifact.event.metadata.MetadataDeletedEvent
import com.tencent.bkrepo.common.artifact.event.metadata.MetadataSavedEvent
Expand All @@ -35,7 +35,7 @@ import com.tencent.bkrepo.common.artifact.event.node.NodeCreatedEvent
import com.tencent.bkrepo.common.artifact.event.node.NodeDeletedEvent
import com.tencent.bkrepo.common.artifact.event.node.NodeMovedEvent
import com.tencent.bkrepo.common.artifact.event.node.NodeRenamedEvent
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.common.metadata.model.TNode
import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeMoveCopyRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.repository.util
package com.tencent.bkrepo.common.metadata.util

import com.tencent.bkrepo.auth.api.ServicePermissionClient
import com.tencent.bkrepo.common.api.constant.ensureSuffix
import com.tencent.bkrepo.common.api.util.EscapeUtils
import com.tencent.bkrepo.common.artifact.path.PathUtils
import com.tencent.bkrepo.common.artifact.path.PathUtils.escapeRegex
import com.tencent.bkrepo.common.artifact.path.PathUtils.toFullPath
import com.tencent.bkrepo.common.artifact.path.PathUtils.toPath
import com.tencent.bkrepo.common.metadata.constant.FAKE_SHA256
import com.tencent.bkrepo.common.metadata.model.TNode
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.util.MongoEscapeUtils
import com.tencent.bkrepo.repository.model.TNode
import com.tencent.bkrepo.repository.pojo.metadata.MetadataModel
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -93,7 +93,7 @@ object NodeQueryHelper {
Criteria.where(TNode::archived.name).isEqualTo(true),
Criteria.where(TNode::compressed.name).isEqualTo(true),
)
path?.let { criteria.and(TNode::fullPath).regex("^${MongoEscapeUtils.escapeRegex(it)}") }
path?.let { criteria.and(TNode::fullPath).regex("^${EscapeUtils.escapeRegex(it)}") }
val metadataCriteria = metadata.map {
val elemCriteria = Criteria().andOperator(
MetadataModel::key.isEqualTo(it.key),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

package com.tencent.bkrepo.common.query.handler.impl

import com.tencent.bkrepo.common.api.util.EscapeUtils
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.handler.MongoQueryRuleHandler
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.common.query.util.MongoEscapeUtils
import org.springframework.data.mongodb.core.query.Criteria

class MatchHandler : MongoQueryRuleHandler {
Expand All @@ -44,7 +44,7 @@ class MatchHandler : MongoQueryRuleHandler {
}

override fun handle(rule: Rule.QueryRule): Criteria {
val escapedValue = MongoEscapeUtils.escapeRegexExceptWildcard(rule.value.toString())
val escapedValue = EscapeUtils.escapeRegexExceptWildcard(rule.value.toString())
val regexPattern = escapedValue.replace("*", ".*")
return Criteria.where(rule.field).regex("^$regexPattern$")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

package com.tencent.bkrepo.common.query.handler.impl

import com.tencent.bkrepo.common.api.util.EscapeUtils
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.handler.MongoQueryRuleHandler
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.common.query.util.MongoEscapeUtils
import org.springframework.data.mongodb.core.query.Criteria

/**
Expand All @@ -47,7 +47,7 @@ class MatchIHandler : MongoQueryRuleHandler {
}

override fun handle(rule: Rule.QueryRule): Criteria {
val escapedValue = MongoEscapeUtils.escapeRegexExceptWildcard(rule.value.toString())
val escapedValue = EscapeUtils.escapeRegexExceptWildcard(rule.value.toString())
val regexPattern = escapedValue.replace("*", ".*")
return Criteria.where(rule.field).regex("^$regexPattern$", "i")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

package com.tencent.bkrepo.common.query.handler.impl

import com.tencent.bkrepo.common.api.util.EscapeUtils
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.handler.MongoQueryRuleHandler
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.common.query.util.MongoEscapeUtils
import org.springframework.data.mongodb.core.query.Criteria

class PrefixHandler : MongoQueryRuleHandler {
Expand All @@ -44,7 +44,7 @@ class PrefixHandler : MongoQueryRuleHandler {
}

override fun handle(rule: Rule.QueryRule): Criteria {
val escapedValue = MongoEscapeUtils.escapeRegex(rule.value.toString())
val escapedValue = EscapeUtils.escapeRegex(rule.value.toString())
return Criteria.where(rule.field).regex("^$escapedValue")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

package com.tencent.bkrepo.common.query.handler.impl

import com.tencent.bkrepo.common.api.util.EscapeUtils
import com.tencent.bkrepo.common.query.enums.OperationType
import com.tencent.bkrepo.common.query.handler.MongoQueryRuleHandler
import com.tencent.bkrepo.common.query.model.Rule
import com.tencent.bkrepo.common.query.util.MongoEscapeUtils
import org.springframework.data.mongodb.core.query.Criteria

class SuffixHandler : MongoQueryRuleHandler {
Expand All @@ -44,7 +44,7 @@ class SuffixHandler : MongoQueryRuleHandler {
}

override fun handle(rule: Rule.QueryRule): Criteria {
val escapedValue = MongoEscapeUtils.escapeRegex(rule.value.toString())
val escapedValue = EscapeUtils.escapeRegex(rule.value.toString())
return Criteria.where(rule.field).regex("$escapedValue$")
}
}
Loading

0 comments on commit 5584b5a

Please sign in to comment.