Browse Source

Adapting partial code(file name start with P #1) to the sonar cloud rule (#2171) (#2187)

pull/2/head
gabry.wu 5 years ago committed by GitHub
parent
commit
1658176ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java
  2. 10
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessBuilderForWin32.java
  3. 2
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/datasource/PostgreDataSource.java
  4. 39
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java
  5. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/utils/PostgrePerformance.java
  6. 6
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java
  7. 4
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/Ping.java
  8. 4
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/Pong.java
  9. 22
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ParamUtils.java
  10. 27
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/processdure/ProcedureTask.java
  11. 2
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/permission/PermissionCheck.java

6
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/PlaceholderUtils.java

@ -31,12 +31,12 @@ public class PlaceholderUtils {
/** /**
* Prefix of the position to be replaced * 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 * The suffix of the position to be replaced
*/ */
public static final String placeholderSuffix = "}"; public static final String PLACEHOLDER_SUFFIX = "}";
/** /**
@ -68,7 +68,7 @@ public class PlaceholderUtils {
*/ */
public static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { public static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {
return new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, null, ignoreUnresolvablePlaceholders); return new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, null, ignoreUnresolvablePlaceholders);
} }
/** /**

10
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/process/ProcessBuilderForWin32.java

@ -426,6 +426,7 @@ public class ProcessBuilderForWin32 {
static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream(); static final ProcessBuilderForWin32.NullInputStream INSTANCE = new ProcessBuilderForWin32.NullInputStream();
private NullInputStream() {} private NullInputStream() {}
public int read() { return -1; } public int read() { return -1; }
@Override
public int available() { return 0; } public int available() { return 0; }
} }
@ -462,7 +463,7 @@ public class ProcessBuilderForWin32 {
* *
* @since 1.7 * @since 1.7
*/ */
public static abstract class Redirect { public abstract static class Redirect {
/** /**
* The type of a {@link ProcessBuilderForWin32.Redirect}. * The type of a {@link ProcessBuilderForWin32.Redirect}.
*/ */
@ -494,7 +495,7 @@ public class ProcessBuilderForWin32 {
* {@link ProcessBuilderForWin32.Redirect#appendTo Redirect.appendTo(File)}. * {@link ProcessBuilderForWin32.Redirect#appendTo Redirect.appendTo(File)}.
*/ */
APPEND APPEND
}; }
/** /**
* Returns the type of this {@code Redirect}. * Returns the type of this {@code Redirect}.
@ -568,6 +569,7 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException(); throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.READ; } public Type type() { return Type.READ; }
@Override
public File file() { return file; } public File file() { return file; }
public String toString() { public String toString() {
return "redirect to read from file \"" + file + "\""; return "redirect to read from file \"" + file + "\"";
@ -595,10 +597,12 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException(); throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.WRITE; } public Type type() { return Type.WRITE; }
@Override
public File file() { return file; } public File file() { return file; }
public String toString() { public String toString() {
return "redirect to write to file \"" + file + "\""; return "redirect to write to file \"" + file + "\"";
} }
@Override
boolean append() { return false; } boolean append() { return false; }
}; };
} }
@ -626,10 +630,12 @@ public class ProcessBuilderForWin32 {
throw new NullPointerException(); throw new NullPointerException();
return new ProcessBuilderForWin32.Redirect() { return new ProcessBuilderForWin32.Redirect() {
public Type type() { return Type.APPEND; } public Type type() { return Type.APPEND; }
@Override
public File file() { return file; } public File file() { return file; }
public String toString() { public String toString() {
return "redirect to append to file \"" + file + "\""; return "redirect to append to file \"" + file + "\"";
} }
@Override
boolean append() { return true; } boolean append() { return true; }
}; };
} }

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

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

39
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/upgrade/PostgresqlUpgradeDao.java

@ -30,16 +30,8 @@ import java.sql.SQLException;
*/ */
public class PostgresqlUpgradeDao extends UpgradeDao { public class PostgresqlUpgradeDao extends UpgradeDao {
public static final Logger logger = LoggerFactory.getLogger(UpgradeDao.class); public static final Logger logger = LoggerFactory.getLogger(PostgresqlUpgradeDao.class);
private static final String schema = getSchema(); private static final String SCHEMA = getSchema();
/**
* init
*/
@Override
protected void init() {
}
/** /**
* postgresql upgrade dao holder * postgresql upgrade dao holder
@ -58,16 +50,6 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
return PostgresqlUpgradeDaoHolder.INSTANCE; return PostgresqlUpgradeDaoHolder.INSTANCE;
} }
/**
* init schema
* @param initSqlPath initSqlPath
*/
@Override
public void initSchema(String initSqlPath) {
super.initSchema(initSqlPath);
}
/** /**
* getSchema * getSchema
* @return schema * @return schema
@ -107,13 +89,9 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
try { try {
conn = dataSource.getConnection(); conn = dataSource.getConnection();
rs = conn.getMetaData().getTables(null, schema, tableName, null); rs = conn.getMetaData().getTables(null, SCHEMA, tableName, null);
if (rs.next()) {
return true;
} else {
return false;
}
return rs.next();
} 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);
@ -135,13 +113,8 @@ public class PostgresqlUpgradeDao extends UpgradeDao {
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = dataSource.getConnection(); conn = dataSource.getConnection();
rs = conn.getMetaData().getColumns(null,schema,tableName,columnName); rs = conn.getMetaData().getColumns(null, SCHEMA,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);
throw new RuntimeException(e.getMessage(),e); throw new RuntimeException(e.getMessage(),e);

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

@ -24,7 +24,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;
@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory;
*/ */
public class PostgrePerformance extends BaseDBPerformance { public class PostgrePerformance extends BaseDBPerformance {
private static Logger logger = LoggerFactory.getLogger(MonitorDBDao.class); private static Logger logger = LoggerFactory.getLogger(PostgrePerformance.class);
/** /**
* get monitor record * get monitor record

6
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -77,7 +77,7 @@ public class ProcessDefinitionMapperTest {
//update //update
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
int update = processDefinitionMapper.updateById(processDefinition); int update = processDefinitionMapper.updateById(processDefinition);
Assert.assertEquals(update, 1); Assert.assertEquals(1, update);
processDefinitionMapper.deleteById(processDefinition.getId()); processDefinitionMapper.deleteById(processDefinition.getId());
} }
@ -88,7 +88,7 @@ public class ProcessDefinitionMapperTest {
public void testDelete(){ public void testDelete(){
ProcessDefinition processDefinition = insertOne(); ProcessDefinition processDefinition = insertOne();
int delete = processDefinitionMapper.deleteById(processDefinition.getId()); int delete = processDefinitionMapper.deleteById(processDefinition.getId());
Assert.assertEquals(delete, 1); Assert.assertEquals(1, delete);
} }
/** /**
@ -189,7 +189,7 @@ public class ProcessDefinitionMapperTest {
List<ProcessDefinition> processDefinitions = processDefinitionMapper.queryDefinitionListByIdList(array); List<ProcessDefinition> processDefinitions = processDefinitionMapper.queryDefinitionListByIdList(array);
processDefinitionMapper.deleteById(processDefinition.getId()); processDefinitionMapper.deleteById(processDefinition.getId());
processDefinitionMapper.deleteById(processDefinition1.getId()); processDefinitionMapper.deleteById(processDefinition1.getId());
Assert.assertEquals(processDefinitions.size(), 2); Assert.assertEquals(2, processDefinitions.size());
} }

4
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/Ping.java

@ -30,12 +30,12 @@ public class Ping implements Serializable {
/** /**
* ping body * ping body
*/ */
protected static ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER; protected static final ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
/** /**
* request command body * request command body
*/ */
private static byte[] EMPTY_BODY_ARRAY = new byte[0]; private static final byte[] EMPTY_BODY_ARRAY = new byte[0];
private static final ByteBuf PING_BUF; private static final ByteBuf PING_BUF;

4
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/command/Pong.java

@ -30,12 +30,12 @@ public class Pong implements Serializable {
/** /**
* pong body * pong body
*/ */
protected static ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER; protected static final ByteBuf EMPTY_BODY = Unpooled.EMPTY_BUFFER;
/** /**
* pong command body * pong command body
*/ */
private static byte[] EMPTY_BODY_ARRAY = new byte[0]; private static final byte[] EMPTY_BODY_ARRAY = new byte[0];
/** /**
* ping byte buffer * ping byte buffer

22
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ParamUtils.java

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.server.utils;
import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.process.Property; import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.utils.ParameterUtils; import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils;
import java.util.Date; import java.util.Date;
@ -70,17 +71,16 @@ public class ParamUtils {
Map.Entry<String, Property> en = iter.next(); Map.Entry<String, Property> en = iter.next();
Property property = en.getValue(); Property property = en.getValue();
if (property.getValue() != null && property.getValue().length() > 0){ if (StringUtils.isNotEmpty(property.getValue())
if (property.getValue().startsWith("$")){ && property.getValue().startsWith("$")){
/** /**
* local parameter refers to global parameter with the same name * local parameter refers to global parameter with the same name
* note: the global parameters of the process instance here are solidified parameters, * note: the global parameters of the process instance here are solidified parameters,
* and there are no variables in them. * and there are no variables in them.
*/ */
String val = property.getValue(); String val = property.getValue();
val = ParameterUtils.convertParameterPlaceholders(val, timeParams); val = ParameterUtils.convertParameterPlaceholders(val, timeParams);
property.setValue(val); property.setValue(val);
}
} }
} }

27
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/processdure/ProcedureTask.java

@ -60,11 +60,6 @@ public class ProcedureTask extends AbstractTask {
*/ */
private ProcessService processService; private ProcessService processService;
/**
* base datasource
*/
private BaseDataSource baseDataSource;
/** /**
* constructor * constructor
* @param taskProps task props * @param taskProps task props
@ -117,7 +112,7 @@ public class ProcedureTask extends AbstractTask {
// load class // load class
DataSourceFactory.loadClass(dataSource.getType()); DataSourceFactory.loadClass(dataSource.getType());
// get datasource // get datasource
baseDataSource = DataSourceFactory.getDatasource(dataSource.getType(), BaseDataSource baseDataSource = DataSourceFactory.getDatasource(dataSource.getType(),
dataSource.getConnectionParams()); dataSource.getConnectionParams());
// get jdbc connection // get jdbc connection
@ -163,7 +158,7 @@ public class ProcedureTask extends AbstractTask {
stmt.setQueryTimeout(taskProps.getTaskTimeout()); stmt.setQueryTimeout(taskProps.getTaskTimeout());
} }
Map<Integer,Property> outParameterMap = new HashMap<>(); Map<Integer,Property> outParameterMap = new HashMap<>();
if (userDefParamsList != null && userDefParamsList.size() > 0){ if (CollectionUtils.isNotEmpty(userDefParamsList)){
int index = 1; int index = 1;
for (Property property : userDefParamsList){ for (Property property : userDefParamsList){
logger.info("localParams : prop : {} , dirct : {} , type : {} , value : {}" logger.info("localParams : prop : {} , dirct : {} , type : {} , value : {}"
@ -237,31 +232,31 @@ public class ProcedureTask extends AbstractTask {
private void getOutputParameter(CallableStatement stmt, int index, String prop, DataType dataType) throws SQLException { private void getOutputParameter(CallableStatement stmt, int index, String prop, DataType dataType) throws SQLException {
switch (dataType){ switch (dataType){
case VARCHAR: case VARCHAR:
logger.info("out prameter key : {} , value : {}",prop,stmt.getString(index)); logger.info("out prameter varchar key : {} , value : {}",prop,stmt.getString(index));
break; break;
case INTEGER: case INTEGER:
logger.info("out prameter key : {} , value : {}", prop, stmt.getInt(index)); logger.info("out prameter integer key : {} , value : {}", prop, stmt.getInt(index));
break; break;
case LONG: case LONG:
logger.info("out prameter key : {} , value : {}",prop,stmt.getLong(index)); logger.info("out prameter long key : {} , value : {}",prop,stmt.getLong(index));
break; break;
case FLOAT: case FLOAT:
logger.info("out prameter key : {} , value : {}",prop,stmt.getFloat(index)); logger.info("out prameter float key : {} , value : {}",prop,stmt.getFloat(index));
break; break;
case DOUBLE: case DOUBLE:
logger.info("out prameter key : {} , value : {}",prop,stmt.getDouble(index)); logger.info("out prameter double key : {} , value : {}",prop,stmt.getDouble(index));
break; break;
case DATE: case DATE:
logger.info("out prameter key : {} , value : {}",prop,stmt.getDate(index)); logger.info("out prameter date key : {} , value : {}",prop,stmt.getDate(index));
break; break;
case TIME: case TIME:
logger.info("out prameter key : {} , value : {}",prop,stmt.getTime(index)); logger.info("out prameter time key : {} , value : {}",prop,stmt.getTime(index));
break; break;
case TIMESTAMP: case TIMESTAMP:
logger.info("out prameter key : {} , value : {}",prop,stmt.getTimestamp(index)); logger.info("out prameter timestamp key : {} , value : {}",prop,stmt.getTimestamp(index));
break; break;
case BOOLEAN: case BOOLEAN:
logger.info("out prameter key : {} , value : {}",prop, stmt.getBoolean(index)); logger.info("out prameter boolean key : {} , value : {}",prop, stmt.getBoolean(index));
break; break;
default: default:
break; break;

2
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/permission/PermissionCheck.java

@ -147,7 +147,7 @@ public class PermissionCheck<T> {
List<T> unauthorizedList = processService.listUnauthorized(userId,needChecks,authorizationType); List<T> unauthorizedList = processService.listUnauthorized(userId,needChecks,authorizationType);
// if exist unauthorized resource // if exist unauthorized resource
if(CollectionUtils.isNotEmpty(unauthorizedList)){ if(CollectionUtils.isNotEmpty(unauthorizedList)){
logger.error("user {} didn't has permission of {}: {}", user.getUserName(), authorizationType.getDescp(),unauthorizedList.toString()); logger.error("user {} didn't has permission of {}: {}", user.getUserName(), authorizationType.getDescp(),unauthorizedList);
throw new RuntimeException(String.format("user %s didn't has permission of %s %s", user.getUserName(), authorizationType.getDescp(), unauthorizedList.get(0))); throw new RuntimeException(String.format("user %s didn't has permission of %s %s", user.getUserName(), authorizationType.getDescp(), unauthorizedList.get(0)));
} }
} }

Loading…
Cancel
Save