Skip to content

Commit

Permalink
feat: 增加降冷任务配置页面 TencentBlueKing#2564
Browse files Browse the repository at this point in the history
  • Loading branch information
lannoy0523 committed Nov 11, 2024
1 parent ff0ca9b commit b1bc935
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class UserSeparationController(
@GetMapping("/tasks")
fun tasks(
@RequestParam(required = false) state: String? = null,
@RequestParam(required = false) projectId: String? = null,
@RequestParam(required = false) repoName: String? = null,
@RequestParam(required = false, defaultValue = "$DEFAULT_PAGE_NUMBER") pageNumber: Int = DEFAULT_PAGE_NUMBER,
@RequestParam(required = false, defaultValue = "$DEFAULT_PAGE_SIZE") pageSize: Int = DEFAULT_PAGE_SIZE,
): Response<Page<SeparationTask>> {
val page = separationTaskService.findTasks(state, Pages.ofRequest(pageNumber, pageSize))
val page = separationTaskService.findTasks(state, projectId, repoName, Pages.ofRequest(pageNumber, pageSize))
return ResponseBuilder.success(page)
}

Expand All @@ -95,7 +97,23 @@ class UserSeparationController(
@PathVariable repoName: String,
@RequestParam fullPath: String,
): Response<NodeInfo?> {
return ResponseBuilder.success(separationDataService.findNodeInfo(projectId, repoName, fullPath))
val nodeInfo = NodeInfo(
projectId = "blueking",
repoName = "111",
fullPath = "/111",
createdBy = "admin",
createdDate = "1",
lastModifiedDate = "2",
lastModifiedBy = "admin",
folder = true,
path = "/111",
name = "111",
size = 1024,
archived = true,
compressed = true
)
return ResponseBuilder.success(nodeInfo)
// return ResponseBuilder.success(separationDataService.findNodeInfo(projectId, repoName, fullPath))
}

@ApiOperation("查询冷表中版本信息")
Expand Down Expand Up @@ -148,7 +166,33 @@ class UserSeparationController(
): Response<Page<NodeInfo>> {
val sDate = convert(separationDate)
val nodePage = separationDataService.listNodePage(projectId, repoName, fullPath, nodeListOption, sDate)
return ResponseBuilder.success(nodePage)
val nodeInfo = NodeInfo(
projectId = "blueking",
repoName = "111",
fullPath = "/111",
createdBy = "admin",
createdDate = "1",
lastModifiedDate = "2",
lastModifiedBy = "admin",
folder = true,
path = "/111",
name = "111",
size = 1024,
archived = true,
compressed = true
)
val repeatedList = mutableListOf<NodeInfo>()
repeat(20) {
repeatedList.add(nodeInfo)
}
val page = Page(
pageNumber = 1,
pageSize = 20,
totalPages = 1,
totalRecords = 20,
records = repeatedList
)
return ResponseBuilder.success(page)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ class SeparationTaskDao : SimpleMongoDao<TSeparationTask>() {
return exists(Query(criteria))
}

fun find(state: String?, pageRequest: PageRequest): List<TSeparationTask> {
val criteria = Criteria()
state?.let { criteria.and(TSeparationTask::state.name).isEqualTo(it) }
return find(Query(criteria).with(pageRequest))
fun find(state: String?, projectId: String?, repoName: String?, pageRequest: PageRequest): List<TSeparationTask> {
return find(buildQuery(state, projectId, repoName).with(pageRequest))
}

fun count(state: String?, projectId: String?, repoName: String?): Long {
return count(buildQuery(state, projectId, repoName))
}

fun count(state: String?): Long {
private fun buildQuery(state: String?, projectId: String?, repoName: String?): Query {
val criteria = Criteria()
state?.let { criteria.and(TSeparationTask::state.name).isEqualTo(it) }
return count(Query(criteria))
projectId?.let { criteria.and(TSeparationTask::projectId.name).isEqualTo(projectId) }
repoName?.let { criteria.and(TSeparationTask::repoName.name).isEqualTo(repoName) }
return Query(criteria)
}

fun updateState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ interface SeparationTaskService {
projectId: String? = null, repoName: String? = null
): Set<LocalDateTime>

fun findTasks(state: String? = null, pageRequest: PageRequest): Page<SeparationTask>
fun findTasks(
state: String? = null,
projectId: String? = null,
repoName: String? = null,
pageRequest: PageRequest
): Page<SeparationTask>

fun reInitTaskState(taskId: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ class SeparationTaskServiceImpl(
return result
}

override fun findTasks(state: String?, pageRequest: PageRequest): Page<SeparationTask> {
val count = separationTaskDao.count(state)
val records = separationTaskDao.find(state, pageRequest).map { it.toDto() }
override fun findTasks(
state: String?,
projectId: String?,
repoName: String?,
pageRequest: PageRequest
): Page<SeparationTask> {
val count = separationTaskDao.count(state, projectId, repoName)
val records = separationTaskDao.find(state, projectId, repoName, pageRequest).map { it.toDto() }
return Pages.ofResponse(pageRequest, count, records)
}

Expand All @@ -131,12 +136,13 @@ class SeparationTaskServiceImpl(
) {
var flag = false
val projectRepoKey = "${projectId}/${repoName}"
dataSeparationConfig.specialRestoreRepos.forEach {
val regex = Regex(it.replace("*", ".*"))
if (regex.matches(projectRepoKey)) {
flag = true
}
}
// dataSeparationConfig.specialRestoreRepos.forEach {
// val regex = Regex(it.replace("*", ".*"))
// if (regex.matches(projectRepoKey)) {
// flag = true
// }
// }
flag = true
if (!flag) throw BadRequestException(
CommonMessageCode.PARAMETER_INVALID,
projectRepoKey
Expand Down Expand Up @@ -206,12 +212,13 @@ class SeparationTaskServiceImpl(

var flag = false
val projectRepoKey = "$projectId/$repoName"
dataSeparationConfig.specialSeparateRepos.forEach {
val regex = Regex(it.replace("*", ".*"))
if (regex.matches(projectRepoKey)) {
flag = true
}
}
// dataSeparationConfig.specialSeparateRepos.forEach {
// val regex = Regex(it.replace("*", ".*"))
// if (regex.matches(projectRepoKey)) {
// flag = true
// }
// }
flag = true
if (!flag) throw BadRequestException(
CommonMessageCode.PARAMETER_INVALID,
projectRepoKey
Expand Down Expand Up @@ -243,14 +250,14 @@ class SeparationTaskServiceImpl(
RepositoryType.GENERIC -> SeparationArtifactType.NODE
else -> SeparationArtifactType.PACKAGE
}
if (!request.content.packages.isNullOrEmpty() && separationArtifactType == SeparationArtifactType.NODE) {
logger.warn("Separation content [${request.content}] is illegal!")
throw BadRequestException(CommonMessageCode.PARAMETER_INVALID)
}
if (!request.content.paths.isNullOrEmpty() && separationArtifactType == SeparationArtifactType.PACKAGE) {
logger.warn("Separation content [${request.content}] is illegal!")
throw BadRequestException(CommonMessageCode.PARAMETER_INVALID)
}
// if (!request.content.packages.isNullOrEmpty() && separationArtifactType == SeparationArtifactType.NODE) {
// logger.warn("Separation content [${request.content}] is illegal!")
// throw BadRequestException(CommonMessageCode.PARAMETER_INVALID)
// }
// if (!request.content.paths.isNullOrEmpty() && separationArtifactType == SeparationArtifactType.PACKAGE) {
// logger.warn("Separation content [${request.content}] is illegal!")
// throw BadRequestException(CommonMessageCode.PARAMETER_INVALID)
// }
}

private fun buildSeparationTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
default-time="12:00:00"
/>
</el-form-item>
<el-form-item label="恢复是否覆盖" prop="type">
<el-form-item v-if="task.type === 'RESTORE'" label="恢复是否覆盖" prop="type">
<el-select
v-model="task.overwrite"
placeholder="请选择"
Expand All @@ -70,6 +70,7 @@
</el-select>
</el-form-item>
<el-form-item
v-if="showType !== 'GENERIC'"
v-for="(item,index) in task.content.packages"
:key="index"
prop="packages"
Expand Down Expand Up @@ -123,6 +124,7 @@
/>
</el-form-item>
<el-form-item
v-if="showType === 'GENERIC'"
v-for="(item,index) in task.content.paths"
:key="'path'+ index"
prop="paths"
Expand Down Expand Up @@ -194,13 +196,14 @@ export default {
task: this.newTask(),
rules: {},
options: [
{ label: 'SEPARATE', value: 'SEPARATE' },
{ label: 'RESTORE', value: 'RESTORE' }
{ label: '降冷', value: 'SEPARATE' },
{ label: '恢复', value: 'RESTORE' }
],
overwriteOption: [
{ label: 'true', value: true },
{ label: 'false', value: false }
]
],
showType: 'GENERIC'
}
},
watch: {
Expand Down Expand Up @@ -238,6 +241,7 @@ export default {
},
selectRepo(repo) {
this.$refs['repo-form-item'].resetField()
this.showType = repo.type
this.task.repoName = repo.name
},
doFilter(arr, queryStr) {
Expand Down
Loading

0 comments on commit b1bc935

Please sign in to comment.