From 42b45e0b502e2fc643d536d5fd903b40bc43bdf3 Mon Sep 17 00:00:00 2001 From: zacYL <100330102+zacYL@users.noreply.github.com> Date: Thu, 7 Mar 2024 20:03:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E8=AE=A1=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE=E5=90=AF=E7=94=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=20#1833?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/bkrepo/job/Constants.kt | 1 + .../stat/ProjectMetricsReport2BkbaseJob.kt | 8 ++++--- .../batch/stat/ProjectRepoMetricsStatJob.kt | 21 +++++++++++++++++++ .../job/pojo/project/TProjectMetrics.kt | 3 ++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt index a63c09a2fd..3b4fc308b5 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/Constants.kt @@ -55,6 +55,7 @@ const val DELETED_DATE = "deleted" const val FULL_PATH = "fullPath" const val PATH = "path" const val LAST_MODIFIED_BY = "lastModifiedBy" +const val NAME = "name" /** * 缓存类型 diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt index f6f2fe8eaf..dfe0d98c4f 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectMetricsReport2BkbaseJob.kt @@ -88,7 +88,9 @@ class ProjectMetricsReport2BkbaseJob( capSize = row[TProjectMetrics::capSize.name].toString().toLongOrNull() ?: 0, repoMetrics = row[TProjectMetrics::repoMetrics.name]?.toJsonString() ?.readJsonString>() ?: emptyList(), - createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString()) + createdDate = TimeUtils.parseMongoDateTimeStr(row[TProjectMetrics::createdDate.name].toString()), + active = row[TProjectMetrics::active.name].toString().toBoolean(), + projectStatus = row[TProjectMetrics::projectStatus.name]?.toString()?.toBoolean() ) } @@ -123,8 +125,8 @@ class ProjectMetricsReport2BkbaseJob( deptName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_DEPT_NAME }?.value as? String, centerName = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_CENTER_NAME }?.value as? String, productId = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_PRODUCT_ID }?.value as? Int, - enabled = project.metadata.firstOrNull { it.key == ProjectMetadata.KEY_ENABLED }?.value as? Boolean, - active = current.active + enabled = current.projectStatus, + active = current.active, ) } diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt index b435cf28a6..4cb5635732 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/stat/ProjectRepoMetricsStatJob.kt @@ -30,6 +30,7 @@ package com.tencent.bkrepo.job.batch.stat import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.job.CREATED_DATE import com.tencent.bkrepo.job.DELETED_DATE +import com.tencent.bkrepo.job.NAME import com.tencent.bkrepo.job.PATH import com.tencent.bkrepo.job.PROJECT import com.tencent.bkrepo.job.REPO @@ -42,6 +43,7 @@ import com.tencent.bkrepo.job.batch.utils.FolderUtils import com.tencent.bkrepo.job.batch.utils.MongoShardingUtils import com.tencent.bkrepo.job.config.properties.MongodbJobProperties import com.tencent.bkrepo.job.pojo.project.TProjectMetrics +import com.tencent.bkrepo.repository.pojo.project.ProjectMetadata import org.slf4j.LoggerFactory import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query @@ -139,9 +141,27 @@ open class ProjectRepoMetricsStatJob( val criteria = Criteria.where(CREATED_DATE).isEqualTo(statDate).and(PROJECT).`is`(projectMetric.projectId) mongoTemplate.remove(Query(criteria), COLLECTION_NAME_PROJECT_METRICS) logger.info("stat project: [${projectMetric.projectId}], size: [${projectMetric.capSize}]") + projectMetric.projectStatus = getProjectEnableStatus(projectMetric.projectId) mongoTemplate.insert(projectMetric, COLLECTION_NAME_PROJECT_METRICS) } + private fun getProjectEnableStatus(projectId: String): Boolean? { + val query = Query.query(Criteria.where(NAME).isEqualTo(projectId)) + val project = mongoTemplate.find(query, Project::class.java, COLLECTION_NAME_PROJECT) + .firstOrNull() ?: return null + return project.metadata.firstOrNull() { it.key == "enabled" }?.value as Boolean? + } + + data class Project(var name: String, var metadata: List = emptyList()) { + constructor(map: Map) : this( + map[Project::name.name].toString(), + (map[Project::metadata.name] as? List>)?.map { + ProjectMetadata(it[ProjectMetadata::key.name].toString(), it[ProjectMetadata::value.name]!!) + } ?: emptyList(), + ) + } + + data class Repository( var projectId: String, var name: String, @@ -180,5 +200,6 @@ open class ProjectRepoMetricsStatJob( private const val COLLECTION_REPOSITORY_NAME = "repository" private const val COLLECTION_NODE_PREFIX = "node_" private const val COLLECTION_NAME_PROJECT_METRICS = "project_metrics" + private const val COLLECTION_NAME_PROJECT = "project" } } diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt index e3778f2f07..4f4f89dc9b 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/project/TProjectMetrics.kt @@ -35,5 +35,6 @@ data class TProjectMetrics( var capSize: Long, val repoMetrics: List, val createdDate: LocalDateTime? = LocalDateTime.now(), - val active: Boolean = true + val active: Boolean = true, + var projectStatus: Boolean? = null )