未验证 提交 d83a94a3 编写于 作者: G gabry.wu 提交者: GitHub

Adapting partial code(file name start with T) to the sonar cloud rule (#2271)

上级 74525c28
......@@ -43,36 +43,36 @@ public class TaskCountDto {
}
private void countTaskDtos(List<ExecuteStatusCount> taskInstanceStateCounts){
int submitted_success = 0;
int running_exeution = 0;
int ready_pause = 0;
int submittedSuccess = 0;
int runningExeution = 0;
int readyPause = 0;
int pause = 0;
int ready_stop = 0;
int readyStop = 0;
int stop = 0;
int failure = 0;
int success = 0;
int need_fault_tolerance = 0;
int needFaultTolerance = 0;
int kill = 0;
int waitting_thread = 0;
int waittingThread = 0;
for(ExecuteStatusCount taskInstanceStateCount : taskInstanceStateCounts){
ExecutionStatus status = taskInstanceStateCount.getExecutionStatus();
totalCount += taskInstanceStateCount.getCount();
switch (status){
case SUBMITTED_SUCCESS:
submitted_success += taskInstanceStateCount.getCount();
submittedSuccess += taskInstanceStateCount.getCount();
break;
case RUNNING_EXEUTION:
running_exeution += taskInstanceStateCount.getCount();
runningExeution += taskInstanceStateCount.getCount();
break;
case READY_PAUSE:
ready_pause += taskInstanceStateCount.getCount();
readyPause += taskInstanceStateCount.getCount();
break;
case PAUSE:
pause += taskInstanceStateCount.getCount();
break;
case READY_STOP:
ready_stop += taskInstanceStateCount.getCount();
readyStop += taskInstanceStateCount.getCount();
break;
case STOP:
stop += taskInstanceStateCount.getCount();
......@@ -84,13 +84,13 @@ public class TaskCountDto {
success += taskInstanceStateCount.getCount();
break;
case NEED_FAULT_TOLERANCE:
need_fault_tolerance += taskInstanceStateCount.getCount();
needFaultTolerance += taskInstanceStateCount.getCount();
break;
case KILL:
kill += taskInstanceStateCount.getCount();
break;
case WAITTING_THREAD:
waitting_thread += taskInstanceStateCount.getCount();
waittingThread += taskInstanceStateCount.getCount();
break;
default:
......@@ -98,17 +98,17 @@ public class TaskCountDto {
}
}
this.taskCountDtos = new ArrayList<>();
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submitted_success));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, running_exeution));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, ready_pause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submittedSuccess));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, runningExeution));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, readyPause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.PAUSE, pause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, ready_stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, readyStop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.STOP, stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.FAILURE, failure));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUCCESS, success));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, need_fault_tolerance));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, needFaultTolerance));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.KILL, kill));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waitting_thread));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waittingThread));
}
......
......@@ -32,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.service.process.ProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -46,8 +44,6 @@ import java.util.*;
@Service
public class TaskInstanceService extends BaseService {
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceService.class);
@Autowired
ProjectMapper projectMapper;
......
......@@ -21,8 +21,6 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.dao.TaskRecordDao;
import org.apache.dolphinscheduler.dao.entity.TaskRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.HashMap;
......@@ -37,8 +35,6 @@ import static org.apache.dolphinscheduler.common.Constants.*;
@Service
public class TaskRecordService extends BaseService{
private static final Logger logger = LoggerFactory.getLogger(TaskRecordService.class);
/**
* query task record list paging
*
......
......@@ -310,7 +310,7 @@ public class TenantService extends BaseService{
Map<String, Object> result = new HashMap<>(5);
List<Tenant> resourceList = tenantMapper.queryByTenantCode(tenantCode);
if (resourceList != null && resourceList.size() > 0) {
if (CollectionUtils.isNotEmpty(resourceList)) {
result.put(Constants.DATA_LIST, resourceList);
putMsg(result, Status.SUCCESS);
} else {
......@@ -346,6 +346,6 @@ public class TenantService extends BaseService{
*/
private boolean checkTenantExists(String tenantCode) {
List<Tenant> tenants = tenantMapper.queryByTenantCode(tenantCode);
return (tenants != null && tenants.size() > 0);
return CollectionUtils.isNotEmpty(tenants);
}
}
......@@ -60,7 +60,7 @@ public enum TaskStateType {
default:
break;
}
return null;
return new int[0];
}
}
......@@ -293,14 +293,14 @@ public class TaskNode {
public TaskTimeoutParameter getTaskTimeoutParameter() {
if(StringUtils.isNotEmpty(this.getTimeout())){
String formatStr = String.format("%s,%s", TaskTimeoutStrategy.WARN.name(), TaskTimeoutStrategy.FAILED.name());
String timeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
return JSON.parseObject(timeout,TaskTimeoutParameter.class);
String taskTimeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
return JSON.parseObject(taskTimeout,TaskTimeoutParameter.class);
}
return new TaskTimeoutParameter(false);
}
public boolean isConditionsTask(){
return this.getType().toUpperCase().equals(TaskType.CONDITIONS.toString());
return TaskType.CONDITIONS.toString().equalsIgnoreCase(this.getType());
}
@Override
......
......@@ -74,21 +74,21 @@ public class ThreadPoolExecutors {
* @param event
*/
public void execute(final Runnable event) {
Executor executor = getExecutor();
if (executor == null) {
logger.error("Cannot execute [" + event + "] because the executor is missing.");
Executor eventExecutor = getExecutor();
if (eventExecutor == null) {
logger.error("Cannot execute [{}}] because the executor is missing.", event);
} else {
executor.execute(event);
eventExecutor.execute(event);
}
}
public Future<?> submit(Runnable event) {
Executor executor = getExecutor();
if (executor == null) {
logger.error("Cannot submit [" + event + "] because the executor is missing.");
Executor eventExecutor = getExecutor();
if (eventExecutor == null) {
logger.error("Cannot submit [{}}] because the executor is missing.", event);
} else {
return executor.submit(event);
return eventExecutor.submit(event);
}
return null;
......@@ -97,11 +97,11 @@ public class ThreadPoolExecutors {
public Future<?> submit(Callable<?> task) {
Executor executor = getExecutor();
if (executor == null) {
logger.error("Cannot submit [" + task + "] because the executor is missing.");
Executor taskExecutor = getExecutor();
if (taskExecutor == null) {
logger.error("Cannot submit [{}] because the executor is missing.", task);
} else {
return executor.submit(task);
return taskExecutor.submit(task);
}
return null;
......@@ -110,8 +110,8 @@ public class ThreadPoolExecutors {
public void printStatus() {
Executor executor = getExecutor();
executor.getStatus().dumpInfo();
Executor printExecutor = getExecutor();
printExecutor.getStatus().dumpInfo();
}
......@@ -125,7 +125,7 @@ public class ThreadPoolExecutors {
List<Runnable> wasRunning = executor.threadPoolExecutor
.shutdownNow();
if (!wasRunning.isEmpty()) {
logger.info(executor + " had " + wasRunning + " on shutdown");
logger.info("{} had {} on shutdown", executor, wasRunning);
}
}
}
......@@ -138,7 +138,7 @@ public class ThreadPoolExecutors {
/**
* how long to retain excess threads
*/
final long keepAliveTimeInMillis = 1000;
static final long KEEP_ALIVE_TIME_IN_MILLIS = 1000;
/**
* the thread pool executor that services the requests
*/
......@@ -146,7 +146,7 @@ public class ThreadPoolExecutors {
/**
* work queue to use - unbounded queue
*/
final BlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>();
final BlockingQueue<Runnable> q = new LinkedBlockingQueue<>();
private final String name;
private static final AtomicLong seqids = new AtomicLong(0);
private final long id;
......@@ -156,7 +156,7 @@ public class ThreadPoolExecutors {
this.name = name;
//create the thread pool executor
this.threadPoolExecutor = new TrackingThreadPoolExecutor(
maxThreads, maxThreads, keepAliveTimeInMillis,
maxThreads, maxThreads, KEEP_ALIVE_TIME_IN_MILLIS,
TimeUnit.MILLISECONDS, q);
// name the threads for this threadpool
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
......
......@@ -35,12 +35,12 @@ public class TimePlaceholderUtils {
/**
* Prefix of the position to be replaced
*/
public static final String placeholderPrefix = "$[";
public static final String PLACEHOLDER_PREFIX = "$[";
/**
* The suffix of the position to be replaced
*/
public static final String placeholderSuffix = "]";
public static final String PLACEHOLDER_SUFFIX = "]";
/**
* Replaces all placeholders of format {@code ${name}} with the value returned
......@@ -66,7 +66,7 @@ public class TimePlaceholderUtils {
* be ignored ({@code true}) or cause an exception ({@code false})
*/
private static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {
return new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, null, ignoreUnresolvablePlaceholders);
return new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, null, ignoreUnresolvablePlaceholders);
}
/**
......@@ -503,7 +503,7 @@ public class TimePlaceholderUtils {
* @return calculate need minutes
*/
public static Integer calcMinutes(String minuteExpression) {
int index = minuteExpression.indexOf("/");
int index = minuteExpression.indexOf('/');
String calcExpression;
......
......@@ -84,9 +84,9 @@ public class TaskRecordDao {
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
logger.error("Exception ", e);
logger.error("Class not found Exception ", e);
} catch (SQLException e) {
logger.error("Exception ", e);
logger.error("SQL Exception ", e);
}
return conn;
}
......
......@@ -78,7 +78,7 @@ public class TaskInstanceMapperTest {
TaskInstance taskInstance = insertOne();
//update
int update = taskInstanceMapper.updateById(taskInstance);
Assert.assertEquals(update, 1);
Assert.assertEquals(1, update);
taskInstanceMapper.deleteById(taskInstance.getId());
}
......@@ -89,7 +89,7 @@ public class TaskInstanceMapperTest {
public void testDelete(){
TaskInstance taskInstance = insertOne();
int delete = taskInstanceMapper.deleteById(taskInstance.getId());
Assert.assertEquals(delete, 1);
Assert.assertEquals(1, delete);
}
/**
......
......@@ -64,7 +64,7 @@ public class TenantMapperTest {
tenant.setUpdateTime(new Date());
//update
int update = tenantMapper.updateById(tenant);
Assert.assertEquals(update, 1);
Assert.assertEquals(1, update);
tenantMapper.deleteById(tenant.getId());
}
......@@ -75,7 +75,7 @@ public class TenantMapperTest {
public void testDelete(){
Tenant tenant = insertOne();
int delete = tenantMapper.deleteById(tenant.getId());
Assert.assertEquals(delete, 1);
Assert.assertEquals(1, delete);
}
/**
......
......@@ -230,7 +230,7 @@ public class TaskScheduleThread implements Runnable {
taskInstance.getId() + ".log";
}
}catch (Exception e){
logger.error("logger" + e);
logger.error("logger {}", e.getMessage(), e);
logPath = "";
}
return logPath;
......
......@@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.service.queue;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.IpUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.service.zk.ZookeeperOperator;
......@@ -67,8 +68,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
@Override
public List<String> getAllTasks(String key) {
try {
List<String> list = zookeeperOperator.getChildrenKeys(getTasksPath(key));
return list;
return zookeeperOperator.getChildrenKeys(getTasksPath(key));
} catch (Exception e) {
logger.error("get all tasks from tasks queue exception",e);
}
......@@ -141,7 +141,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
try{
List<String> list = zookeeperOperator.getChildrenKeys(getTasksPath(key));
if(list != null && list.size() > 0){
if(CollectionUtils.isNotEmpty(list)){
String workerIp = OSUtils.getHost();
String workerIpLongStr = String.valueOf(IpUtils.ipToLong(workerIp));
......
......@@ -58,11 +58,11 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
init();
// get all
List<String> allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
assertEquals(allTasks.size(),2);
assertEquals(2, allTasks.size());
//delete all
tasksQueue.delete();
allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
assertEquals(allTasks.size(),0);
assertEquals(0, allTasks.size());
}
@Test
public void hasTask(){
......@@ -126,10 +126,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
//add
init();
List<String> taskList = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 2);
assertEquals(taskList.size(),2);
assertEquals(2, taskList.size());
assertEquals(taskList.get(0),"0_1_1_1_-1");
assertEquals(taskList.get(1),"1_0_1_1_-1");
assertEquals("0_1_1_1_-1", taskList.get(0));
assertEquals("1_0_1_1_-1", taskList.get(1));
}
/**
......@@ -153,7 +153,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
......@@ -166,10 +166,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//remove and get size
tasksQueue.srem(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0);
assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
/**
......@@ -179,17 +179,17 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
public void smembers(){
//first init
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0);
assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add
String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1);
assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add
task = "0_1_1_1_";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),2);
assertEquals(2, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
}
......@@ -222,7 +222,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
}
String node1 = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 1).get(0);
assertEquals(node1,"0");
assertEquals("0", node1);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册