Skip to content

Commit

Permalink
resolve sonar: class is part of one cycle containing 2 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyu10 committed Oct 14, 2024
1 parent de1fa82 commit 5438d66
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

@Slf4j
Expand All @@ -63,20 +62,6 @@ public class DAGOperations implements DAGOperationsInterface {
private final DAGResultHandler dagResultHandler;


public static final BiConsumer<Runnable, Integer> OPERATE_WITH_RETRY = (operation, retryTimes) -> {
int exceptionCatchTimes = retryTimes;
for (int i = 1; i <= exceptionCatchTimes; i++) {
try {
operation.run();
return;
} catch (Exception e) {
log.warn("operateWithRetry fails, invokeTimes:{}", i, e);
}
}

operation.run();
};

public DAGOperations(ExecutorService runnerExecutor, Map<String, TaskRunner> taskRunners, DAGRunner dagRunner,
TimeCheckRunner timeCheckRunner, DAGTraversal dagTraversal, Callback<DAGCallbackInfo> callback,
DAGResultHandler dagResultHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.weibo.rill.flow.olympicene.traversal.helper.ContextHelper;
import com.weibo.rill.flow.olympicene.traversal.helper.PluginHelper;
import com.weibo.rill.flow.olympicene.traversal.helper.Stasher;
import com.weibo.rill.flow.olympicene.traversal.utils.OperationUtil;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void submitTraversal(String executionId, String completedTaskName) {
Runnable basicActions = () -> dagStorageProcedure.lockAndRun(
LockerKey.buildDagInfoLockName(executionId), () -> doTraversal(executionId, completedTaskName));
Runnable runnable = PluginHelper.pluginInvokeChain(basicActions, params, SystemConfig.TRAVERSAL_CUSTOMIZED_PLUGINS);
DAGOperations.OPERATE_WITH_RETRY.accept(runnable, SystemConfig.getTraversalRetryTimes());
OperationUtil.OPERATE_WITH_RETRY.accept(runnable, SystemConfig.getTraversalRetryTimes());
} catch (Exception e) {
log.error("executionId:{} traversal exception with completedTaskName:{}. ", executionId, completedTaskName, e);
}
Expand All @@ -99,7 +100,7 @@ public void submitTasks(String executionId, Set<TaskInfo> taskInfos, Map<String,
runTasks(executionId, taskToContexts);
}
});
DAGOperations.OPERATE_WITH_RETRY.accept(runnable, SystemConfig.getTraversalRetryTimes());
OperationUtil.OPERATE_WITH_RETRY.accept(runnable, SystemConfig.getTraversalRetryTimes());
} catch (Exception e) {
log.error("dag {} traversal exception with tasks {}. ", executionId, Joiner.on(",").join(taskInfos.stream().map(TaskInfo::getName).collect(Collectors.toList())), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.weibo.rill.flow.olympicene.traversal.checker.TimeChecker;
import com.weibo.rill.flow.olympicene.traversal.helper.ContextHelper;
import com.weibo.rill.flow.olympicene.traversal.serialize.DAGTraversalSerializer;
import com.weibo.rill.flow.olympicene.traversal.utils.OperationUtil;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void handleTimeCheck(String timeCheckMember) {
Map<String, Object> context = ContextHelper.getInstance().getContext(dagContextStorage, executionId, taskInfo);
dagOperations.runTasks(executionId, Lists.newArrayList(Pair.of(taskInfo, context)));
};
DAGOperations.OPERATE_WITH_RETRY.accept(operations, SystemConfig.getTimerRetryTimes());
OperationUtil.OPERATE_WITH_RETRY.accept(operations, SystemConfig.getTimerRetryTimes());

Check warning on line 99 in rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/runners/TimeCheckRunner.java

View check run for this annotation

Codecov / codecov/patch

rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/runners/TimeCheckRunner.java#L99

Added line #L99 was not covered by tests
break;
default:
log.warn("handleTimeCheck time check type nonsupport, type:{}", type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.weibo.rill.flow.olympicene.traversal.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.function.BiConsumer;

@Slf4j
public class OperationUtil {
private OperationUtil() {}

public static final BiConsumer<Runnable, Integer> OPERATE_WITH_RETRY = (operation, retryTimes) -> {
int exceptionCatchTimes = retryTimes;
for (int i = 1; i <= exceptionCatchTimes; i++) {
try {
operation.run();
return;
} catch (Exception e) {
log.warn("operateWithRetry fails, invokeTimes:{}", i, e);

Check warning on line 18 in rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/utils/OperationUtil.java

View check run for this annotation

Codecov / codecov/patch

rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/utils/OperationUtil.java#L17-L18

Added lines #L17 - L18 were not covered by tests
}
}

operation.run();
};

Check warning on line 23 in rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/utils/OperationUtil.java

View check run for this annotation

Codecov / codecov/patch

rill-flow-dag/olympicene-traversal/src/main/java/com/weibo/rill/flow/olympicene/traversal/utils/OperationUtil.java#L22-L23

Added lines #L22 - L23 were not covered by tests
}

0 comments on commit 5438d66

Please sign in to comment.