Skip to content

Commit

Permalink
feat: Node提取到common-metadata #2619
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan committed Oct 15, 2024
1 parent 0dcf5b9 commit 87e13d6
Show file tree
Hide file tree
Showing 42 changed files with 2,084 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ class ArtifactPreloadPlanServiceImplTest @Autowired constructor(
@Test
fun testCreatePlan() {
val node = NodeDetail(buildNodeInfo(UT_PROJECT_ID, UT_REPO_NAME))
whenever(nodeClient.getNodeDetail(anyString(), anyString(), anyString())).thenReturn(
Response(0, data = node)
)
whenever(nodeService.getNodeDetail(any(), anyOrNull())).thenReturn(node)
val executeTime = System.currentTimeMillis()
val request = ArtifactPreloadPlanCreateRequest(
projectId = UT_PROJECT_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.tencent.bkrepo.common.metadata.client

import com.tencent.bkrepo.auth.pojo.oauth.AuthorizationGrantType
import com.tencent.bkrepo.auth.pojo.permission.CheckPermissionRequest
import com.tencent.bkrepo.auth.pojo.permission.ListPathResult
import com.tencent.bkrepo.auth.pojo.user.CreateUserRequest
import com.tencent.bkrepo.auth.pojo.user.CreateUserToProjectRequest
import com.tencent.bkrepo.auth.pojo.user.User
Expand Down Expand Up @@ -113,6 +114,16 @@ interface RAuthClient {
@RequestParam userId: String
): Mono<Response<List<String>>>

@GetMapping("/permission/path/list")
fun listPermissionPath(
@ApiParam(value = "用户ID")
@RequestParam userId: String,
@ApiParam(value = "项目ID")
@RequestParam projectId: String,
@ApiParam(value = "仓库名称")
@RequestParam repoName: String
): Mono<Response<ListPathResult>>

@PostMapping("/bkiamv3/rbac/group/check")
fun getExistRbacDefaultGroupProjectIds(
@ApiParam(value = "项目ID列表")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@
package com.tencent.bkrepo.common.metadata.client

import com.tencent.bkrepo.common.api.constant.REPOSITORY_SERVICE_NAME
import com.tencent.bkrepo.common.api.pojo.Page
import com.tencent.bkrepo.common.api.pojo.Response
import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest
import com.tencent.bkrepo.repository.pojo.node.NodeDeleteResult
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import com.tencent.bkrepo.repository.pojo.node.NodeInfo
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import com.tencent.bkrepo.repository.pojo.node.NodeSizeInfo
import com.tencent.bkrepo.repository.pojo.node.service.NodeCreateRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeDeleteRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeLinkRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeRenameRequest
import com.tencent.bkrepo.repository.pojo.repo.RepositoryDetail
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
Expand All @@ -55,48 +43,6 @@ import reactor.core.publisher.Mono
@RequestMapping("/service")
interface RRepositoryClient {

@GetMapping("/node/detail/{projectId}/{repoName}")
fun getNodeDetail(
@PathVariable projectId: String,
@PathVariable repoName: String,
@RequestParam fullPath: String
): Mono<Response<NodeDetail?>>

@PostMapping("/node/page/{projectId}/{repoName}")
fun listNodePage(
@PathVariable projectId: String,
@PathVariable repoName: String,
@RequestParam path: String,
@RequestBody option: NodeListOption = NodeListOption()
): Mono<Response<Page<NodeInfo>>>

@DeleteMapping("/node/delete")
fun deleteNode(@RequestBody nodeDeleteRequest: NodeDeleteRequest): Mono<Response<NodeDeleteResult>>

@PostMapping("/node/rename")
fun renameNode(@RequestBody nodeRenameRequest: NodeRenameRequest): Mono<Response<Void>>

@PostMapping("/node/create")
fun createNode(@RequestBody nodeCreateRequest: NodeCreateRequest): Mono<Response<NodeDetail>>

@GetMapping("/node/size/{projectId}/{repoName}")
fun computeSize(
@PathVariable projectId: String,
@PathVariable repoName: String,
@RequestParam fullPath: String,
@RequestParam estimated: Boolean = false
): Mono<Response<NodeSizeInfo>>

@PostMapping("/node/link")
fun link(@RequestBody nodeLinkRequest: NodeLinkRequest): Mono<Response<NodeDetail>>

@GetMapping("/repo/detail/{projectId}/{repoName}")
fun getRepoDetail(
@PathVariable projectId: String,
@PathVariable repoName: String,
@RequestParam type: String? = null
): Mono<Response<RepositoryDetail?>>

@PostMapping("/metadata/save")
fun saveMetadata(@RequestBody request: MetadataSaveRequest): Mono<Response<Void>>

Expand All @@ -107,9 +53,4 @@ interface RRepositoryClient {
@RequestParam fullPath: String
): Mono<Response<Map<String, Any>>>

@GetMapping("/repo/stat/{projectId}/{repoName}")
fun statRepo(
@PathVariable projectId: String,
@PathVariable repoName: String,
): Mono<Response<NodeSizeInfo>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

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

import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException
import com.tencent.bkrepo.common.artifact.stream.Range
import com.tencent.bkrepo.common.metadata.condition.ReactiveCondition
import com.tencent.bkrepo.common.metadata.constant.FAKE_SHA256
import com.tencent.bkrepo.common.metadata.constant.ID
import com.tencent.bkrepo.common.metadata.dao.blocknode.RBlockNodeDao
import com.tencent.bkrepo.common.metadata.dao.node.RNodeDao
import com.tencent.bkrepo.common.metadata.model.TBlockNode
import com.tencent.bkrepo.common.metadata.service.blocknode.RBlockNodeService
import com.tencent.bkrepo.common.metadata.service.file.RFileReferenceService
Expand All @@ -39,15 +42,20 @@ import com.tencent.bkrepo.common.storage.credentials.StorageCredentials
import com.tencent.bkrepo.common.storage.pojo.RegionResource
import com.tencent.bkrepo.repository.pojo.node.NodeDetail
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Conditional
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Query
import org.springframework.data.mongodb.core.query.and
import org.springframework.data.mongodb.core.query.isEqualTo
import org.springframework.stereotype.Service
import java.time.LocalDateTime

abstract class RAbstractBlockNodeService(
@Service
@Conditional(ReactiveCondition::class)
class RBlockNodeServiceImpl(
private val rBlockNodeDao: RBlockNodeDao,
private val rFileReferenceService: RFileReferenceService
private val rFileReferenceService: RFileReferenceService,
private val rNodeDao: RNodeDao
) : RBlockNodeService {

override suspend fun createBlock(blockNode: TBlockNode, storageCredentials: StorageCredentials?): TBlockNode {
Expand Down Expand Up @@ -82,7 +90,7 @@ abstract class RAbstractBlockNodeService(
}

override suspend fun moveBlocks(projectId: String, repoName: String, fullPath: String, dstFullPath: String) {
val nodeDetail = getNodeDetail(projectId, repoName, dstFullPath)
val nodeDetail = rNodeDao.findNode(projectId, repoName, dstFullPath) ?: throw NodeNotFoundException(dstFullPath)
if (nodeDetail.folder) {
val criteria = BlockNodeQueryHelper.fullPathCriteria(projectId, repoName, fullPath, true)
val blocks = rBlockNodeDao.find(Query(criteria))
Expand Down Expand Up @@ -133,9 +141,7 @@ abstract class RAbstractBlockNodeService(
}
}

abstract suspend fun getNodeDetail(projectId: String, repoName: String, fullPath: String): NodeDetail

companion object {
private val logger = LoggerFactory.getLogger(RAbstractBlockNodeService::class.java)
private val logger = LoggerFactory.getLogger(RBlockNodeService::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ import com.tencent.bkrepo.common.metadata.constant.FAKE_SHA256
import com.tencent.bkrepo.common.metadata.dao.node.RNodeDao
import com.tencent.bkrepo.common.metadata.model.TNode
import com.tencent.bkrepo.common.metadata.service.fs.FsService
import com.tencent.bkrepo.common.metadata.service.node.impl.NodeBaseService
import com.tencent.bkrepo.common.metadata.util.MetadataUtils
import com.tencent.bkrepo.common.metadata.util.NodeBaseServiceHelper.convertToDetail
import com.tencent.bkrepo.common.metadata.util.NodeBaseServiceHelper.parseExpireDate
import com.tencent.bkrepo.common.metadata.util.NodeEventFactory
import com.tencent.bkrepo.common.metadata.util.NodeQueryHelper
import com.tencent.bkrepo.common.service.util.SpringContextUtils
Expand Down Expand Up @@ -71,7 +72,7 @@ class FsServiceImpl(
}
SpringContextUtils.publishEvent(NodeEventFactory.buildCreatedEvent(node))
logger.info("Create node[/$projectId/$repoName$fullPath], sha256[$sha256] success.")
return NodeBaseService.convertToDetail(node)!!
return convertToDetail(node)!!
}
}

Expand All @@ -85,7 +86,7 @@ class FsServiceImpl(
name = PathUtils.resolveName(fullPath),
fullPath = fullPath,
folder = folder,
expireDate = if (folder) null else NodeBaseService.parseExpireDate(expires),
expireDate = if (folder) null else parseExpireDate(expires),
size = if (folder) 0 else size ?: 0,
sha256 = if (folder) null else sha256,
md5 = if (folder) null else md5,
Expand Down
Loading

0 comments on commit 87e13d6

Please sign in to comment.