Skip to content

Commit

Permalink
feat: 执行引擎任务调度配额限制 TencentBlueKing#261
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jun 24, 2024
1 parent 15d288b commit f91fcd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,19 +55,11 @@ public InternalResponse<Map<String, ResourceQuotaLimit>> getResourceQuotaConfig(

@Override
public InternalResponse<RunningJobQuotaUsage> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,10 +210,26 @@ public long getRunningJobTotal() {
}

public Map<String, Long> getAppRunningJobCount() {
return redisTemplate.<String, Long>opsForHash().entries(APP_RUNNING_JOB_COUNT_HASH_KEY);
Map<String, String> countMap =
redisTemplate.<String, String>opsForHash().entries(APP_RUNNING_JOB_COUNT_HASH_KEY);
if (countMap.isEmpty()) {
return null;
}
return convertMap(countMap);
}

public Map<String, Long> getResourceScopeRunningJobCount() {
return redisTemplate.<String, Long>opsForHash().entries(RESOURCE_SCOPE_RUNNING_JOB_COUNT_HASH_KEY);
Map<String, String> countMap =
redisTemplate.<String, String>opsForHash().entries(RESOURCE_SCOPE_RUNNING_JOB_COUNT_HASH_KEY);
if (countMap.isEmpty()) {
return null;
}
return convertMap(countMap);
}

private Map<String, Long> convertMap(Map<String, String> map) {
Map<String, Long> finalMap = new HashMap<>();
map.forEach((k, v) -> finalMap.put(k, Long.parseLong(v)));
return finalMap;
}
}

0 comments on commit f91fcd4

Please sign in to comment.