|
|
@ -53,7 +53,7 @@ import static org.apache.dolphinscheduler.common.utils.PropertyUtils.getString; |
|
|
|
* datasource service |
|
|
|
* datasource service |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
public class DataSourceService extends BaseService{ |
|
|
|
public class DataSourceService extends BaseService { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceService.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(DataSourceService.class); |
|
|
|
|
|
|
|
|
|
|
@ -65,7 +65,6 @@ public class DataSourceService extends BaseService{ |
|
|
|
public static final String PRINCIPAL = "principal"; |
|
|
|
public static final String PRINCIPAL = "principal"; |
|
|
|
public static final String DATABASE = "database"; |
|
|
|
public static final String DATABASE = "database"; |
|
|
|
public static final String USER_NAME = "userName"; |
|
|
|
public static final String USER_NAME = "userName"; |
|
|
|
public static final String PASSWORD = Constants.PASSWORD; |
|
|
|
|
|
|
|
public static final String OTHER = "other"; |
|
|
|
public static final String OTHER = "other"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -80,9 +79,9 @@ public class DataSourceService extends BaseService{ |
|
|
|
* create data source |
|
|
|
* create data source |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param name data source name |
|
|
|
* @param name data source name |
|
|
|
* @param desc data source description |
|
|
|
* @param desc data source description |
|
|
|
* @param type data source type |
|
|
|
* @param type data source type |
|
|
|
* @param parameter datasource parameters |
|
|
|
* @param parameter datasource parameters |
|
|
|
* @return create result code |
|
|
|
* @return create result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -131,11 +130,11 @@ public class DataSourceService extends BaseService{ |
|
|
|
* updateProcessInstance datasource |
|
|
|
* updateProcessInstance datasource |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param name data source name |
|
|
|
* @param name data source name |
|
|
|
* @param desc data source description |
|
|
|
* @param desc data source description |
|
|
|
* @param type data source type |
|
|
|
* @param type data source type |
|
|
|
* @param parameter datasource parameters |
|
|
|
* @param parameter datasource parameters |
|
|
|
* @param id data source id |
|
|
|
* @param id data source id |
|
|
|
* @return update result code |
|
|
|
* @return update result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> updateDataSource(int id, User loginUser, String name, String desc, DbType type, String parameter) { |
|
|
|
public Map<String, Object> updateDataSource(int id, User loginUser, String name, String desc, DbType type, String parameter) { |
|
|
@ -148,13 +147,13 @@ public class DataSourceService extends BaseService{ |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!hasPerm(loginUser, dataSource.getUserId())){ |
|
|
|
if (!hasPerm(loginUser, dataSource.getUserId())) { |
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM); |
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//check name can use or not
|
|
|
|
//check name can use or not
|
|
|
|
if(!name.trim().equals(dataSource.getName()) && checkName(name)){ |
|
|
|
if (!name.trim().equals(dataSource.getName()) && checkName(name)) { |
|
|
|
putMsg(result, Status.DATASOURCE_EXIST); |
|
|
|
putMsg(result, Status.DATASOURCE_EXIST); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
@ -199,6 +198,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* updateProcessInstance datasource |
|
|
|
* updateProcessInstance datasource |
|
|
|
|
|
|
|
* |
|
|
|
* @param id datasource id |
|
|
|
* @param id datasource id |
|
|
|
* @return data source detail |
|
|
|
* @return data source detail |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -220,11 +220,11 @@ public class DataSourceService extends BaseService{ |
|
|
|
String parameter = dataSource.getConnectionParams(); |
|
|
|
String parameter = dataSource.getConnectionParams(); |
|
|
|
|
|
|
|
|
|
|
|
BaseDataSource datasourceForm = DataSourceFactory.getDatasource(dataSource.getType(), parameter); |
|
|
|
BaseDataSource datasourceForm = DataSourceFactory.getDatasource(dataSource.getType(), parameter); |
|
|
|
DbConnectType connectType = null; |
|
|
|
DbConnectType connectType = null; |
|
|
|
String hostSeperator = Constants.DOUBLE_SLASH; |
|
|
|
String hostSeperator = Constants.DOUBLE_SLASH; |
|
|
|
if(DbType.ORACLE.equals(dataSource.getType())){ |
|
|
|
if (DbType.ORACLE.equals(dataSource.getType())) { |
|
|
|
connectType = ((OracleDataSource) datasourceForm).getConnectType(); |
|
|
|
connectType = ((OracleDataSource) datasourceForm).getConnectType(); |
|
|
|
if(DbConnectType.ORACLE_SID.equals(connectType)){ |
|
|
|
if (DbConnectType.ORACLE_SID.equals(connectType)) { |
|
|
|
hostSeperator = Constants.AT_SIGN; |
|
|
|
hostSeperator = Constants.AT_SIGN; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -233,7 +233,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
String other = datasourceForm.getOther(); |
|
|
|
String other = datasourceForm.getOther(); |
|
|
|
String address = datasourceForm.getAddress(); |
|
|
|
String address = datasourceForm.getAddress(); |
|
|
|
|
|
|
|
|
|
|
|
String[] hostsPorts = getHostsAndPort(address,hostSeperator); |
|
|
|
String[] hostsPorts = getHostsAndPort(address, hostSeperator); |
|
|
|
// ip host
|
|
|
|
// ip host
|
|
|
|
String host = hostsPorts[0]; |
|
|
|
String host = hostsPorts[0]; |
|
|
|
// prot
|
|
|
|
// prot
|
|
|
@ -285,14 +285,13 @@ public class DataSourceService extends BaseService{ |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* query datasource list by keyword |
|
|
|
* query datasource list by keyword |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param searchVal search value |
|
|
|
* @param searchVal search value |
|
|
|
* @param pageNo page number |
|
|
|
* @param pageNo page number |
|
|
|
* @param pageSize page size |
|
|
|
* @param pageSize page size |
|
|
|
* @return data source list page |
|
|
|
* @return data source list page |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { |
|
|
|
public Map<String, Object> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { |
|
|
@ -302,14 +301,14 @@ public class DataSourceService extends BaseService{ |
|
|
|
|
|
|
|
|
|
|
|
if (isAdmin(loginUser)) { |
|
|
|
if (isAdmin(loginUser)) { |
|
|
|
dataSourceList = dataSourceMapper.selectPaging(dataSourcePage, 0, searchVal); |
|
|
|
dataSourceList = dataSourceMapper.selectPaging(dataSourcePage, 0, searchVal); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
dataSourceList = dataSourceMapper.selectPaging(dataSourcePage, loginUser.getId(), searchVal); |
|
|
|
dataSourceList = dataSourceMapper.selectPaging(dataSourcePage, loginUser.getId(), searchVal); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<DataSource> dataSources = dataSourceList.getRecords(); |
|
|
|
List<DataSource> dataSources = dataSourceList != null ? dataSourceList.getRecords() : new ArrayList<>(); |
|
|
|
handlePasswd(dataSources); |
|
|
|
handlePasswd(dataSources); |
|
|
|
PageInfo pageInfo = new PageInfo<Resource>(pageNo, pageSize); |
|
|
|
PageInfo pageInfo = new PageInfo<Resource>(pageNo, pageSize); |
|
|
|
pageInfo.setTotalCount((int)(dataSourceList.getTotal())); |
|
|
|
pageInfo.setTotalCount((int) (dataSourceList != null ? dataSourceList.getTotal() : 0L)); |
|
|
|
pageInfo.setLists(dataSources); |
|
|
|
pageInfo.setLists(dataSources); |
|
|
|
result.put(Constants.DATA_LIST, pageInfo); |
|
|
|
result.put(Constants.DATA_LIST, pageInfo); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
@ -319,14 +318,15 @@ public class DataSourceService extends BaseService{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* handle datasource connection password for safety |
|
|
|
* handle datasource connection password for safety |
|
|
|
|
|
|
|
* |
|
|
|
* @param dataSourceList |
|
|
|
* @param dataSourceList |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void handlePasswd(List<DataSource> dataSourceList) { |
|
|
|
private void handlePasswd(List<DataSource> dataSourceList) { |
|
|
|
|
|
|
|
|
|
|
|
for (DataSource dataSource : dataSourceList) { |
|
|
|
for (DataSource dataSource : dataSourceList) { |
|
|
|
|
|
|
|
|
|
|
|
String connectionParams = dataSource.getConnectionParams(); |
|
|
|
String connectionParams = dataSource.getConnectionParams(); |
|
|
|
ObjectNode object = JSONUtils.parseObject(connectionParams); |
|
|
|
ObjectNode object = JSONUtils.parseObject(connectionParams); |
|
|
|
object.put(Constants.PASSWORD, Constants.XXXXXX); |
|
|
|
object.put(Constants.PASSWORD, Constants.XXXXXX); |
|
|
|
dataSource.setConnectionParams(object.toString()); |
|
|
|
dataSource.setConnectionParams(object.toString()); |
|
|
|
|
|
|
|
|
|
|
@ -337,7 +337,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
* query data resource list |
|
|
|
* query data resource list |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param type data source type |
|
|
|
* @param type data source type |
|
|
|
* @return data source list page |
|
|
|
* @return data source list page |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> queryDataSourceList(User loginUser, Integer type) { |
|
|
|
public Map<String, Object> queryDataSourceList(User loginUser, Integer type) { |
|
|
@ -347,7 +347,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
|
|
|
|
|
|
|
|
if (isAdmin(loginUser)) { |
|
|
|
if (isAdmin(loginUser)) { |
|
|
|
datasourceList = dataSourceMapper.listAllDataSourceByType(type); |
|
|
|
datasourceList = dataSourceMapper.listAllDataSourceByType(type); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
datasourceList = dataSourceMapper.queryDataSourceByType(loginUser.getId(), type); |
|
|
|
datasourceList = dataSourceMapper.queryDataSourceByType(loginUser.getId(), type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -360,11 +360,10 @@ public class DataSourceService extends BaseService{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* verify datasource exists |
|
|
|
* verify datasource exists |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param name datasource name |
|
|
|
* @param name datasource name |
|
|
|
|
|
|
|
* @return true if data datasource not exists, otherwise return false |
|
|
|
* @return true if data datasource not exists, otherwise return false |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Result verifyDataSourceName(User loginUser, String name) { |
|
|
|
public Result verifyDataSourceName(String name) { |
|
|
|
Result result = new Result(); |
|
|
|
Result result = new Result(); |
|
|
|
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(name); |
|
|
|
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(name); |
|
|
|
if (dataSourceList != null && dataSourceList.size() > 0) { |
|
|
|
if (dataSourceList != null && dataSourceList.size() > 0) { |
|
|
@ -380,7 +379,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* get connection |
|
|
|
* get connection |
|
|
|
* |
|
|
|
* |
|
|
|
* @param dbType datasource type |
|
|
|
* @param dbType datasource type |
|
|
|
* @param parameter parameter |
|
|
|
* @param parameter parameter |
|
|
|
* @return connection for datasource |
|
|
|
* @return connection for datasource |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -399,18 +398,18 @@ public class DataSourceService extends BaseService{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
case HIVE: |
|
|
|
case HIVE: |
|
|
|
case SPARK: |
|
|
|
case SPARK: |
|
|
|
if (CommonUtils.getKerberosStartupState()) { |
|
|
|
if (CommonUtils.getKerberosStartupState()) { |
|
|
|
System.setProperty(org.apache.dolphinscheduler.common.Constants.JAVA_SECURITY_KRB5_CONF, |
|
|
|
System.setProperty(org.apache.dolphinscheduler.common.Constants.JAVA_SECURITY_KRB5_CONF, |
|
|
|
getString(org.apache.dolphinscheduler.common.Constants.JAVA_SECURITY_KRB5_CONF_PATH)); |
|
|
|
getString(org.apache.dolphinscheduler.common.Constants.JAVA_SECURITY_KRB5_CONF_PATH)); |
|
|
|
Configuration configuration = new Configuration(); |
|
|
|
Configuration configuration = new Configuration(); |
|
|
|
configuration.set(org.apache.dolphinscheduler.common.Constants.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); |
|
|
|
configuration.set(org.apache.dolphinscheduler.common.Constants.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); |
|
|
|
UserGroupInformation.setConfiguration(configuration); |
|
|
|
UserGroupInformation.setConfiguration(configuration); |
|
|
|
UserGroupInformation.loginUserFromKeytab(getString(org.apache.dolphinscheduler.common.Constants.LOGIN_USER_KEY_TAB_USERNAME), |
|
|
|
UserGroupInformation.loginUserFromKeytab(getString(org.apache.dolphinscheduler.common.Constants.LOGIN_USER_KEY_TAB_USERNAME), |
|
|
|
getString(org.apache.dolphinscheduler.common.Constants.LOGIN_USER_KEY_TAB_PATH)); |
|
|
|
getString(org.apache.dolphinscheduler.common.Constants.LOGIN_USER_KEY_TAB_PATH)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (dbType == DbType.HIVE){ |
|
|
|
if (dbType == DbType.HIVE) { |
|
|
|
datasource = JSONUtils.parseObject(parameter, HiveDataSource.class); |
|
|
|
datasource = JSONUtils.parseObject(parameter, HiveDataSource.class); |
|
|
|
}else if (dbType == DbType.SPARK){ |
|
|
|
} else if (dbType == DbType.SPARK) { |
|
|
|
datasource = JSONUtils.parseObject(parameter, SparkDataSource.class); |
|
|
|
datasource = JSONUtils.parseObject(parameter, SparkDataSource.class); |
|
|
|
} |
|
|
|
} |
|
|
|
Class.forName(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER); |
|
|
|
Class.forName(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER); |
|
|
@ -439,20 +438,19 @@ public class DataSourceService extends BaseService{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(datasource != null){ |
|
|
|
if (datasource != null) { |
|
|
|
connection = DriverManager.getConnection(datasource.getJdbcUrl(), datasource.getUser(), datasource.getPassword()); |
|
|
|
connection = DriverManager.getConnection(datasource.getJdbcUrl(), datasource.getUser(), datasource.getPassword()); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
return connection; |
|
|
|
return connection; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* check connection |
|
|
|
* check connection |
|
|
|
* |
|
|
|
* |
|
|
|
* @param type data source type |
|
|
|
* @param type data source type |
|
|
|
* @param parameter data source parameters |
|
|
|
* @param parameter data source parameters |
|
|
|
* @return true if connect successfully, otherwise false |
|
|
|
* @return true if connect successfully, otherwise false |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -470,35 +468,35 @@ public class DataSourceService extends BaseService{ |
|
|
|
return isConnection; |
|
|
|
return isConnection; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test connection |
|
|
|
* test connection |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
|
|
|
|
* @param id datasource id |
|
|
|
* @param id datasource id |
|
|
|
* @return connect result code |
|
|
|
* @return connect result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean connectionTest(User loginUser, int id) { |
|
|
|
public boolean connectionTest(int id) { |
|
|
|
DataSource dataSource = dataSourceMapper.selectById(id); |
|
|
|
DataSource dataSource = dataSourceMapper.selectById(id); |
|
|
|
return checkConnection(dataSource.getType(), dataSource.getConnectionParams()); |
|
|
|
if (dataSource != null) { |
|
|
|
|
|
|
|
return checkConnection(dataSource.getType(), dataSource.getConnectionParams()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* build paramters |
|
|
|
* build paramters |
|
|
|
* |
|
|
|
* |
|
|
|
* @param name data source name |
|
|
|
* @param type data source type |
|
|
|
* @param desc data source description |
|
|
|
* @param host data source host |
|
|
|
* @param type data source type |
|
|
|
* @param port data source port |
|
|
|
* @param host data source host |
|
|
|
* @param database data source database name |
|
|
|
* @param port data source port |
|
|
|
* @param userName user name |
|
|
|
* @param database data source database name |
|
|
|
* @param password password |
|
|
|
* @param userName user name |
|
|
|
* @param other other parameters |
|
|
|
* @param password password |
|
|
|
|
|
|
|
* @param other other parameters |
|
|
|
|
|
|
|
* @param principal principal |
|
|
|
* @param principal principal |
|
|
|
* @return datasource parameter |
|
|
|
* @return datasource parameter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String buildParameter(String name, String desc, DbType type, String host, |
|
|
|
public String buildParameter(DbType type, String host, |
|
|
|
String port, String database, String principal, String userName, |
|
|
|
String port, String database, String principal, String userName, |
|
|
|
String password, DbConnectType connectType, String other) { |
|
|
|
String password, DbConnectType connectType, String other) { |
|
|
|
|
|
|
|
|
|
|
@ -510,7 +508,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (CommonUtils.getKerberosStartupState() && |
|
|
|
if (CommonUtils.getKerberosStartupState() && |
|
|
|
(type == DbType.HIVE || type == DbType.SPARK)){ |
|
|
|
(type == DbType.HIVE || type == DbType.SPARK)) { |
|
|
|
jdbcUrl += ";principal=" + principal; |
|
|
|
jdbcUrl += ";principal=" + principal; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -535,14 +533,14 @@ public class DataSourceService extends BaseService{ |
|
|
|
parameterMap.put(Constants.USER, userName); |
|
|
|
parameterMap.put(Constants.USER, userName); |
|
|
|
parameterMap.put(Constants.PASSWORD, CommonUtils.encodePassword(password)); |
|
|
|
parameterMap.put(Constants.PASSWORD, CommonUtils.encodePassword(password)); |
|
|
|
if (CommonUtils.getKerberosStartupState() && |
|
|
|
if (CommonUtils.getKerberosStartupState() && |
|
|
|
(type == DbType.HIVE || type == DbType.SPARK)){ |
|
|
|
(type == DbType.HIVE || type == DbType.SPARK)) { |
|
|
|
parameterMap.put(Constants.PRINCIPAL,principal); |
|
|
|
parameterMap.put(Constants.PRINCIPAL, principal); |
|
|
|
} |
|
|
|
} |
|
|
|
if (other != null && !"".equals(other)) { |
|
|
|
if (other != null && !"".equals(other)) { |
|
|
|
Map<String, String> map = JSONUtils.toMap(other); |
|
|
|
Map<String, String> map = JSONUtils.toMap(other); |
|
|
|
if (map.size() > 0) { |
|
|
|
if (map.size() > 0) { |
|
|
|
StringBuilder otherSb = new StringBuilder(); |
|
|
|
StringBuilder otherSb = new StringBuilder(); |
|
|
|
for (Map.Entry<String, String> entry: map.entrySet()) { |
|
|
|
for (Map.Entry<String, String> entry : map.entrySet()) { |
|
|
|
otherSb.append(String.format("%s=%s%s", entry.getKey(), entry.getValue(), separator)); |
|
|
|
otherSb.append(String.format("%s=%s%s", entry.getKey(), entry.getValue(), separator)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!Constants.DB2.equals(type.name())) { |
|
|
|
if (!Constants.DB2.equals(type.name())) { |
|
|
@ -553,7 +551,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(logger.isDebugEnabled()){ |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.info("parameters map:{}", JSONUtils.toJsonString(parameterMap)); |
|
|
|
logger.info("parameters map:{}", JSONUtils.toJsonString(parameterMap)); |
|
|
|
} |
|
|
|
} |
|
|
|
return JSONUtils.toJsonString(parameterMap); |
|
|
|
return JSONUtils.toJsonString(parameterMap); |
|
|
@ -605,7 +603,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* delete datasource |
|
|
|
* delete datasource |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param datasourceId data source id |
|
|
|
* @param datasourceId data source id |
|
|
|
* @return delete result code |
|
|
|
* @return delete result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -615,12 +613,12 @@ public class DataSourceService extends BaseService{ |
|
|
|
try { |
|
|
|
try { |
|
|
|
//query datasource by id
|
|
|
|
//query datasource by id
|
|
|
|
DataSource dataSource = dataSourceMapper.selectById(datasourceId); |
|
|
|
DataSource dataSource = dataSourceMapper.selectById(datasourceId); |
|
|
|
if(dataSource == null){ |
|
|
|
if (dataSource == null) { |
|
|
|
logger.error("resource id {} not exist", datasourceId); |
|
|
|
logger.error("resource id {} not exist", datasourceId); |
|
|
|
putMsg(result, Status.RESOURCE_NOT_EXIST); |
|
|
|
putMsg(result, Status.RESOURCE_NOT_EXIST); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!hasPerm(loginUser, dataSource.getUserId())){ |
|
|
|
if (!hasPerm(loginUser, dataSource.getUserId())) { |
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM); |
|
|
|
putMsg(result, Status.USER_NO_OPERATION_PERM); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
@ -628,7 +626,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
datasourceUserMapper.deleteByDatasourceId(datasourceId); |
|
|
|
datasourceUserMapper.deleteByDatasourceId(datasourceId); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("delete datasource error",e); |
|
|
|
logger.error("delete datasource error", e); |
|
|
|
throw new RuntimeException("delete datasource error"); |
|
|
|
throw new RuntimeException("delete datasource error"); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
@ -638,7 +636,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
* unauthorized datasource |
|
|
|
* unauthorized datasource |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param userId user id |
|
|
|
* @param userId user id |
|
|
|
* @return unauthed data source result code |
|
|
|
* @return unauthed data source result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> unauthDatasource(User loginUser, Integer userId) { |
|
|
|
public Map<String, Object> unauthDatasource(User loginUser, Integer userId) { |
|
|
@ -679,7 +677,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
* authorized datasource |
|
|
|
* authorized datasource |
|
|
|
* |
|
|
|
* |
|
|
|
* @param loginUser login user |
|
|
|
* @param loginUser login user |
|
|
|
* @param userId user id |
|
|
|
* @param userId user id |
|
|
|
* @return authorized result code |
|
|
|
* @return authorized result code |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, Object> authedDatasource(User loginUser, Integer userId) { |
|
|
|
public Map<String, Object> authedDatasource(User loginUser, Integer userId) { |
|
|
@ -700,11 +698,11 @@ public class DataSourceService extends BaseService{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* get host and port by address |
|
|
|
* get host and port by address |
|
|
|
* |
|
|
|
* |
|
|
|
* @param address address |
|
|
|
* @param address address |
|
|
|
* @return sting array: [host,port] |
|
|
|
* @return sting array: [host,port] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String[] getHostsAndPort(String address) { |
|
|
|
private String[] getHostsAndPort(String address) { |
|
|
|
return getHostsAndPort(address,Constants.DOUBLE_SLASH); |
|
|
|
return getHostsAndPort(address, Constants.DOUBLE_SLASH); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -714,7 +712,7 @@ public class DataSourceService extends BaseService{ |
|
|
|
* @param separator separator |
|
|
|
* @param separator separator |
|
|
|
* @return sting array: [host,port] |
|
|
|
* @return sting array: [host,port] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String[] getHostsAndPort(String address,String separator) { |
|
|
|
private String[] getHostsAndPort(String address, String separator) { |
|
|
|
String[] result = new String[2]; |
|
|
|
String[] result = new String[2]; |
|
|
|
String[] tmpArray = address.split(separator); |
|
|
|
String[] tmpArray = address.split(separator); |
|
|
|
String hostsAndPorts = tmpArray[tmpArray.length - 1]; |
|
|
|
String hostsAndPorts = tmpArray[tmpArray.length - 1]; |
|
|
|