Browse Source

Adapting partial code(file name start with M #2) to the sonar cloud rule (#2179)

* Adapting partial code(file name start with M #2) to the sonar cloud rule

* remove unused import
pull/3/MERGE
gabry.wu 5 years ago committed by gaojun2048
parent
commit
015a8ca269
  1. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/MonitorDBDao.java
  2. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java
  3. 23
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java
  4. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/MysqlPerformance.java
  5. 3
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java
  6. 7
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/runner/MasterTaskExecThread.java
  7. 2
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/monitor/MonitorServer.java
  8. 7
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sqoop/generator/sources/MysqlSourceGenerator.java
  9. 7
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sqoop/generator/targets/MysqlTargetGenerator.java

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

@ -61,7 +61,7 @@ public class MonitorDBDao {
return new PostgrePerformance().getMonitorRecord(conn); return new PostgrePerformance().getMonitorRecord(conn);
} }
}catch (Exception e) { }catch (Exception e) {
logger.error("SQLException " + e); logger.error("SQLException: {}", e.getMessage(), e);
}finally { }finally {
try { try {
if (conn != null) { if (conn != null) {

2
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/MySQLDataSource.java

@ -39,7 +39,7 @@ public class MySQLDataSource extends BaseDataSource {
@Override @Override
public String getJdbcUrl() { public String getJdbcUrl() {
String address = getAddress(); String address = getAddress();
if (address.lastIndexOf("/") != (address.length() - 1)) { if (address.lastIndexOf('/') != (address.length() - 1)) {
address += "/"; address += "/";
} }
String jdbcUrl = address + getDatabase(); String jdbcUrl = address + getDatabase();

23
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/MysqlUpgradeDao.java

@ -29,15 +29,7 @@ import java.sql.SQLException;
*/ */
public class MysqlUpgradeDao extends UpgradeDao { public class MysqlUpgradeDao extends UpgradeDao {
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class); public static final Logger logger = LoggerFactory.getLogger(MysqlUpgradeDao.class);
/**
* init
*/
@Override
protected void init() {
}
/** /**
* mysql upgrade dao holder * mysql upgrade dao holder
@ -69,12 +61,7 @@ public class MysqlUpgradeDao extends UpgradeDao {
try { try {
conn = dataSource.getConnection(); conn = dataSource.getConnection();
rs = conn.getMetaData().getTables(null, null, tableName, null); rs = conn.getMetaData().getTables(null, null, tableName, null);
if (rs.next()) { return rs.next();
return true;
} else {
return false;
}
} catch (SQLException e) { } catch (SQLException e) {
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);
throw new RuntimeException(e.getMessage(),e); throw new RuntimeException(e.getMessage(),e);
@ -96,11 +83,7 @@ public class MysqlUpgradeDao extends UpgradeDao {
try { try {
conn = dataSource.getConnection(); conn = dataSource.getConnection();
ResultSet rs = conn.getMetaData().getColumns(null,null,tableName,columnName); ResultSet rs = conn.getMetaData().getColumns(null,null,tableName,columnName);
if (rs.next()) { return rs.next();
return true;
} else {
return false;
}
} catch (SQLException e) { } catch (SQLException e) {
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);

3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/MysqlPerformance.java

@ -27,7 +27,6 @@ import java.util.Date;
import org.apache.dolphinscheduler.common.enums.DbType; import org.apache.dolphinscheduler.common.enums.DbType;
import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.dao.MonitorDBDao;
import org.apache.dolphinscheduler.dao.entity.MonitorRecord; import org.apache.dolphinscheduler.dao.entity.MonitorRecord;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -37,7 +36,7 @@ import org.slf4j.LoggerFactory;
*/ */
public class MysqlPerformance extends BaseDBPerformance{ public class MysqlPerformance extends BaseDBPerformance{
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class); private static Logger logger = LoggerFactory.getLogger(MysqlPerformance.class);
/** /**

3
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/master/MasterServer.java

@ -243,7 +243,7 @@ public class MasterServer implements IStoppable {
*/ */
private Runnable heartBeatThread(){ private Runnable heartBeatThread(){
logger.info("start master heart beat thread..."); logger.info("start master heart beat thread...");
Runnable heartBeatThread = new Runnable() { return new Runnable() {
@Override @Override
public void run() { public void run() {
if(Stopper.isRunning()) { if(Stopper.isRunning()) {
@ -257,7 +257,6 @@ public class MasterServer implements IStoppable {
} }
} }
}; };
return heartBeatThread;
} }
} }

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

@ -64,7 +64,7 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
/** /**
* whether already Killed,default false * whether already Killed,default false
*/ */
private Boolean alreadyKilled = false; private boolean alreadyKilled = false;
/** /**
* submit task instance and wait complete * submit task instance and wait complete
@ -98,7 +98,7 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
logger.info("wait task: process id: {}, task id:{}, task name:{} complete", logger.info("wait task: process id: {}, task id:{}, task name:{} complete",
this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName()); this.taskInstance.getProcessInstanceId(), this.taskInstance.getId(), this.taskInstance.getName());
// task time out // task time out
Boolean checkTimeout = false; boolean checkTimeout = false;
TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter(); TaskTimeoutParameter taskTimeoutParameter = getTaskTimeoutParameter();
if(taskTimeoutParameter.getEnable()){ if(taskTimeoutParameter.getEnable()){
TaskTimeoutStrategy strategy = taskTimeoutParameter.getStrategy(); TaskTimeoutStrategy strategy = taskTimeoutParameter.getStrategy();
@ -189,7 +189,6 @@ public class MasterTaskExecThread extends MasterBaseTaskExecThread {
private long getRemaintime(long timeoutSeconds) { private long getRemaintime(long timeoutSeconds) {
Date startTime = taskInstance.getStartTime(); Date startTime = taskInstance.getStartTime();
long usedTime = (System.currentTimeMillis() - startTime.getTime()) / 1000; long usedTime = (System.currentTimeMillis() - startTime.getTime()) / 1000;
long remainTime = timeoutSeconds - usedTime; return timeoutSeconds - usedTime;
return remainTime;
} }
} }

2
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/monitor/MonitorServer.java

@ -30,7 +30,7 @@ import org.springframework.context.annotation.ComponentScan;
@ComponentScan("org.apache.dolphinscheduler") @ComponentScan("org.apache.dolphinscheduler")
public class MonitorServer implements CommandLineRunner { public class MonitorServer implements CommandLineRunner {
private static Integer ARGS_LENGTH = 4; private static final Integer ARGS_LENGTH = 4;
private static final Logger logger = LoggerFactory.getLogger(MonitorServer.class); private static final Logger logger = LoggerFactory.getLogger(MonitorServer.class);

7
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sqoop/generator/sources/MysqlSourceGenerator.java

@ -69,9 +69,8 @@ public class MysqlSourceGenerator implements ISourceGenerator {
result.append(" --columns ").append(sourceMysqlParameter.getSrcColumns()); result.append(" --columns ").append(sourceMysqlParameter.getSrcColumns());
} }
}else if(sourceMysqlParameter.getSrcQueryType() == QueryType.SQL.ordinal()){ }else if(sourceMysqlParameter.getSrcQueryType() == QueryType.SQL.ordinal()
if(StringUtils.isNotEmpty(sourceMysqlParameter.getSrcQuerySql())){ && StringUtils.isNotEmpty(sourceMysqlParameter.getSrcQuerySql())){
String srcQuery = sourceMysqlParameter.getSrcQuerySql(); String srcQuery = sourceMysqlParameter.getSrcQuerySql();
if(srcQuery.toLowerCase().contains("where")){ if(srcQuery.toLowerCase().contains("where")){
srcQuery += " AND "+"$CONDITIONS"; srcQuery += " AND "+"$CONDITIONS";
@ -79,7 +78,7 @@ public class MysqlSourceGenerator implements ISourceGenerator {
srcQuery += " WHERE $CONDITIONS"; srcQuery += " WHERE $CONDITIONS";
} }
result.append(" --query \'"+srcQuery+"\'"); result.append(" --query \'"+srcQuery+"\'");
}
} }
List<Property> mapColumnHive = sourceMysqlParameter.getMapColumnHive(); List<Property> mapColumnHive = sourceMysqlParameter.getMapColumnHive();

7
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/sqoop/generator/targets/MysqlTargetGenerator.java

@ -75,15 +75,14 @@ public class MysqlTargetGenerator implements ITargetGenerator {
result.append(" --lines-terminated-by '").append(targetMysqlParameter.getLinesTerminated()).append("'"); result.append(" --lines-terminated-by '").append(targetMysqlParameter.getLinesTerminated()).append("'");
} }
if(targetMysqlParameter.isUpdate()){ if(targetMysqlParameter.isUpdate()
if(StringUtils.isNotEmpty(targetMysqlParameter.getTargetUpdateKey())&& && StringUtils.isNotEmpty(targetMysqlParameter.getTargetUpdateKey())
StringUtils.isNotEmpty(targetMysqlParameter.getTargetUpdateMode())){ && StringUtils.isNotEmpty(targetMysqlParameter.getTargetUpdateMode())){
result.append(" --update-key ").append(targetMysqlParameter.getTargetUpdateKey()) result.append(" --update-key ").append(targetMysqlParameter.getTargetUpdateKey())
.append(" --update-mode ").append(targetMysqlParameter.getTargetUpdateMode()); .append(" --update-mode ").append(targetMysqlParameter.getTargetUpdateMode());
} }
} }
} }
}
}catch (Exception e){ }catch (Exception e){
logger.error(e.getMessage()); logger.error(e.getMessage());
} }

Loading…
Cancel
Save