From 9f05d334f2f9de5ec47dc4847786b93cc0376750 Mon Sep 17 00:00:00 2001 From: Hongsheng Zhong Date: Tue, 19 Sep 2023 20:25:40 +0800 Subject: [PATCH] Reduce Cognitive Complexity for ConsistencyCheckJobAPI.getJobItemInfo --- .../api/impl/ConsistencyCheckJobAPI.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/impl/ConsistencyCheckJobAPI.java b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/impl/ConsistencyCheckJobAPI.java index 029750013e254..13b2d2a671ec9 100644 --- a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/impl/ConsistencyCheckJobAPI.java +++ b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/impl/ConsistencyCheckJobAPI.java @@ -313,16 +313,10 @@ private ConsistencyCheckJobItemInfo getJobItemInfo(final String parentJobId) { } fillInJobItemInfoWithTimes(result, jobItemProgress, jobConfigPOJO); result.setTableNames(Optional.ofNullable(jobItemProgress.getTableNames()).orElse("")); - fillInJobItemInfoWithAlgorithm(result, checkJobId); + fillInJobItemInfoWithCheckAlgorithm(result, checkJobId); result.setErrorMessage(getJobItemErrorMessage(checkJobId, 0)); Map checkJobResult = governanceRepositoryAPI.getCheckJobResult(parentJobId, checkJobId); - if (checkJobResult.isEmpty()) { - result.setCheckSuccess(null); - } else { - InventoryIncrementalJobAPI inventoryIncrementalJobAPI = (InventoryIncrementalJobAPI) TypedSPILoader.getService( - PipelineJobAPI.class, PipelineJobIdUtils.parseJobType(parentJobId).getType()); - result.setCheckSuccess(inventoryIncrementalJobAPI.aggregateDataConsistencyCheckResults(parentJobId, checkJobResult)); - } + fillInJobItemInfoWithCheckResult(result, checkJobResult, parentJobId); result.setCheckFailedTableNames(checkJobResult.entrySet().stream().filter(each -> !each.getValue().isIgnored() && !each.getValue().isMatched()) .map(Entry::getKey).collect(Collectors.joining(","))); return result; @@ -353,7 +347,7 @@ private void fillInJobItemInfoWithTimes(final ConsistencyCheckJobItemInfo result } } - private void fillInJobItemInfoWithAlgorithm(final ConsistencyCheckJobItemInfo result, final String checkJobId) { + private void fillInJobItemInfoWithCheckAlgorithm(final ConsistencyCheckJobItemInfo result, final String checkJobId) { ConsistencyCheckJobConfiguration jobConfig = getJobConfiguration(checkJobId); result.setAlgorithmType(jobConfig.getAlgorithmTypeName()); if (null != jobConfig.getAlgorithmProps()) { @@ -361,6 +355,16 @@ private void fillInJobItemInfoWithAlgorithm(final ConsistencyCheckJobItemInfo re } } + private void fillInJobItemInfoWithCheckResult(final ConsistencyCheckJobItemInfo result, final Map checkJobResult, final String parentJobId) { + if (checkJobResult.isEmpty()) { + result.setCheckSuccess(null); + } else { + InventoryIncrementalJobAPI inventoryIncrementalJobAPI = (InventoryIncrementalJobAPI) TypedSPILoader.getService( + PipelineJobAPI.class, PipelineJobIdUtils.parseJobType(parentJobId).getType()); + result.setCheckSuccess(inventoryIncrementalJobAPI.aggregateDataConsistencyCheckResults(parentJobId, checkJobResult)); + } + } + @Override public ConsistencyCheckJobConfiguration getJobConfiguration(final String jobId) { return getJobConfiguration(getElasticJobConfigPOJO(jobId));