-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature-9467] add DAMENG DataSource #12860
Changes from 5 commits
e5357f1
c2b365c
fe43cf3
3b54440
bccd90e
ce54f59
5f0efa8
885dbab
2f589a0
66a13f4
923665c
a64e13c
cbc3aa4
7a27b9c
6198f23
0f9fe20
ca52089
22969a2
c642406
a7d455a
29f1dcf
631efb8
7a12dc7
3799dcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# DM数据源 | ||
|
||
![dm](../../../../img/new_ui/dev/datasource/dm.png) | ||
|
||
- 数据源:选择 DM | ||
- 数据源名称:输入数据源的名称 | ||
- 描述:输入数据源的描述 | ||
- IP 主机名:输入连接 DM 的 IP | ||
- 端口:输入连接 DM 的端口 | ||
- 用户名:设置连接 DM 的用户名 | ||
- 密码:设置连接 DM 的密码 | ||
- 数据库名:输入连接 DM 的 schema | ||
- Jdbc 连接参数:用于 DM 连接的参数设置,以 JSON 形式填写 | ||
|
||
## 是否原生支持 | ||
|
||
否,使用前需请参考 [数据源配置](../howto/datasource-setting.md) 中的 "数据源中心" 章节激活数据源。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,5 +142,10 @@ | |
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid</artifactId> | ||
</dependency> | ||
</dependencies> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you introducing a new database connection pool? we already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HikariCP does not support Dameng, druid supports Dameng There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand, it's just a data source connector management, why doesn't it support dm, can you explain why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks,I just tested the DaMeng database with HikariCP,HikariCP supports DaMeng |
||
</project> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,129 @@ | ||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||
* 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 org.apache.dolphinscheduler.plugin.datasource.api.client; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import org.apache.dolphinscheduler.plugin.datasource.api.provider.JDBCDataSourceProvider; | ||||||||||||||||||||||||||||||||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; | ||||||||||||||||||||||||||||||||
import org.apache.dolphinscheduler.spi.datasource.DataSourceClient; | ||||||||||||||||||||||||||||||||
import org.apache.dolphinscheduler.spi.enums.DbType; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import org.apache.commons.lang3.StringUtils; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import java.sql.Connection; | ||||||||||||||||||||||||||||||||
import java.sql.SQLException; | ||||||||||||||||||||||||||||||||
import java.util.concurrent.TimeUnit; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||
import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||
import org.springframework.jdbc.core.JdbcTemplate; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
import com.alibaba.druid.pool.DruidDataSource; | ||||||||||||||||||||||||||||||||
import com.google.common.base.Stopwatch; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
public class DruidDataSourceClient implements DataSourceClient { | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
private static final Logger logger = LoggerFactory.getLogger(DruidDataSourceClient.class); | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
public static final String COMMON_USER = "root"; | ||||||||||||||||||||||||||||||||
public static final String COMMON_VALIDATION_QUERY = "select 1"; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected final BaseConnectionParam baseConnectionParam; | ||||||||||||||||||||||||||||||||
protected DruidDataSource dataSource; | ||||||||||||||||||||||||||||||||
protected JdbcTemplate jdbcTemplate; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
public DruidDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { | ||||||||||||||||||||||||||||||||
this.baseConnectionParam = baseConnectionParam; | ||||||||||||||||||||||||||||||||
preInit(); | ||||||||||||||||||||||||||||||||
checkEnv(baseConnectionParam); | ||||||||||||||||||||||||||||||||
initClient(baseConnectionParam, dbType); | ||||||||||||||||||||||||||||||||
checkClient(); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void preInit() { | ||||||||||||||||||||||||||||||||
logger.info("preInit in DruidDataSourceClient"); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void checkEnv(BaseConnectionParam baseConnectionParam) { | ||||||||||||||||||||||||||||||||
checkValidationQuery(baseConnectionParam); | ||||||||||||||||||||||||||||||||
checkUser(baseConnectionParam); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||
* HikariCP does not support DM, druid supports DM | ||||||||||||||||||||||||||||||||
* @param baseConnectionParam | ||||||||||||||||||||||||||||||||
* @param dbType | ||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||
protected void initClient(BaseConnectionParam baseConnectionParam, DbType dbType) { | ||||||||||||||||||||||||||||||||
this.dataSource = JDBCDataSourceProvider.createDruidDataSource(baseConnectionParam, dbType); | ||||||||||||||||||||||||||||||||
this.jdbcTemplate = new JdbcTemplate(dataSource); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void checkUser(BaseConnectionParam baseConnectionParam) { | ||||||||||||||||||||||||||||||||
if (StringUtils.isBlank(baseConnectionParam.getUser())) { | ||||||||||||||||||||||||||||||||
setDefaultUsername(baseConnectionParam); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void setDefaultUsername(BaseConnectionParam baseConnectionParam) { | ||||||||||||||||||||||||||||||||
baseConnectionParam.setUser(COMMON_USER); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void checkValidationQuery(BaseConnectionParam baseConnectionParam) { | ||||||||||||||||||||||||||||||||
if (StringUtils.isBlank(baseConnectionParam.getValidationQuery())) { | ||||||||||||||||||||||||||||||||
setDefaultValidationQuery(baseConnectionParam); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
protected void setDefaultValidationQuery(BaseConnectionParam baseConnectionParam) { | ||||||||||||||||||||||||||||||||
baseConnectionParam.setValidationQuery(COMMON_VALIDATION_QUERY); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||
public void checkClient() { | ||||||||||||||||||||||||||||||||
// Checking data source client | ||||||||||||||||||||||||||||||||
Stopwatch stopwatch = Stopwatch.createStarted(); | ||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||
this.jdbcTemplate.execute(this.baseConnectionParam.getValidationQuery()); | ||||||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||||||
throw new RuntimeException("JDBC connect failed", e); | ||||||||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||||||||
logger.info("Time to execute check jdbc client with sql {} for {} ms ", | ||||||||||||||||||||||||||||||||
this.baseConnectionParam.getValidationQuery(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will modify it according to your suggestion |
||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||
public Connection getConnection() { | ||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||
return this.dataSource.getConnection(); | ||||||||||||||||||||||||||||||||
} catch (SQLException e) { | ||||||||||||||||||||||||||||||||
logger.error("get druidDataSource Connection fail SQLException: {}", e.getMessage(), e); | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will modify it according to your suggestion |
||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||
public void close() { | ||||||||||||||||||||||||||||||||
logger.info("do close dataSource {}.", baseConnectionParam.getDatabase()); | ||||||||||||||||||||||||||||||||
try (DruidDataSource closedDatasource = dataSource) { | ||||||||||||||||||||||||||||||||
// only close the resource | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
this.jdbcTemplate = null; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-datasource-plugin</artifactId> | ||
<version>dev-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dolphinscheduler-datasource-dm</artifactId> | ||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-spi</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dolphinscheduler</groupId> | ||
<artifactId>dolphinscheduler-datasource-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.dameng</groupId> | ||
<artifactId>DmJdbcDriver18</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 org.apache.dolphinscheduler.plugin.datasource.dm; | ||
|
||
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; | ||
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; | ||
import org.apache.dolphinscheduler.spi.datasource.DataSourceClient; | ||
import org.apache.dolphinscheduler.spi.enums.DbType; | ||
|
||
public class DmDataSourceChannel implements DataSourceChannel { | ||
|
||
@Override | ||
public DataSourceClient createDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { | ||
return new DmDataSourceClient(baseConnectionParam, dbType); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 org.apache.dolphinscheduler.plugin.datasource.dm; | ||
|
||
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; | ||
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
@AutoService(DataSourceChannelFactory.class) | ||
public class DmDataSourceChannelFactory implements DataSourceChannelFactory { | ||
|
||
@Override | ||
public String getName() { | ||
return "dm"; | ||
} | ||
|
||
@Override | ||
public DataSourceChannel create() { | ||
return new DmDataSourceChannel(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unnessnary change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll remove the unnecessary changes right away