add Microsoft SQL Server support
This commit is contained in:
parent
2d3b7baa1a
commit
9ed962a35f
|
|
@ -210,6 +210,7 @@ public class DataSourceService extends BaseService{
|
|||
|
||||
switch (dataSource.getType()) {
|
||||
case HIVE:
|
||||
case SQLSERVER:
|
||||
separator = ";";
|
||||
break;
|
||||
case MYSQL:
|
||||
|
|
@ -376,6 +377,10 @@ public class DataSourceService extends BaseService{
|
|||
datasource = JSONObject.parseObject(parameter, OracleDataSource.class);
|
||||
Class.forName(Constants.COM_ORACLE_JDBC_DRIVER);
|
||||
break;
|
||||
case SQLSERVER:
|
||||
datasource = JSONObject.parseObject(parameter, SQLServerDataSource.class);
|
||||
Class.forName(Constants.COM_SQLSERVER_JDBC_DRIVER);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -447,7 +452,9 @@ public class DataSourceService extends BaseService{
|
|||
|| Constants.CLICKHOUSE.equals(type.name())
|
||||
|| Constants.ORACLE.equals(type.name())) {
|
||||
separator = "&";
|
||||
} else if (Constants.HIVE.equals(type.name()) || Constants.SPARK.equals(type.name())) {
|
||||
} else if (Constants.HIVE.equals(type.name())
|
||||
|| Constants.SPARK.equals(type.name())
|
||||
|| Constants.SQLSERVER.equals(type.name())) {
|
||||
separator = ";";
|
||||
}
|
||||
|
||||
|
|
@ -502,6 +509,9 @@ public class DataSourceService extends BaseService{
|
|||
} else if (Constants.ORACLE.equals(type.name())) {
|
||||
sb.append(Constants.JDBC_ORACLE);
|
||||
sb.append(host).append(":").append(port);
|
||||
} else if (Constants.SQLSERVER.equals(type.name())) {
|
||||
sb.append(Constants.JDBC_SQLSERVER);
|
||||
sb.append(host).append(":").append(port);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ public class Constants {
|
|||
public static final String ORG_APACHE_HIVE_JDBC_HIVE_DRIVER = "org.apache.hive.jdbc.HiveDriver";
|
||||
public static final String COM_CLICKHOUSE_JDBC_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
|
||||
public static final String COM_ORACLE_JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
public static final String COM_SQLSERVER_JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
|
||||
/**
|
||||
* database type
|
||||
|
|
@ -94,6 +95,7 @@ public class Constants {
|
|||
public static final String SPARK = "SPARK";
|
||||
public static final String CLICKHOUSE = "CLICKHOUSE";
|
||||
public static final String ORACLE = "ORACLE";
|
||||
public static final String SQLSERVER = "SQLSERVER";
|
||||
|
||||
/**
|
||||
* jdbc url
|
||||
|
|
@ -103,6 +105,7 @@ public class Constants {
|
|||
public static final String JDBC_HIVE_2 = "jdbc:hive2://";
|
||||
public static final String JDBC_CLICKHOUSE = "jdbc:clickhouse://";
|
||||
public static final String JDBC_ORACLE = "jdbc:oracle:thin:@//";
|
||||
public static final String JDBC_SQLSERVER = "jdbc:sqlserver://";
|
||||
|
||||
|
||||
public static final String ADDRESS = "address";
|
||||
|
|
|
|||
|
|
@ -386,6 +386,17 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>com.microsoft.azure</artifactId>
|
||||
<groupId>azure-keyvault</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -621,6 +621,11 @@ public final class Constants {
|
|||
*/
|
||||
public static final String JDBC_ORACLE_CLASS_NAME = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
/**
|
||||
* Oracle
|
||||
*/
|
||||
public static final String JDBC_SQLSERVER_CLASS_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
|
||||
/**
|
||||
* spark params constant
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ public enum DbType {
|
|||
* 3 spark
|
||||
* 4 clickhouse
|
||||
* 5 oracle
|
||||
* 6 sqlserver
|
||||
*/
|
||||
MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE
|
||||
MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE, SQLSERVER
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public class DataSourceFactory {
|
|||
return JSONUtils.parseObject(parameter, ClickHouseDataSource.class);
|
||||
case ORACLE:
|
||||
return JSONUtils.parseObject(parameter, OracleDataSource.class);
|
||||
case SQLSERVER:
|
||||
return JSONUtils.parseObject(parameter, SQLServerDataSource.class);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.escheduler.common.job.db;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* data source of SQL Server
|
||||
*/
|
||||
public class SQLServerDataSource extends BaseDataSource {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SQLServerDataSource.class);
|
||||
|
||||
/**
|
||||
* gets the JDBC url for the data source connection
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getJdbcUrl() {
|
||||
String jdbcUrl = getAddress();
|
||||
jdbcUrl += ";databaseName=" + getDatabase();
|
||||
|
||||
if (StringUtils.isNotEmpty(getOther())) {
|
||||
jdbcUrl += ";" + getOther();
|
||||
}
|
||||
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* test whether the data source can be connected successfully
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void isConnectable() throws Exception {
|
||||
Connection con = null;
|
||||
try {
|
||||
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
con = DriverManager.getConnection(getJdbcUrl(), getUser(), getPassword());
|
||||
} finally {
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("SQL Server datasource try conn close conn error", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import cn.escheduler.common.job.db.ClickHouseDataSource;
|
|||
import cn.escheduler.common.job.db.MySQLDataSource;
|
||||
import cn.escheduler.common.job.db.OracleDataSource;
|
||||
import cn.escheduler.common.job.db.PostgreDataSource;
|
||||
import cn.escheduler.common.job.db.SQLServerDataSource;
|
||||
import cn.escheduler.common.process.Property;
|
||||
import cn.escheduler.common.task.AbstractParameters;
|
||||
import cn.escheduler.common.task.procedure.ProcedureParameters;
|
||||
|
|
@ -121,6 +122,9 @@ public class ProcedureTask extends AbstractTask {
|
|||
}else if (DbType.ORACLE.name().equals(dataSource.getType().name())){
|
||||
baseDataSource = JSONObject.parseObject(dataSource.getConnectionParams(), OracleDataSource.class);
|
||||
Class.forName(Constants.JDBC_ORACLE_CLASS_NAME);
|
||||
}else if (DbType.SQLSERVER.name().equals(dataSource.getType().name())){
|
||||
baseDataSource = JSONObject.parseObject(dataSource.getConnectionParams(), SQLServerDataSource.class);
|
||||
Class.forName(Constants.JDBC_SQLSERVER_CLASS_NAME);
|
||||
}
|
||||
|
||||
// get jdbc connection
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ public class SqlTask extends AbstractTask {
|
|||
}else if (DbType.ORACLE.name().equals(dataSource.getType().name())){
|
||||
baseDataSource = JSONObject.parseObject(dataSource.getConnectionParams(),OracleDataSource.class);
|
||||
Class.forName(Constants.JDBC_ORACLE_CLASS_NAME);
|
||||
}else if (DbType.SQLSERVER.name().equals(dataSource.getType().name())){
|
||||
baseDataSource = JSONObject.parseObject(dataSource.getConnectionParams(),SQLServerDataSource.class);
|
||||
Class.forName(Constants.JDBC_SQLSERVER_CLASS_NAME);
|
||||
}
|
||||
|
||||
Map<Integer,Property> sqlParamMap = new HashMap<Integer,Property>();
|
||||
|
|
|
|||
|
|
@ -77,6 +77,15 @@ public class SqlExecutorTest {
|
|||
sharedTestSqlTask(nodeName, taskAppId, tenantCode, taskInstId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSQLServer() throws Exception {
|
||||
String nodeName = "SQL Server sql test";
|
||||
String taskAppId = "3_14_27";
|
||||
String tenantCode = "demo";
|
||||
int taskInstId = 27;
|
||||
sharedTestSqlTask(nodeName, taskAppId, tenantCode, taskInstId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test template for SQLTasks, mainly test different types of DBMS types
|
||||
* @param nodeName node name for selected task
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<m-datasource
|
||||
ref="refDs"
|
||||
@on-dsData="_onDsData"
|
||||
:supportType="['MYSQL','POSTGRESQL','CLICKHOUSE', 'ORACLE']"
|
||||
:supportType="['MYSQL','POSTGRESQL','CLICKHOUSE', 'ORACLE', 'SQLSERVER']"
|
||||
:data="{ type:type,datasource:datasource }">
|
||||
</m-datasource>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
<x-radio :label="'SPARK'">SPARK</x-radio>
|
||||
<x-radio :label="'CLICKHOUSE'">CLICKHOUSE</x-radio>
|
||||
<x-radio :label="'ORACLE'">ORACLE</x-radio>
|
||||
<x-radio :label="'SQLSERVER'">SQLSERVER</x-radio>
|
||||
</x-radio-group>
|
||||
</template>
|
||||
</m-list-box-f>
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ export default {
|
|||
id: 5,
|
||||
code: 'ORACLE',
|
||||
disabled: false
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
code: 'SQLSERVER',
|
||||
disabled: false
|
||||
}
|
||||
],
|
||||
// Alarm interface
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import io from '@/module/io'
|
|||
export default {
|
||||
/**
|
||||
* Data source creation
|
||||
* @param "type": string,//MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE
|
||||
* @param "type": string,//MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE, SQLSERVER
|
||||
* @param "name": string,
|
||||
* @param "desc": string,
|
||||
* @param "parameter":string //{"address":"jdbc:hive2://192.168.220.189:10000","autoReconnect":"true","characterEncoding":"utf8","database":"default","initialTimeout":3000,"jdbcUrl":"jdbc:hive2://192.168.220.189:10000/default","maxReconnect":10,"password":"","useUnicode":true,"user":"hive"}
|
||||
|
|
@ -49,7 +49,7 @@ export default {
|
|||
},
|
||||
/**
|
||||
* Query data source list - no paging
|
||||
* @param "type": string//MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE
|
||||
* @param "type": string//MYSQL, POSTGRESQL, HIVE, SPARK, CLICKHOUSE, ORACLE, SQLSERVER
|
||||
*/
|
||||
getDatasourcesList ({ state }, payload) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue