diff --git a/docs/apidoc/node/node.md b/docs/apidoc/node/node.md index 4b8d6bf47c..c4dce57d0e 100644 --- a/docs/apidoc/node/node.md +++ b/docs/apidoc/node/node.md @@ -636,16 +636,16 @@ | packages | Int | 节点数量 | node count | -## 清理创建时间早于{date}的文件节点 +## 清理最后修改时间早于{date}的文件节点 - API: DELETE /repository/api/node/clean/{projectId}/{repoName}?date=yyyy-MM-dd'T'HH:mm:ss.SSSXXX -- API 名称: delete_node_created_before_date +- API 名称: delete_node_last_modified_before_date - 功能说明: - - 中文:清理创建时间早于{date}的文件节点 - - English:delete node created before date + - 中文:清理最后修改时间早于{date}的文件节点 + - English:delete node last modified before date - 请求体 此接口请求体为空 diff --git a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/api/NodeClient.kt b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/api/NodeClient.kt index 5a25d11333..6dbf3b95f5 100644 --- a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/api/NodeClient.kt +++ b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/api/NodeClient.kt @@ -41,6 +41,7 @@ import com.tencent.bkrepo.repository.pojo.node.NodeInfo import com.tencent.bkrepo.repository.pojo.node.NodeListOption import com.tencent.bkrepo.repository.pojo.node.NodeRestoreResult import com.tencent.bkrepo.repository.pojo.node.NodeSizeInfo +import com.tencent.bkrepo.repository.pojo.node.service.NodeCleanRequest 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.NodeMoveCopyRequest @@ -204,4 +205,8 @@ interface NodeClient { ): Response + + @ApiOperation("清理最后修改时间早于{date}的文件节点") + @DeleteMapping("/clean") + fun cleanNodes(@RequestBody nodeCleanRequest: NodeCleanRequest): Response } diff --git a/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/node/service/NodeCleanRequest.kt b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/node/service/NodeCleanRequest.kt new file mode 100644 index 0000000000..e4492a0302 --- /dev/null +++ b/src/backend/repository/api-repository/src/main/kotlin/com/tencent/bkrepo/repository/pojo/node/service/NodeCleanRequest.kt @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2022 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.repository.pojo.node.service + +import com.tencent.bkrepo.repository.pojo.ServiceRequest +import io.swagger.annotations.ApiModelProperty +import java.time.LocalDateTime + +data class NodeCleanRequest( + @ApiModelProperty("所属项目", required = true) + val projectId: String, + @ApiModelProperty("仓库名称", required = true) + val repoName: String, + @ApiModelProperty("清理目录", required = true) + val path: String, + @ApiModelProperty("时间条件", required = true) + val date: LocalDateTime, + @ApiModelProperty("操作用户", required = true) + override val operator: String +): ServiceRequest diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/service/NodeController.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/service/NodeController.kt index c954cf223c..803d608fb3 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/service/NodeController.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/service/NodeController.kt @@ -43,6 +43,7 @@ import com.tencent.bkrepo.repository.pojo.node.NodeInfo import com.tencent.bkrepo.repository.pojo.node.NodeListOption import com.tencent.bkrepo.repository.pojo.node.NodeRestoreResult import com.tencent.bkrepo.repository.pojo.node.NodeSizeInfo +import com.tencent.bkrepo.repository.pojo.node.service.NodeCleanRequest 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.NodeMoveCopyRequest @@ -184,4 +185,14 @@ class NodeController( ): Response { return ResponseBuilder.success(nodeService.getDeletedNodeDetailBySha256(projectId, repoName, sha256)) } + + override fun cleanNodes(nodeCleanRequest: NodeCleanRequest): Response { + return ResponseBuilder.success(nodeService.deleteBeforeDate( + projectId = nodeCleanRequest.projectId, + repoName = nodeCleanRequest.repoName, + path = nodeCleanRequest.path, + date = nodeCleanRequest.date, + operator = nodeCleanRequest.operator + )) + } } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt index b6c3f5c154..031b28c605 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt @@ -181,10 +181,10 @@ class UserNodeController( return ResponseBuilder.success(nodeService.countDeleteNodes(nodesDeleteRequest)) } - @ApiOperation("清理创建时间早于{date}的文件节点") + @ApiOperation("清理最后修改时间早于{date}的文件节点") @Permission(type = ResourceType.NODE, action = PermissionAction.DELETE) @DeleteMapping("/clean/$DEFAULT_MAPPING_URI") - fun deleteNodeCreatedBeforeDate( + fun deleteNodeLastModifiedBeforeDate( @RequestAttribute userId: String, @ArtifactPathVariable artifactInfo: ArtifactInfo, @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) date: LocalDateTime diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt index 2383d62ca7..41b099cc81 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt @@ -67,7 +67,7 @@ interface NodeDeleteOperation { fun deleteByPaths(projectId: String, repoName: String, fullPaths: List, operator: String): NodeDeleteResult /** - * 根据创建时间删除[date]之前的历史数据 + * 根据最后修改时间删除[date]之前的历史数据 */ fun deleteBeforeDate( projectId: String, repoName: String, diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt index 36a0a600aa..d24513c464 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt @@ -161,7 +161,7 @@ open class NodeDeleteSupport( ): NodeDeleteResult { val option = NodeListOption(includeFolder = false, deep = true) val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, path, option) - .and(TNode::createdDate).lt(date) + .and(TNode::lastModifiedDate).lt(date) val query = Query(criteria) return delete(query, operator, criteria, projectId, repoName) }