From f91fcd4e1253764d661bcafb330c7615a86830a1 Mon Sep 17 00:00:00 2001 From: wangyu096 Date: Mon, 24 Jun 2024 21:20:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=A7=E8=A1=8C=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6=E9=85=8D=E9=A2=9D=E9=99=90?= =?UTF-8?q?=E5=88=B6=20#261?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServiceResourceQuotaResourceImpl.java | 19 +++++------------ .../limit/RunningJobResourceQuotaManager.java | 21 +++++++++++++++++-- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceResourceQuotaResourceImpl.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceResourceQuotaResourceImpl.java index e8f1858f15..68044d3ecb 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceResourceQuotaResourceImpl.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/api/inner/ServiceResourceQuotaResourceImpl.java @@ -24,7 +24,6 @@ package com.tencent.bk.job.execute.api.inner; -import com.tencent.bk.job.common.exception.InternalException; import com.tencent.bk.job.common.model.InternalResponse; import com.tencent.bk.job.common.resource.quota.ResourceQuotaLimit; import com.tencent.bk.job.common.service.quota.ResourceQuotaStore; @@ -56,19 +55,11 @@ public InternalResponse> getResourceQuotaConfig( @Override public InternalResponse getRunningJobQuotaUsage() { - try { - log.info("getRunningJobQuotaUsage start"); - RunningJobQuotaUsage runningJobQuotaUsage = new RunningJobQuotaUsage(); - runningJobQuotaUsage.setTotal(runningJobResourceQuotaManager.getRunningJobTotal()); - runningJobQuotaUsage.setAppCount(runningJobResourceQuotaManager.getAppRunningJobCount()); - runningJobQuotaUsage.setResourceScopeCount(runningJobResourceQuotaManager.getResourceScopeRunningJobCount()); - log.info("runningJobQuotaUsage : {}", runningJobQuotaUsage); - - return InternalResponse.buildSuccessResp(runningJobQuotaUsage); - } catch (Throwable e) { - log.error("GetRunningJobQuotaUsage error", e); - return InternalResponse.buildCommonFailResp(new InternalException("GetRunningJobQuotaUsage error", e)); - } + RunningJobQuotaUsage runningJobQuotaUsage = new RunningJobQuotaUsage(); + runningJobQuotaUsage.setTotal(runningJobResourceQuotaManager.getRunningJobTotal()); + runningJobQuotaUsage.setAppCount(runningJobResourceQuotaManager.getAppRunningJobCount()); + runningJobQuotaUsage.setResourceScopeCount(runningJobResourceQuotaManager.getResourceScopeRunningJobCount()); + return InternalResponse.buildSuccessResp(runningJobQuotaUsage); } } diff --git a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/quota/limit/RunningJobResourceQuotaManager.java b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/quota/limit/RunningJobResourceQuotaManager.java index 97a46f7a4b..aef5285778 100644 --- a/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/quota/limit/RunningJobResourceQuotaManager.java +++ b/src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/quota/limit/RunningJobResourceQuotaManager.java @@ -44,6 +44,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -209,10 +210,26 @@ public long getRunningJobTotal() { } public Map getAppRunningJobCount() { - return redisTemplate.opsForHash().entries(APP_RUNNING_JOB_COUNT_HASH_KEY); + Map countMap = + redisTemplate.opsForHash().entries(APP_RUNNING_JOB_COUNT_HASH_KEY); + if (countMap.isEmpty()) { + return null; + } + return convertMap(countMap); } public Map getResourceScopeRunningJobCount() { - return redisTemplate.opsForHash().entries(RESOURCE_SCOPE_RUNNING_JOB_COUNT_HASH_KEY); + Map countMap = + redisTemplate.opsForHash().entries(RESOURCE_SCOPE_RUNNING_JOB_COUNT_HASH_KEY); + if (countMap.isEmpty()) { + return null; + } + return convertMap(countMap); + } + + private Map convertMap(Map map) { + Map finalMap = new HashMap<>(); + map.forEach((k, v) -> finalMap.put(k, Long.parseLong(v))); + return finalMap; } }