forked from TencentBlueKing/bk-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request TencentBlueKing#1025 from lannoy0523/issue_1020
feat:admin后台新增仓库大小统计 TencentBlueKing#1020
- Loading branch information
Showing
7 changed files
with
340 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
.../opdata/api-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/pojo/ProjectMetricsOption.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.opdata.pojo | ||
|
||
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_NUMBER | ||
import com.tencent.bkrepo.common.api.constant.DEFAULT_PAGE_SIZE | ||
|
||
data class ProjectMetricsOption( | ||
var projectId: String? = null, | ||
val pageNumber: Int = DEFAULT_PAGE_NUMBER, | ||
val pageSize: Int = DEFAULT_PAGE_SIZE | ||
) |
58 changes: 58 additions & 0 deletions
58
...data/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/controller/ProjectController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.opdata.controller | ||
|
||
import com.tencent.bkrepo.common.api.pojo.Page | ||
import com.tencent.bkrepo.common.api.pojo.Response | ||
import com.tencent.bkrepo.common.security.permission.Principal | ||
import com.tencent.bkrepo.common.security.permission.PrincipalType | ||
import com.tencent.bkrepo.common.service.util.ResponseBuilder | ||
import com.tencent.bkrepo.opdata.model.TProjectMetrics | ||
import com.tencent.bkrepo.opdata.pojo.ProjectMetricsOption | ||
import com.tencent.bkrepo.opdata.service.ProjectMetricsService | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/project/metrics") | ||
@Principal(PrincipalType.ADMIN) | ||
class ProjectController( | ||
private val projectMetricsService: ProjectMetricsService | ||
) { | ||
|
||
/** | ||
* 获取项目的统计数据 | ||
*/ | ||
@GetMapping("/list") | ||
fun getProjectMetrics( | ||
option: ProjectMetricsOption | ||
): Response<Page<TProjectMetrics>> { | ||
return ResponseBuilder.success(projectMetricsService.page(option)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ata/biz-opdata/src/main/kotlin/com/tencent/bkrepo/opdata/service/ProjectMetricsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.opdata.service | ||
|
||
import com.tencent.bkrepo.common.api.pojo.Page | ||
import com.tencent.bkrepo.common.mongo.dao.util.Pages | ||
import com.tencent.bkrepo.opdata.model.TProjectMetrics | ||
import com.tencent.bkrepo.opdata.pojo.ProjectMetricsOption | ||
import com.tencent.bkrepo.opdata.repository.ProjectMetricsRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ProjectMetricsService ( | ||
private val projectMetricsRepository: ProjectMetricsRepository | ||
){ | ||
|
||
fun page(option: ProjectMetricsOption): Page<TProjectMetrics> { | ||
with(option) { | ||
val pageRequest = Pages.ofRequest(pageNumber, pageSize) | ||
val queryResult = if (!projectId.isNullOrEmpty()) { | ||
projectMetricsRepository.findByProjectIdOrderByCreatedDateDesc(projectId!!, pageRequest) | ||
} else { | ||
projectMetricsRepository.findAllByOrderByCreatedDateDesc(pageRequest) | ||
} | ||
return Pages.ofResponse(pageRequest, queryResult.totalElements, queryResult.content) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import request from '@/utils/request' | ||
|
||
export const DEFAULT_PAGE_SIZE = 10 | ||
const PREFIX = '/opdata/api/project/metrics' | ||
|
||
export function queryProjectMetrics(projectId, pageNumber) { | ||
return request({ | ||
url: `${PREFIX}/list`, | ||
method: 'get', | ||
params: { | ||
pageNumber: pageNumber, | ||
pageSize: DEFAULT_PAGE_SIZE, | ||
projectId: projectId | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
src/frontend/devops-op/src/views/node/ProjectMetrics.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<template> | ||
<div class="app-container"> | ||
<el-form ref="form" :inline="true"> | ||
<el-form-item ref="project-form-item" label="项目ID"> | ||
<el-autocomplete | ||
v-model="projectId" | ||
class="inline-input" | ||
:fetch-suggestions="queryProjects" | ||
placeholder="请输入项目ID" | ||
size="mini" | ||
@select="selectProject" | ||
> | ||
<template slot-scope="{ item }"> | ||
<div>{{ item.name }}</div> | ||
</template> | ||
</el-autocomplete> | ||
</el-form-item> | ||
<el-form-item> | ||
<el-button size="mini" type="primary" @click="queryPage(1)">查询</el-button> | ||
</el-form-item> | ||
</el-form> | ||
<el-table | ||
:data="projectData" | ||
style="width: 100%" | ||
> | ||
<el-table-column type="expand"> | ||
<template slot-scope="props"> | ||
<el-table | ||
:data="props.row.repoMetrics" | ||
> | ||
<el-table-column | ||
label="仓库名称" | ||
prop="repoName" | ||
/> | ||
<el-table-column | ||
label="数量" | ||
prop="num" | ||
/> | ||
<el-table-column | ||
label="大小" | ||
prop="size" | ||
/> | ||
<el-table-column | ||
label="存储凭据" | ||
prop="credentialsKey" | ||
/> | ||
</el-table> | ||
</template> | ||
</el-table-column> | ||
<el-table-column | ||
prop="projectId" | ||
label="项目ID" | ||
/> | ||
<el-table-column | ||
label="创建时间" | ||
prop="createdDate" | ||
> | ||
<template slot-scope="scope"> | ||
<span>{{ formatNormalDate(scope.row.createdDate) }}</span> | ||
</template> | ||
</el-table-column> | ||
<el-table-column | ||
label="节点数" | ||
prop="nodeNum" | ||
/> | ||
<el-table-column | ||
label="容量大小" | ||
prop="capSize" | ||
/> | ||
</el-table> | ||
<div v-if="total>0" style="margin-top:20px"> | ||
<el-pagination | ||
:current-page="query.pageNumber" | ||
:page-size="query.pageSize" | ||
layout="total, prev, pager, next, jumper" | ||
:total="total" | ||
@current-change="handleCurrentChange" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
import { queryProjectMetrics } from '@/api/projectMetrics' | ||
import { formatNormalDate } from '@/utils/date' | ||
import { searchProjects } from '@/api/project' | ||
export default { | ||
name: 'ProjectMetrics', | ||
data() { | ||
return { | ||
loading: true, | ||
projectData: [], | ||
projectId: this.$route.query.projectId ? this.$route.query.projectId : '', | ||
total: 0, | ||
query: { | ||
pageNumber: 1, | ||
pageSize: 10 | ||
} | ||
} | ||
}, | ||
mounted() { | ||
this.onRouteUpdate(this.$route) | ||
}, | ||
beforeRouteUpdate(to, from, next) { | ||
this.onRouteUpdate(to) | ||
next() | ||
}, | ||
methods: { | ||
queryProjects(queryStr, cb) { | ||
searchProjects(queryStr).then(res => { | ||
this.projects = res.data.records | ||
cb(this.projects) | ||
}) | ||
}, | ||
selectProject(project) { | ||
this.projectId = project.name | ||
}, | ||
handleCurrentChange(val) { | ||
this.currentPage = val | ||
this.queryPage(val) | ||
}, | ||
queryPage(pageNum) { | ||
const query = { | ||
pageNumber: String(pageNum) | ||
} | ||
query.projectId = this.projectId | ||
this.$router.push({ path: '/nodes/ProjectMetrics', query: query }) | ||
}, | ||
onRouteUpdate(route) { | ||
const query = route.query | ||
const projectMetricsQuery = { | ||
pageNumber: String(query.pageNumber ? Number(query.pageNumber) : 1), | ||
projectId: query.projectId ? query.projectId : '' | ||
} | ||
this.$nextTick(() => { | ||
this.queryMetrics(projectMetricsQuery) | ||
}) | ||
}, | ||
queryMetrics(projectMetricsQuery) { | ||
this.loading = true | ||
let promise = null | ||
promise = queryProjectMetrics(projectMetricsQuery.projectId, projectMetricsQuery.pageNumber) | ||
promise.then(res => { | ||
this.projectData = res.data.records | ||
this.total = res.data.totalRecords | ||
}).catch(_ => { | ||
this.projectData = [] | ||
this.total = 0 | ||
}).finally(() => { | ||
this.loading = false | ||
}) | ||
}, | ||
formatNormalDate(data) { | ||
return formatNormalDate(data) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
</style> |