From e59d04fe65735f10375f3cfb0dfb103de4c5418b Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Mon, 22 Jul 2024 19:55:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20fs-server=E7=A7=BB=E9=99=A4=E5=AF=B9gen?= =?UTF-8?q?eric=20remote=E4=BB=93=E5=BA=93=E7=9A=84=E6=94=AF=E6=8C=81=20#2?= =?UTF-8?q?411?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/fs/server/api/NodeClient.kt | 115 ------------------ .../server/handler/NodeOperationsHandler.kt | 35 +++--- .../bkrepo/generic/api/GenericClient.kt | 61 ---------- .../service/ServiceGenericController.kt | 70 ----------- 4 files changed, 15 insertions(+), 266 deletions(-) delete mode 100644 src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/NodeClient.kt delete mode 100644 src/backend/generic/api-generic/src/main/kotlin/com/tencent/bkrepo/generic/api/GenericClient.kt delete mode 100644 src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/controller/service/ServiceGenericController.kt diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/NodeClient.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/NodeClient.kt deleted file mode 100644 index 39a9392ec6..0000000000 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/api/NodeClient.kt +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2023 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.api - -import com.tencent.bkrepo.common.api.constant.ensureSuffix -import com.tencent.bkrepo.common.artifact.pojo.RepositoryCategory -import com.tencent.bkrepo.common.artifact.pojo.RepositoryType -import com.tencent.bkrepo.common.artifact.pojo.configuration.composite.CompositeConfiguration -import com.tencent.bkrepo.fs.server.context.ReactiveArtifactContextHolder -import com.tencent.bkrepo.fs.server.model.Node -import com.tencent.bkrepo.fs.server.toNode -import com.tencent.bkrepo.repository.pojo.node.NodeDetail -import com.tencent.bkrepo.repository.pojo.node.NodeListOption -import com.tencent.bkrepo.repository.pojo.repo.RepositoryDetail -import com.tencent.bkrepo.repository.pojo.search.NodeQueryBuilder -import kotlinx.coroutines.reactor.awaitSingle -import kotlin.reflect.full.declaredMemberProperties - -class NodeClient( - private val repositoryClient: RRepositoryClient, - private val genericClient: RGenericClient, -) { - - suspend fun getNodeDetail( - projectId: String, - repo: RepositoryDetail, - fullPath: String, - category: String, - ): NodeDetail? { - return if (category == RepositoryCategory.LOCAL.name) { - repositoryClient.getNodeDetail( - projectId = projectId, - repoName = repo.name, - fullPath = fullPath - ).awaitSingle().data - } else if (repo.type == RepositoryType.GENERIC) { - genericClient.getNodeDetail( - projectId = projectId, - repoName = repo.name, - fullPath = fullPath - ).awaitSingle().data - } else { - null - } - } - - - suspend fun listNodes( - projectId: String, - repo: RepositoryDetail, - path: String, - option: NodeListOption - ): List? { - val nodes = if (ReactiveArtifactContextHolder.getRepoDetail().isLocalRepo()) { - repositoryClient.listNodePage( - path = path, - projectId = projectId, - repoName = repo.name, - option = option - ).awaitSingle().data?.records?.map { it.toNode() }?.toList() - } else if (repo.type == RepositoryType.GENERIC) { - val builder = NodeQueryBuilder() - .page(option.pageNumber, option.pageSize) - .select(*select) - .projectId(projectId) - .repoName(repo.name) - .path(path.ensureSuffix("/")) - if (!option.includeFolder) { - builder.excludeFolder() - } - return genericClient.search(projectId, repo.name, builder.build()).awaitSingle().data - ?.map { (it as Map).toNode() } - ?.toList() - ?.filterNotNull() - } else { - null - } - return nodes - } - - private fun RepositoryDetail.isLocalRepo(): Boolean { - val repoConfiguration = configuration - return category == RepositoryCategory.LOCAL || - repoConfiguration is CompositeConfiguration && repoConfiguration.proxy.channelList.isEmpty() - } - - companion object { - private val select = Node::class.declaredMemberProperties.map { it.name }.toTypedArray() - } -} diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/NodeOperationsHandler.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/NodeOperationsHandler.kt index ea9686cefa..7d2f8519ae 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/NodeOperationsHandler.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/handler/NodeOperationsHandler.kt @@ -31,7 +31,6 @@ import com.github.benmanes.caffeine.cache.Caffeine import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.api.message.CommonMessageCode import com.tencent.bkrepo.common.storage.core.overlay.OverlayRangeUtils -import com.tencent.bkrepo.fs.server.api.NodeClient import com.tencent.bkrepo.fs.server.api.RGenericClient import com.tencent.bkrepo.fs.server.api.RRepositoryClient import com.tencent.bkrepo.fs.server.constant.FAKE_MD5 @@ -81,32 +80,29 @@ class NodeOperationsHandler( private val rRepositoryClient: RRepositoryClient, private val fileNodeService: FileNodeService ) { - private val nodeClient = NodeClient(rRepositoryClient, rGenericClient) suspend fun getNode(request: ServerRequest): ServerResponse { with(NodeRequest(request)) { - val nodeDetail = nodeClient.getNodeDetail( + val nodeDetail = rRepositoryClient.getNodeDetail( projectId = projectId, - repo = ReactiveArtifactContextHolder.getRepoDetail(), - fullPath = fullPath, - category = category - ) - return nodeDetail - ?.let { ReactiveResponseBuilder.success(it.nodeInfo.toNode()) } - ?: ServerResponse.notFound().buildAndAwait() + repoName = repoName, + fullPath = fullPath + ).awaitSingle().data ?: return ServerResponse.notFound().buildAndAwait() + return ReactiveResponseBuilder.success(nodeDetail.nodeInfo.toNode()) } } suspend fun listNodes(request: ServerRequest): ServerResponse { val pageRequest = NodePageRequest(request) with(pageRequest) { - val nodes = nodeClient.listNodes( - projectId = projectId, - repo = ReactiveArtifactContextHolder.getRepoDetail(), + val nodes = rRepositoryClient.listNodePage( path = fullPath, + projectId = projectId, + repoName = repoName, option = listOption - ) - return nodes?.let { ReactiveResponseBuilder.success(it) } ?: ServerResponse.notFound().buildAndAwait() + ).awaitSingle().data?.records?.map { it.toNode() }?.toList() + ?: return ServerResponse.notFound().buildAndAwait() + return ReactiveResponseBuilder.success(nodes) } } @@ -226,12 +222,11 @@ class NodeOperationsHandler( suspend fun info(request: ServerRequest): ServerResponse { with(NodeRequest(request)) { - val nodeDetail = nodeClient.getNodeDetail( + val nodeDetail = rRepositoryClient.getNodeDetail( projectId = projectId, - repo = ReactiveArtifactContextHolder.getRepoDetail(), - fullPath = fullPath, - category = category - ) ?: return ServerResponse.notFound().buildAndAwait() + repoName = repoName, + fullPath = fullPath + ).awaitSingle().data ?: return ServerResponse.notFound().buildAndAwait() val range = try { request.resolveRange(nodeDetail.size) } catch (e: IllegalArgumentException) { diff --git a/src/backend/generic/api-generic/src/main/kotlin/com/tencent/bkrepo/generic/api/GenericClient.kt b/src/backend/generic/api-generic/src/main/kotlin/com/tencent/bkrepo/generic/api/GenericClient.kt deleted file mode 100644 index 2657bc12ea..0000000000 --- a/src/backend/generic/api-generic/src/main/kotlin/com/tencent/bkrepo/generic/api/GenericClient.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2023 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.generic.api - -import com.tencent.bkrepo.common.api.constant.GENERIC_SERVICE_NAME -import com.tencent.bkrepo.common.api.pojo.Response -import com.tencent.bkrepo.common.query.model.QueryModel -import com.tencent.bkrepo.repository.pojo.node.NodeDetail -import io.swagger.annotations.Api -import org.springframework.cloud.openfeign.FeignClient -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RequestParam - -@Api("节点服务接口") -@FeignClient(GENERIC_SERVICE_NAME, contextId = "GenericClient", primary = false) -@RequestMapping("/service") -interface GenericClient { - - @GetMapping("/detail/{projectId}/{repoName}") - fun getNodeDetail( - @PathVariable projectId: String, - @PathVariable repoName: String, - @RequestParam fullPath: String - ): Response - - @PostMapping("/{projectId}/{repoName}/search") - fun search( - @PathVariable("projectId") projectId: String, - @PathVariable("repoName") repoName: String, - @RequestBody queryModel: QueryModel - ): Response> -} diff --git a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/controller/service/ServiceGenericController.kt b/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/controller/service/ServiceGenericController.kt deleted file mode 100644 index 75e572a0c5..0000000000 --- a/src/backend/generic/biz-generic/src/main/kotlin/com/tencent/bkrepo/generic/controller/service/ServiceGenericController.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. - * - * Copyright (C) 2023 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.generic.controller.service - -import com.tencent.bkrepo.common.api.pojo.Response -import com.tencent.bkrepo.common.artifact.api.ArtifactInfo -import com.tencent.bkrepo.common.artifact.constant.ARTIFACT_INFO_KEY -import com.tencent.bkrepo.common.artifact.repository.context.ArtifactContextHolder -import com.tencent.bkrepo.common.query.model.QueryModel -import com.tencent.bkrepo.common.service.util.HttpContextHolder -import com.tencent.bkrepo.common.service.util.ResponseBuilder -import com.tencent.bkrepo.generic.api.GenericClient -import com.tencent.bkrepo.generic.artifact.GenericArtifactInfo -import com.tencent.bkrepo.generic.service.DownloadService -import com.tencent.bkrepo.repository.pojo.node.NodeDetail -import org.springframework.context.annotation.Primary -import org.springframework.web.bind.annotation.RestController - -@Primary -@RestController -class ServiceGenericController( - private val downloadService: DownloadService, -) : GenericClient { - override fun getNodeDetail(projectId: String, repoName: String, fullPath: String): Response { - prepareRepo(projectId, repoName) - val nodeDetail = downloadService.query(GenericArtifactInfo(projectId, repoName, fullPath)) - return if (nodeDetail is NodeDetail) { - ResponseBuilder.success(nodeDetail) - } else { - ResponseBuilder.success(null) - } - } - - override fun search(projectId: String, repoName: String, queryModel: QueryModel): Response> { - prepareRepo(projectId, repoName) - return ResponseBuilder.success(downloadService.search(queryModel)) - } - - private fun prepareRepo(projectId: String, repoName: String) { - // 设置artifact,避免创建context失败 - HttpContextHolder.getRequest().setAttribute(ARTIFACT_INFO_KEY, ArtifactInfo(projectId, repoName, "")) - // 填充repo缓存,避免创建context失败 - ArtifactContextHolder.getRepoDetail() - } -}