Browse Source

spotbugs: bug check and modify (#1018)

* spotbugs bug check and modify

* tmp var

* alter third parameter
pull/2/head
khadgarmage 5 years ago committed by Baoqi Wu
parent
commit
26c96d8ed1
  1. 2
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
  2. 5
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/PropertyUtils.java
  3. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java
  4. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java
  5. 8
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNodeRelation.java
  6. 5
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java
  7. 4
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
  8. 7
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java
  9. 6
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java
  10. 10
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
  11. 5
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/PropertyUtils.java
  12. 11
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java
  13. 1
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractTask.java
  14. 2
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

2
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java

@ -214,7 +214,7 @@ public class EnterpriseWeChatUtils {
}
StringBuilder contents = new StringBuilder(100);
contents.append(String.format("`%s`\n",title));
contents.append(String.format("`%s`%n",title));
for (String str : list){
contents.append(Constants.MARKDOWN_QUOTE);
contents.append(str);

5
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/PropertyUtils.java

@ -56,6 +56,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
@ -121,7 +124,7 @@ public class PropertyUtils {
return Boolean.parseBoolean(value);
}
return null;
return false;
}
/**

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionService.java

@ -870,7 +870,7 @@ public class ProcessDefinitionService extends BaseDAGService {
ProcessDefinition processDefinition = processDefineMapper.selectById(defineId);
if (processDefinition == null) {
logger.info("process define not exists");
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, processDefinition.getId());
putMsg(result, Status.PROCESS_DEFINE_NOT_EXIST, defineId);
return result;
}

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProcessInstanceService.java

@ -120,9 +120,9 @@ public class ProcessInstanceService extends BaseDAGService {
}else{
WorkerGroup workerGroup = workerGroupMapper.selectById(processInstance.getWorkerGroupId());
if(workerGroup != null){
workerGroupName = DEFAULT;
}else{
workerGroupName = workerGroup.getName();
}else{
workerGroupName = DEFAULT;
}
}
processInstance.setWorkerGroupName(workerGroupName);
@ -165,14 +165,10 @@ public class ProcessInstanceService extends BaseDAGService {
}
int[] statusArray = null;
String statesStr = null;
// filter by state
if (stateType != null) {
statusArray = new int[]{stateType.ordinal()};
}
if (statusArray != null) {
statesStr = Arrays.toString(statusArray).replace("[", "").replace("]", "");
}
Date start = null;
Date end = null;

8
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNodeRelation.java

@ -53,8 +53,12 @@ public class TaskNodeRelation {
}
public boolean equals(TaskNodeRelation e){
return (e.getStartNode() == this.startNode && e.getEndNode() == this.endNode);
public boolean equals(Object o){
if (!(o instanceof TaskNodeRelation)) {
return false;
}
TaskNodeRelation relation = (TaskNodeRelation)o;
return (relation.getStartNode().equals(this.startNode) && relation.getEndNode().equals(this.endNode));
}
@Override

5
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java

@ -153,8 +153,9 @@ public class FileUtils {
BufferedWriter bufferedWriter = null;
try {
File distFile = new File(filePath);
if (!distFile.getParentFile().exists()) {
distFile.getParentFile().mkdirs();
if (!distFile.getParentFile().exists() && !distFile.getParentFile().mkdirs()) {
FileUtils.logger.error("mkdir parent failed");
return false;
}
bufferedReader = new BufferedReader(new StringReader(content));
bufferedWriter = new BufferedWriter(new FileWriter(distFile));

4
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java

@ -156,7 +156,9 @@ public class OSUtils {
logger.error(e.getMessage(), e);
} finally {
try {
bufferedReader.close();
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e) {
logger.error(e.getMessage(), e);
}

7
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/PropertyUtils.java

@ -60,6 +60,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
@ -173,7 +176,7 @@ public class PropertyUtils {
public static String[] getArray(String key, String splitStr) {
String value = getString(key);
if (value == null) {
return null;
return new String[0];
}
try {
String[] propertyArray = value.split(splitStr);
@ -181,7 +184,7 @@ public class PropertyUtils {
} catch (NumberFormatException e) {
logger.info(e.getMessage(),e);
}
return null;
return new String[0];
}
/**

6
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java

@ -83,6 +83,7 @@ public class MonitorDBDao {
List<MonitorRecord> list = new ArrayList<>(1);
Connection conn = null;
Statement pstmt = null;
long maxConnections = 0;
long maxUsedConnections = 0;
long threadsConnections = 0;
@ -98,7 +99,7 @@ public class MonitorDBDao {
return list;
}
Statement pstmt = conn.createStatement();
pstmt = conn.createStatement();
ResultSet rs1 = pstmt.executeQuery("show global variables");
while(rs1.next()){
@ -124,6 +125,9 @@ public class MonitorDBDao {
state = 0;
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}

10
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java

@ -147,6 +147,7 @@ public class TaskRecordDao {
int count = 0;
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConn();
if(conn == null){
@ -154,7 +155,6 @@ public class TaskRecordDao {
}
String sql = String.format("select count(1) as count from %s", table);
sql += getWhereString(filterMap);
PreparedStatement pstmt;
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
@ -165,6 +165,9 @@ public class TaskRecordDao {
logger.error("Exception ", e);
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}
@ -234,12 +237,12 @@ public class TaskRecordDao {
private static List<TaskRecord> getQueryResult(String selectSql) {
List<TaskRecord> recordList = new ArrayList<>();
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = getConn();
if(conn == null){
return recordList;
}
PreparedStatement pstmt;
pstmt = conn.prepareStatement(selectSql);
ResultSet rs = pstmt.executeQuery();
@ -251,6 +254,9 @@ public class TaskRecordDao {
logger.error("Exception ", e);
}finally {
try {
if(pstmt != null) {
pstmt.close();
}
if(conn != null){
conn.close();
}

5
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/PropertyUtils.java

@ -55,6 +55,9 @@ public class PropertyUtils {
} catch (IOException e) {
logger.error(e.getMessage(), e);
if (fis != null) {
IOUtils.closeQuietly(fis);
}
System.exit(1);
} finally {
IOUtils.closeQuietly(fis);
@ -120,7 +123,7 @@ public class PropertyUtils {
return Boolean.parseBoolean(value);
}
return null;
return false;
}
/**

11
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java

@ -74,7 +74,6 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
public Boolean waitTaskQuit(){
// query new state
taskInstance = processDao.findTaskInstanceById(taskInstance.getId());
Boolean result = true;
// task time out
Boolean checkTimeout = false;
TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter();
@ -89,7 +88,7 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
try {
if(this.processInstance == null){
logger.error("process instance not exists , master task exec thread exit");
return result;
return true;
}
// task instance add queue , waiting worker to kill
if(this.cancel || this.processInstance.getState() == ExecutionStatus.READY_STOP){
@ -116,11 +115,13 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
} catch (Exception e) {
logger.error("exception: "+ e.getMessage(),e);
logger.error("wait task quit failed, instance id:{}, task id:{}",
processInstance.getId(), taskInstance.getId());
if (processInstance != null) {
logger.error("wait task quit failed, instance id:{}, task id:{}",
processInstance.getId(), taskInstance.getId());
}
}
}
return result;
return true;
}

1
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractTask.java

@ -181,6 +181,7 @@ public abstract class AbstractTask {
break;
case FLINK:
paramsClass = FlinkParameters.class;
break;
case PYTHON:
paramsClass = PythonParameters.class;
break;

2
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sql/SqlTask.java

@ -303,7 +303,7 @@ public class SqlTask extends AbstractTask {
}
resultJSONArray.add(mapOfColValues);
}
resultSet.close();
logger.debug("execute sql : {}", JSONObject.toJSONString(resultJSONArray, SerializerFeature.WriteMapNullValue));
// if there is a result set

Loading…
Cancel
Save